class LoadTestSchedule

Attributes

events[RW]

Public Class Methods

new() click to toggle source
# File lib/load/load_test_schedule.rb, line 4
def initialize
  @events = []
  @previous_action = nil
end

Public Instance Methods

add(time, action) click to toggle source
# File lib/load/load_test_schedule.rb, line 9
def add(time, action)
  if (action != @previous_action)
    remove_action_at_time(time)
    @events << {time: time, action: action}
  else
    warn "Attempt to add same action consecutively, ignoring the later one.  Time: #{time}  Action: #{action}"
  end
  @previous_action = action
end
current_action(time) click to toggle source
# File lib/load/load_test_schedule.rb, line 37
def current_action(time)
  event = current_event(time)
  if (event == nil)
    return :pause
  else
    return event[:action]
  end
end
current_event(time) click to toggle source
# File lib/load/load_test_schedule.rb, line 57
def current_event(time)
  current_event = nil
  @events.each do |event|
    if (event[:time] <= time.to_i)
      current_event = event
    end
  end
  return current_event
end
load_json(schedule_events) click to toggle source
# File lib/load/load_test_schedule.rb, line 19
def load_json(schedule_events)
  schedule_events.each do |event|
    time = event["time"].to_i
    action = event["action"].to_sym
    add(time, action)
  end
end
next_action(time) click to toggle source
# File lib/load/load_test_schedule.rb, line 47
def next_action(time)
  event = next_event(time)
  if (event == nil)
    return nil
  else
    return event[:action]
  end
end
next_event(time) click to toggle source
# File lib/load/load_test_schedule.rb, line 68
def next_event(time)
  @events.each do |event|
    if (event[:time] > time.to_i)
      return event
    end
  end
  return @events.last
end
remove_action_at_time(time) click to toggle source
# File lib/load/load_test_schedule.rb, line 27
def remove_action_at_time(time)
  (0..@events.length - 1).each do |i|
    if (@events[i][:time] == time)
      @events.delete_at(i)
      return
    end
  end
end