god 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_watch.rb CHANGED
@@ -5,15 +5,19 @@ class TestWatch < Test::Unit::TestCase
5
5
  @watch = Watch.new(nil)
6
6
  end
7
7
 
8
- def test_should_have_empty_start_conditions
9
- assert_equal [], @watch.conditions[:start]
10
- end
8
+ # new
11
9
 
12
- def test_should_have_empty_restart_conditions
13
- assert_equal [], @watch.conditions[:restart]
10
+ def test_new_should_have_no_behaviors
11
+ assert_equal [], @watch.behaviors
14
12
  end
15
13
 
16
- def test_should_have_standard_attributes
14
+ def test_new_should_have_no_metrics
15
+ Watch::VALID_STATES.each do |state|
16
+ assert_equal [], @watch.metrics[state]
17
+ end
18
+ end
19
+
20
+ def test_new_should_have_standard_attributes
17
21
  assert_nothing_raised do
18
22
  @watch.name = 'foo'
19
23
  @watch.start = 'start'
@@ -24,100 +28,67 @@ class TestWatch < Test::Unit::TestCase
24
28
  end
25
29
  end
26
30
 
27
- # _if methods
28
-
29
- def test_start_if_should_modify_action_within_scope
30
- assert_equal nil, @watch.instance_variable_get(:@action)
31
- @watch.start_if do |w|
32
- assert_equal :start, @watch.instance_variable_get(:@action)
33
- end
34
- assert_equal nil, @watch.instance_variable_get(:@action)
31
+ def test_new_should_have_nil_state
32
+ assert_equal nil, @watch.state
35
33
  end
36
34
 
37
- def test_restart_if_should_modify_action_within_scope
38
- assert_equal nil, @watch.instance_variable_get(:@action)
39
- @watch.restart_if do |w|
40
- assert_equal :restart, @watch.instance_variable_get(:@action)
41
- end
42
- assert_equal nil, @watch.instance_variable_get(:@action)
35
+ # mutex
36
+
37
+ def test_mutex_should_return_the_same_mutex_each_time
38
+ assert_equal @watch.mutex, @watch.mutex
43
39
  end
44
40
 
45
- # condition
41
+ # behavior
46
42
 
47
- def test_start_condition_should_record_condition_in_correct_list
48
- cond = nil
49
- @watch.interval = 0
50
- @watch.start_if do |w|
51
- w.condition(:fake_poll_condition) { |c| cond = c }
52
- end
53
- assert_equal 1, @watch.conditions[:start].size
54
- assert_equal cond, @watch.conditions[:start].first
43
+ def test_behavior_should_record_behavior
44
+ beh = nil
45
+ @watch.behavior(:fake_behavior) { |b| beh = b }
46
+ assert_equal 1, @watch.behaviors.size
47
+ assert_equal beh, @watch.behaviors.first
55
48
  end
56
49
 
57
- def test_restart_condition_should_record_condition_in_correct_list
58
- cond = nil
59
- @watch.interval = 0
60
- @watch.restart_if do |w|
61
- w.condition(:fake_poll_condition) { |c| cond = c }
62
- end
63
- assert_equal 1, @watch.conditions[:restart].size
64
- assert_equal cond, @watch.conditions[:restart].first
65
- end
50
+ # transition
66
51
 
67
- def test_condition_called_from_outside_if_block_should_raise
52
+ def test_transition_should_abort_on_invalid_start_state
68
53
  assert_raise AbortCalledError do
69
- @watch.condition(:fake_poll_condition) { |c| cond = c }
54
+ @watch.transition(:foo, :bar)
70
55
  end
71
56
  end
72
57
 
73
- def test_condition_should_be_block_optional
74
- @watch.interval = 0
75
- @watch.start_if do |w|
76
- w.condition(:always)
58
+ def test_transition_should_accept_all_valid_start_states
59
+ assert_nothing_raised do
60
+ Watch::VALID_STATES.each do |state|
61
+ @watch.transition(state, :bar) { }
62
+ end
77
63
  end
78
- assert_equal 1, @watch.conditions[:start].size
79
64
  end
80
65
 
81
- def test_poll_condition_should_inherit_interval_from_watch_if_not_specified
82
- @watch.interval = 27
83
- @watch.start_if do |w|
84
- w.condition(:fake_poll_condition)
85
- end
86
- assert_equal 27, @watch.conditions[:start].first.interval
66
+ def test_transition_should_create_and_record_a_metric_for_the_given_start_state
67
+ @watch.transition(:init, :start) { }
68
+ assert_equal 1, @watch.metrics[:init].size
87
69
  end
88
70
 
89
- def test_poll_condition_should_abort_if_no_interval_and_no_watch_interval
90
- assert_raise AbortCalledError do
91
- @watch.start_if do |w|
92
- w.condition(:fake_poll_condition)
93
- end
94
- end
71
+ # start_if
72
+
73
+ def test_start_if_should_place_a_metric_on_up_state
74
+ @watch.start_if { }
75
+ assert_equal 1, @watch.metrics[:up].size
95
76
  end
96
77
 
