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
@@ -61,6 +61,21 @@ describe DRbQS::Node::TaskClient do
61
61
  end
62
62
  end
63
63
 
64
+ context "when getting new task" do
65
+ before(:all) do
66
+ init_task_client(7)
67
+ end
68
+
69
+ it "should return nil" do
70
+ subject.add_new_task.should be_nil
71
+ end
72
+
73
+ it "should return nil" do
74
+ add_task_to_tuplespace(100, [[1, 3, 5, 7], :size, []])
75
+ subject.add_new_task.should be_true
76
+ end
77
+ end
78
+
64
79
  context "when adding new task" do
65
80
  before(:all) do
66
81
  init_task_client(7)
@@ -11,59 +11,56 @@ describe DRbQS::Server::History do
11
11
  end
12
12
  end
13
13
 
14
+ subject do
15
+ DRbQS::Server::History.new
16
+ end
17
+
14
18
  context "when setting events" do
15
19
  before(:all) do
16
- @history = DRbQS::Server::History.new
17
- @history.set(1, :abc)
18
- @history.set(1, :def)
19
- @history.set(2, 'ABC', 'DEF')
20
- @history.set(3, :ghi)
21
- @history.set(1, :jkl)
22
- @history.set(2, 123, 456)
20
+ subject.set(1, :abc)
21
+ subject.set(1, :def)
22
+ subject.set(2, 'ABC', 'DEF')
23
+ subject.set(3, :ghi)
24
+ subject.set(1, :jkl)
25
+ subject.set(2, 123, 456)
23
26
  end
24
27
 
25
28
  it "should have 3 items." do
26
- @history.should have(3).items
29
+ subject.should have(3).items
27
30
  end
28
31
 
29
32
  it "should 3 events of ID 1." do
30
- @history.number_of_events(1).should == 3
33
+ subject.number_of_events(1).should == 3
31
34
  end
32
35
 
33
36
  it "should 2 events of ID 2" do
34
- @history.number_of_events(2).should == 2
37
+ subject.number_of_events(2).should == 2
35
38
  end
36
39
 
37
40
  it "should 1 event of ID 3" do
38
- @history.number_of_events(3).should == 1
41
+ subject.number_of_events(3).should == 1
39
42
  end
40
43
 
41
44
  it "should check events of ID 1" do
42
- events = @history.events(1)
45
+ events = subject.events(1)
43
46
  check_event(events[0], :abc)
44
47
  check_event(events[1], :def)
45
48
  check_event(events[2], :jkl)
46
49
  end
47
50
 
48
51
  it "should check events of ID 2" do
49
- events = @history.events(2)
52
+ events = subject.events(2)
50
53
  check_event(events[0], 'ABC', 'DEF')
51
54
  check_event(events[1], 123, 456)
52
55
  end
53
56
 
54
57
  it "should check events of ID 1" do
55
- events = @history.events(3)
58
+ events = subject.events(3)
56
59
  check_event(events[0], :ghi)
57
60
  end
58
-
59
- it "should return strings of log" do
60
- @history.log_strings.should be_an_instance_of String
61
- end
62
61
  end
63
62
 
64
63
  context "when executing a method" do
65
- subject { DRbQS::Server::History.new }
66
-
67
64
  it "should add new event" do
68
65
  id = 1
69
66
  subject.set(id, :connect)
@@ -88,3 +85,37 @@ describe DRbQS::Server::History do
88
85
  end
89
86
  end
90
87
  end
