eye 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. data/.gitignore +31 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +132 -0
  6. data/Rakefile +18 -0
  7. data/bin/eye +282 -0
  8. data/bin/loader_eye +56 -0
  9. data/examples/processes/em.rb +56 -0
  10. data/examples/processes/forking.rb +20 -0
  11. data/examples/processes/sample.rb +144 -0
  12. data/examples/rbenv.eye +11 -0
  13. data/examples/test.eye +65 -0
  14. data/examples/unicorn.eye +29 -0
  15. data/eye.gemspec +37 -0
  16. data/lib/eye.rb +25 -0
  17. data/lib/eye/application.rb +65 -0
  18. data/lib/eye/checker.rb +118 -0
  19. data/lib/eye/checker/cpu.rb +27 -0
  20. data/lib/eye/checker/file_ctime.rb +29 -0
  21. data/lib/eye/checker/file_size.rb +38 -0
  22. data/lib/eye/checker/http.rb +94 -0
  23. data/lib/eye/checker/memory.rb +27 -0
  24. data/lib/eye/checker/socket.rb +148 -0
  25. data/lib/eye/checker/validation.rb +49 -0
  26. data/lib/eye/child_process.rb +75 -0
  27. data/lib/eye/client.rb +32 -0
  28. data/lib/eye/control.rb +2 -0
  29. data/lib/eye/controller.rb +43 -0
  30. data/lib/eye/controller/commands.rb +64 -0
  31. data/lib/eye/controller/helpers.rb +61 -0
  32. data/lib/eye/controller/load.rb +224 -0
  33. data/lib/eye/controller/send_command.rb +88 -0
  34. data/lib/eye/controller/status.rb +136 -0
  35. data/lib/eye/dsl.rb +52 -0
  36. data/lib/eye/dsl/application_opts.rb +33 -0
  37. data/lib/eye/dsl/chain.rb +12 -0
  38. data/lib/eye/dsl/child_process_opts.rb +7 -0
  39. data/lib/eye/dsl/config_opts.rb +11 -0
  40. data/lib/eye/dsl/group_opts.rb +27 -0
  41. data/lib/eye/dsl/helpers.rb +12 -0
  42. data/lib/eye/dsl/main.rb +58 -0
  43. data/lib/eye/dsl/opts.rb +88 -0
  44. data/lib/eye/dsl/process_opts.rb +21 -0
  45. data/lib/eye/dsl/pure_opts.rb +132 -0
  46. data/lib/eye/dsl/validate.rb +41 -0
  47. data/lib/eye/group.rb +125 -0
  48. data/lib/eye/group/chain.rb +68 -0
  49. data/lib/eye/io/unix_server.rb +44 -0
  50. data/lib/eye/io/unix_socket.rb +39 -0
  51. data/lib/eye/loader.rb +13 -0
  52. data/lib/eye/logger.rb +80 -0
  53. data/lib/eye/process.rb +83 -0
  54. data/lib/eye/process/child.rb +61 -0
  55. data/lib/eye/process/commands.rb +256 -0
  56. data/lib/eye/process/config.rb +70 -0
  57. data/lib/eye/process/controller.rb +72 -0
  58. data/lib/eye/process/data.rb +46 -0
  59. data/lib/eye/process/monitor.rb +97 -0
  60. data/lib/eye/process/notify.rb +17 -0
  61. data/lib/eye/process/scheduler.rb +50 -0
  62. data/lib/eye/process/states.rb +92 -0
  63. data/lib/eye/process/states_history.rb +62 -0
  64. data/lib/eye/process/system.rb +60 -0
  65. data/lib/eye/process/trigger.rb +32 -0
  66. data/lib/eye/process/watchers.rb +67 -0
  67. data/lib/eye/server.rb +51 -0
  68. data/lib/eye/settings.rb +35 -0
  69. data/lib/eye/system.rb +145 -0
  70. data/lib/eye/system_resources.rb +83 -0
  71. data/lib/eye/trigger.rb +53 -0
  72. data/lib/eye/trigger/flapping.rb +24 -0
  73. data/lib/eye/utils.rb +5 -0
  74. data/lib/eye/utils/alive_array.rb +31 -0
  75. data/lib/eye/utils/celluloid_chain.rb +51 -0
  76. data/lib/eye/utils/leak_19.rb +7 -0
  77. data/lib/eye/utils/tail.rb +20 -0
  78. data/spec/checker/cpu_spec.rb +58 -0
  79. data/spec/checker/file_ctime_spec.rb +34 -0
  80. data/spec/checker/file_size_spec.rb +107 -0
  81. data/spec/checker/http_spec.rb +109 -0
  82. data/spec/checker/memory_spec.rb +64 -0
  83. data/spec/checker/socket_spec.rb +116 -0
  84. data/spec/checker_spec.rb +188 -0
  85. data/spec/child_process/child_process_spec.rb +46 -0
  86. data/spec/client_server_spec.rb +34 -0
  87. data/spec/controller/commands_spec.rb +92 -0
  88. data/spec/controller/controller_spec.rb +133 -0
  89. data/spec/controller/find_objects_spec.rb +150 -0
  90. data/spec/controller/group_spec.rb +110 -0
  91. data/spec/controller/intergration_spec.rb +327 -0
  92. data/spec/controller/load_spec.rb +326 -0
  93. data/spec/controller/races_spec.rb +70 -0
  94. data/spec/controller/stop_on_delete_spec.rb +157 -0
  95. data/spec/dsl/chain_spec.rb +140 -0
  96. data/spec/dsl/checks_spec.rb +202 -0
  97. data/spec/dsl/config_spec.rb +44 -0
  98. data/spec/dsl/dsl_spec.rb +73 -0
  99. data/spec/dsl/getter_spec.rb +223 -0
  100. data/spec/dsl/integration_spec.rb +311 -0
  101. data/spec/dsl/load_spec.rb +52 -0
  102. data/spec/dsl/process_spec.rb +330 -0
  103. data/spec/dsl/sub_procs_spec.rb +93 -0
  104. data/spec/dsl/with_server_spec.rb +104 -0
  105. data/spec/example/em.rb +57 -0
  106. data/spec/example/forking.rb +20 -0
  107. data/spec/example/sample.rb +154 -0
  108. data/spec/fixtures/dsl/0.rb +8 -0
  109. data/spec/fixtures/dsl/0a.rb +8 -0
  110. data/spec/fixtures/dsl/0c.rb +8 -0
  111. data/spec/fixtures/dsl/1.rb +5 -0
  112. data/spec/fixtures/dsl/bad.eye +6 -0
  113. data/spec/fixtures/dsl/configs/1.eye +3 -0
  114. data/spec/fixtures/dsl/configs/2.eye +1 -0
  115. data/spec/fixtures/dsl/configs/3.eye +1 -0
  116. data/spec/fixtures/dsl/configs/4.eye +3 -0
  117. data/spec/fixtures/dsl/empty.eye +20 -0
  118. data/spec/fixtures/dsl/include_test.eye +5 -0
  119. data/spec/fixtures/dsl/include_test/1.rb +6 -0
  120. data/spec/fixtures/dsl/include_test/ha.rb +4 -0
  121. data/spec/fixtures/dsl/include_test2.eye +5 -0
  122. data/spec/fixtures/dsl/integration.eye +30 -0
  123. data/spec/fixtures/dsl/integration2.eye +32 -0
  124. data/spec/fixtures/dsl/integration_locks.eye +30 -0
  125. data/spec/fixtures/dsl/integration_sor.eye +32 -0
  126. data/spec/fixtures/dsl/integration_sor2.eye +27 -0
  127. data/spec/fixtures/dsl/integration_sor3.eye +32 -0
  128. data/spec/fixtures/dsl/load.eye +25 -0
  129. data/spec/fixtures/dsl/load2.eye +7 -0
  130. data/spec/fixtures/dsl/load2_dup2.eye +13 -0
  131. data/spec/fixtures/dsl/load2_dup_pid.eye +7 -0
  132. data/spec/fixtures/dsl/load3.eye +10 -0
  133. data/spec/fixtures/dsl/load4.eye +7 -0
  134. data/spec/fixtures/dsl/load5.eye +8 -0
  135. data/spec/fixtures/dsl/load6.eye +17 -0
  136. data/spec/fixtures/dsl/load_dubls.eye +36 -0
  137. data/spec/fixtures/dsl/load_dup_ex_names.eye +15 -0
  138. data/spec/fixtures/dsl/load_error.eye +5 -0
  139. data/spec/fixtures/dsl/load_error_folder/load3.eye +10 -0
  140. data/spec/fixtures/dsl/load_error_folder/load4.eye +7 -0
  141. data/spec/fixtures/dsl/load_folder/load3.eye +10 -0
  142. data/spec/fixtures/dsl/load_folder/load4.eye +7 -0
  143. data/spec/fixtures/dsl/load_int.eye +8 -0
  144. data/spec/fixtures/dsl/load_int2.eye +13 -0
  145. data/spec/fixtures/dsl/load_logger.eye +26 -0
  146. data/spec/fixtures/dsl/load_logger2.eye +3 -0
  147. data/spec/fixtures/dsl/long_load.eye +5 -0
  148. data/spec/fixtures/dsl/subfolder1/proc1.rb +3 -0
  149. data/spec/fixtures/dsl/subfolder2.eye +9 -0
  150. data/spec/fixtures/dsl/subfolder2/common.rb +1 -0
  151. data/spec/fixtures/dsl/subfolder2/proc2.rb +3 -0
  152. data/spec/fixtures/dsl/subfolder2/sub/proc3.rb +6 -0
  153. data/spec/fixtures/dsl/subfolder3.eye +8 -0
  154. data/spec/fixtures/dsl/subfolder3/common.rb +1 -0
  155. data/spec/fixtures/dsl/subfolder3/proc4.rb +3 -0
  156. data/spec/fixtures/dsl/subfolder3/sub/proc5.rb +6 -0
  157. data/spec/fixtures/dsl/subfolder4.eye +6 -0
  158. data/spec/fixtures/dsl/subfolder4/a.rb +2 -0
  159. data/spec/fixtures/dsl/subfolder4/b.rb +1 -0
  160. data/spec/fixtures/dsl/subfolder4/c.rb +1 -0
  161. data/spec/mock_spec.rb +32 -0
  162. data/spec/process/checks/child_checks_spec.rb +79 -0
  163. data/spec/process/checks/cpu_spec.rb +114 -0
  164. data/spec/process/checks/ctime_spec.rb +43 -0
  165. data/spec/process/checks/fsize_spec.rb +22 -0
  166. data/spec/process/checks/http_spec.rb +52 -0
  167. data/spec/process/checks/intergration_spec.rb +32 -0
  168. data/spec/process/checks/memory_spec.rb +113 -0
  169. data/spec/process/child_process_spec.rb +125 -0
  170. data/spec/process/config_spec.rb +75 -0
  171. data/spec/process/controller_spec.rb +173 -0
  172. data/spec/process/monitoring_spec.rb +180 -0
  173. data/spec/process/restart_spec.rb +174 -0
  174. data/spec/process/scheduler_spec.rb +150 -0
  175. data/spec/process/start_spec.rb +261 -0
  176. data/spec/process/states_history_spec.rb +118 -0
  177. data/spec/process/stop_spec.rb +150 -0
  178. data/spec/process/system_spec.rb +100 -0
  179. data/spec/process/triggers/flapping_spec.rb +81 -0
  180. data/spec/process/update_config_spec.rb +63 -0
  181. data/spec/spec_helper.rb +120 -0
  182. data/spec/support/rr_celluloid.rb +36 -0
  183. data/spec/support/scheduler_hack.rb +16 -0
  184. data/spec/support/spec_support.rb +164 -0
  185. data/spec/system_resources_spec.rb +59 -0
  186. data/spec/system_spec.rb +170 -0
  187. data/spec/utils/alive_array_spec.rb +50 -0
  188. data/spec/utils/celluloid_chain_spec.rb +82 -0
  189. data/spec/utils/tail_spec.rb +21 -0
  190. metadata +558 -0
