1 require File.dirname(__FILE__) + '/helper'
3 class TestHub < Test::Unit::TestCase
5 Server.stubs(:new).returns(true)
14 @watch = God.watches['foo']
19 def test_attach_should_store_condition_metric_association
20 c = Conditions::FakePollCondition.new
21 m = Metric.new(@watch, :foo)
24 assert_equal m, Hub.directory[c]
27 def test_attach_should_schedule_for_poll_condition
28 c = Conditions::FakePollCondition.new
29 m = Metric.new(@watch, :foo)
31 Timer.any_instance.expects(:schedule).with(c, 0)
36 def test_attach_should_regsiter_for_event_condition
37 c = Conditions::FakeEventCondition.new
38 m = Metric.new(@watch, :foo)
47 def test_detach_should_remove_condition_metric_association
48 c = Conditions::FakePollCondition.new
49 m = Metric.new(@watch, :foo)
54 assert_nil Hub.directory[c]
57 def test_detach_should_unschedule_poll_conditions
58 c = Conditions::FakePollCondition.new
59 m = Metric.new(@watch, :foo)
62 Timer.any_instance.expects(:unschedule).with(c)
63 c.expects(:deregister).never
68 def test_detach_should_deregister_event_conditions
69 c = Conditions::FakeEventCondition.new
70 m = Metric.new(@watch, :foo)
73 c.expects(:deregister).once
80 def test_trigger_should_handle_poll_for_poll_condition
81 c = Conditions::FakePollCondition.new
82 Hub.expects(:handle_poll).with(c)
87 def test_trigger_should_handle_event_for_event_condition
88 c = Conditions::FakeEventCondition.new
89 Hub.expects(:handle_event).with(c)
96 def test_handle_poll_no_change_should_reschedule
97 c = Conditions::FakePollCondition.new
100 m = Metric.new(@watch, {true => :up})
103 c.expects(:test).returns(false)
104 Timer.any_instance.expects(:schedule)
107 t = Hub.handle_poll(c)
112 def test_handle_poll_change_should_move
113 c = Conditions::FakePollCondition.new
116 m = Metric.new(@watch, {true => :up})
119 c.expects(:test).returns(true)
120 @watch.expects(:move).with(:up)
123 t = Hub.handle_poll(c)
128 def test_handle_poll_should_abort_on_exception
129 c = Conditions::FakePollCondition.new
132 m = Metric.new(@watch, {true => :up})
135 c.expects(:test).raises(StandardError.new)
138 t = Hub.handle_poll(c)
143 def test_handle_poll_should_use_overridden_transition
144 c = Conditions::Tries.new
146 c.transition = :start
149 m = Metric.new(@watch, {true => :up})
152 @watch.expects(:move).with(:start)
155 t = Hub.handle_poll(c)
162 def test_handle_event_should_move
163 c = Conditions::FakeEventCondition.new
165 m = Metric.new(@watch, {true => :up})
168 @watch.expects(:move).with(:up)
171 t = Hub.handle_event(c)