88
+
89
+ describe DRbQS::Server::TaskHistory do
90
+ subject do
91
+ DRbQS::Server::TaskHistory.new
92
+ end
93
+
94
+ it "should return strings of log" do
95
+ subject.set(1, :def)
96
+ subject.set(2, 'ABC', 'DEF')
97
+ subject.set(3, :ghi)
98
+ subject.set(1, :jkl)
99
+ subject.log_strings.should be_an_instance_of String
100
+ end
101
+
102
+ it "should return zero for finished_task_number." do
103
+ subject.finished_task_number.should == 0
104
+ end
105
+
106
+ it "should count finished task when setting :result." do
107
+ 5.times do |i|
108
+ lambda do
109
+ subject.set(i, :result)
110
+ end.should change(subject, :finished_task_number).by(1)
111
+ end
112
+ end
113
+
114
+ it "should not change finished task number for :add." do
115
+ [:add, :requeue, :hook, :calculate].each do |sym|
116
+ lambda do
117
+ subject.set(1, sym)
118
+ end.should_not change(subject, :finished_task_number)
119
+ end
120
+ end
121
+ end
@@ -21,7 +21,7 @@ describe DRbQS::Server::Message do
21
21
 
22
22
  def clear_all_node
23
23
  @message_server.get_all_nodes.each do |id_num, id_str|
24
- @node_list.delete(id_num)
24
+ @node_list.delete(id_num, :disconnect)
25
25
  end
26
26
  end
27
27
 
@@ -65,10 +65,15 @@ describe DRbQS::Server::Message do
65
65
  it "should get :node_error message" do
66
66
  node_id = 74
67
67
  @message.write([:server, :node_error, [node_id, 'Error occurs.']])
68
- @node_list.should_receive(:delete).with(node_id)
68
+ @node_list.should_receive(:delete).with(node_id, :error)
69
69
  @message_server.get_message.should == [:node_error, node_id]
70
70
  end
71
71
 
72
+ it "should get :new_data message" do
73
+ @message.write([:server, :new_data, 'data string'])
74
+ @message_server.get_message.should == [:new_data, 'data string']
75
+ end
76
+
72
77
  it "should return nil for invalid message" do
73
78
  @message.write([:server, :invalid_message])
74
79
  @message_server.get_message.should be_nil
@@ -58,7 +58,7 @@ describe DRbQS::Server::NodeList do
58
58
 
59
59
  it "should delete a node" do
60
60
  id = subject.get_new_id(create_id_string)
61
- subject.delete(id)
61
+ subject.delete(id, :disconnect)
62
62
  subject.exist?(id).should_not be_true
63
63
  end
64
64
  end
@@ -38,6 +38,10 @@ describe DRbQS::Server::Queue do
38
38
  subject.calculating_task_number.should == 0
39
39
  end
40
40
 
41
+ it "should get number of stocked tasks." do
42
+ subject.stocked_task_number.should == 0
43
+ end
44
+
41
45
  it "should be empty." do
42
46
  subject.should be_empty
43
47
  end
@@ -45,6 +49,10 @@ describe DRbQS::Server::Queue do
45
49
  it "should be finished." do
46
50
  subject.should be_finished
47
51
  end
52
+
53
+ it "should return an array of calculating nodes." do
54
+ subject.calculating_nodes.should == []
55
+ end
48
56
  end
49
57
 
50
58
  context "when adding a task" do
@@ -65,6 +73,10 @@ describe DRbQS::Server::Queue do
65
73
  subject.calculating_task_number.should == 0
66
74
  end
67
75
 
76
+ it "should get number of stocked tasks." do
77
+ subject.stocked_task_number.should == 1
78
+ end
79
+
68
80
  it "should not be empty." do
69
81
  subject.empty?.should be_false
70
82
  end
@@ -76,6 +88,10 @@ describe DRbQS::Server::Queue do
76
88
  it "should take objects from queue." do
77
89
  @ts[:queue].take([nil, nil, nil, nil]).should be_true
78
90
  end
91
+
92
+ it "should return an array of calculating nodes." do
93
+ subject.calculating_nodes.should == []
94
+ end
79
95
  end
80
96
 
81
97
  context "when getting accept signal" do
@@ -83,7 +99,7 @@ describe DRbQS::Server::Queue do
83
99
  object_init
84
100
  @node_id = 100
85
101
  @task_id = subject.add(@task[:obj])