@@ -0,0 +1,100 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe "Eye::Process::System" do
5
+ before :each do
6
+ @process = Eye::Process.new(C.p1)
7
+ end
8
+
9
+ it "load_pid_from_file" do
10
+ File.open(@process[:pid_file_ex], 'w'){|f| f.write("asdf") }
11
+ @process.load_pid_from_file.should == nil
12
+
13
+ File.open(@process[:pid_file_ex], 'w'){|f| f.write(12345) }
14
+ @process.load_pid_from_file.should == 12345
15
+
16
+ FileUtils.rm(@process[:pid_file_ex]) rescue nil
17
+ @process.load_pid_from_file.should == nil
18
+ end
19
+
20
+ it "set_pid_from_file" do
21
+ File.open(@process[:pid_file_ex], 'w'){|f| f.write(12345) }
22
+ @process.set_pid_from_file
23
+ @process.pid.should == 12345
24
+ @process.pid = nil
25
+ end
26
+
27
+ it "save_pid_to_file" do
28
+ @process.pid = 123456789
29
+ @process.save_pid_to_file
30
+ File.read(@process[:pid_file_ex]).to_i.should == 123456789
31
+ end
32
+
33
+ it "clear_pid_file" do
34
+ @process.pid = 123456789
35
+ @process.save_pid_to_file
36
+ File.read(@process[:pid_file_ex]).to_i.should == 123456789
37
+
38
+ @process.clear_pid_file.should == true
39
+ File.exists?(@process[:pid_file_ex]).should == false
40
+ end
41
+
42
+ it "process_realy_running?" do
43
+ @process.pid = $$
44
+ @process.process_realy_running?.should == true
45
+
46
+ @process.pid = nil
47
+ @process.process_realy_running?.should == nil
48
+
49
+ @process.pid = -123434
50
+ @process.process_realy_running?.should == false
51
+ end
52
+
53
+ it "send_signal ok" do
54
+ mock(Eye::System).send_signal(@process.pid, :TERM){ {:status => :ok} }
55
+ @process.send_signal(:TERM).should == true
56
+ end
57
+
58
+ it "send_signal not ok" do
59
+ mock(Eye::System).send_signal(@process.pid, :TERM){ {:status => :error} }
60
+ @process.send_signal(:TERM).should == false
61
+ end
62
+
63
+ it "pid_file_ctime" do
64
+ File.open(@process[:pid_file_ex], 'w'){|f| f.write("asdf") }
65
+ sleep 1
66
+ (Time.now - @process.pid_file_ctime).should > 1.second
67
+
68
+ @process.clear_pid_file
69
+ (Time.now - @process.pid_file_ctime).should < 0.1.second
70
+ end
71
+
72
+ it "with_timeout" do
73
+ res = @process.with_timeout(0.5) do
74
+ sleep 0.3
75
+ 11
76
+ end
77
+
78
+ res.should == 11
79
+
80
+ res = @process.with_timeout(0.5) do
81
+ sleep 0.7
82
+ 11
83
+ end
84
+ res.should == :timeout
85
+ end
86
+
87
+ [C.p1, C.p2].each do |cfg|
88
+ it "blocking execute should not block process actor mailbox #{cfg[:name]}" do
89
+ @process = Eye::Process.new(cfg.merge(:start_command => "sleep 5", :start_timeout => 10.seconds))
90
+ tm1 = Time.now
91
+ @process.start!
92
+ sleep 1
93
+
94
+ # here mailbox should anwser without blocks
95
+ @process.name.should == cfg[:name]
96
+ (Time.now - tm1).should < 2 # seconds
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe "Flapping" do
4
+ before :each do
5
+ @c = C.p1.merge(
6
+ :triggers => C.flapping(:times => 4, :within => 10)
7
+ )
8
+ end
9
+
10
+ it "should create trigger from config" do
11
+ start_ok_process(@c)
12
+
13
+ triggers = @process.triggers
14
+ triggers.size.should == 1
15
+
16
+ triggers.first.class.should == Eye::Trigger::Flapping
17
+ triggers.first.within.should == 10
18
+ triggers.first.times.should == 4
19
+ end
20
+
21
+ it "should check speedy flapping by default" do
22
+ start_ok_process(C.p1)
23
+
24
+ triggers = @process.triggers
25
+ triggers.size.should == 1
26
+
27
+ triggers.first.class.should == Eye::Trigger::Flapping
28
+ triggers.first.within.should == 10
29
+ triggers.first.times.should == 10
30
+ end
31
+
32
+ it "process flapping" do
33
+ @process = process(@c.merge(:start_command => @c[:start_command] + " -r"))
34
+ @process.start!
35
+
36
+ stub(@process).notify(:warn, anything)
37
+ mock(@process).notify(:crit, anything)
38
+
39
+ sleep 13
40
+
41
+ # check flapping happens here
42
+
43
+ @process.state_name.should == :unmonitored
44
+ @process.watchers.keys.should == []
45
+ end
46
+
47
+ it "process flapping emulate with kill" do
48
+ @process = process(@c.merge(:triggers => C.flapping(:times => 3, :within => 7)))
49
+
50
+ @process.start
51
+
52
+ # 4 times because, flapping flag, check on next switch
53
+ 4.times do
54
+ die_process!(@process.pid)
55
+ sleep 3
56
+ end
57
+
58
+ @process.state_name.should == :unmonitored
59
+ @process.watchers.keys.should == []
60
+ end
61
+
62
+ it "flapping not happens" do
63
+ @process = process(@c)
64
+ @process.start!
65
+
66
+ proxy(@process).schedule(:start, anything)
67
+ proxy(@process).schedule(:check_crush, anything)
68
+ dont_allow(@process).schedule(:unmonitor)
69
+
70
+
71
+ sleep 5
72
+
73
+ # even if process die in middle
74
+ die_process!(@process.pid)
75
+
76
+ sleep 5
77
+
78
+ @process.state_name.should == :up
79
+ end
80
+
81
+ end
@@ -0,0 +1,63 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe "#update_config" do
5
+ before :each do
6
+ @cfg = C.p3.merge(:checks => join(C.check_mem, C.check_cpu), :monitor_children => {})
7
+ start_ok_process(@cfg)
8
+ sleep 6
9
+ end
10
+
11
+ after :each do
12
+ @process.stop if @process
13
+ end
14
+
15
+ it "update only env" do
16
+ @process.watchers.keys.should == [:check_alive, :check_childs, :check_memory, :check_cpu]
17
+ @process.childs.keys.size.should == 3
18
+ child_pids = @process.childs.keys
19
+ @process[:environment].should == {"ENV1" => "SUPER"}
20
+
21
+ @process.update_config(@cfg.merge(:environment => {"ENV2" => "SUPER"}))
22
+ sleep 5
23
+
24
+ @process.state_name.should == :up
25
+ @process.watchers.keys.should == [:check_alive, :check_childs, :check_memory, :check_cpu]
26
+ @process.childs.keys.size.should == 3
27
+ @process.childs.keys.should == child_pids
28
+ @process[:environment].should == {"ENV2" => "SUPER"}
29
+ @process.pid.should == @pid
30
+ end
31
+
32
+ it "update watchers" do
33
+ @process.watchers.keys.should == [:check_alive, :check_childs, :check_memory, :check_cpu]
34
+ @process.childs.keys.size.should == 3
35
+ child_pids = @process.childs.keys
36
+
37
+ @process.update_config(@cfg.merge(:checks => C.check_mem))
38
+ sleep 5
39
+
40
+ @process.state_name.should == :up
41
+ @process.watchers.keys.should == [:check_alive, :check_childs, :check_memory]
42
+ @process.childs.keys.size.should == 3
43
+ @process.childs.keys.should == child_pids
44
+ @process.pid.should == @pid
45
+ end
46
+
47
+ it "when disable monitor_children they should remove" do
48
+ @process.watchers.keys.should == [:check_alive, :check_childs, :check_memory, :check_cpu]
49
+ @process.childs.keys.size.should == 3
50
+ child_pids = @process.childs.keys
51
+
52
+ @process.update_config(@cfg.merge(:monitor_children => nil))
53
+ sleep 5
54
+
55
+ @process.state_name.should == :up
56
+ @process.watchers.keys.should == [:check_alive, :check_memory, :check_cpu]
57
+ @process.childs.keys.size.should == 0
58
+ @process.pid.should == @pid
59
+ end
60
+
61
+ end
62
+
63
+
@@ -0,0 +1,120 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rubygems'
3
+ require "bundler/setup"
4
+ require 'celluloid'
5
+
6
+ if ENV['COV']
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+ end
10
+
11
+ Bundler.require :default
12
+
13
+ # preload
14
+ Eye::Control
15
+ Eye::Controller
16
+ Eye::Process
17
+
18
+ class Eye::Controller
19
+ public :find_objects, :remove_object_from_tree
20
+ end
21
+
22
+ require 'rspec/mocks'
23
+ require 'fakeweb'
24
+
25
+ require File.join(File.dirname(__FILE__), %w{support spec_support})
26
+ require File.join(File.dirname(__FILE__), %w{support scheduler_hack})
27
+
28
+ $logger_path = File.join(File.dirname(__FILE__), %w{spec.log})
29
+
30
+ def set_glogger
31
+ Eye::Logger.log_level = Logger::DEBUG
32
+ Eye::Logger.link_logger($logger_path)
33
+ end
34
+
35
+ set_glogger
36
+
37
+ $logger = Eye::Logger.new("spec")
38
+ Celluloid.logger = $logger
39
+ STDERR.reopen($logger_path)
40
+
41
+ RSpec.configure do |config|
42
+ config.mock_with :rr
43
+
44
+ config.before(:all) do
45
+ silence_warnings{ Eye::SystemResources::PsAxActor::UPDATE_INTERVAL = 2 }
46
+ end
47
+
48
+ config.before(:each) do
49
+ FileUtils.rm(C.p1[:pid_file]) rescue nil
50
+ FileUtils.rm(C.p2[:pid_file]) rescue nil
51
+
52
+ @log = C.base[:stdout]
53
+ FileUtils.rm(@log) rescue nil
54
+
55
+ $logger.info "================== #{ self.class.description} '#{ example.description }'========================"
56
+ end
57
+
58
+ config.after(:each) do
59
+ # clearing all
60
+
61
+ if @pid_file
62
+ FileUtils.rm(@pid_file) rescue nil
63
+ end
64
+
65
+ force_kill_process(@process)
66
+ force_kill_pid(@pid)
67
+
68
+ FileUtils.rm(C.p1[:pid_file]) rescue nil
69
+ FileUtils.rm(C.p2[:pid_file]) rescue nil
70
+
71
+ GC.start # for kill spawned threads
72
+
73
+ terminate_old_actors
74
+
75
+ # actors = Celluloid::Actor.all.map(&:class)
76
+ # $logger.info "Actors: #{actors.inspect}"
77
+ end
78
+ end
79
+
80
+ def terminate_old_actors
81
+ Celluloid::Actor.all.each do |actor|
82
+ next unless actor.alive?
83
+ if [Eye::Process, Eye::Group, Eye::ChildProcess].include?(actor.class)
84
+ actor.terminate
85
+ end
86
+ end
87
+ end
88
+
89
+ def force_kill_process(process)
90
+ if process && process.alive?
91
+ pid = process.pid
92
+
93
+ process.terminate
94
+
95
+ if pid && Eye::System.pid_alive?(pid)
96
+ Eye::System.send_signal(pid, 9)
97
+ end
98
+
99
+ process = nil
100
+ end
101
+ end
102
+
103
+ def force_kill_pid(pid)
104
+ if pid && Eye::System.pid_alive?(pid)
105
+ Eye::System.send_signal(pid, 9)
106
+ end
107
+ end
108
+
109
+ def fixture(name)
110
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', name))
111
+ end
112
+
113
+ def join(*args)
114
+ result = {}
115
+ args.each do |a|
116
+ result.merge!(a)
117
+ end
118
+
119
+ result
120
+ end
@@ -0,0 +1,36 @@
1
+ require 'rr'
2
+ require 'rspec/core/mocking/with_rr'
3
+
4
+ module RR
5
+
6
+ module Celluloid
7
+ def mock(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
8
+ s = subject.respond_to?(:wrapped_object) ? subject.wrapped_object : subject
9
+ super(s, method_name, &definition_eval_block)
10
+ end
11
+
12
+ def stub(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
13
+ s = subject.respond_to?(:wrapped_object) ? subject.wrapped_object : subject
14
+ super(s, method_name, &definition_eval_block)
15
+ end
16
+
17
+ def dont_allow(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
18
+ s = subject.respond_to?(:wrapped_object) ? subject.wrapped_object : subject
19
+ super(s, method_name, &definition_eval_block)
20
+ end
21
+
22
+ def proxy(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
23
+ s = subject.respond_to?(:wrapped_object) ? subject.wrapped_object : subject
24
+ super(s, method_name, &definition_eval_block)
25
+ end
26
+
27
+ def strong(subject=DoubleDefinitions::DoubleDefinitionCreate::NO_SUBJECT, method_name=nil, &definition_eval_block)
28
+ s = subject.respond_to?(:wrapped_object) ? subject.wrapped_object : subject
29
+ super(s, method_name, &definition_eval_block)
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ RSpec::Core::MockFrameworkAdapter.send(:include, RR::Celluloid)
@@ -0,0 +1,16 @@
1
+ module Eye::Process::SchedulerHack
2
+
3
+ def scheduled_action(command, *args, &block)
4
+ super
5
+
6
+ schedule_history << command
7
+ end
8
+
9
+ def schedule_history
10
+ @schedule_history ||= Eye::Process::StatesHistory.new(100)
11
+ end
12
+
13
+ end
14
+
15
+ Eye::Process.send :include, Eye::Process::SchedulerHack
16
+ Eye::Group.send :include, Eye::Process::SchedulerHack
@@ -0,0 +1,164 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module C
3
+ extend self
4
+
5
+ def sample_dir
6
+ File.expand_path(File.join(File.dirname(__FILE__), %w{.. example}))
7
+ end
8
+
9
+ def pid_name
10
+ "1.pid"
11
+ end
12
+
13
+ def log_name
14
+ "1111.log"
15
+ end
16
+
17
+ def base
18
+ {
19
+ :environment => {"ENV1" => "SUPER"},
20
+ :working_dir => sample_dir,
21
+ :application => "main",
22
+ :group => "default",
23
+ :name => "base",
24
+ :pid_file => sample_dir + "/#{pid_name}",
25
+ :stdout => sample_dir + "/#{log_name}",
26
+ :stderr => sample_dir + "/#{log_name}",
27
+ :check_alive_period => 1.seconds,
28
+ :start_timeout => 5.seconds,
29
+ :stop_timeout => 2.seconds,
30
+ }
31
+ end
32
+
33
+ # eye daemonize process
34
+ def p1
35
+ base.merge(
36
+ :name => "blocking process",
37
+ :start_command => "ruby sample.rb",
38
+ :daemonize => true
39
+ )
40
+ end
41
+
42
+ # self daemonized process
43
+ def p2
44
+ base.merge(
45
+ :name => "self daemonized process",
46
+ :start_command => "ruby sample.rb -d --pid #{pid_name} --log #{log_name}",
47
+ )
48
+ end
49
+
50
+ # forking example
51
+ def p3
52
+ base.merge(
53
+ :name => "forking",
54
+ :start_command => "ruby forking.rb start",
55
+ :stop_command => "ruby forking.rb stop",
56
+ :pid_file => "forking.pid",
57
+ :childs_update_period => Eye::SystemResources::PsAxActor::UPDATE_INTERVAL + 1,
58
+ :stop_timeout => 5.seconds,
59
+ :start_timeout => 15.seconds
60
+ )
61
+ end
62
+
63
+ # event machine
64
+ def p4
65
+ base.merge(
66
+ :pid_file => "em.pid",
67
+ :name => "em",
68
+ :start_command => "ruby em.rb",
69
+ :daemonize => true,
70
+ :start_grace => 3.5,
71
+ :stop_grace => 0.5
72
+ )
73
+ end
74
+
75
+ def check_mem(a = {})
76
+ {:memory => {:type => :memory, :every => 2.seconds, :below => 100.megabytes, :times => [3,5]}.merge(a)}
77
+ end
78
+
79
+ def check_cpu(a = {})
80
+ {:cpu => {:type => :cpu, :every => 2.seconds, :below => 80, :times => [4,5]}.merge(a)}
81
+ end
82
+
83
+ def check_ctime(a = {})
84
+ {:ctime => {:type => :ctime, :every => 2, :file => sample_dir + "/#{log_name}", :times => [3,5]}.merge(a)}
85
+ end
86
+
87
+ def check_fsize(a = {})
88
+ {:fsize => {:type => :fsize, :every => 2, :file => sample_dir + "/#{log_name}", :times => [3,5]}.merge(a)}
89
+ end
90
+
91
+ def check_http(a = {})
92
+ {:http => {
93
+ :type => :http, :every => 2, :times => 1,
94
+ :url => "http://localhost:3000/bla", :kind => :sucess,
95
+ :pattern => /OK/, :timeout => 3.seconds
96
+ }.merge(a)
97
+ }
98
+ end
99
+
100
+ def flapping(a = {})
101
+ {:flapping => { :type => :flapping, :times => 2, :within => 10.seconds }.merge(a)}
102
+ end
103
+
104
+ def restart_sync
105
+ {:restart => {:action => :restart, :type => :sync, :grace => 5}}
106
+ end
107
+
108
+ def restart_async
109
+ {:restart => {:action => :restart, :type => :async, :grace => 5}}
110
+ end
111
+
112
+ def socket_path
113
+ File.join(sample_dir, 'sock1')
114
+ end
115
+
116
+ end
117
+
118
+ class TrapError
119
+ include Celluloid
120
+
121
+ trap_exit :actor_died
122
+
123
+ def actor_died(actor, reason)
124
+ if reason
125
+ $logger.error "Actor Died! #{actor.inspect} has died because of a #{reason.inspect}"
126
+ end
127
+ #$logger.error "#{reason.message}"
128
+ #$logger.error "#{reason.backtrace * "\n"}"
129
+ end
130
+ end
131
+
132
+ def process(cfg)
133
+ p = Eye::Process.new(cfg)
134
+ @trap = TrapError.new
135
+ @trap.link(p)
136
+ p
137
+ end
138
+
139
+ def start_ok_process(cfg = C.p1)
140
+ @process = process(cfg)
141
+ @process.start
142
+ sleep 0.2
143
+
144
+ @process.process_realy_running?.should == true
145
+ @process.pid.should > 0
146
+ @process.watchers.keys.should == [:check_alive] if !cfg[:check_alive] == false
147
+ @process.state_name.should == :up
148
+ @pid = @process.pid
149
+ Eye::System.pid_alive?(@pid).should == true
150
+
151
+ @process
152
+ end
153
+
154
+ def die_process!(pid, signal = :term, int = 0.2)
155
+ Eye::System.send_signal(pid, signal)
156
+ sleep int.to_f
157
+ Eye::System.pid_alive?(pid).should == false
158
+ end
159
+
160
+ def ensure_kill_samples
161
+ `ps aux | grep 'ruby sample.rb' | awk '{print $2}' | xargs kill -2 2>/dev/null` rescue nil
162
+ end
163
+
164
+ require_relative 'rr_celluloid'