drbqs 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/VERSION +1 -1
  2. data/bin/drbqs-execute +6 -0
  3. data/bin/drbqs-manage +2 -2
  4. data/bin/drbqs-node +2 -2
  5. data/bin/drbqs-server +2 -2
  6. data/bin/drbqs-ssh +2 -2
  7. data/drbqs.gemspec +53 -16
  8. data/example/error_server/error.rb +6 -0
  9. data/example/error_server/server_def.rb +7 -0
  10. data/example/{error → error_task}/error.rb +0 -0
  11. data/example/{error → error_task}/server_def.rb +0 -0
  12. data/example/sum2/execute_def.rb +27 -0
  13. data/lib/drbqs/command_line/argument.rb +29 -0
  14. data/lib/drbqs/command_line/command_base.rb +81 -0
  15. data/lib/drbqs/command_line/command_execute.rb +33 -0
  16. data/lib/drbqs/command_line/command_line.rb +19 -0
  17. data/lib/drbqs/command_line/command_manage.rb +34 -0
  18. data/lib/drbqs/command_line/command_node.rb +26 -0
  19. data/lib/drbqs/command_line/command_server.rb +41 -0
  20. data/lib/drbqs/command_line/command_ssh.rb +51 -0
  21. data/lib/drbqs/command_line/option_setting.rb +42 -0
  22. data/lib/drbqs/execute/process_define.rb +213 -0
  23. data/lib/drbqs/execute/register.rb +147 -0
  24. data/lib/drbqs/{utility → execute}/server_define.rb +7 -14
  25. data/lib/drbqs/manage/execute_node.rb +4 -2
  26. data/lib/drbqs/manage/manage.rb +23 -16
  27. data/lib/drbqs/manage/send_signal.rb +31 -4
  28. data/lib/drbqs/manage/ssh_execute.rb +50 -6
  29. data/lib/drbqs/manage/ssh_shell.rb +95 -50
  30. data/lib/drbqs/node/connection.rb +1 -1
  31. data/lib/drbqs/node/node.rb +67 -17
  32. data/lib/drbqs/node/state.rb +109 -0
  33. data/lib/drbqs/node/task_client.rb +7 -7
  34. data/lib/drbqs/server/history.rb +16 -0
  35. data/lib/drbqs/server/message.rb +80 -15
  36. data/lib/drbqs/server/node_list.rb +16 -3
  37. data/lib/drbqs/server/prof.rb +48 -0
  38. data/lib/drbqs/server/queue.rb +20 -2
  39. data/lib/drbqs/server/server.rb +112 -70
  40. data/lib/drbqs/server/server_hook.rb +26 -6
  41. data/lib/drbqs/server/test/node.rb +34 -0
  42. data/lib/drbqs/server/test/server.rb +74 -0
  43. data/lib/drbqs/setting/base.rb +120 -0
  44. data/lib/drbqs/setting/data_container.rb +39 -0
  45. data/lib/drbqs/setting/execute.rb +71 -0
  46. data/lib/drbqs/setting/manage.rb +163 -0
  47. data/lib/drbqs/setting/node.rb +84 -0
  48. data/lib/drbqs/setting/server.rb +230 -0
  49. data/lib/drbqs/setting/setting.rb +14 -0
  50. data/lib/drbqs/setting/source.rb +220 -0
  51. data/lib/drbqs/setting/ssh.rb +165 -0
  52. data/lib/drbqs/task/task_generator.rb +4 -2
  53. data/lib/drbqs/utility/misc.rb +15 -1
  54. data/lib/drbqs/utility/temporary.rb +4 -2
  55. data/lib/drbqs.rb +3 -2
  56. data/spec/command_line/command_base_spec.rb +47 -0
  57. data/spec/{utility/command_line → command_line}/commands_spec.rb +3 -3
  58. data/spec/command_line/option_setting_spec.rb +29 -0
  59. data/spec/execute/def/execute1.rb +24 -0
  60. data/spec/execute/def/no_def.rb +2 -0
  61. data/spec/execute/process_define_spec.rb +167 -0
  62. data/spec/execute/register_spec.rb +77 -0
  63. data/spec/{utility → execute}/server_define_spec.rb +0 -0
  64. data/spec/integration_test/01_basic_usage_spec.rb +1 -1
  65. data/spec/integration_test/02_use_generator_spec.rb +1 -1
  66. data/spec/integration_test/03_use_temporary_file_spec.rb +1 -1
  67. data/spec/integration_test/04_use_unix_domain_spec.rb +1 -1
  68. data/spec/integration_test/05_server_exit_signal_spec.rb +1 -1
  69. data/spec/integration_test/06_node_exit_after_task_spec.rb +1 -1
  70. data/spec/integration_test/07_command_server_with_node_spec.rb +19 -16
  71. data/spec/integration_test/08_shutdown_unused_nodes_spec.rb +38 -0
  72. data/spec/integration_test/09_server_process_data_spec.rb +74 -0
  73. data/spec/integration_test/10_test_server_spec.rb +18 -0
  74. data/spec/integration_test/definition/task_obj_definition.rb +14 -0
  75. data/spec/manage/send_signal_spec.rb +8 -0
  76. data/spec/manage/ssh_shell_spec.rb +1 -1
  77. data/spec/node/state_spec.rb +148 -0
  78. data/spec/node/task_client_spec.rb +15 -0
  79. data/spec/server/history_spec.rb +51 -20
  80. data/spec/server/message_spec.rb +7 -2
  81. data/spec/server/node_list_spec.rb +1 -1
  82. data/spec/server/queue_spec.rb +93 -4
  83. data/spec/server/server_hook_spec.rb +62 -0
  84. data/spec/setting/base_spec.rb +35 -0
  85. data/spec/setting/data_container_spec.rb +92 -0
  86. data/spec/setting/execute_spec.rb +51 -0
  87. data/spec/setting/manage_spec.rb +63 -0
  88. data/spec/setting/node_spec.rb +43 -0
  89. data/spec/setting/server_spec.rb +46 -0
  90. data/spec/setting/source_spec.rb +245 -0
  91. data/spec/spec_helper.rb +17 -10
  92. data/spec/utility/argument_spec.rb +7 -7
  93. metadata +179 -146
  94. data/lib/drbqs/utility/argument.rb +0 -27
  95. data/lib/drbqs/utility/command_line/command_base.rb +0 -27
  96. data/lib/drbqs/utility/command_line/command_manage.rb +0 -121
  97. data/lib/drbqs/utility/command_line/command_node.rb +0 -103
  98. data/lib/drbqs/utility/command_line/command_server.rb +0 -165
  99. data/lib/drbqs/utility/command_line/command_ssh.rb +0 -126
  100. data/lib/drbqs/utility/command_line.rb +0 -15
  101. data/spec/utility/command_line/command_base_spec.rb +0 -33
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DRbQS::Setting::Node do
4
+ subject do
5
+ DRbQS::Setting::Node.new
6
+ end
7
+
8
+ context "when there are invalid arguments" do
9
+ it "should raise error by a value of invalid argument size." do
10
+ subject.set_argument('1', 2, 3, 4)
11
+ lambda do
12
+ subject.parse!
13
+ end.should raise_error
14
+ end
15
+
16
+ it "should raise error by a value of invalid key." do
17
+ subject.set(:invalid_key, 1, 2, 3)
18
+ subject.set_argument('first')
19
+ lambda do
20
+ subject.parse!
21
+ end.should raise_error
22
+ end
23
+ end
24
+
25
+ context "when parsing" do
26
+ it "should not raise error." do
27
+ subject.set(:load, '/path/to/load/file')
28
+ subject.set(:connect, 'druby://example.com:12345')
29
+ lambda do
30
+ subject.parse!
31
+ end.should_not raise_error
32
+ end
33
+
34
+ it "should not change string for shell." do
35
+ subject.set(:load, '/path/to/load/file')
36
+ subject.set(:connect, 'druby://example.com:12345')
37
+ subject.parse!
38
+ lambda do
39
+ subject.parse!
40
+ end.should_not change(subject, :string_for_shell)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DRbQS::Setting::Server do
4
+ subject do
5
+ DRbQS::Setting::Server.new
6
+ end
7
+
8
+ context "when there are invalid arguments" do
9
+ it "should raise error by a value of invalid argument size." do
10
+ lambda do
11
+ subject.parse!
12
+ end.should raise_error
13
+ end
14
+
15
+ it "should raise error by a value of invalid key." do
16
+ subject.set(:invalid_key, 1, 2, 3)
17
+ subject.set_argument('first')
18
+ lambda do
19
+ subject.parse!
20
+ end.should raise_error
21
+ end
22
+ end
23
+
24
+ context "when parsing" do
25
+ it "should not raise error." do
26
+ subject.set(:port, 123)
27
+ subject.set(:log_file, '/path/to/log')
28
+ subject.set(:load, '/path/to/load/file')
29
+ subject.set_server_argument('arg1', 'arg2')
30
+ lambda do
31
+ subject.parse!
32
+ end.should_not raise_error
33
+ end
34
+
35
+ it "should not change string for shell." do
36
+ subject.set(:port, 123)
37
+ subject.set(:log_file, '/path/to/log')
38
+ subject.set(:load, '/path/to/load/file')
39
+ subject.set_server_argument('arg1', 'arg2')
40
+ subject.parse!
41
+ lambda do
42
+ subject.parse!
43
+ end.should_not change(subject, :string_for_shell)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,245 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ require 'drbqs/setting/setting'
4
+
5
+ describe DRbQS::Setting::Source do
6
+ subject do
7
+ DRbQS::Setting::Source.new
8
+ end
9
+
10
+ context "when setting argument keys and values" do
11
+ it "should return registered keys." do
12
+ subject.register_key(:key1, :check => 1)
13
+ subject.register_key(:key2, :bool => 1)
14
+ subject.register_key(:key3, :default => [true])
15
+ subject.registered_keys.sort.should == [:key1, :key2, :key3].sort
16
+ end
17
+
18
+ it "should set just an argument." do
19
+ subject.register_key(:key1, :check => 1)
20
+ subject.set(:key1, :val)
21
+ subject.check!
22
+ subject.get(:key1).should == [:val]
23
+ end
24
+
25
+ it "should set just an argument with a string key." do
26
+ subject.register_key('key2', :check => 1)
27
+ subject.set('key2', :val)
28
+ subject.check!
29
+ subject.get('key2').should == [:val]
30
+ end
31
+
32
+ it "should raise error with more than one arguments." do
33
+ subject.register_key(:key3, :check => 1)
34
+ subject.set(:key3, :val, :val2)
35
+ lambda do
36
+ subject.check!
37
+ end.should raise_error DRbQS::Setting::InvalidArgument
38
+ end
39
+
40
+ it "should set more than two arguments." do
41
+ subject.register_key(:key4, :check => [:>, 2])
42
+ subject.set(:key4, 1, 2, 3)
43
+ subject.check!
44
+ subject.get(:key4).should == [1, 2, 3]
45
+ end
46
+
47
+ it "should raise error with less than three arguments." do
48
+ subject.register_key(:key5, :check => [:>, 2])
49
+ subject.set(:key5, 1, 2)
50
+ lambda do
51
+ subject.check!
52
+ end.should raise_error DRbQS::Setting::InvalidArgument
53
+ end
54
+
55
+ it "should set arguments with multiple conditions." do
56
+ subject.register_key(:key, :check => [:>, 2, :<=, 4])
57
+ subject.set(:key, 1, 2, 3, 4)
58
+ subject.get(:key).should == [1, 2, 3, 4]
59
+ end
60
+
61
+ it "should raise error for second condition." do
62
+ subject.register_key(:key, :check => [:>, 2, :<=, 4])
63
+ subject.set(:key, 1, 2, 3, 4, 5)
64
+ lambda do
65
+ subject.check!
66
+ end.should raise_error DRbQS::Setting::InvalidArgument
67
+ end
68
+
69
+ it "should set some arguments" do
70
+ subject.register_key(:key1, :check => 1)
71
+ subject.register_key(:key2, :check => [:>, 1])
72
+ subject.set(:key1, 3)
73
+ subject.set(:key2, 2, 4)
74
+ subject.check!
75
+ subject.get(:key1).should == [3]
76
+ subject.get(:key2).should == [2, 4]
77
+ end
78
+
79
+ it "should cancel an argument set before." do
80
+ subject.register_key(:key, :check => 1)
81
+ subject.set(:key, 1)
82
+ subject.set(:key, 2)
83
+ subject.check!
84
+ subject.get(:key).should == [2]
85
+ end
86
+
87
+ it "should add an arguments." do
88
+ subject.register_key(:key, :add => true)
89
+ subject.set(:key, 1)
90
+ subject.set(:key, 2)
91
+ subject.check!
92
+ subject.get(:key).should == [1, 2]
93
+ end
94
+
95
+ it "should set default value." do
96
+ subject.register_key(:key, :default => [0])
97
+ lambda do
98
+ subject.set(:key, 10)
99
+ subject.check!
100
+ end.should change { subject.get(:key) }.from([0]).to([10])
101
+ end
102
+
103
+ it "should clear value." do
104
+ subject.register_key(:key, :check => 1)
105
+ subject.set(:key, 1)
106
+ subject.check!
107
+ subject.clear(:key)
108
+ subject.get(:key).should be_nil
109
+ end
110
+
111
+ it "should get first element." do
112
+ subject.register_key(:key, :check => 1)
113
+ subject.set(:key, 'first')
114
+ subject.check!
115
+ subject.get_first(:key).should == 'first'
116
+ end
117
+
118
+ it "should get after processing by block." do
119
+ subject.register_key(:key, :check => 2)
120
+ subject.set(:key, 'hello', 'world')
121
+ subject.check!
122
+ subject.get(:key) do |val|
123
+ val.join(' ')
124
+ end.should == 'hello world'
125
+ end
126
+
127
+ it "should get first element after processing by block." do
128
+ subject.register_key(:key, :check => 2)
129
+ subject.set(:key, 'hello', 'world')
130
+ subject.check!
131
+ subject.get_first(:key) do |first|
132
+ first + ' ' + first
133
+ end.should == 'hello hello'
134
+ end
135
+ end
136
+
137
+ context "when setting arguments" do
138
+ it "should set arguments" do
139
+ subject.set_argument(1, 2, 3)
140
+ subject.get_argument.should == [1, 2, 3]
141
+ end
142
+
143
+ it "should set arguments with checking." do
144
+ subject.set_argument_condition(3)
145
+ subject.set_argument(1, 2, 3)
146
+ subject.check!
147
+ subject.get_argument.should == [1, 2, 3]
148
+ end
149
+
150
+ it "should raise error for invalid arguments." do
151
+ subject.set_argument_condition(:>, 1)
152
+ subject.set_argument(1)
153
+ lambda do
154
+ subject.check!
155
+ end.should raise_error DRbQS::Setting::InvalidArgument
156
+ end
157
+ end
158
+
159
+ context "when cloning an object" do
160
+ before(:all) do
161
+ subject.register_key(:key1, :check => [:>, 1])
162
+ subject.register_key(:key2, :bool => true)
163
+ subject.register_key(:key3, :add => true)
164
+ subject.register_key(:key4, :default => [1, 2, 3])
165
+ @source_new = subject.clone
166
+ end
167
+
168
+ it "should have different @cond." do
169
+ obj_new = @source_new.instance_variable_get(:@cond)
170
+ obj_old = subject.instance_variable_get(:@cond)
171
+ obj_new.should == obj_old
172
+ obj_new.object_id.should_not == obj_old.object_id
173
+ end
174
+
175
+ it "should have different @default." do
176
+ obj_new = @source_new.instance_variable_get(:@default)
177
+ obj_old = subject.instance_variable_get(:@default)
178
+ obj_new.should == obj_old
179
+ obj_new.object_id.should_not == obj_old.object_id
180
+ end
181
+
182
+ it "should have different @value." do
183
+ obj_new = @source_new.instance_variable_get(:@value)
184
+ obj_old = subject.instance_variable_get(:@value)
185
+ [:key1, :key2, :key3, :key4].each do |k|
186
+ obj_new.__send__(k).should == obj_old.__send__(k)
187
+ end
188
+ end
189
+
190
+ it "should have different @argument_condition." do
191
+ obj_new = @source_new.instance_variable_get(:@argument_condition)
192
+ obj_old = subject.instance_variable_get(:@argument_condition)
193
+ obj_new.should == obj_old
194
+ end
195
+
196
+ it "should have same value of @all_keys_defined." do
197
+ @source_new.instance_variable_get(:@all_keys_defined).should ==
198
+ subject.instance_variable_get(:@all_keys_defined)
199
+ end
200
+ end
201
+
202
+ context "when converting to an array of command line arguments" do
203
+ it "should return boolean options." do
204
+ subject.register_key(:a, :bool => true)
205
+ subject.register_key(:bc, :bool => true)
206
+ subject.set(:a)
207
+ subject.set(:bc)
208
+ subject.command_line_argument.should == ['-a', '--bc']
209
+ end
210
+
211
+ it "should return short options." do
212
+ subject.register_key(:a)
213
+ subject.set(:a, 'val1', 'val2')
214
+ subject.command_line_argument.should == ['-a', 'val1', '-a', 'val2']
215
+ end
216
+
217
+ it "should return long options." do
218
+ subject.register_key(:long)
219
+ subject.set(:long, 'val1', 'val2')
220
+ subject.command_line_argument.should == ['--long', 'val1', '--long', 'val2']
221
+ end
222
+
223
+ it "should replace '_' by '-'." do
224
+ subject.register_key(:long_opts)
225
+ subject.set(:long_opts, 'val1', 'val2')
226
+ subject.command_line_argument.should == ['--long-opts', 'val1', '--long-opts', 'val2']
227
+ end
228
+
229
+ it "should escape strings." do
230
+ subject.register_key(:long)
231
+ subject.set(:long, 'val1', 'val"2')
232
+ subject.command_line_argument(true).should == ['--long', '"val1"', '--long', '"val\"2"']
233
+ end
234
+
235
+ it "should return arguments." do
236
+ subject.set_argument(1, 23, 'a')
237
+ subject.command_line_argument.should == ['1', '23', 'a']
238
+ end
239
+
240
+ it "should escape arguments." do
241
+ subject.set_argument(1, 23, 'a"bc')
242
+ subject.command_line_argument(true).should == ['"1"', '"23"', '"a\"bc"']
243
+ end
244
+ end
245
+ end
data/spec/spec_helper.rb CHANGED
@@ -39,26 +39,33 @@ def drbqs_wait_kill_server(process_id, wait_time = 10)
39
39
  end
