Class: MockServer::LoadScenario

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Overview

A load-injection scenario: a named set of steps driven by a traffic profile. template_type selects the templating engine (+VELOCITY+ or MUSTACHE) used to render step requests; max_requests caps the total requests issued. thresholds are in-run pass/fail checks; +abort_on_fail+/+abort_grace_millis+ control early-abort behaviour; pacing shapes inter-iteration timing; feeder supplies per-iteration data; step_selection (+SEQUENTIAL+ or WEIGHTED) controls how each iteration selects steps.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, profile:, steps:, template_type: nil, labels: nil, max_requests: nil, start_delay_millis: nil, thresholds: nil, abort_on_fail: nil, abort_grace_millis: nil, pacing: nil, feeder: nil, step_selection: nil) ⇒ LoadScenario

Returns a new instance of LoadScenario.



3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
# File 'lib/mockserver/models.rb', line 3174

def initialize(name:, profile:, steps:, template_type: nil, labels: nil, max_requests: nil,
               start_delay_millis: nil, thresholds: nil, abort_on_fail: nil,
               abort_grace_millis: nil, pacing: nil, feeder: nil, step_selection: nil)
  @name = name
  @profile = profile
  @steps = steps
  @template_type = template_type
  @labels = labels
  @max_requests = max_requests
  @start_delay_millis = start_delay_millis
  @thresholds = thresholds
  @abort_on_fail = abort_on_fail
  @abort_grace_millis = abort_grace_millis
  @pacing = pacing
  @feeder = feeder
  @step_selection = step_selection
end

Instance Attribute Details

#abort_grace_millisObject

Returns the value of attribute abort_grace_millis.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def abort_grace_millis
  @abort_grace_millis
end

#abort_on_failObject

Returns the value of attribute abort_on_fail.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def abort_on_fail
  @abort_on_fail
end

#feederObject

Returns the value of attribute feeder.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def feeder
  @feeder
end

#labelsObject

Returns the value of attribute labels.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def labels
  @labels
end

#max_requestsObject

Returns the value of attribute max_requests.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def max_requests
  @max_requests
end

#nameObject

Returns the value of attribute name.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def name
  @name
end

#pacingObject

Returns the value of attribute pacing.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def pacing
  @pacing
end

#profileObject

Returns the value of attribute profile.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def profile
  @profile
end

#start_delay_millisObject

Returns the value of attribute start_delay_millis.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def start_delay_millis
  @start_delay_millis
end

#step_selectionObject

Returns the value of attribute step_selection.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def step_selection
  @step_selection
end

#stepsObject

Returns the value of attribute steps.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def steps
  @steps
end

#template_typeObject

Returns the value of attribute template_type.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def template_type
  @template_type
end

#thresholdsObject

Returns the value of attribute thresholds.



3170
3171
3172
# File 'lib/mockserver/models.rb', line 3170

def thresholds
  @thresholds
end

Class Method Details

.from_hash(data) ⇒ Object



3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
# File 'lib/mockserver/models.rb', line 3210

def self.from_hash(data)
  return nil if data.nil?

  steps_data = data['steps']
  thresholds_data = data['thresholds']
  new(
    name:               data['name'],
    template_type:      data['templateType'],
    labels:             data['labels'],
    max_requests:       data['maxRequests'],
    start_delay_millis: data['startDelayMillis'],
    thresholds:         thresholds_data ? thresholds_data.map { |t| LoadThreshold.from_hash(t) } : nil,
    abort_on_fail:      data['abortOnFail'],
    abort_grace_millis: data['abortGraceMillis'],
    pacing:             LoadPacing.from_hash(data['pacing']),
    feeder:             LoadFeeder.from_hash(data['feeder']),
    step_selection:     data['stepSelection'],
    profile:            LoadProfile.from_hash(data['profile']),
    steps:              steps_data ? steps_data.map { |s| LoadStep.from_hash(s) } : nil
  )
end

Instance Method Details

#to_hObject



3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
# File 'lib/mockserver/models.rb', line 3192

def to_h
  MockServer.strip_none({
    'name'             => @name,
    'templateType'     => @template_type,
    'labels'           => @labels,
    'maxRequests'      => @max_requests,
    'startDelayMillis' => @start_delay_millis,
    'thresholds'       => @thresholds.nil? ? nil : @thresholds.map(&:to_h),
    'abortOnFail'      => @abort_on_fail,
    'abortGraceMillis' => @abort_grace_millis,
    'pacing'           => @pacing&.to_h,
    'feeder'           => @feeder&.to_h,
    'stepSelection'    => @step_selection,
    'profile'          => @profile&.to_h,
    'steps'            => @steps&.map(&:to_h)
  })
end