97
- def test_condition_should_allow_generation_of_subclasses_of_poll_or_event
98
- @watch.interval = 27
99
- assert_nothing_raised do
100
- @watch.start_if do |w|
101
- w.condition(:fake_poll_condition)
102
- w.condition(:fake_event_condition)
103
- end
104
- end
78
+ # restart_if
79
+
80
+ def test_restart_if_should_place_a_metric_on_up_state
81
+ @watch.restart_if { }
82
+ assert_equal 1, @watch.metrics[:up].size
105
83
  end
106
84
 
107
- def test_condition_should_abort_if_not_subclass_of_poll_or_event
108
- assert_raise AbortCalledError do
109
- @watch.start_if do |w|
110
- w.condition(:fake_condition) { |c| }
111
- end
112
- end
85
+ # canonical_hash_form
86
+
87
+ def test_canonical_hash_form_should_convert_symbol_to_hash
88
+ assert_equal({true => :foo}, @watch.canonical_hash_form(:foo))
113
89
  end
114
-
115
- # behavior
116
90
 
117
- def test_behavior_should_record_behavior
118
- beh = nil
119
- @watch.behavior(:fake_behavior) { |b| beh = b }
120
- assert_equal 1, @watch.behaviors.size
121
- assert_equal beh, @watch.behaviors.first
91
+ def test_canonical_hash_form_should_convert_hash_to_hash
92
+ assert_equal({true => :foo}, @watch.canonical_hash_form(true => :foo))
122
93
  end
123
94
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: god
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-07-07 00:00:00 -07:00
6
+ version: 0.2.0
7
+ date: 2007-07-18 00:00:00 -07:00
8
8
  summary: Like monit, only awesome
9
9
  require_paths:
10
10
  - lib
11
+ - ext
11
12
  email: tom@rubyisawesome.com
12
13
  homepage: http://god.rubyforge.org/
13
14
  rubyforge_project: god
@@ -36,6 +37,10 @@ files:
36
37
  - bin/god
37
38
  - examples/gravatar.god
38
39
  - examples/local.god
40
+ - ext/god/Makefile
41
+ - ext/god/extconf.rb
42
+ - ext/god/kqueue_handler.c
43
+ - ext/god/netlink_handler.c
39
44
  - lib/god.rb
40
45
  - lib/god/base.rb
41
46
  - lib/god/behavior.rb
@@ -44,22 +49,30 @@ files:
44
49
  - lib/god/conditions/always.rb
45
50
  - lib/god/conditions/cpu_usage.rb
46
51
  - lib/god/conditions/memory_usage.rb
47
- - lib/god/conditions/process_not_running.rb
52
+ - lib/god/conditions/process_exits.rb
53
+ - lib/god/conditions/process_running.rb
48
54
  - lib/god/conditions/timeline.rb
49
55
  - lib/god/errors.rb
56
+ - lib/god/event_handler.rb
57
+ - lib/god/event_handlers/kqueue_handler.rb
58
+ - lib/god/event_handlers/netlink_handler.rb
59
+ - lib/god/hub.rb
50
60
  - lib/god/meddle.rb
61
+ - lib/god/metric.rb
51
62
  - lib/god/reporter.rb
52
63
  - lib/god/server.rb
53
64
  - lib/god/system/process.rb
54
65
  - lib/god/timer.rb
55
66
  - lib/god/watch.rb
56
67
  - test/configs/real.rb
68
+ - test/configs/test.rb
57
69
  - test/helper.rb
58
70
  - test/suite.rb
59
71
  - test/test_behavior.rb
60
72
  - test/test_condition.rb
61
73
  - test/test_god.rb
62
74
  - test/test_meddle.rb
75
+ - test/test_metric.rb
63
76
  - test/test_reporter.rb
64
77
  - test/test_server.rb
65
78
  - test/test_system_process.rb
@@ -71,6 +84,7 @@ test_files:
71
84
  - test/test_condition.rb
72
85
  - test/test_god.rb
73
86
  - test/test_meddle.rb
87
+ - test/test_metric.rb
74
88
  - test/test_reporter.rb
75
89
  - test/test_server.rb
76
90
  - test/test_system_process.rb
@@ -86,8 +100,8 @@ extra_rdoc_files:
86
100
  - README.txt
87
101
  executables:
88
102
  - god
89
- extensions: []
90
-
103
+ extensions:
104
+ - ext/god/extconf.rb
91
105
  requirements: []
92
106
 
93
107
  dependencies:
@@ -1,22 +0,0 @@
1
- module God
2
- module Conditions
3
-
4
- class ProcessNotRunning < PollCondition
5
- attr_accessor :pid_file
6
-
7
- def valid?
8
- valid = true
9
- valid &= complain("You must specify the 'pid_file' attribute for :process_not_running") if self.pid_file.nil?
10
- valid
11
- end
12
-
13
- def test
14
- return false unless File.exist?(self.pid_file)
15
-
16
- pid = File.open(self.pid_file).read.strip
17
- System::Process.new(pid).exists?
18
- end
19
- end
20
-
21
- end
22
- end