40
40
  end
41
41
 
42
- def drbqs_fork_server(uri_arg, task_args, opts = {})
42
+ def drbqs_fork_server(uri_arg, opts = {}, &block)
43
+ server_args = opts[:opts] || {}
43
44
  if Integer === uri_arg
44
- server_args = { :port => uri_arg }
45
+ server_args[:port] = uri_arg
45
46
  uri = "druby://:#{uri_arg}"
46
47
  else
47
- server_args = { :unix => uri_arg }
48
+ server_args[:unix] = uri_arg
48
49
  uri = "drbunix:#{uri_arg}"
49
50
  end
50
51
 
51
52
  pid = fork do
52
53
  server = DRbQS::Server.new(server_args)
53
54
 
54
- unless task_args.respond_to?(:each)
55
- task_args = [task_args]
55
+ if block_given?
56
+ yield(server)
56
57
  end
57
- task_args.each do |arg|
58
- if DRbQS::TaskGenerator === arg
59
- server.add_task_generator(arg)
60
- else
61
- server.queue.add(arg)
58
+
59
+ if task_args = opts[:task]
60
+ unless task_args.respond_to?(:each)
61
+ task_args = [task_args]
62
+ end
63
+ task_args.each do |arg|
64
+ if DRbQS::TaskGenerator === arg
65
+ server.add_task_generator(arg)
66
+ else
67
+ server.queue.add(arg)
68
+ end
62
69
  end
