drbqs 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -7
- data/README.md +52 -11
- data/Rakefile +32 -10
- data/VERSION +1 -1
- data/bin/drbqs-manage +3 -93
- data/bin/drbqs-node +3 -89
- data/bin/drbqs-server +3 -117
- data/bin/drbqs-ssh +6 -0
- data/drbqs.gemspec +118 -97
- data/example/README.md +2 -2
- data/lib/drbqs/config/config.rb +88 -0
- data/lib/drbqs/config/process_list.rb +194 -0
- data/lib/drbqs/config/ssh_host.rb +41 -0
- data/lib/drbqs/{execute_node.rb → manage/execute_node.rb} +6 -4
- data/lib/drbqs/manage/manage.rb +100 -0
- data/lib/drbqs/manage/send_signal.rb +45 -0
- data/lib/drbqs/manage/ssh_execute.rb +23 -0
- data/lib/drbqs/manage/ssh_shell.rb +143 -0
- data/lib/drbqs/node/connection.rb +69 -0
- data/lib/drbqs/{client.rb → node/node.rb} +48 -18
- data/lib/drbqs/node/task_client.rb +94 -0
- data/lib/drbqs/server/acl_file.rb +15 -0
- data/lib/drbqs/server/check_alive.rb +23 -0
- data/lib/drbqs/server/history.rb +49 -0
- data/lib/drbqs/server/message.rb +142 -0
- data/lib/drbqs/server/node_list.rb +59 -0
- data/lib/drbqs/server/queue.rb +128 -0
- data/lib/drbqs/{server.rb → server/server.rb} +66 -74
- data/lib/drbqs/server/server_hook.rb +72 -0
- data/lib/drbqs/server/transfer_setting.rb +30 -0
- data/lib/drbqs/task/command_task.rb +43 -0
- data/lib/drbqs/{task.rb → task/task.rb} +18 -39
- data/lib/drbqs/{task_generator.rb → task/task_generator.rb} +2 -0
- data/lib/drbqs/utility/argument.rb +27 -0
- data/lib/drbqs/utility/command_line/command_base.rb +27 -0
- data/lib/drbqs/utility/command_line/command_manage.rb +121 -0
- data/lib/drbqs/utility/command_line/command_node.rb +103 -0
- data/lib/drbqs/utility/command_line/command_server.rb +165 -0
- data/lib/drbqs/utility/command_line/command_ssh.rb +126 -0
- data/lib/drbqs/utility/command_line.rb +15 -0
- data/lib/drbqs/utility/misc.rb +72 -0
- data/lib/drbqs/{server_define.rb → utility/server_define.rb} +23 -8
- data/lib/drbqs/utility/temporary.rb +49 -0
- data/lib/drbqs/{ssh/transfer.rb → utility/transfer/file_transfer.rb} +18 -58
- data/lib/drbqs/utility/transfer/transfer_client.rb +90 -0
- data/lib/drbqs.rb +10 -22
- data/spec/config/config_spec.rb +84 -0
- data/spec/config/process_list_spec.rb +149 -0
- data/spec/config/ssh_host_spec.rb +81 -0
- data/spec/integration_test/01_basic_usage_spec.rb +54 -0
- data/spec/integration_test/02_use_generator_spec.rb +53 -0
- data/spec/integration_test/03_use_temporary_file_spec.rb +26 -0
- data/spec/integration_test/04_use_unix_domain_spec.rb +34 -0
- data/spec/integration_test/05_server_exit_signal_spec.rb +23 -0
- data/spec/integration_test/06_node_exit_after_task_spec.rb +42 -0
- data/spec/integration_test/07_command_server_with_node_spec.rb +44 -0
- data/spec/integration_test/definition/server01.rb +20 -0
- data/spec/integration_test/definition/server02.rb +16 -0
- data/spec/integration_test/definition/task_obj_definition.rb +49 -0
- data/spec/manage/manage_spec.rb +33 -0
- data/spec/manage/send_signal_spec.rb +39 -0
- data/spec/{ssh_shell_spec.rb → manage/ssh_shell_spec.rb} +8 -8
- data/spec/node/connection_spec.rb +66 -0
- data/spec/node/task_client_spec.rb +212 -0
- data/spec/server/acl_file_spec.rb +9 -0
- data/spec/{server_check_alive_spec.rb → server/check_alive_spec.rb} +15 -11
- data/spec/{data → server/data}/acl.txt +0 -0
- data/spec/{history_spec.rb → server/history_spec.rb} +9 -5
- data/spec/server/message_spec.rb +195 -0
- data/spec/server/node_list_spec.rb +111 -0
- data/spec/server/queue_spec.rb +239 -0
- data/spec/{server_hook_spec.rb → server/server_hook_spec.rb} +23 -17
- data/spec/server/server_spec.rb +89 -0
- data/spec/server/transfer_setting_spec.rb +37 -0
- data/spec/spec_helper.rb +65 -0
- data/spec/task/file_transfer_spec.rb +107 -0
- data/spec/{task_generator_spec.rb → task/task_generator_spec.rb} +2 -2
- data/spec/{task_spec.rb → task/task_spec.rb} +3 -1
- data/spec/utility/argument_spec.rb +39 -0
- data/spec/utility/command_line/command_base_spec.rb +33 -0
- data/spec/utility/command_line/commands_spec.rb +15 -0
- data/spec/utility/misc_spec.rb +77 -0
- data/spec/utility/server_define_spec.rb +59 -0
- data/spec/utility/temporary_spec.rb +39 -0
- metadata +158 -93
- data/example/drbqs-manage-test.rb +0 -3
- data/example/drbqs-node-test.rb +0 -3
- data/example/drbqs-server-test.rb +0 -3
- data/lib/drbqs/acl_file.rb +0 -13
- data/lib/drbqs/config.rb +0 -98
- data/lib/drbqs/connection.rb +0 -67
- data/lib/drbqs/history.rb +0 -34
- data/lib/drbqs/manage.rb +0 -84
- data/lib/drbqs/message.rb +0 -119
- data/lib/drbqs/node_list.rb +0 -52
- data/lib/drbqs/queue.rb +0 -138
- data/lib/drbqs/server_hook.rb +0 -67
- data/lib/drbqs/ssh/host.rb +0 -26
- data/lib/drbqs/ssh/shell.rb +0 -139
- data/lib/drbqs/task_client.rb +0 -86
- data/lib/drbqs/utils.rb +0 -19
- data/spec/acl_file_spec.rb +0 -9
- data/spec/config_spec.rb +0 -14
- data/spec/connection_spec.rb +0 -49
- data/spec/manage_spec.rb +0 -57
- data/spec/message_spec.rb +0 -81
- data/spec/node_list_spec.rb +0 -68
- data/spec/queue_spec.rb +0 -59
- data/spec/server_define_spec.rb +0 -45
- data/spec/server_spec.rb +0 -56
- data/spec/task_client_spec.rb +0 -53
- data/spec/test/test1.rb +0 -13
- data/spec/test1_spec.rb +0 -80
- data/spec/test2_spec.rb +0 -69
- data/spec/transfer_spec.rb +0 -13
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/server/node_list'
|
4
|
+
|
5
|
+
describe DRbQS::Server::NodeList do
|
6
|
+
before(:all) do
|
7
|
+
@count = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
subject do
|
11
|
+
DRbQS::Server::NodeList.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_id_string
|
15
|
+
sprintf("ID_%05d", (@count += 1))
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when checking nodes" do
|
19
|
+
it "should be empty." do
|
20
|
+
subject.empty?.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not be empty." do
|
24
|
+
subject.get_new_id(create_id_string)
|
25
|
+
subject.empty?.should_not be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true for existence of node id" do
|
29
|
+
id = subject.get_new_id(create_id_string)
|
30
|
+
subject.exist?(id).should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not return true for nonexistent node id" do
|
34
|
+
subject.exist?(-100).should_not be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when managing nodes" do
|
39
|
+
it "should get ids that are not duplicated." do
|
40
|
+
id_strings = 10.times.map do |i|
|
41
|
+
create_id_string
|
42
|
+
end.uniq
|
43
|
+
id_nums = id_strings.map do |str|
|
44
|
+
subject.get_new_id(str)
|
45
|
+
end
|
46
|
+
id_nums.should have(id_strings.size).items
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should yield each nodes." do
|
50
|
+
id_data = 10.times.map do |i|
|
51
|
+
id_str = create_id_string
|
52
|
+
[id_str, subject.get_new_id(id_str)]
|
53
|
+
end
|
54
|
+
subject.each do |id_num, id_str|
|
55
|
+
id_data.assoc(id_str)[1].should == id_num
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should delete a node" do
|
60
|
+
id = subject.get_new_id(create_id_string)
|
61
|
+
subject.delete(id)
|
62
|
+
subject.exist?(id).should_not be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when setting alive checkings" do
|
67
|
+
it "should delete all ids" do
|
68
|
+
5.times do |i|
|
69
|
+
subject.get_new_id(create_id_string)
|
70
|
+
end
|
71
|
+
subject.set_check_connection
|
72
|
+
subject.delete_not_alive
|
73
|
+
subject.empty?.should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should set alive flag" do
|
77
|
+
delete_ids = 3.times.map do |i|
|
78
|
+
subject.get_new_id(create_id_string)
|
79
|
+
end
|
80
|
+
alive_ids = 3.times.map do |i|
|
81
|
+
subject.get_new_id(create_id_string)
|
82
|
+
end
|
83
|
+
subject.set_check_connection
|
84
|
+
alive_ids.each do |id|
|
85
|
+
subject.set_alive(id)
|
86
|
+
end
|
87
|
+
subject.delete_not_alive
|
88
|
+
alive_ids.all? do |id|
|
89
|
+
subject.exist?(id)
|
90
|
+
end.should be_true
|
91
|
+
delete_ids.all? do |id|
|
92
|
+
!subject.exist?(id)
|
93
|
+
end.should be_true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when managing history" do
|
98
|
+
it "should add to history" do
|
99
|
+
subject.history.should_receive(:set).with(1, :connect, 'hello')
|
100
|
+
subject.get_new_id('hello')
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should set disconnection to history" do
|
104
|
+
subject.get_new_id('hello')
|
105
|
+
subject.set_check_connection
|
106
|
+
subject.history.should_receive(:set).with(1, :disconnect)
|
107
|
+
subject.delete_not_alive
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,239 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/server/queue'
|
4
|
+
require 'drbqs/task/task'
|
5
|
+
|
6
|
+
describe DRbQS::Server::Queue do
|
7
|
+
def object_init
|
8
|
+
@ts = {
|
9
|
+
:queue => Rinda::TupleSpace.new,
|
10
|
+
:result => Rinda::TupleSpace.new
|
11
|
+
}
|
12
|
+
@queue_server = DRbQS::Server::Queue.new(@ts[:queue], @ts[:result])
|
13
|
+
@server_dummy = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
subject do
|
17
|
+
@queue_server
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:all) do
|
21
|
+
@task = { :obj => DRbQS::Task.new([1, 2, 3], :size, []), :id => nil }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when initializing queue" do
|
25
|
+
before(:all) do
|
26
|
+
object_init
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return number of acceptances of signals." do
|
30
|
+
subject.get_accept_signal.should == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return number of acceptances of resultss." do
|
34
|
+
subject.get_result(@server_dummy).should == 0
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have no calculating task." do
|
38
|
+
subject.calculating_task_number.should == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be empty." do
|
42
|
+
subject.should be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be finished." do
|
46
|
+
subject.should be_finished
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when adding a task" do
|
51
|
+
before(:all) do
|
52
|
+
object_init
|
53
|
+
@task_id = subject.add(@task[:obj])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return number of acceptances of signals." do
|
57
|
+
subject.get_accept_signal.should == 0
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return number of acceptances of resultss." do
|
61
|
+
subject.get_result(@server_dummy).should == 0
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have no calculating task." do
|
65
|
+
subject.calculating_task_number.should == 0
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not be empty." do
|
69
|
+
subject.empty?.should be_false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not be finished." do
|
73
|
+
subject.finished?.should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should take objects from queue." do
|
77
|
+
@ts[:queue].take([nil, nil, nil, nil]).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when getting accept signal" do
|
82
|
+
before(:all) do
|
83
|
+
object_init
|
84
|
+
@node_id = 100
|
85
|
+
@task_id = subject.add(@task[:obj])
|
86
|
+
@ts[:result].write([:accept, @task_id, 100])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return number of acceptances of signals." do
|
90
|
+
subject.get_accept_signal.should == 1
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return number of acceptances of resultss." do
|
94
|
+
subject.get_result(@server_dummy).should == 0
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return number of calculating task." do
|
98
|
+
subject.calculating_task_number.should == 1
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should be empty." do
|
102
|
+
subject.should be_empty
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not be finished." do
|
106
|
+
subject.should_not be_finished
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should take objects from queue." do
|
110
|
+
@ts[:result].read_all([nil, nil, nil]).size.should == 0
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when getting result" do
|
115
|
+
before(:all) do
|
116
|
+
object_init
|
117
|
+
@node_id = 100
|
118
|
+
@task_id = subject.add(@task[:obj])
|
119
|
+
@ts[:result].write([:accept, @task_id, 100])
|
120
|
+
subject.get_accept_signal
|
121
|
+
@ts[:result].write([:result, @task_id, @node_id, :result_object])
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should return number of acceptances of signals." do
|
125
|
+
subject.get_accept_signal.should == 0
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return number of acceptances of resultss." do
|
129
|
+
subject.get_result(@server_dummy).should == 1
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return number of calculating task." do
|
133
|
+
subject.calculating_task_number.should == 0
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should be empty." do
|
137
|
+
subject.should be_empty
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should not be finished." do
|
141
|
+
subject.should be_finished
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when requeueing a task" do
|
146
|
+
before(:all) do
|
147
|
+
object_init
|
148
|
+
@node_id = 100
|
149
|
+
@task_id = subject.add(@task[:obj])
|
150
|
+
@ts[:result].write([:accept, @task_id, 100])
|
151
|
+
subject.get_accept_signal
|
152
|
+
subject.requeue_for_deleted_node_id([@node_id])
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should return number of acceptances of signals." do
|
156
|
+
subject.get_accept_signal.should == 0
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should return number of acceptances of resultss." do
|
160
|
+
subject.get_result(@server_dummy).should == 0
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should return number of calculating task." do
|
164
|
+
subject.calculating_task_number.should == 0
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should be empty." do
|
168
|
+
subject.should_not be_empty
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should not be finished." do
|
172
|
+
subject.should_not be_finished
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should return task ID." do
|
176
|
+
(ary = @ts[:queue].take([nil, nil, nil, nil])).should be_true
|
177
|
+
ary[0].should == @task_id
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "when executing hook of task" do
|
182
|
+
before(:all) do
|
183
|
+
object_init
|
184
|
+
@result_dummy = nil
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should do nothing" do
|
188
|
+
subject.exec_task_hook(@server_dummy, 1, @result_dummy).should be_false
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should execute hook of task" do
|
192
|
+
task_id = subject.add(@task[:obj])
|
193
|
+
@task_id = subject.add(@task[:obj])
|
194
|
+
@ts[:result].write([:accept, @task_id, 100])
|
195
|
+
subject.get_accept_signal
|
196
|
+
@ts[:result].write([:result, @task_id, @node_id, :result_object])
|
197
|
+
subject.get_result(@server_dummy)
|
198
|
+
@task[:obj].should_receive(:exec_hook)
|
199
|
+
subject.exec_task_hook(@server_dummy, task_id, @result_dummy).should be_true
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when managing some tasks" do
|
204
|
+
before(:all) do
|
205
|
+
@task_ary = [DRbQS::Task.new([1, 2, 3], :size, []),
|
206
|
+
DRbQS::Task.new([1, 3], :size, []),
|
207
|
+
DRbQS::Task.new([2, 1, 2, 3], :size, [])]
|
208
|
+
object_init
|
209
|
+
@node_id = 100
|
210
|
+
@task_id_ary = @task_ary.map do |task|
|
211
|
+
subject.add(task)
|
212
|
+
end
|
213
|
+
@ts[:result].write([:accept, @task_id_ary[0], 100])
|
214
|
+
@ts[:result].write([:accept, @task_id_ary[1], 101])
|
215
|
+
@ts[:result].write([:result, @task_id_ary[0], @node_id, :result_object])
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should return number of acceptances of signals." do
|
219
|
+
subject.get_accept_signal.should == 2
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should return number of acceptances of resultss." do
|
223
|
+
subject.get_result(@server_dummy).should == 1
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should return number of calculating task." do
|
227
|
+
subject.calculating_task_number.should == 1
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should be empty." do
|
231
|
+
subject.should_not be_empty
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should not be finished." do
|
235
|
+
subject.should_not be_finished
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
@@ -1,24 +1,30 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
require 'drbqs/server_hook'
|
3
|
+
require 'drbqs/server/server_hook'
|
4
4
|
|
5
|
-
describe DRbQS::
|
6
|
-
subject { DRbQS::
|
5
|
+
describe DRbQS::Server::Hook do
|
6
|
+
subject { DRbQS::Server::Hook.new }
|
7
7
|
|
8
|
-
it "should add hook" do
|
9
|
-
subject.
|
8
|
+
it "should add a hook with automatic creation of name." do
|
9
|
+
n = subject.number_of_hook(:finish)
|
10
|
+
name = subject.add(:finish) do |server|
|
10
11
|
3 + 4
|
11
|
-
end
|
12
|
+
end
|
13
|
+
name.should match(/^finish\d+/)
|
14
|
+
subject.number_of_hook(:finish).should == (n + 1)
|
12
15
|
end
|
13
16
|
|
14
|
-
it "should add hook with name" do
|
17
|
+
it "should add a hook with name." do
|
18
|
+
n = subject.number_of_hook(:finish)
|
15
19
|
name = 'hello'
|
16
|
-
subject.add(:finish, name) do |server|
|
20
|
+
name_new = subject.add(:finish, name) do |server|
|
17
21
|
3 + 4
|
18
|
-
end
|
22
|
+
end
|
23
|
+
name_new.should == name
|
24
|
+
subject.number_of_hook(:finish).should == (n + 1)
|
19
25
|
end
|
20
26
|
|
21
|
-
it "should raise error" do
|
27
|
+
it "should raise error for invalid number of block arguments." do
|
22
28
|
lambda do
|
23
29
|
subject.add(:finish) do |a, b|
|
24
30
|
a + b
|
@@ -26,29 +32,29 @@ describe DRbQS::ServerHook do
|
|
26
32
|
end.should raise_error
|
27
33
|
end
|
28
34
|
|
29
|
-
it "should delete hook" do
|
35
|
+
it "should delete a hook." do
|
30
36
|
name = subject.add(:finish) do |server|
|
31
37
|
3 + 4
|
32
38
|
end
|
33
|
-
subject.
|
39
|
+
subject.number_of_hook(:finish).should == 1
|
34
40
|
subject.hook_names(:finish).should include(name)
|
35
41
|
subject.delete(:finish, name)
|
36
42
|
subject.hook_names(:finish).should be_empty
|
37
43
|
end
|
38
44
|
|
39
|
-
it "should delete all hooks" do
|
45
|
+
it "should delete all hooks." do
|
40
46
|
name = subject.add(:finish) do |server|
|
41
47
|
3 + 4
|
42
48
|
end
|
43
49
|
name = subject.add(:finish) do |server|
|
44
50
|
5 + 6
|
45
51
|
end
|
46
|
-
subject.
|
52
|
+
subject.number_of_hook(:finish).should == 2
|
47
53
|
subject.delete(:finish)
|
48
54
|
subject.hook_names(:finish).should be_empty
|
49
55
|
end
|
50
56
|
|
51
|
-
it "should execute hooks" do
|
57
|
+
it "should execute hooks." do
|
52
58
|
exec_flag = {}
|
53
59
|
subject.add(:finish) do |server|
|
54
60
|
exec_flag[:first] = true
|
@@ -61,7 +67,7 @@ describe DRbQS::ServerHook do
|
|
61
67
|
exec_flag[:second].should be_true
|
62
68
|
end
|
63
69
|
|
64
|
-
it "should execute finish_exit" do
|
70
|
+
it "should execute finish_exit that is special proc." do
|
65
71
|
execute = nil
|
66
72
|
subject.set_finish_exit do
|
67
73
|
execute = true
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DRbQS::Server do
|
4
|
+
context "when loading ACL for druby" do
|
5
|
+
it "should initialize an ACL object by ACLFile.load" do
|
6
|
+
path = File.dirname(__FILE__) + '/data/acl.txt'
|
7
|
+
DRbQS::Server::ACLFile.should_receive(:load).with(path)
|
8
|
+
DRbQS::Server.new(:acl => path, :log_file => nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should initialize an ACL object by ACL.new" do
|
12
|
+
ary = ['deny', 'all', 'allow', 'localhost']
|
13
|
+
ACL.should_receive(:new).with(ary)
|
14
|
+
DRbQS::Server.new(:acl => ary, :log_file => nil)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when we initialize uri of server" do
|
19
|
+
it "should raise error for existing path" do
|
20
|
+
lambda do
|
21
|
+
DRbQS::Server.new(:unix => __FILE__)
|
22
|
+
end.should raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise error for none of parent directory" do
|
26
|
+
lambda do
|
27
|
+
DRbQS::Server.new(:unix => "not_exist/dir/abc")
|
28
|
+
end.should raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should get default uri" do
|
32
|
+
server = DRbQS::Server.new
|
33
|
+
server.uri.should == "druby://:#{DRbQS::ROOT_DEFAULT_PORT}"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should get uri of tcp" do
|
37
|
+
server = DRbQS::Server.new(:port => 9999)
|
38
|
+
server.uri.should == "druby://:9999"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should get uri of unix domain" do
|
42
|
+
server = DRbQS::Server.new(:unix => "/tmp/drbqs")
|
43
|
+
server.uri.should == "drbunix:/tmp/drbqs"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should prefer port number option" do
|
47
|
+
server = DRbQS::Server.new(:unix => "/tmp/drbqs", :port => 9999)
|
48
|
+
server.uri.should == "druby://:9999"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when initializing server" do
|
53
|
+
it "should call set_signal_trap." do
|
54
|
+
Signal.should_receive(:trap).with(:TERM)
|
55
|
+
DRbQS::Server.new(:signal_trap => true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set finish hook" do
|
59
|
+
server_hook = mock
|
60
|
+
DRbQS::Server::Hook.stub!(:new).and_return(server_hook)
|
61
|
+
server_hook.should_receive(:set_finish_exit)
|
62
|
+
DRbQS::Server.new(:finish_exit => true)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when starting DRbQS::Server" do
|
67
|
+
it "should not set DRbQS::FileTransfer" do
|
68
|
+
server = DRbQS::Server.new
|
69
|
+
DRbQS::TransferClient.should_not_receive(:new)
|
70
|
+
DRb.should_receive(:start_service).once
|
71
|
+
server.start
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should set DRbQS::FileTransfer" do
|
75
|
+
server = DRbQS::Server.new(:file_directory => '/tmp', :sftp_user => 'hello', :sftp_host => 'example.com')
|
76
|
+
DRbQS::TransferClient::SFTP.should_receive(:new).with('hello', 'example.com', '/tmp')
|
77
|
+
DRb.should_receive(:start_service).once
|
78
|
+
server.start
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set DRbQS::FileTransfer by DRbQS::Server#set_file_transfer with optional arguments" do
|
82
|
+
server = DRbQS::Server.new
|
83
|
+
DRbQS::TransferClient::SFTP.should_receive(:new).with('hello', 'example.com', '/tmp')
|
84
|
+
DRb.should_receive(:start_service).once
|
85
|
+
server.set_file_transfer('/tmp', :user => 'hello', :host => 'example.com')
|
86
|
+
server.start
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/utility/temporary'
|
4
|
+
|
5
|
+
describe DRbQS::Server::TransferSetting do
|
6
|
+
it "should return nil." do
|
7
|
+
setting = DRbQS::Server::TransferSetting.new('example.com', 'user', nil)
|
8
|
+
setting.create(nil).should be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return transfer client." do
|
12
|
+
dir = DRbQS::Temporary.file
|
13
|
+
setting = DRbQS::Server::TransferSetting.new('example.com', 'user', dir)
|
14
|
+
client = setting.create(nil)
|
15
|
+
client.should be_an_instance_of DRbQS::TransferClient
|
16
|
+
client.sftp.should be_an_instance_of DRbQS::TransferClient::SFTP
|
17
|
+
setting.create(nil).should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return transfer client with a directory argument." do
|
21
|
+
dir = DRbQS::Temporary.file
|
22
|
+
setting = DRbQS::Server::TransferSetting.new('example.com', 'user', nil)
|
23
|
+
client = setting.create(dir)
|
24
|
+
client.should be_an_instance_of DRbQS::TransferClient
|
25
|
+
client.sftp.should be_an_instance_of DRbQS::TransferClient::SFTP
|
26
|
+
setting.create(dir).should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return transfer client without sftp" do
|
30
|
+
dir = DRbQS::Temporary.file
|
31
|
+
setting = DRbQS::Server::TransferSetting.new(nil, nil, dir)
|
32
|
+
client = setting.create(nil)
|
33
|
+
client.should be_an_instance_of DRbQS::TransferClient
|
34
|
+
client.sftp.should be_nil
|
35
|
+
setting.create(nil).should be_nil
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
4
|
require 'drbqs'
|
5
|
+
require 'drbqs/manage/manage'
|
5
6
|
|
6
7
|
# Requires supporting files with custom matchers and macros, etc,
|
7
8
|
# in ./support/ and its subdirectories.
|
@@ -10,3 +11,67 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
10
11
|
RSpec.configure do |config|
|
11
12
|
|
12
13
|
end
|
14
|
+
|
15
|
+
HOME_FOR_SPEC = File.join(File.dirname(__FILE__), 'home_for_spec')
|
16
|
+
|
17
|
+
DRbQS::Config.set_home_directory(HOME_FOR_SPEC)
|
18
|
+
|
19
|
+
def drbqs_test_tuple_space(uri)
|
20
|
+
ts = {
|
21
|
+
:message => Rinda::TupleSpace.new,
|
22
|
+
:queue => Rinda::TupleSpace.new,
|
23
|
+
:result => Rinda::TupleSpace.new,
|
24
|
+
:transfer => nil
|
25
|
+
}
|
26
|
+
DRb.start_service(uri, ts)
|
27
|
+
ts
|
28
|
+
end
|
29
|
+
|
30
|
+
def drbqs_wait_kill_server(process_id, wait_time = 10)
|
31
|
+
i = 0
|
32
|
+
while !Process.waitpid(process_id, Process::WNOHANG)
|
33
|
+
i += 1
|
34
|
+
if i > wait_time
|
35
|
+
Process.kill(:KILL, process_id)
|
36
|
+
raise "Server process does not finish."
|
37
|
+
end
|
38
|
+
sleep(1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def drbqs_fork_server(uri_arg, task_args, opts = {})
|
43
|
+
if Integer === uri_arg
|
44
|
+
server_args = { :port => uri_arg }
|
45
|
+
uri = "druby://:#{uri_arg}"
|
46
|
+
else
|
47
|
+
server_args = { :unix => uri_arg }
|
48
|
+
uri = "drbunix:#{uri_arg}"
|
49
|
+
end
|
50
|
+
|
51
|
+
pid = fork do
|
52
|
+
server = DRbQS::Server.new(server_args)
|
53
|
+
|
54
|
+
unless task_args.respond_to?(:each)
|
55
|
+
task_args = [task_args]
|
56
|
+
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)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
unless opts[:continue]
|
66
|
+
server.add_hook(:finish) do |serv|
|
67
|
+
serv.exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
server.set_signal_trap
|
72
|
+
server.start
|
73
|
+
server.wait
|
74
|
+
end
|
75
|
+
sleep(opts[:sleep] || 1)
|
76
|
+
[pid, uri]
|
77
|
+
end
|