drbqs 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/drbqs-execute +6 -0
- data/bin/drbqs-manage +2 -2
- data/bin/drbqs-node +2 -2
- data/bin/drbqs-server +2 -2
- data/bin/drbqs-ssh +2 -2
- data/drbqs.gemspec +53 -16
- data/example/error_server/error.rb +6 -0
- data/example/error_server/server_def.rb +7 -0
- data/example/{error → error_task}/error.rb +0 -0
- data/example/{error → error_task}/server_def.rb +0 -0
- data/example/sum2/execute_def.rb +27 -0
- data/lib/drbqs/command_line/argument.rb +29 -0
- data/lib/drbqs/command_line/command_base.rb +81 -0
- data/lib/drbqs/command_line/command_execute.rb +33 -0
- data/lib/drbqs/command_line/command_line.rb +19 -0
- data/lib/drbqs/command_line/command_manage.rb +34 -0
- data/lib/drbqs/command_line/command_node.rb +26 -0
- data/lib/drbqs/command_line/command_server.rb +41 -0
- data/lib/drbqs/command_line/command_ssh.rb +51 -0
- data/lib/drbqs/command_line/option_setting.rb +42 -0
- data/lib/drbqs/execute/process_define.rb +213 -0
- data/lib/drbqs/execute/register.rb +147 -0
- data/lib/drbqs/{utility → execute}/server_define.rb +7 -14
- data/lib/drbqs/manage/execute_node.rb +4 -2
- data/lib/drbqs/manage/manage.rb +23 -16
- data/lib/drbqs/manage/send_signal.rb +31 -4
- data/lib/drbqs/manage/ssh_execute.rb +50 -6
- data/lib/drbqs/manage/ssh_shell.rb +95 -50
- data/lib/drbqs/node/connection.rb +1 -1
- data/lib/drbqs/node/node.rb +67 -17
- data/lib/drbqs/node/state.rb +109 -0
- data/lib/drbqs/node/task_client.rb +7 -7
- data/lib/drbqs/server/history.rb +16 -0
- data/lib/drbqs/server/message.rb +80 -15
- data/lib/drbqs/server/node_list.rb +16 -3
- data/lib/drbqs/server/prof.rb +48 -0
- data/lib/drbqs/server/queue.rb +20 -2
- data/lib/drbqs/server/server.rb +112 -70
- data/lib/drbqs/server/server_hook.rb +26 -6
- data/lib/drbqs/server/test/node.rb +34 -0
- data/lib/drbqs/server/test/server.rb +74 -0
- data/lib/drbqs/setting/base.rb +120 -0
- data/lib/drbqs/setting/data_container.rb +39 -0
- data/lib/drbqs/setting/execute.rb +71 -0
- data/lib/drbqs/setting/manage.rb +163 -0
- data/lib/drbqs/setting/node.rb +84 -0
- data/lib/drbqs/setting/server.rb +230 -0
- data/lib/drbqs/setting/setting.rb +14 -0
- data/lib/drbqs/setting/source.rb +220 -0
- data/lib/drbqs/setting/ssh.rb +165 -0
- data/lib/drbqs/task/task_generator.rb +4 -2
- data/lib/drbqs/utility/misc.rb +15 -1
- data/lib/drbqs/utility/temporary.rb +4 -2
- data/lib/drbqs.rb +3 -2
- data/spec/command_line/command_base_spec.rb +47 -0
- data/spec/{utility/command_line → command_line}/commands_spec.rb +3 -3
- data/spec/command_line/option_setting_spec.rb +29 -0
- data/spec/execute/def/execute1.rb +24 -0
- data/spec/execute/def/no_def.rb +2 -0
- data/spec/execute/process_define_spec.rb +167 -0
- data/spec/execute/register_spec.rb +77 -0
- data/spec/{utility → execute}/server_define_spec.rb +0 -0
- data/spec/integration_test/01_basic_usage_spec.rb +1 -1
- data/spec/integration_test/02_use_generator_spec.rb +1 -1
- data/spec/integration_test/03_use_temporary_file_spec.rb +1 -1
- data/spec/integration_test/04_use_unix_domain_spec.rb +1 -1
- data/spec/integration_test/05_server_exit_signal_spec.rb +1 -1
- data/spec/integration_test/06_node_exit_after_task_spec.rb +1 -1
- data/spec/integration_test/07_command_server_with_node_spec.rb +19 -16
- data/spec/integration_test/08_shutdown_unused_nodes_spec.rb +38 -0
- data/spec/integration_test/09_server_process_data_spec.rb +74 -0
- data/spec/integration_test/10_test_server_spec.rb +18 -0
- data/spec/integration_test/definition/task_obj_definition.rb +14 -0
- data/spec/manage/send_signal_spec.rb +8 -0
- data/spec/manage/ssh_shell_spec.rb +1 -1
- data/spec/node/state_spec.rb +148 -0
- data/spec/node/task_client_spec.rb +15 -0
- data/spec/server/history_spec.rb +51 -20
- data/spec/server/message_spec.rb +7 -2
- data/spec/server/node_list_spec.rb +1 -1
- data/spec/server/queue_spec.rb +93 -4
- data/spec/server/server_hook_spec.rb +62 -0
- data/spec/setting/base_spec.rb +35 -0
- data/spec/setting/data_container_spec.rb +92 -0
- data/spec/setting/execute_spec.rb +51 -0
- data/spec/setting/manage_spec.rb +63 -0
- data/spec/setting/node_spec.rb +43 -0
- data/spec/setting/server_spec.rb +46 -0
- data/spec/setting/source_spec.rb +245 -0
- data/spec/spec_helper.rb +17 -10
- data/spec/utility/argument_spec.rb +7 -7
- metadata +179 -146
- data/lib/drbqs/utility/argument.rb +0 -27
- data/lib/drbqs/utility/command_line/command_base.rb +0 -27
- data/lib/drbqs/utility/command_line/command_manage.rb +0 -121
- data/lib/drbqs/utility/command_line/command_node.rb +0 -103
- data/lib/drbqs/utility/command_line/command_server.rb +0 -165
- data/lib/drbqs/utility/command_line/command_ssh.rb +0 -126
- data/lib/drbqs/utility/command_line.rb +0 -15
- data/spec/utility/command_line/command_base_spec.rb +0 -33
@@ -0,0 +1,167 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/execute/process_define'
|
4
|
+
|
5
|
+
describe DRbQS::ProcessDefinition do
|
6
|
+
def definition_file(name)
|
7
|
+
File.join(File.dirname(__FILE__), 'def', name)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when creating without default process names" do
|
11
|
+
subject do
|
12
|
+
DRbQS::ProcessDefinition.new(nil, nil, nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
subject.load(definition_file('execute1.rb'))
|
17
|
+
@info = subject.information
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get server list." do
|
21
|
+
info = @info[:server].sort_by { |a| a [0] }
|
22
|
+
info.should == [[:server_local, :server], [:server_ssh, :ssh]].sort_by { |a| a [0] }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should get node list." do
|
26
|
+
info = @info[:node].sort_by { |a| a[0] }
|
27
|
+
info.should == [[:node_local, :node], [:node_ssh, :ssh]].sort_by { |a| a[0] }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should get default server." do
|
31
|
+
@info[:default][:server].should == :server_local
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should get default nodes." do
|
35
|
+
info = @info[:default][:node].sort
|
36
|
+
info.should == @info[:node].map { |a| a[0] }.sort
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should get default port." do
|
40
|
+
@info[:default][:port].should be_an_instance_of Fixnum
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should get information as string." do
|
44
|
+
subject.information_string.should be_an_instance_of String
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should get usage." do
|
48
|
+
subject.usage.should be_an_instance_of String
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:all) do
|
52
|
+
DRbQS.clear_definition
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when there is no definition" do
|
57
|
+
subject do
|
58
|
+
DRbQS::ProcessDefinition.new(nil, nil, nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
before(:all) do
|
62
|
+
subject.load(definition_file('no_def.rb'))
|
63
|
+
@info = subject.information
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should get server list." do
|
67
|
+
@info[:server].should be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should get node list." do
|
71
|
+
@info[:node].should be_empty
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should get default server." do
|
75
|
+
@info[:default][:server].should be_nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should get default nodes." do
|
79
|
+
@info[:default][:node].should be_empty
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should get default port." do
|
83
|
+
@info[:default][:port].should be_an_instance_of Fixnum
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should get information as string." do
|
87
|
+
subject.information_string.should be_an_instance_of String
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get usage." do
|
91
|
+
subject.usage.should be_an_instance_of String
|
92
|
+
end
|
93
|
+
|
94
|
+
after(:all) do
|
95
|
+
DRbQS.clear_definition
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when execute all nodes" do
|
100
|
+
before(:all) do
|
101
|
+
@port = 11111
|
102
|
+
@hostname = 'localhost' # defined in execute1.rb
|
103
|
+
@tmp = '/tmp/drbqs_tmp_log' # defined in execute1.rb
|
104
|
+
@process_def = DRbQS::ProcessDefinition.new(nil, nil, @port)
|
105
|
+
@process_def.load(definition_file('execute1.rb'))
|
106
|
+
@server_setting = subject.__send__(:get_server_setting)[:setting]
|
107
|
+
@node_local_setting = subject.__send__(:get_node_data, :node_local)[:setting]
|
108
|
+
@node_ssh_setting = subject.__send__(:get_node_data, :node_ssh)[:setting]
|
109
|
+
end
|
110
|
+
|
111
|
+
subject do
|
112
|
+
@process_def
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should check port number of server." do
|
116
|
+
@server_setting.should_receive(:exec)
|
117
|
+
subject.execute_server([])
|
118
|
+
@server_setting.get_first(:port).should == @port
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should check port number set in node." do
|
122
|
+
@node_local_setting.should_receive(:exec)
|
123
|
+
@node_ssh_setting.should_receive(:exec)
|
124
|
+
subject.execute_node
|
125
|
+
uri = "druby://#{@hostname}:#{@port}"
|
126
|
+
@node_local_setting.value.argument.should == [uri]
|
127
|
+
@node_ssh_setting.mode_setting.value.argument == [uri]
|
128
|
+
end
|
129
|
+
|
130
|
+
after(:all) do
|
131
|
+
FileUtils.rm_r(@tmp)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when execute a specified node" do
|
136
|
+
before(:all) do
|
137
|
+
@port = DRbQS::ROOT_DEFAULT_PORT
|
138
|
+
@hostname = 'localhost' # defined in execute1.rb
|
139
|
+
@tmp = '/tmp/drbqs_tmp_log' # defined in execute1.rb
|
140
|
+
@process_def = DRbQS::ProcessDefinition.new(nil, [:node_local], nil)
|
141
|
+
@process_def.load(definition_file('execute1.rb'))
|
142
|
+
@server_setting = subject.__send__(:get_server_setting)[:setting]
|
143
|
+
@node_local_setting = subject.__send__(:get_node_data, :node_local)[:setting]
|
144
|
+
end
|
145
|
+
|
146
|
+
subject do
|
147
|
+
@process_def
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should check port number of server." do
|
151
|
+
@server_setting.should_receive(:exec)
|
152
|
+
subject.execute_server([])
|
153
|
+
@server_setting.get_first(:port).should == @port
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should check port number set in node." do
|
157
|
+
@node_local_setting.should_receive(:exec)
|
158
|
+
subject.execute_node
|
159
|
+
uri = "druby://#{@hostname}:#{@port}"
|
160
|
+
@node_local_setting.value.argument.should == [uri]
|
161
|
+
end
|
162
|
+
|
163
|
+
after(:all) do
|
164
|
+
FileUtils.rm_r(@tmp)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/execute/process_define'
|
4
|
+
|
5
|
+
describe DRbQS::ProcessDefinition::Register do
|
6
|
+
subject do
|
7
|
+
DRbQS::ProcessDefinition::Register.new
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when registering a server" do
|
11
|
+
it "should define a server on localhost." do
|
12
|
+
load_file = 'file.rb'
|
13
|
+
subject.register_server(:server1) do |server|
|
14
|
+
server.load load_file
|
15
|
+
end
|
16
|
+
name, data = subject.__server__.assoc(:server1)
|
17
|
+
data[:type].should == :server
|
18
|
+
data[:setting].get(:load).should == [load_file]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should define a server over ssh." do
|
22
|
+
dest = "user@example.com"
|
23
|
+
load_file = 'file.rb'
|
24
|
+
subject.register_server(:server1) do |server, ssh|
|
25
|
+
server.load load_file
|
26
|
+
ssh.connect dest
|
27
|
+
end
|
28
|
+
name, data = subject.__server__.assoc(:server1)
|
29
|
+
data[:type].should == :ssh
|
30
|
+
setting = data[:setting]
|
31
|
+
setting.get(:connect).should == [dest]
|
32
|
+
setting.mode_setting.get(:load).should == [load_file]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when registering a node" do
|
37
|
+
it "should define a node on localhost." do
|
38
|
+
uri = 'druby://:12345'
|
39
|
+
subject.register_node(:node1) do |node|
|
40
|
+
node.connect uri
|
41
|
+
end
|
42
|
+
name, data = subject.__node__.assoc(:node1)
|
43
|
+
data[:type].should == :node
|
44
|
+
data[:setting].get(:connect).should == [uri]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should define a node over ssh." do
|
48
|
+
dest = "user@example.com"
|
49
|
+
uri = 'druby://:12345'
|
50
|
+
subject.register_node(:node2) do |node, ssh|
|
51
|
+
node.connect uri
|
52
|
+
ssh.connect dest
|
53
|
+
end
|
54
|
+
name, data = subject.__node__.assoc(:node2)
|
55
|
+
data[:type].should == :ssh
|
56
|
+
setting = data[:setting]
|
57
|
+
setting.get(:connect).should == [dest]
|
58
|
+
setting.mode_setting.get(:connect).should == [uri]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when setting default" do
|
63
|
+
it "should set default server and default port." do
|
64
|
+
subject.default(:server => :server1, :port => 1234)
|
65
|
+
h = subject.__default__
|
66
|
+
h[:server].should == :server1
|
67
|
+
h[:port].should == 1234
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set default server and default port with conversion." do
|
71
|
+
subject.default(:server => 'server2', :port => '12345')
|
72
|
+
h = subject.__default__
|
73
|
+
h[:server].should == :server2
|
74
|
+
h[:port].should == 12345
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
File without changes
|
@@ -8,7 +8,7 @@ describe DRbQS do
|
|
8
8
|
@tasks = 5.times.map do |i|
|
9
9
|
DRbQS::Task.new(Test1.new, :echo, [i])
|
10
10
|
end
|
11
|
-
@process_id, @uri = drbqs_fork_server(
|
11
|
+
@process_id, @uri = drbqs_fork_server(14010, :task => @tasks)
|
12
12
|
@node = DRbQS::Node.new(@uri, :log_file => $stdout, :continue => true)
|
13
13
|
end
|
14
14
|
|
@@ -13,7 +13,7 @@ describe DRbQS do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
|
-
@process_id, @uri = drbqs_fork_server(
|
16
|
+
@process_id, @uri = drbqs_fork_server(14020, :task => @task_generators)
|
17
17
|
@node = DRbQS::Node.new(@uri, :log_file => $stdout, :continue => true)
|
18
18
|
end
|
19
19
|
|
@@ -6,7 +6,7 @@ require_relative 'definition/task_obj_definition.rb'
|
|
6
6
|
describe DRbQS do
|
7
7
|
before(:all) do
|
8
8
|
@tasks = [DRbQS::Task.new(Test3.new, :temp_file)]
|
9
|
-
@process_id, @uri = drbqs_fork_server(
|
9
|
+
@process_id, @uri = drbqs_fork_server(14030, :task => @tasks)
|
10
10
|
@node = DRbQS::Node.new(@uri, :log_file => $stdout, :continue => true)
|
11
11
|
end
|
12
12
|
|
@@ -9,7 +9,7 @@ describe DRbQS::Server do
|
|
9
9
|
DRbQS::Task.new(Test1.new, :echo, [i])
|
10
10
|
end
|
11
11
|
path = "/tmp/drbqs"
|
12
|
-
@process_id, @uri = drbqs_fork_server(path, @tasks)
|
12
|
+
@process_id, @uri = drbqs_fork_server(path, :task => @tasks)
|
13
13
|
@manage = DRbQS::Manage.new(:uri => @uri)
|
14
14
|
@node = DRbQS::Node.new(@uri, :log_file => $stdout, :continue => true)
|
15
15
|
end
|
@@ -8,7 +8,7 @@ describe DRbQS do
|
|
8
8
|
@tasks = 3.times.map do |i|
|
9
9
|
DRbQS::Task.new(Test1.new, :echo, [i])
|
10
10
|
end
|
11
|
-
@process_id, @uri = drbqs_fork_server(
|
11
|
+
@process_id, @uri = drbqs_fork_server(14050, :task => @tasks)
|
12
12
|
@manage = DRbQS::Manage.new(:uri => @uri)
|
13
13
|
end
|
14
14
|
|
@@ -9,7 +9,7 @@ describe DRbQS::Server do
|
|
9
9
|
@tasks = 10.times.map do |i|
|
10
10
|
DRbQS::Task.new(Test2.new, :echo_wait, [@wait])
|
11
11
|
end
|
12
|
-
@server_process_id, @uri = drbqs_fork_server(
|
12
|
+
@server_process_id, @uri = drbqs_fork_server(14060, :task => @tasks, :continue => true)
|
13
13
|
@manage = DRbQS::Manage.new(:uri => @uri)
|
14
14
|
end
|
15
15
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
require 'drbqs/task/task'
|
4
|
-
require 'drbqs/
|
4
|
+
require 'drbqs/command_line/command_line'
|
5
5
|
|
6
6
|
describe DRbQS do
|
7
7
|
context "when server is executed with nodes." do
|
8
8
|
it "should exit normally." do
|
9
9
|
@path = File.expand_path(File.join(File.dirname(__FILE__), 'definition/server01.rb'))
|
10
|
-
@port =
|
10
|
+
@port = 14070
|
11
11
|
@pid_server = fork do
|
12
|
-
DRbQS::
|
12
|
+
DRbQS::Command::Server.exec([@path, '-p', @port.to_s, '--execute-node', '2'])
|
13
13
|
end
|
14
14
|
lambda do
|
15
15
|
i = 0
|
@@ -25,20 +25,23 @@ describe DRbQS do
|
|
25
25
|
|
26
26
|
it "should raise error in server." do
|
27
27
|
@path = File.expand_path(File.join(File.dirname(__FILE__), 'definition/server02.rb'))
|
28
|
-
@port =
|
29
|
-
@pid_server = fork do
|
30
|
-
DRbQS::CommandServer.exec([@path, '-p', @port.to_s, '--execute-node', '2'])
|
31
|
-
end
|
28
|
+
@port = 14071
|
32
29
|
lambda do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
DRbQS::Command::Server.exec([@path, '-p', @port.to_s, '--execute-node', '2'])
|
31
|
+
end.should raise_error
|
32
|
+
# @pid_server = fork do
|
33
|
+
# DRbQS::Command::Server.exec([@path, '-p', @port.to_s, '--execute-node', '2'])
|
34
|
+
# end
|
35
|
+
# lambda do
|
36
|
+
# i = 0
|
37
|
+
# until exit_data = Process.waitpid2(@pid_server, Process::WNOHANG)
|
38
|
+
# sleep(1)
|
39
|
+
# if i > 10
|
40
|
+
# raise "Server can not stop within 10 seconds."
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# exit_data[1].success?.should_not be_true
|
44
|
+
# end.should_not raise_error
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/task/task'
|
4
|
+
require 'drbqs/command_line/command_line'
|
5
|
+
|
6
|
+
describe DRbQS::Server do
|
7
|
+
before(:all) do
|
8
|
+
@max_wait_time = 10
|
9
|
+
@server_process_id, @uri = drbqs_fork_server(14080, :continue => true, :opts => { :shutdown_unused_nodes => true })
|
10
|
+
@manage = DRbQS::Manage.new(:uri => @uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should send node exit" do
|
14
|
+
execute_node = DRbQS::ExecuteNode.new(@uri, nil, nil)
|
15
|
+
execute_node.execute(1)
|
16
|
+
client_process_id = execute_node.pid[0]
|
17
|
+
th = Process.detach(client_process_id)
|
18
|
+
lambda do
|
19
|
+
@max_wait_time.times do |i|
|
20
|
+
sleep(1)
|
21
|
+
unless th.alive?
|
22
|
+
break
|
23
|
+
end
|
24
|
+
if i == (@max_wait_time - 1)
|
25
|
+
raise "Client does not exit."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end.should_not raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:all) do
|
32
|
+
@manage.send_exit_signal
|
33
|
+
lambda do
|
34
|
+
drbqs_wait_kill_server(@server_process_id)
|
35
|
+
end.should_not raise_error
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/command_line/command_line'
|
4
|
+
require 'drbqs/task/task'
|
5
|
+
require 'drbqs/utility/temporary'
|
6
|
+
|
7
|
+
describe DRbQS::Server do
|
8
|
+
def wait_file_creation(path)
|
9
|
+
@max_wait_time.times do |i|
|
10
|
+
if File.exist?(path)
|
11
|
+
break
|
12
|
+
end
|
13
|
+
sleep(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:all) do
|
18
|
+
@file = DRbQS::Temporary.file
|
19
|
+
@initial_data = ['abc', 'def']
|
20
|
+
@max_wait_time = 10
|
21
|
+
@server_process_id, @uri = drbqs_fork_server(14090, :continue => true) do |server|
|
22
|
+
server.add_hook(:process_data) do |srv, data|
|
23
|
+
open(@file, 'a+') do |f|
|
24
|
+
f.print data
|
25
|
+
end
|
26
|
+
end
|
27
|
+
server.set_data(*@initial_data)
|
28
|
+
end
|
29
|
+
@manage = DRbQS::Manage.new(:uri => @uri)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should process initial data." do
|
33
|
+
wait_file_creation(@file)
|
34
|
+
File.read(@file).should == 'abcdef'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should save to the file." do
|
38
|
+
data = 'hello world'
|
39
|
+
@manage.send_data(data)
|
40
|
+
wait_file_creation(@file)
|
41
|
+
File.read(@file).should == data
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should send string by command." do
|
45
|
+
data = 'send command'
|
46
|
+
fork do
|
47
|
+
DRbQS::Command::Manage.exec(['send', 'string', @uri, data])
|
48
|
+
end
|
49
|
+
wait_file_creation(@file)
|
50
|
+
File.read(@file).should == data
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should send file by command." do
|
54
|
+
path = File.expand_path(__FILE__)
|
55
|
+
fork do
|
56
|
+
DRbQS::Command::Manage.exec(['send', 'file', @uri, path])
|
57
|
+
end
|
58
|
+
wait_file_creation(@file)
|
59
|
+
File.read(@file).should == File.read(path)
|
60
|
+
end
|
61
|
+
|
62
|
+
after(:each) do
|
63
|
+
FileUtils.rm(@file) if File.exist?(@file)
|
64
|
+
end
|
65
|
+
|
66
|
+
after(:all) do
|
67
|
+
DRbQS::Temporary.delete_all
|
68
|
+
@manage.send_exit_signal
|
69
|
+
lambda do
|
70
|
+
drbqs_wait_kill_server(@server_process_id)
|
71
|
+
end.should_not raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'drbqs/server/test/server'
|
4
|
+
require_relative 'definition/task_obj_definition.rb'
|
5
|
+
|
6
|
+
describe DRbQS::Test::Server do
|
7
|
+
it "should execute as test." do
|
8
|
+
DRbQS.define_server do |server, argv, opts|
|
9
|
+
5.times do |i|
|
10
|
+
server.queue.add(DRbQS::Task.new(TestCount.new, :calc))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
server = DRbQS.create_test_server({})
|
14
|
+
data = server.test_exec
|
15
|
+
data.should be_an_instance_of Hash
|
16
|
+
TestCount.get.should == 5
|
17
|
+
end
|
18
|
+
end
|
@@ -36,4 +36,12 @@ describe DRbQS::Manage::SendSignal do
|
|
36
36
|
@ts.should_receive(:take).once.and_return([:status, mes])
|
37
37
|
@send_signal.get_status.should == mes
|
38
38
|
end
|
39
|
+
|
40
|
+
it "should send data." do
|
41
|
+
data = 'hello world'
|
42
|
+
@send_signal.send_data(data)
|
43
|
+
lambda do
|
44
|
+
@ts.take([:server, :new_data, data], 0)
|
45
|
+
end.should_not raise_error
|
46
|
+
end
|
39
47
|
end
|
@@ -12,7 +12,7 @@ describe DRbQS::Manage::SSHShell do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should split destination including directory" do
|
15
|
-
ssh = DRbQS::Manage::SSHShell.new('user@hostname:22', :
|
15
|
+
ssh = DRbQS::Manage::SSHShell.new('user@hostname:22', :directory => '/path/to/directory')
|
16
16
|
ssh.user.should == 'user'
|
17
17
|
ssh.host.should == 'hostname'
|
18
18
|
ssh.port.should == 22
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DRbQS::Node::State do
|
4
|
+
subject do
|
5
|
+
DRbQS::Node::State.new(:wait)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when state is :wait" do
|
9
|
+
before(:each) do
|
10
|
+
subject.change(:wait)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should change to :wait." do
|
14
|
+
lambda do
|
15
|
+
subject.change_to_wait
|
16
|
+
end.should_not change { subject.state }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should change to :sleep." do
|
20
|
+
lambda do
|
21
|
+
subject.change_to_sleep
|
22
|
+
end.should change { subject.state }.from(:wait).to(:sleep)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should change to :calculate." do
|
26
|
+
lambda do
|
27
|
+
subject.change_to_calculate
|
28
|
+
end.should change { subject.state }.from(:wait).to(:calculate)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when state is :sleep" do
|
33
|
+
before(:each) do
|
34
|
+
subject.change(:sleep)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should change to :sleep." do
|
38
|
+
lambda do
|
39
|
+
subject.change_to_wait
|
40
|
+
end.should change { subject.state }.from(:sleep).to(:wait)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should change to :sleep." do
|
44
|
+
lambda do
|
45
|
+
subject.change_to_sleep
|
46
|
+
end.should_not change { subject.state }
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should change to :calculate." do
|
50
|
+
lambda do
|
51
|
+
subject.change_to_calculate
|
52
|
+
end.should change { subject.state }.from(:sleep).to(:calculate)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when state is :calculate" do
|
57
|
+
before(:each) do
|
58
|
+
subject.change(:calculate)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should change to :sleep." do
|
62
|
+
lambda do
|
63
|
+
subject.change_to_wait
|
64
|
+
end.should_not change { subject.state }
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should change to :sleep." do
|
68
|
+
lambda do
|
69
|
+
subject.change_to_sleep
|
70
|
+
end.should_not change { subject.state }
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should change to :calculate." do
|
74
|
+
lambda do
|
75
|
+
subject.change_to_calculate
|
76
|
+
end.should_not change { subject.state }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when getting load average." do
|
81
|
+
it "should get load average." do
|
82
|
+
File.stub(:read).with(DRbQS::Node::State::LOADAVG_PATH).and_return('0.00 0.01 0.05 1/404 5903')
|
83
|
+
ary = subject.__send__(:get_load_average)
|
84
|
+
ary.should be_an_instance_of Array
|
85
|
+
ary.should have(3).items
|
86
|
+
ary.all? do |num|
|
87
|
+
Float === num
|
88
|
+
end.should be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when setting load average" do
|
93
|
+
subject do
|
94
|
+
DRbQS::Node::State.new(:wait, :max_loadavg => 2)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be true" do
|
98
|
+
subject.stub(:get_load_average).and_return([2.0, 2,0, 2.0])
|
99
|
+
subject.system_busy?.should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be nil" do
|
103
|
+
subject.stub(:get_load_average).and_return([1.0, 1,0, 1.0])
|
104
|
+
subject.system_busy?.should be_nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when changing state to finish calculating" do
|
109
|
+
before(:each) do
|
110
|
+
subject.change(:calculate)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should change to :wait." do
|
114
|
+
lambda do
|
115
|
+
subject.change_to_finish_calculating
|
116
|
+
end.should change { subject.state }.from(:calculate).to(:wait)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should change to :sleep." do
|
120
|
+
subject.change_to_sleep
|
121
|
+
lambda do
|
122
|
+
subject.change_to_finish_calculating
|
123
|
+
end.should change { subject.state }.from(:calculate).to(:sleep)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when setting auto wakeup" do
|
128
|
+
subject do
|
129
|
+
DRbQS::Node::State.new(:wait, :sleep_time => 0)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should do nothing." do
|
133
|
+
subject.stub(:system_busy?).and_return(nil)
|
134
|
+
subject.change(:wait)
|
135
|
+
lambda do
|
136
|
+
subject.wakeup_automatically_for_unbusy_system
|
137
|
+
end.should_not change { subject.state }
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should do nothing." do
|
141
|
+
subject.stub(:system_busy?).and_return(nil)
|
142
|
+
subject.sleep_with_auto_wakeup
|
143
|
+
lambda do
|
144
|
+
subject.wakeup_automatically_for_unbusy_system
|
145
|
+
end.should change { subject.state }.from(:sleep).to(:wait)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|