Class: LoadTestSchedule

Inherits:
Object
  • Object
show all
Defined in:
lib/load/load_test_schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoadTestSchedule

Returns a new instance of LoadTestSchedule.



4
5
6
7
# File 'lib/load/load_test_schedule.rb', line 4

def initialize
  @events = []
  @previous_action = nil
end

Instance Attribute Details

#eventsObject

Returns the value of attribute events.



2
3
4
# File 'lib/load/load_test_schedule.rb', line 2

def events
  @events
end

Instance Method Details

#add(time, action) ⇒ Object



9
10
11
12
13
14
15
16
17
# 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) ⇒ Object



37
38
39
40
41
42
43
44
# 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) ⇒ Object



57
58
59
60
61
62
63
64
65
# 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) ⇒ Object



19
20
21
22
23
24
25
# 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) ⇒ Object



47
48
49
50
51
52
53
54
# 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) ⇒ Object



68
69
70
71
72
73
74
75
# 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) ⇒ Object



27
28
29
30
31
32
33
34
# 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