86
- @ts[:result].write([:accept, @task_id, 100])
102
+ @ts[:result].write([:accept, @task_id, @node_id])
87
103
  end
88
104
 
89
105
  it "should return number of acceptances of signals." do
@@ -98,6 +114,10 @@ describe DRbQS::Server::Queue do
98
114
  subject.calculating_task_number.should == 1
99
115
  end
100
116
 
117
+ it "should get number of stocked tasks." do
118
+ subject.stocked_task_number.should == 0
119
+ end
120
+
101
121
  it "should be empty." do
102
122
  subject.should be_empty
103
123
  end
@@ -109,6 +129,10 @@ describe DRbQS::Server::Queue do
109
129
  it "should take objects from queue." do
110
130
  @ts[:result].read_all([nil, nil, nil]).size.should == 0
111
131
  end
132
+
133
+ it "should return an array of calculating nodes." do
134
+ subject.calculating_nodes.should == [@node_id]
135
+ end
112
136
  end
113
137
 
114
138
  context "when getting result" do
@@ -116,7 +140,7 @@ describe DRbQS::Server::Queue do
116
140
  object_init
117
141
  @node_id = 100
118
142
  @task_id = subject.add(@task[:obj])
119
- @ts[:result].write([:accept, @task_id, 100])
143
+ @ts[:result].write([:accept, @task_id, @node_id])
120
144
  subject.get_accept_signal
121
145
  @ts[:result].write([:result, @task_id, @node_id, :result_object])
122
146
  end
@@ -133,6 +157,10 @@ describe DRbQS::Server::Queue do
133
157
  subject.calculating_task_number.should == 0
134
158
  end
135
159
 
160
+ it "should get number of stocked tasks." do
161
+ subject.stocked_task_number.should == 0
162
+ end
163
+
136
164
  it "should be empty." do
137
165
  subject.should be_empty
138
166
  end
@@ -140,6 +168,10 @@ describe DRbQS::Server::Queue do
140
168
  it "should not be finished." do
141
169
  subject.should be_finished
142
170
  end
171
+
172
+ it "should return an array of calculating nodes." do
173
+ subject.calculating_nodes.should == []
174
+ end
143
175
  end
144
176
 
145
177
  context "when requeueing a task" do
@@ -147,7 +179,7 @@ describe DRbQS::Server::Queue do
147
179
  object_init
148
180
  @node_id = 100
149
181
  @task_id = subject.add(@task[:obj])
150
- @ts[:result].write([:accept, @task_id, 100])
182
+ @ts[:result].write([:accept, @task_id, @node_id])
151
183
  subject.get_accept_signal
152
184
  subject.requeue_for_deleted_node_id([@node_id])
153
185
  end
@@ -164,6 +196,10 @@ describe DRbQS::Server::Queue do
164
196
  subject.calculating_task_number.should == 0
165
197
  end
166
198
 
199
+ it "should get number of stocked tasks." do
200
+ subject.stocked_task_number.should == 1
201
+ end
202
+
167
203
  it "should be empty." do
168
204
  subject.should_not be_empty
169
205
  end
@@ -176,6 +212,54 @@ describe DRbQS::Server::Queue do
176
212
  (ary = @ts[:queue].take([nil, nil, nil, nil])).should be_true
177
213
  ary[0].should == @task_id
178
214
  end