63
70
  end
64
71
 
@@ -1,12 +1,12 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- require 'drbqs/utility/command_line'
3
+ require 'drbqs/command_line/command_line'
4
4
 
5
- describe DRbQS::CommandLineArgument do
5
+ describe DRbQS::Command::Argument do
6
6
 
7
7
  it "should split arguments" do
8
8
  ary = ['abc', 'def', '--', '123', '45', '6']
9
- a1, a2 = DRbQS::CommandLineArgument.split_arguments(ary)
9
+ a1, a2 = DRbQS::Command::Argument.split_arguments(ary)
10
10
  a1.should == ['abc', 'def']
11
11
  a2.should == ['123', '45', '6']
12
12
  end
@@ -14,25 +14,25 @@ describe DRbQS::CommandLineArgument do
14
14
  context "when checking size of array" do
15
15
  it "should return true" do
16
16
  ary = [1, 2, 3]
17
- DRbQS::CommandLineArgument.check_argument_size(ary, :>=, 1).should be_true
17
+ DRbQS::Command::Argument.check_argument_size(ary, :>=, 1).should be_true
18
18
  end
19
19
 
20
20
  it "should return true" do
21
21
  ary = [1, 2, 3]
22
- DRbQS::CommandLineArgument.check_argument_size(ary, :>=, 1, :<=, 4).should be_true
22
+ DRbQS::Command::Argument.check_argument_size(ary, :>=, 1, :<=, 4).should be_true
23
23
  end
24
24
 
25
25
  it "should raise error" do
26
26
  ary = [1, 2, 3]
27
27
  lambda do
28
- DRbQS::CommandLineArgument.check_argument_size(ary, :==, 9)
28
+ DRbQS::Command::Argument.check_argument_size(ary, :==, 9)
29
29
  end.should raise_error
30
30
  end
31
31
 
32
32
  it "should raise error" do
33
33
  ary = [1, 2, 3]
34
34
  lambda do
35
- DRbQS::CommandLineArgument.check_argument_size(ary, :>, 0, :<=, 2)
35
+ DRbQS::Command::Argument.check_argument_size(ary, :>, 0, :<=, 2)
36
36
  end.should raise_error
37
37
  end
38
38
  end