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
data/spec/connection_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'drbqs/connection.rb'
|
4
|
-
|
5
|
-
describe DRbQS::ConnectionClient do
|
6
|
-
before(:all) do
|
7
|
-
@message = Rinda::TupleSpace.new
|
8
|
-
@connection = DRbQS::ConnectionClient.new(@message)
|
9
|
-
@node_id = 23
|
10
|
-
id_string = @connection.instance_variable_get(:@id_string)
|
11
|
-
@message.write([id_string, @node_id])
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should get node ID." do
|
15
|
-
@connection.get_id.should == @node_id
|
16
|
-
@message.take([:server, :connect, nil], 0).should be_true
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should get no initialization method." do
|
20
|
-
@connection.get_initialization.should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should get initialization" do
|
24
|
-
ary = [:initialize, [1, 2], :size, []]
|
25
|
-
@message.write(ary)
|
26
|
-
@connection.get_initialization.should == ary[1..-1]
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should get no finalization method." do
|
30
|
-
@connection.get_finalization.should be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should get finalization" do
|
34
|
-
ary = [:finalize, [1, 2], :size, []]
|
35
|
-
@message.write(ary)
|
36
|
-
@connection.get_finalization.should == ary[1..-1]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should respond :alive_p signal" do
|
40
|
-
@message.write([@node_id, :alive_p])
|
41
|
-
@connection.respond_signal
|
42
|
-
@message.take([:server, :alive, nil], 0).should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should respond :exit signal" do
|
46
|
-
@message.write([@node_id, :exit])
|
47
|
-
@connection.respond_signal.should == :exit
|
48
|
-
end
|
49
|
-
end
|
data/spec/manage_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require_relative 'test/test1.rb'
|
4
|
-
|
5
|
-
describe DRbQS do
|
6
|
-
before(:all) do
|
7
|
-
@tasks = []
|
8
|
-
5.times do |i|
|
9
|
-
@tasks << DRbQS::Task.new(Test1.new, :echo, [i])
|
10
|
-
end
|
11
|
-
@process_id = fork do
|
12
|
-
server = DRbQS::Server.new(:port => 13501)
|
13
|
-
|
14
|
-
@tasks.each do |task|
|
15
|
-
server.queue.add(task)
|
16
|
-
end
|
17
|
-
|
18
|
-
server.add_hook(:finish) do |serv|
|
19
|
-
serv.exit
|
20
|
-
end
|
21
|
-
|
22
|
-
server.set_signal_trap
|
23
|
-
server.start
|
24
|
-
server.wait
|
25
|
-
end
|
26
|
-
sleep(1)
|
27
|
-
|
28
|
-
@uri = 'druby://:13501'
|
29
|
-
|
30
|
-
@manage = DRbQS::Manage.new
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should send exit signal" do
|
34
|
-
lambda do
|
35
|
-
@manage.send_exit_signal(@uri)
|
36
|
-
end.should_not raise_error
|
37
|
-
lambda do
|
38
|
-
i = 0
|
39
|
-
while !Process.waitpid(@process_id, Process::WNOHANG)
|
40
|
-
i += 1
|
41
|
-
if i > 10
|
42
|
-
Process.kill(:KILL, @process_id)
|
43
|
-
raise "Server process does not finish."
|
44
|
-
end
|
45
|
-
sleep(1)
|
46
|
-
end
|
47
|
-
end.should_not raise_error
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should split arguments" do
|
51
|
-
ary = ['abc', 'def', '--', '123', '45', '6']
|
52
|
-
a1, a2 = DRbQS::Manage.split_arguments(ary)
|
53
|
-
a1.should == ['abc', 'def']
|
54
|
-
a2.should == ['123', '45', '6']
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
data/spec/message_spec.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'drbqs/message.rb'
|
4
|
-
|
5
|
-
describe DRbQS::MessageServer do
|
6
|
-
before(:all) do
|
7
|
-
@message = Rinda::TupleSpace.new
|
8
|
-
@message_server = DRbQS::MessageServer.new(@message)
|
9
|
-
@node_id_list = []
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should return nil" do
|
13
|
-
@message_server.get_message.should be_nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should have no node" do
|
17
|
-
@message_server.node_not_exist?.should be_true
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should set initialization task" do
|
21
|
-
lambda do
|
22
|
-
@message.take([:initialize, nil, Symbol, nil], 0)
|
23
|
-
end.should raise_error Rinda::RequestExpiredError
|
24
|
-
@message_server.set_initialization(DRbQS::Task.new(Object.new, :object_id))
|
25
|
-
@message.take([:initialize, nil, Symbol, nil], 0).should be_true
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should get :connect message" do
|
29
|
-
5.times do |i|
|
30
|
-
id_str = "connect_test_#{i}"
|
31
|
-
@message.write([:server, :connect, id_str])
|
32
|
-
@message_server.get_message
|
33
|
-
(ary = @message.take([id_str, Fixnum])).should be_true
|
34
|
-
@node_id_list << ary[1]
|
35
|
-
@message_server.node_not_exist?.should be_false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should get :alive message" do
|
40
|
-
node_id = 73
|
41
|
-
@message.write([:server, :alive, node_id])
|
42
|
-
node_list = @message_server.instance_variable_get(:@node_list)
|
43
|
-
node_list.should_receive(:set_alive).with(node_id)
|
44
|
-
@message_server.get_message
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should get :exit_server message" do
|
48
|
-
@message.write([:server, :exit_server, 'message_test'])
|
49
|
-
@message_server.get_message.should == [:exit_server]
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should send exit message" do
|
53
|
-
@message_server.send_exit
|
54
|
-
@node_id_list.each do |id|
|
55
|
-
@message.take([id, :exit]).should be_true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should delete a node" do
|
60
|
-
@message_server.check_connection.should == []
|
61
|
-
@node_id_list.each do |id|
|
62
|
-
@message.take([id, :alive_p]).should be_true
|
63
|
-
end
|
64
|
-
@message_server.check_connection.should == @node_id_list
|
65
|
-
@node_id_list.each do |id|
|
66
|
-
lambda do
|
67
|
-
@message.take([id, :alive_p], 0)
|
68
|
-
end.should raise_error Rinda::RequestExpiredError
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should get :request_status message" do
|
73
|
-
@message.write([:server, :request_status, 'message_test'])
|
74
|
-
@message_server.get_message.should == [:request_status]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should send status" do
|
78
|
-
@message_server.send_status({})
|
79
|
-
@message.take([:status, nil]).should be_true
|
80
|
-
end
|
81
|
-
end
|
data/spec/node_list_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'drbqs/node_list'
|
4
|
-
|
5
|
-
describe DRbQS::NodeList do
|
6
|
-
before(:all) do
|
7
|
-
@node_list = DRbQS::NodeList.new
|
8
|
-
@id_strings = 10.times.map { |i| sprintf("%05d", i) }
|
9
|
-
@id_list = []
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should be empty." do
|
13
|
-
@node_list.empty?.should be_true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should get ids that are not duplicated." do
|
17
|
-
@id_strings.each do |str|
|
18
|
-
@id_list << @node_list.get_new_id(str)
|
19
|
-
end
|
20
|
-
@id_list.uniq!
|
21
|
-
@id_list.all? { |i| Integer === i }.should be_true
|
22
|
-
@id_list.size.should == @id_strings.size
|
23
|
-
@node_list.each do |id_num, id_str|
|
24
|
-
@id_strings.include?(id_str).should be_true
|
25
|
-
@id_list.include?(id_num).should be_true
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should delete all ids" do
|
30
|
-
@node_list.empty?.should_not be_true
|
31
|
-
@node_list.set_check_connection
|
32
|
-
ids = @node_list.delete_not_alive
|
33
|
-
ids.sort.should == @id_list.sort
|
34
|
-
@node_list.empty?.should be_true
|
35
|
-
@id_list.clear
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should set alive flag" do
|
39
|
-
alive_id_num = [3, 4, 5]
|
40
|
-
@id_strings.each do |str|
|
41
|
-
@id_list << @node_list.get_new_id(str)
|
42
|
-
end
|
43
|
-
@node_list.set_check_connection
|
44
|
-
alive_id_num.each do |i|
|
45
|
-
@node_list.set_alive(@id_list[i])
|
46
|
-
end
|
47
|
-
@node_list.delete_not_alive
|
48
|
-
alive_ids = alive_id_num.map { |i| @id_list[i] }
|
49
|
-
@node_list.each do |id_num, id_str|
|
50
|
-
alive_ids.include?(id_num).should be_true
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should add to history" do
|
55
|
-
node_list = DRbQS::NodeList.new
|
56
|
-
node_list.history.should_receive(:set).with(1, :connect, 'hello')
|
57
|
-
node_list.get_new_id('hello')
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should set disconnection to history" do
|
61
|
-
node_list = DRbQS::NodeList.new
|
62
|
-
node_list.get_new_id('hello')
|
63
|
-
node_list.set_check_connection
|
64
|
-
node_list.history.should_receive(:set).with(1, :disconnect)
|
65
|
-
node_list.delete_not_alive
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
data/spec/queue_spec.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'drbqs/queue'
|
4
|
-
|
5
|
-
describe DRbQS::QueueServer do
|
6
|
-
before(:all) do
|
7
|
-
@ts = {
|
8
|
-
:queue => Rinda::TupleSpace.new,
|
9
|
-
:result => Rinda::TupleSpace.new
|
10
|
-
}
|
11
|
-
@queue_server = DRbQS::QueueServer.new(@ts[:queue], @ts[:result])
|
12
|
-
@task = { :obj => DRbQS::Task.new([1, 2, 3], :size, []), :id => nil }
|
13
|
-
@node_id = 100
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should be empty" do
|
17
|
-
@queue_server.calculating_task_number.should == 0
|
18
|
-
@queue_server.empty?.should be_true
|
19
|
-
@queue_server.finished?.should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should add a task" do
|
23
|
-
@task[:id] = @queue_server.add(@task[:obj])
|
24
|
-
@queue_server.calculating_task_number.should == 0
|
25
|
-
@queue_server.empty?.should be_false
|
26
|
-
@queue_server.finished?.should be_false
|
27
|
-
@ts[:queue].take([nil, nil, nil, nil]).should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should get accept signal" do
|
31
|
-
@ts[:result].write([:accept, @task[:id], @node_id])
|
32
|
-
@queue_server.get_accept_signal.should == 1
|
33
|
-
@queue_server.calculating_task_number.should == 1
|
34
|
-
@queue_server.empty?.should be_true
|
35
|
-
@queue_server.finished?.should be_false
|
36
|
-
@ts[:result].read_all([nil, nil, nil]).size.should == 0
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should get result" do
|
40
|
-
@ts[:result].write([:result, @task[:id], @node_id, :result_object])
|
41
|
-
@queue_server.get_result(nil) # The argument should be DRbQS::Server by right.
|
42
|
-
@queue_server.calculating_task_number.should == 0
|
43
|
-
@queue_server.empty?.should be_true
|
44
|
-
@queue_server.finished?.should be_true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should delete node" do
|
48
|
-
@task[:id] = @queue_server.add(@task[:obj])
|
49
|
-
@ts[:queue].take([nil, nil, nil, nil]).should be_true
|
50
|
-
@ts[:result].write([:accept, @task[:id], 100])
|
51
|
-
@queue_server.get_accept_signal.should == 1
|
52
|
-
@queue_server.requeue_for_deleted_node_id([@node_id])
|
53
|
-
@queue_server.calculating_task_number.should == 0
|
54
|
-
@queue_server.empty?.should be_false
|
55
|
-
@queue_server.finished?.should be_false
|
56
|
-
(ary = @ts[:queue].take([nil, nil, nil, nil])).should be_true
|
57
|
-
ary[0].should == @task[:id]
|
58
|
-
end
|
59
|
-
end
|
data/spec/server_define_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe DRbQS::ServerDefinition do
|
4
|
-
context "when we call class methods" do
|
5
|
-
before(:all) do
|
6
|
-
@server_definition = DRbQS.class_variable_get(:@@server_def)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should define server" do
|
10
|
-
lambda do
|
11
|
-
DRbQS.define_server do |server, argv, opts|
|
12
|
-
server.add_hook(:finish) do |serv|
|
13
|
-
serv.exit
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end.should change { @server_definition.instance_variable_get(:@default_server_opts) }.from(nil).to({})
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should set parser of options" do
|
20
|
-
lambda do
|
21
|
-
DRbQS.option_parser do |opt, hash|
|
22
|
-
opt.on('--test') do |v|
|
23
|
-
hash[:test] = true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end.should change { @server_definition.instance_variable_get(:@option_parse) }.from(nil)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should parse options" do
|
30
|
-
lambda do
|
31
|
-
DRbQS.parse_option(['--test'])
|
32
|
-
end.should change { @server_definition.instance_variable_get(:@argv) }.from(nil)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should start server" do
|
36
|
-
DRbQS::Server.should_receive(:new)
|
37
|
-
begin
|
38
|
-
# After DRbQS::Server.new returns nil, raise error
|
39
|
-
DRbQS.start_server(:uri => 'druby://localhost:13500')
|
40
|
-
rescue
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/spec/server_spec.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe DRbQS::Server do
|
4
|
-
context "when we initialize DRbQS::Server" do
|
5
|
-
it "should initialize an ACL object by ACLFile.load" do
|
6
|
-
path = File.dirname(__FILE__) + '/data/acl.txt'
|
7
|
-
DRbQS::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 start DRbQS::Server" do
|
19
|
-
it "should not set DRbQS::FileTransfer" do
|
20
|
-
server = DRbQS::Server.new
|
21
|
-
DRbQS::Transfer.should_not_receive(:new)
|
22
|
-
DRb.should_receive(:start_service).once
|
23
|
-
server.start
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should set defalt settings of DRbQS::FileTransfer" do
|
27
|
-
server = DRbQS::Server.new(:file_directory => '/tmp')
|
28
|
-
DRbQS::Transfer.should_receive(:new).with(ENV['USER'], 'localhost', '/tmp')
|
29
|
-
DRb.should_receive(:start_service).once
|
30
|
-
server.start
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should set DRbQS::FileTransfer" do
|
34
|
-
server = DRbQS::Server.new(:file_directory => '/tmp', :scp_user => 'hello', :scp_host => 'example.com')
|
35
|
-
DRbQS::Transfer.should_receive(:new).with('hello', 'example.com', '/tmp')
|
36
|
-
DRb.should_receive(:start_service).once
|
37
|
-
server.start
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should set DRbQS::FileTransfer by DRbQS::Server#set_file_transfer" do
|
41
|
-
server = DRbQS::Server.new
|
42
|
-
DRbQS::Transfer.should_receive(:new).with(ENV['USER'], 'localhost', '/tmp')
|
43
|
-
DRb.should_receive(:start_service).once
|
44
|
-
server.set_file_transfer('/tmp')
|
45
|
-
server.start
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should set DRbQS::FileTransfer by DRbQS::Server#set_file_transfer with optional arguments" do
|
49
|
-
server = DRbQS::Server.new
|
50
|
-
DRbQS::Transfer.should_receive(:new).with('hello', 'example.com', '/tmp')
|
51
|
-
DRb.should_receive(:start_service).once
|
52
|
-
server.set_file_transfer('/tmp', :user => 'hello', :host => 'example.com')
|
53
|
-
server.start
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/spec/task_client_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require 'drbqs/task_client'
|
4
|
-
|
5
|
-
describe DRbQS::TaskClient do
|
6
|
-
before(:all) do
|
7
|
-
@node_id = 4
|
8
|
-
@ts_queue = Rinda::TupleSpace.new
|
9
|
-
@ts_result = Rinda::TupleSpace.new
|
10
|
-
@task_client = DRbQS::TaskClient.new(@node_id, @ts_queue, @ts_result)
|
11
|
-
@task_example = [[1, 2, 3], :size, []]
|
12
|
-
@task_id = 10
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should be empty" do
|
16
|
-
@task_client.task_empty?.should be_true
|
17
|
-
@task_client.result_empty?.should be_true
|
18
|
-
@task_client.calculating_task.should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should queue a task" do
|
22
|
-
@ts_queue.write([@task_id] + @task_example)
|
23
|
-
@task_client.add_new_task
|
24
|
-
@task_client.task_empty?.should_not be_true
|
25
|
-
@task_client.result_empty?.should be_true
|
26
|
-
@task_client.calculating_task.should == @task_id
|
27
|
-
@ts_queue.read_all([nil, nil, nil, nil]).size.should == 0
|
28
|
-
@ts_result.take([:accept, nil, nil], 0).should be_true
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should dequeue a task" do
|
32
|
-
ary = @task_client.dequeue_task
|
33
|
-
ary.should == @task_example
|
34
|
-
@task_client.task_empty?.should be_true
|
35
|
-
@task_client.result_empty?.should be_true
|
36
|
-
@task_client.calculating_task.should == @task_id
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should queue result" do
|
40
|
-
@task_client.queue_result(@task_example[0].__send__(@task_example[1], *@task_example[2]))
|
41
|
-
@task_client.task_empty?.should be_true
|
42
|
-
@task_client.result_empty?.should_not be_true
|
43
|
-
@task_client.calculating_task.should == @task_id
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should send result" do
|
47
|
-
@task_client.send_result
|
48
|
-
@task_client.task_empty?.should be_true
|
49
|
-
@task_client.result_empty?.should be_true
|
50
|
-
@task_client.calculating_task.should be_nil
|
51
|
-
@ts_result.take([:result, nil, nil, nil], 0).should be_true
|
52
|
-
end
|
53
|
-
end
|
data/spec/test/test1.rb
DELETED
data/spec/test1_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require_relative '../lib/drbqs.rb'
|
4
|
-
require_relative 'test/test1.rb'
|
5
|
-
|
6
|
-
describe DRbQS do
|
7
|
-
before(:all) do
|
8
|
-
@tasks = []
|
9
|
-
5.times do |i|
|
10
|
-
@tasks << DRbQS::Task.new(Test1.new, :echo, [i])
|
11
|
-
end
|
12
|
-
@process_id = fork do
|
13
|
-
server = DRbQS::Server.new(:port => 13501)
|
14
|
-
|
15
|
-
@tasks.each do |task|
|
16
|
-
server.queue.add(task)
|
17
|
-
end
|
18
|
-
|
19
|
-
server.add_hook(:finish) do |serv|
|
20
|
-
serv.exit
|
21
|
-
end
|
22
|
-
|
23
|
-
server.set_signal_trap
|
24
|
-
server.start
|
25
|
-
server.wait
|
26
|
-
end
|
27
|
-
sleep(1)
|
28
|
-
|
29
|
-
@uri = 'druby://:13501'
|
30
|
-
@client = DRbQS::Client.new(@uri, :log_file => $stdout, :continue => true)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should have nil instance variables" do
|
34
|
-
@client.instance_variable_get(:@task_client).should be_nil
|
35
|
-
@client.instance_variable_get(:@connection).should be_nil
|
36
|
-
@client.connect
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should initialize @task_client" do
|
40
|
-
task_client = @client.instance_variable_get(:@task_client)
|
41
|
-
task_client.should be_an_instance_of DRbQS::TaskClient
|
42
|
-
task_client.node_id.should be_an_instance_of Fixnum
|
43
|
-
task_client.task_empty?.should be_true
|
44
|
-
task_client.result_empty?.should be_true
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should initialize @connection" do
|
48
|
-
connection = @client.instance_eval { @connection }
|
49
|
-
connection.should be_an_instance_of DRbQS::ConnectionClient
|
50
|
-
connection.instance_variable_get(:@id_number).should be_an_instance_of Fixnum
|
51
|
-
connection.instance_variable_get(:@id_string).should be_an_instance_of String
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should calculate" do
|
55
|
-
task_client = @client.instance_eval { @task_client }
|
56
|
-
# *** Too late ***
|
57
|
-
# task_client.should_receive(:add_new_task).at_least(:once)
|
58
|
-
# task_client.should_receive(:transit).exactly(5).times
|
59
|
-
# task_client.should_receive(:send_result).exactly(5).times
|
60
|
-
lambda do
|
61
|
-
@client.calculate
|
62
|
-
end.should_not raise_error
|
63
|
-
Test1.get_execute_echo_number.should == @tasks.size
|
64
|
-
end
|
65
|
-
|
66
|
-
after(:all) do
|
67
|
-
lambda do
|
68
|
-
i = 0
|
69
|
-
while !Process.waitpid(@process_id, Process::WNOHANG)
|
70
|
-
i += 1
|
71
|
-
if i > 10
|
72
|
-
Process.kill(:KILL, @process_id)
|
73
|
-
raise "Server process does not finish."
|
74
|
-
end
|
75
|
-
sleep(1)
|
76
|
-
end
|
77
|
-
end.should_not raise_error
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
data/spec/test2_spec.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
require_relative '../lib/drbqs.rb'
|
4
|
-
require_relative 'test/test1.rb'
|
5
|
-
|
6
|
-
describe DRbQS do
|
7
|
-
before(:all) do
|
8
|
-
@tasks = []
|
9
|
-
@task_generator = DRbQS::TaskGenerator.new(:iterate => 3)
|
10
|
-
@task_generator.set do
|
11
|
-
@iterate.times do |i|
|
12
|
-
create_add_task(Test1.new, :echo, [i])
|
13
|
-
end
|
14
|
-
end
|
15
|
-
@process_id = fork do
|
16
|
-
server = DRbQS::Server.new(:port => 13501, :finish_exit => true)
|
17
|
-
server.add_task_generator(@task_generator)
|
18
|
-
server.set_signal_trap
|
19
|
-
server.start
|
20
|
-
server.wait
|
21
|
-
end
|
22
|
-
sleep(1)
|
23
|
-
|
24
|
-
@uri = 'druby://:13501'
|
25
|
-
@client = DRbQS::Client.new(@uri, :log_file => $stdout, :continue => true)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have nil instance variables" do
|
29
|
-
@client.instance_variable_get(:@task_client).should be_nil
|
30
|
-
@client.instance_variable_get(:@connection).should be_nil
|
31
|
-
@client.connect
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should initialize @task_client" do
|
35
|
-
task_client = @client.instance_variable_get(:@task_client)
|
36
|
-
task_client.should be_an_instance_of DRbQS::TaskClient
|
37
|
-
task_client.node_id.should be_an_instance_of Fixnum
|
38
|
-
task_client.task_empty?.should be_true
|
39
|
-
task_client.result_empty?.should be_true
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should initialize @connection" do
|
43
|
-
connection = @client.instance_eval { @connection }
|
44
|
-
connection.should be_an_instance_of DRbQS::ConnectionClient
|
45
|
-
connection.instance_variable_get(:@id_number).should be_an_instance_of Fixnum
|
46
|
-
connection.instance_variable_get(:@id_string).should be_an_instance_of String
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should calculate" do
|
50
|
-
lambda do
|
51
|
-
@client.calculate
|
52
|
-
end.should_not raise_error
|
53
|
-
end
|
54
|
-
|
55
|
-
after(:all) do
|
56
|
-
lambda do
|
57
|
-
i = 0
|
58
|
-
while !Process.waitpid(@process_id, Process::WNOHANG)
|
59
|
-
i += 1
|
60
|
-
if i > 10
|
61
|
-
Process.kill(:KILL, @process_id)
|
62
|
-
raise "Server process does not finish."
|
63
|
-
end
|
64
|
-
sleep(1)
|
65
|
-
end
|
66
|
-
end.should_not raise_error
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
data/spec/transfer_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe DRbQS::FileTransfer do
|
4
|
-
it "should enqueue path" do
|
5
|
-
DRbQS::FileTransfer.enqueue('hello/world')
|
6
|
-
DRbQS::FileTransfer.empty?.should_not be_true
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should dequeue path" do
|
10
|
-
DRbQS::FileTransfer.dequeue.should == 'hello/world'
|
11
|
-
DRbQS::FileTransfer.empty?.should be_true
|
12
|
-
end
|
13
|
-
end
|