215
+
216
+ it "should return an array of calculating nodes." do
217
+ subject.calculating_nodes.should == []
218
+ end
219
+ end
220
+
221
+ context "when some nodes are calculating" do
222
+ before(:all) do
223
+ object_init
224
+ @node_ids = [200, 300]
225
+ @tasks = [DRbQS::Task.new([1, 2, 3], :size, []),
226
+ DRbQS::Task.new([-1, -2], :size, []),
227
+ DRbQS::Task.new([8, 9, 10, 11], :size, [])]
228
+ @task_ids = @tasks.map do |t|
229
+ subject.add(t)
230
+ end
231
+ @ts[:result].write([:accept, @task_ids[0], @node_ids[0]])
232
+ @ts[:result].write([:accept, @task_ids[1], @node_ids[1]])
233
+ subject.get_accept_signal
234
+ end
235
+
236
+ it "should return number of acceptances of signals." do
237
+ subject.get_accept_signal.should == 0
238
+ end
239
+
240
+ it "should return number of acceptances of resultss." do
241
+ subject.get_result(@server_dummy).should == 0
242
+ end
243
+
244
+ it "should return number of calculating task." do
245
+ subject.calculating_task_number.should == 2
246
+ end
247
+
248
+ it "should get number of stocked tasks." do
249
+ subject.stocked_task_number.should == 1
250
+ end
251
+
252
+ it "should be empty." do
253
+ subject.should_not be_empty
254
+ end
255
+
256
+ it "should not be finished." do
257
+ subject.should_not be_finished
258
+ end
259
+
260
+ it "should return an array of calculating nodes." do
261
+ subject.calculating_nodes.should == @node_ids.sort
262
+ end
179
263
  end
180
264
 
181
265
  context "when executing hook of task" do
@@ -189,9 +273,10 @@ describe DRbQS::Server::Queue do
189
273
  end
190
274
 
191
275
  it "should execute hook of task" do
276
+ @node_id = 100
192
277
  task_id = subject.add(@task[:obj])
193
278
  @task_id = subject.add(@task[:obj])
194
- @ts[:result].write([:accept, @task_id, 100])
279
+ @ts[:result].write([:accept, @task_id, @node_id])
195
280
  subject.get_accept_signal
196
281
  @ts[:result].write([:result, @task_id, @node_id, :result_object])
197
282
  subject.get_result(@server_dummy)
@@ -227,6 +312,10 @@ describe DRbQS::Server::Queue do
227
312
  subject.calculating_task_number.should == 1
228
313
  end
229
314
 
315
+ it "should get number of stocked tasks." do
316
+ subject.stocked_task_number.should == 1
317
+ end
318
+
230
319
  it "should be empty." do
231
320
  subject.should_not be_empty
232
321
  end
@@ -5,6 +5,10 @@ require 'drbqs/server/server_hook'
5
5
  describe DRbQS::Server::Hook do
6
6
  subject { DRbQS::Server::Hook.new }
7
7
 
8
+ it "should return 0 for nonexistent key." do
9
+ subject.number_of_hook(:nonexistent_key).should == 0
10
+ end
11
+
8
12
  it "should add a hook with automatic creation of name." do
9
13
  n = subject.number_of_hook(:finish)
10
14
  name = subject.add(:finish) do |server|
@@ -75,4 +79,62 @@ describe DRbQS::Server::Hook do
75
79
  subject.exec(:finish)
76
80
  execute.should be_true
77
81
  end
82
+
83
+ context "when checking block before executing hook" do
84
+ it "should execute hooks." do
85
+ exec_flag = {}
86
+ subject.add(:finish) do |server|
87
+ exec_flag[:first] = true
88
+ end
89
+ subject.add(:finish) do |server|
90
+ exec_flag[:second] = true
91
+ end
92
+ subject.exec(:finish) do |name|
93
+ name.should be_an_instance_of String
94
+ true
95
+ end
96
+ exec_flag[:first].should be_true
97
+ exec_flag[:second].should be_true
98
+ end
99
+
100
+ it "should execute finish_exit that is special proc." do
101
+ execute = nil
102
+ subject.set_finish_exit do
103
+ execute = true
104
+ end
105
+ subject.exec(:finish) do |name|
106
+ name.should be_an_instance_of String
107
+ true
108
+ end
109
+ execute.should be_true
110
+ end
111
+
112
+ it "should not execute hooks." do
113
+ exec_flag = {}
114
+ subject.add(:finish) do |server|
115
+ exec_flag[:first] = true
116
+ end
117
+ subject.add(:finish) do |server|
118
+ exec_flag[:second] = true
119
+ end
120
+ subject.exec(:finish) do |name|
121
+ name.should be_an_instance_of String
122
+ false
123
+ end
124
+ exec_flag[:first].should be_nil
125
+ exec_flag[:second].should be_nil
126
+ end
127
+
128
+ it "should not execute finish_exit that is special proc." do
129
+ execute = nil
130
+ subject.set_finish_exit do
131
+ execute = true
132
+ end
133
+ subject.exec(:finish) do |name|
134
+ name.should be_an_instance_of String
135
+ false
136
+ end
137
+ execute.should be_nil
138
+ end
139
+ end
78
140
  end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DRbQS::Setting::Base do
