1 require File.dirname(__FILE__) + '/helper'
3 class TestHub < Test::Unit::TestCase
5 Server.stubs(:new).returns(true)
13 @watch = God.watches['foo']
18 def test_attach_should_store_condition_metric_association
19 c = Conditions::FakePollCondition.new
20 m = Metric.new(@watch, :foo)
23 assert_equal m, Hub.directory[c]
26 def test_attach_should_schedule_for_poll_condition
27 c = Conditions::FakePollCondition.new
28 m = Metric.new(@watch, :foo)
30 Timer.any_instance.expects(:schedule).with(c, 0)
35 def test_attach_should_regsiter_for_event_condition
36 c = Conditions::FakeEventCondition.new
37 m = Metric.new(@watch, :foo)
46 def test_detach_should_remove_condition_metric_association
47 c = Conditions::FakePollCondition.new
48 m = Metric.new(@watch, :foo)
53 assert_nil Hub.directory[c]
56 def test_detach_should_unschedule_poll_conditions
57 c = Conditions::FakePollCondition.new
58 m = Metric.new(@watch, :foo)
61 Timer.any_instance.expects(:unschedule).with(c)
62 c.expects(:deregister).never
67 def test_detach_should_deregister_event_conditions
68 c = Conditions::FakeEventCondition.new
69 m = Metric.new(@watch, :foo)
72 c.expects(:deregister).once
79 def test_trigger_should_handle_poll_for_poll_condition
80 c = Conditions::FakePollCondition.new
81 Hub.expects(:handle_poll).with(c)
86 def test_trigger_should_handle_event_for_event_condition
87 c = Conditions::FakeEventCondition.new
88 Hub.expects(:handle_event).with(c)
95 def test_handle_poll_no_change_should_reschedule
96 c = Conditions::FakePollCondition.new
99 m = Metric.new(@watch, {true => :up})
102 c.expects(:test).returns(false)
103 Timer.any_instance.expects(:schedule)
106 t = Hub.handle_poll(c)
111 def test_handle_poll_change_should_move
112 c = Conditions::FakePollCondition.new
115 m = Metric.new(@watch, {true => :up})
118 c.expects(:test).returns(true)
119 @watch.expects(:move).with(:up)
122 t = Hub.handle_poll(c)
127 def test_handle_poll_should_abort_on_exception
128 c = Conditions::FakePollCondition.new
131 m = Metric.new(@watch, {true => :up})
134 c.expects(:test).raises(StandardError.new)
137 t = Hub.handle_poll(c)
142 def test_handle_poll_should_use_overridden_transition
143 c = Conditions::Tries.new
145 c.transition = :start
148 m = Metric.new(@watch, {true => :up})
151 @watch.expects(:move).with(:start)
154 t = Hub.handle_poll(c)
161 def test_handle_event_should_move
162 c = Conditions::FakeEventCondition.new
164 m = Metric.new(@watch, {true => :up})
167 @watch.expects(:move).with(:up)
170 t = Hub.handle_event(c)