4
+ it "should get default registered options." do
5
+ obj = DRbQS::Setting::Base.new
6
+ obj.source.registered_keys.sort.should == [:debug].sort
7
+ end
8
+
9
+ it "should register built-in options." do
10
+ obj = DRbQS::Setting::Base.new(:all_keys_defined => true, :log_level => true, :daemon => true)
11
+ obj.source.registered_keys.sort.should == [:debug, :log_level, :daemon].sort
12
+ end
13
+
14
+ it "should return string for shell." do
15
+ obj = DRbQS::Setting::Base.new(:all_keys_defined => true, :log_level => true, :daemon => true)
16
+ obj.value.log_level 'debug'
17
+ obj.value.daemon '/path/to/log'
18
+ obj.parse!
19
+ str = obj.string_for_shell
20
+ str.should match(/--log-level/)
21
+ str.should match(/--daemon/)
22
+ str.should match(/debug/)
23
+ str.should match(/\/path\/to\/log/)
24
+ end
25
+
26
+ it "should not change when executing parse! twice." do
27
+ obj = DRbQS::Setting::Base.new(:all_keys_defined => true, :log_level => true, :daemon => true)
28
+ obj.value.log_level 'debug'
29
+ obj.value.daemon '/path/to/log'
30
+ obj.parse!
31
+ lambda do
32
+ obj.parse!
33
+ end.should_not change(obj, :string_for_shell)
34
+ end
35
+ end
@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ require 'drbqs/setting/setting'
4
+
5
+ describe DRbQS::Setting::Source::DataContainer do
6
+ subject do
7
+ DRbQS::Setting::Source::DataContainer.new(Array)
8
+ end
9
+
10
+ context "when setting values" do
11
+ it "should set a value." do
12
+ subject.one_argument 3
13
+ subject.__data__[:one_argument].should == [3]
14
+ end
15
+
16
+ it "should set values." do
17
+ subject.some_arguments 'hello', 123, 'world'
18
+ subject.__data__[:some_arguments].should == ['hello', 123, 'world']
19
+ end
20
+
21
+ it "should set a value by a method with '='." do
22
+ subject.one_argument = 3
23
+ subject.__data__[:one_argument].should == [3]
24
+ end
25
+
26
+ it "should set values by a method with '='." do
27
+ subject.some_arguments = 'hello', 123, 'world'
28
+ subject.__data__[:some_arguments].should == ['hello', 123, 'world']
29
+ end
30
+
31
+ it "should delete values with a string key." do
32
+ subject.delete_key = 'abc', 'def'
33
+ lambda do
34
+ subject.__delete__('delete_key')
35
+ end.should change { subject.delete_key }.from(['abc', 'def']).to(nil)
36
+ end
37
+
38
+ it "should delete values with a symbol key." do
39
+ subject.delete_key = 'abc', 'def'
40
+ lambda do
41
+ subject.__delete__(:delete_key)
42
+ end.should change { subject.delete_key }.from(['abc', 'def']).to(nil)
43
+ end
44
+
45
+ it "should set nil." do
46
+ subject.nil_key = nil
47
+ subject.__data__[:nil_key].should == [nil]
48
+ end
49
+ end
50
+
51
+ context "when setting arguments" do
52
+ it "should add an argument" do
53
+ subject.argument << 'hello'
54
+ subject.argument.should include('hello')
55
+ end
56
+
57
+ it "should set argumets" do
58
+ subject.argument = ['ABC', 'DEF']
59
+ subject.argument.should == ['ABC', 'DEF']
60
+ end
61
+
62
+ it "should unshift an argument" do
63
+ subject.argument = ['ABC', 'DEF']
64
+ subject.argument.unshift('first')
65
+ subject.argument.should == ['first', 'ABC', 'DEF']
66
+ end
67
+ end
68
+
69
+ context "when cloning" do
70
+ it "should have same values." do
71
+ subject.argument = ['hello']
72
+ subject.some_key1 = [1, 2]
73
+ subject.some_key2 = 'ABCDE'
74
+ container_clone = DRbQS::Setting::Source.clone_container(subject)
75
+ subject.argument.should == container_clone.argument
76
+ end
77
+
78
+ it "should have a different argument." do
79
+ subject.argument = ['hello']
80
+ container_clone = DRbQS::Setting::Source.clone_container(subject)
81
+ subject.argument << 'world'
82
+ subject.argument.should_not == container_clone.argument
83
+ end
84
+
85
+ it "should have different values." do
86
+ subject.key1 = 'abc'
87
+ container_clone = DRbQS::Setting::Source.clone_container(subject)
88
+ subject.key1 = 'def'
89
+ subject.key1.should_not == container_clone.key1
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DRbQS::Setting::Execute do
4
+ subject do
5
+ DRbQS::Setting::Execute.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('first', 'second')
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(:port, 123)
28
+ subject.set(:server, 'server')
29
+ subject.set(:node, 'node')
30
+ subject.set(:no_server)
31
+ subject.set(:no_node)
32
+ subject.set_argument('one')
33
+ lambda do
34
+ subject.parse!
35
+ end.should_not raise_error
36
+ end
37
+
38
+ it "should not change string for shell." do
39
+ subject.set(:port, 123)
40
+ subject.set(:server, 'server')
41
+ subject.set(:node, 'node')
42
+ subject.set(:no_server)
43
+ subject.set(:no_node)
44
+ subject.set_argument('one')
45
+ subject.parse!
46
+ lambda do
47
+ subject.parse!
48
+ end.should_not change(subject, :string_for_shell)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DRbQS::Setting::Manage do
4
+ subject do
5
+ DRbQS::Setting::Manage.new
6
+ end
7
+
8
+ context "when there are invalid arguments" do
9
+ it "should raise error by an invalid mode." do
10
+ subject.set_argument('first', 'second')
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
+
24
+ [['process', 'invalid_command'],
25
+ ['send', 'invalid_type', 'uri', 'string']].each do |args|
26
+ it "should raise error for #{args.inspect}." do
27
+ subject.set_argument(*args)
28
+ lambda do
29
+ subject.parse!
30
+ end.should raise_error
31
+ end
32
+ end
33
+ end
34
+
35
+ context "when parsing" do
36
+ [['signal', 'uri', 'server-exit'],
37
+ ['signal', 'uri', 'node-exit-after-task', '3'],
38
+ ['signal', 'uri', 'node-wake', '4'],
39
+ ['signal', 'uri', 'node-sleep', '5'],
40
+ ['status', 'uri'],
41
+ ['history', 'uri'],
42
+ ['process', 'list'],
43
+ ['process', 'clear'],
44
+ ['send', 'string', 'uri', 'string'],
45
+ ['send', 'file', 'uri', __FILE__],
46
+ ['initialize']].each do |args|
47
+ it "should not raise error for #{args.inspect}." do
48
+ subject.set_argument(*args)
49
+ lambda do
50
+ subject.parse!
51
+ end.should_not raise_error
52
+ end
53
+
54
+ it "should not change string for shell for #{args.inspect}." do
55
+ subject.set_argument(*args)
56
+ subject.parse!
57
+ lambda do
58
+ subject.parse!
59
+ end.should_not change(subject, :string_for_shell)
60
+ end
61
+ end
62
+ end
63
+ end