xli-dtr 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -115
- data/Rakefile +22 -154
- data/TODO +16 -1
- data/bin/dtr +22 -61
- data/dtr.gemspec +7 -6
- data/lib/dtr/agent/brain.rb +66 -0
- data/lib/dtr/agent/herald.rb +50 -0
- data/lib/dtr/agent/runner.rb +100 -0
- data/lib/dtr/agent/sync_codebase.rb +44 -0
- data/lib/dtr/agent/sync_logger.rb +40 -0
- data/lib/dtr/agent/test_unit.rb +42 -0
- data/lib/dtr/agent/worker.rb +92 -0
- data/lib/dtr/agent/working_env_ext.rb +45 -0
- data/lib/dtr/agent.rb +37 -0
- data/lib/dtr/master.rb +40 -0
- data/lib/dtr/monitor.rb +37 -0
- data/lib/dtr/raketasks.rb +74 -13
- data/lib/dtr/shared/adapter.rb +112 -0
- data/lib/dtr/shared/configuration.rb +76 -0
- data/lib/dtr/shared/message_decorator.rb +28 -0
- data/lib/dtr/shared/ruby_ext.rb +153 -0
- data/lib/dtr/shared/service/agent.rb +33 -0
- data/lib/dtr/shared/service/file.rb +28 -0
- data/lib/dtr/shared/service/rinda.rb +40 -0
- data/lib/dtr/shared/service/runner.rb +33 -0
- data/lib/dtr/shared/service/working_env.rb +28 -0
- data/lib/dtr/shared/service.rb +19 -0
- data/lib/dtr/shared/sync_codebase/codebase.rb +32 -0
- data/lib/dtr/shared/sync_codebase/master_ext.rb +52 -0
- data/lib/dtr/shared/sync_codebase/package.rb +39 -0
- data/lib/dtr/shared/sync_codebase/sync_service.rb +41 -0
- data/lib/dtr/shared/sync_codebase.rb +18 -0
- data/lib/dtr/shared/sync_logger.rb +72 -0
- data/lib/dtr/shared/utils/cmd.rb +30 -0
- data/lib/dtr/shared/utils/env_store.rb +60 -0
- data/lib/dtr/shared/utils/logger.rb +71 -0
- data/lib/dtr/shared/utils.rb +17 -0
- data/lib/dtr/shared/working_env.rb +38 -0
- data/lib/dtr/shared.rb +24 -0
- data/lib/dtr/test_unit/drb_test_runner.rb +57 -0
- data/lib/dtr/test_unit/injection.rb +30 -0
- data/lib/dtr/test_unit/test_case_injection.rb +37 -0
- data/lib/dtr/test_unit/testrunnermediator_injection.rb +72 -0
- data/lib/dtr/test_unit/thread_safe_test_result.rb +40 -0
- data/lib/dtr/test_unit/worker_club.rb +72 -0
- data/lib/dtr/test_unit.rb +8 -275
- data/lib/dtr/test_unit_injection.rb +0 -1
- data/lib/dtr.rb +23 -81
- data/test/acceptance/agent_working_env_test.rb +92 -0
- data/test/acceptance/dtr_package_task_test.rb +26 -0
- data/test/acceptance/general_test.rb +275 -0
- data/test/acceptance/sync_codebase_test.rb +67 -0
- data/test/acceptance/sync_logger_test.rb +41 -0
- data/test/agent_helper.rb +39 -0
- data/test/logger_stub.rb +30 -0
- data/test/test_helper.rb +43 -0
- data/test/unit/adapter_test.rb +107 -0
- data/test/unit/test_unit_test.rb +47 -0
- data/test/unit/working_env_test.rb +71 -0
- data/testdata/Rakefile +15 -0
- data/testdata/a_failed_test_case.rb +8 -0
- data/testdata/a_file_system_test_case.rb +8 -0
- data/testdata/a_test_case.rb +13 -0
- data/testdata/a_test_case2.rb +6 -0
- data/testdata/an_error_test_case.rb +9 -0
- data/testdata/another_project/Rakefile +6 -0
- data/testdata/another_project/passed_test_case.rb +7 -0
- data/testdata/is_required_by_a_test.rb +9 -0
- data/testdata/lib/lib_test_case.rb +7 -0
- data/testdata/package_task_test_rakefile +8 -0
- data/testdata/scenario_test_case.rb +34 -0
- data/testdata/setup_agent_env_test_case.rb +9 -0
- data/testdata/should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process/Rakefile +6 -0
- data/testdata/should_not_sync_codebase_and_setup_working_dir_when_agent_is_in_same_dir_with_master_process/verify_dir_pwd_test_case.rb +10 -0
- metadata +72 -18
- data/lib/dtr/base.rb +0 -172
- data/lib/dtr/runner.rb +0 -270
- data/lib/dtr/service_provider.rb +0 -160
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
|
17
|
+
module Agent
|
18
|
+
class Herald
|
19
|
+
include Service::WorkingEnv
|
20
|
+
include Service::Agent
|
21
|
+
|
22
|
+
def initialize(working_env_key, agent_env_setup_cmd, runners)
|
23
|
+
@working_env_key = working_env_key
|
24
|
+
@agent_env_setup_cmd = agent_env_setup_cmd
|
25
|
+
@runners = runners
|
26
|
+
@env_store = EnvStore.new
|
27
|
+
start_off
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_off
|
31
|
+
start_service
|
32
|
+
DTR.info "=> Herald starts off..."
|
33
|
+
provide_agent_info(@agent_env_setup_cmd, @runners)
|
34
|
+
|
35
|
+
working_env = lookup_working_env
|
36
|
+
DTR.info "=> Got working environment created at #{working_env[:created_at]} by #{working_env[:host]}"
|
37
|
+
if working_env[:files].blank?
|
38
|
+
DTR.error "No test files need to load?(working env: #{working_env})"
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
if working_env.setup_env(@agent_env_setup_cmd)
|
43
|
+
@env_store[@working_env_key] = working_env
|
44
|
+
else
|
45
|
+
DTR.info {'Setup working environment failed, no runner started.'}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module Agent
|
17
|
+
class Runner
|
18
|
+
include DRbUndumped
|
19
|
+
include Service::Runner
|
20
|
+
|
21
|
+
def self.start(name, env)
|
22
|
+
self.new(name, env).start
|
23
|
+
DTR.info "=> Runner #{name} provided"
|
24
|
+
DRb.thread.join if DRb.thread
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :name, :identifier
|
28
|
+
|
29
|
+
def initialize(name, env)
|
30
|
+
@name = name
|
31
|
+
@identifier = env[:identifier]
|
32
|
+
@env = env
|
33
|
+
@started = 0
|
34
|
+
@run_finished = 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def start
|
38
|
+
#start service first, so that all logs can be sync with master process
|
39
|
+
start_service
|
40
|
+
DTR.info("=> Starting runner #{name} at #{Dir.pwd}, pid: #{Process.pid}")
|
41
|
+
init_environment
|
42
|
+
provide_runner(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def init_environment
|
46
|
+
DTR.info "#{name}: Initialize working environment..."
|
47
|
+
@env[:libs].select{ |lib| !$LOAD_PATH.include?(lib) && File.exists?(lib) }.each do |lib|
|
48
|
+
$LOAD_PATH << lib
|
49
|
+
DTR.debug "#{name}: appended lib: #{lib}"
|
50
|
+
end
|
51
|
+
DTR.info "#{name}: libs loaded"
|
52
|
+
DTR.debug "#{name}: $LOAD_PATH: #{$LOAD_PATH.inspect}"
|
53
|
+
|
54
|
+
@env[:files].each do |f|
|
55
|
+
begin
|
56
|
+
load f unless f =~ /^-/
|
57
|
+
DTR.debug "#{name}: loaded #{f}"
|
58
|
+
rescue LoadError => e
|
59
|
+
DTR.error "#{name}: No such file to load -- #{f}"
|
60
|
+
DTR.debug "Environment: #{@env}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
DTR.info "#{name}: test files loaded"
|
64
|
+
end
|
65
|
+
|
66
|
+
def run(test, result, &progress_block)
|
67
|
+
DTR.info "#{name}: +"
|
68
|
+
DTR.debug "#{name}: running #{test}..."
|
69
|
+
@started += 1
|
70
|
+
test.run(result, &progress_block)
|
71
|
+
rescue DRb::DRbConnError => e
|
72
|
+
DTR.info "Rescued DRb::DRbConnError(#{e.message}), while running test: #{test.name}. The master process may be stopped."
|
73
|
+
rescue Exception => e
|
74
|
+
DTR.error "Unexpected exception: #{e.message}"
|
75
|
+
DTR.error e.backtrace.join("\n")
|
76
|
+
result.add_error(Test::Unit::Error.new(test.name, e))
|
77
|
+
result.add_run
|
78
|
+
progress_block.call(Test::Unit::TestCase::FINISHED, test.name)
|
79
|
+
ensure
|
80
|
+
DTR.debug "#{name}: done #{test}"
|
81
|
+
@run_finished += 1
|
82
|
+
provide_runner(self)
|
83
|
+
end
|
84
|
+
|
85
|
+
def reboot
|
86
|
+
DTR.info "#{self} is rebooting. Ran #{@started} tests, finished #{@run_finished}."
|
87
|
+
provide_runner(self)
|
88
|
+
end
|
89
|
+
|
90
|
+
def shutdown
|
91
|
+
DTR.info "#{self} is shutting down. Ran #{@started} tests, finished #{@run_finished}."
|
92
|
+
stop_service rescue exit!
|
93
|
+
end
|
94
|
+
|
95
|
+
def to_s
|
96
|
+
"Runner #{@name}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module SyncCodebase
|
17
|
+
module WorkingEnvExt
|
18
|
+
include SyncService
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.alias_method_chain :setup_env, :sync_codebase
|
22
|
+
base.alias_method_chain :working_dir, :sync_codebase
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_env_with_sync_codebase(setup_env_cmd)
|
26
|
+
unless same_working_dir_with_master_process?
|
27
|
+
Dir.chdir(working_dir_without_sync_codebase) do
|
28
|
+
sync_codebase
|
29
|
+
end
|
30
|
+
end
|
31
|
+
setup_env_without_sync_codebase(setup_env_cmd)
|
32
|
+
end
|
33
|
+
|
34
|
+
def working_dir_with_sync_codebase
|
35
|
+
same_working_dir_with_master_process? ? Dir.pwd : File.join(working_dir_without_sync_codebase, package_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def same_working_dir_with_master_process?
|
40
|
+
self[:host] == Socket.gethostname && self[:pwd] == Dir.pwd
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module SyncLogger
|
17
|
+
|
18
|
+
# Synchronizer loads SyncLogger from master process
|
19
|
+
# Any process need sync logs with master process should start service first.
|
20
|
+
# For logs would be sent back to master process, output log code should use
|
21
|
+
# message string instead of block, for example:
|
22
|
+
# right: DTR.debug 'message'
|
23
|
+
# not: DTR.debug { 'message' }
|
24
|
+
module Synchronizer
|
25
|
+
def self.included(base)
|
26
|
+
base.alias_method_chain :start_service, :sync_logger
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_service_with_sync_logger
|
30
|
+
start_service_without_sync_logger
|
31
|
+
if logger_tuple = lookup_ring.read_all([:logger, nil]).first
|
32
|
+
sync_logger = logger_tuple[1]
|
33
|
+
DTR.logger = sync_logger
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Service::Rinda.send(:include, SyncLogger::Synchronizer)
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'test/unit'
|
16
|
+
require 'test/unit/testcase'
|
17
|
+
|
18
|
+
module DTR
|
19
|
+
module Agent
|
20
|
+
module TestCaseExt
|
21
|
+
include MessageDecorator
|
22
|
+
def self.included(base)
|
23
|
+
base.alias_method_chain :add_failure, :decorating_source
|
24
|
+
base.alias_method_chain :add_error, :decorating_source
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_error_with_decorating_source(exception)
|
28
|
+
add_error_without_decorating_source(DTR::RemoteError.new(exception))
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_failure_with_decorating_source(message, all_locations=caller())
|
32
|
+
add_failure_without_decorating_source(decorate_message(message, 'Assertion failure'), all_locations)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Test::Unit.run = true
|
39
|
+
|
40
|
+
class Test::Unit::TestCase
|
41
|
+
include DTR::Agent::TestCaseExt
|
42
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
|
17
|
+
module Agent
|
18
|
+
class Worker
|
19
|
+
def initialize(runner_names, agent_env_setup_cmd)
|
20
|
+
@runner_names = runner_names.is_a?(Array) ? runner_names : [runner_names.to_s]
|
21
|
+
@agent_env_setup_cmd = agent_env_setup_cmd
|
22
|
+
@runner_pids = []
|
23
|
+
@herald = nil
|
24
|
+
@working_env_key = :working_env
|
25
|
+
@env_store = EnvStore.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def launch
|
29
|
+
DTR.info "=> Agent worker started at: #{Dir.pwd}, pid: #{Process.pid}"
|
30
|
+
setup
|
31
|
+
begin
|
32
|
+
run
|
33
|
+
ensure
|
34
|
+
teardown
|
35
|
+
DTR.info "Agent worker is dieing"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def setup
|
41
|
+
@env_store[@working_env_key] = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def teardown
|
45
|
+
kill_all_runners
|
46
|
+
if @herald
|
47
|
+
Process.kill 'TERM', @herald rescue nil
|
48
|
+
@herald = nil
|
49
|
+
DTR.info "=> Herald is killed."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def run
|
54
|
+
@herald = drb_fork { Herald.new @working_env_key, @agent_env_setup_cmd, @runner_names }
|
55
|
+
while @env_store[@working_env_key].nil?
|
56
|
+
sleep(1)
|
57
|
+
end
|
58
|
+
working_env = @env_store[@working_env_key]
|
59
|
+
|
60
|
+
@runner_names.each do |name|
|
61
|
+
@runner_pids << drb_fork {
|
62
|
+
working_env.within do
|
63
|
+
Runner.start name, working_env
|
64
|
+
end
|
65
|
+
}
|
66
|
+
end
|
67
|
+
Process.waitall
|
68
|
+
DTR.info "=> All agent worker sub processes exited."
|
69
|
+
end
|
70
|
+
|
71
|
+
def kill_all_runners
|
72
|
+
unless @runner_pids.blank?
|
73
|
+
@runner_pids.each{ |pid| Process.kill 'TERM', pid rescue nil }
|
74
|
+
DTR.info "=> All runners(#{@runner_pids.join(", ")}) were killed."
|
75
|
+
@runner_pids = []
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def drb_fork
|
80
|
+
Process.fork do
|
81
|
+
begin
|
82
|
+
yield
|
83
|
+
rescue Interrupt, SystemExit, SignalException
|
84
|
+
rescue Exception => e
|
85
|
+
DTR.error "Worker drb fork is stopped by Exception => #{e.class.name}, message => #{e.message}"
|
86
|
+
DTR.info e.backtrace.join("\n")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module Agent
|
17
|
+
module WorkingEnvExt
|
18
|
+
def within
|
19
|
+
ENV['DTR_MASTER_ENV'] = self[:dtr_master_env]
|
20
|
+
Dir.chdir(working_dir) do
|
21
|
+
yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_env(setup_env_cmd)
|
26
|
+
within do
|
27
|
+
Cmd.execute(setup_env_cmd || self[:agent_env_setup_cmd])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def escape(str)
|
33
|
+
str.gsub(/[^a-zA-Z0-9]/, '_')
|
34
|
+
end
|
35
|
+
|
36
|
+
def working_dir
|
37
|
+
return @working_dir if defined?(@working_dir)
|
38
|
+
project_name = self[:pwd].length > 20 ? self[:pwd][-20..-1] : self[:pwd]
|
39
|
+
@working_dir = File.join(escape(self[:host]), escape(project_name))
|
40
|
+
FileUtils.mkdir_p(@working_dir)
|
41
|
+
@working_dir
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/dtr/agent.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'dtr/shared'
|
16
|
+
require 'dtr/agent/working_env_ext'
|
17
|
+
require 'dtr/agent/sync_codebase'
|
18
|
+
|
19
|
+
require 'dtr/agent/sync_logger'
|
20
|
+
require 'dtr/agent/brain'
|
21
|
+
require 'dtr/agent/worker'
|
22
|
+
require 'dtr/agent/test_unit'
|
23
|
+
require 'dtr/agent/herald'
|
24
|
+
require 'dtr/agent/runner'
|
25
|
+
|
26
|
+
module DTR
|
27
|
+
module Agent
|
28
|
+
def start(runner_names=["Distributed Test Runner"], agent_env_setup_cmd=nil)
|
29
|
+
DTR.logger('dtr_agent.log')
|
30
|
+
Brain.new(runner_names, agent_env_setup_cmd).hypnotize
|
31
|
+
end
|
32
|
+
|
33
|
+
module_function :start
|
34
|
+
end
|
35
|
+
WorkingEnv.send(:include, Agent::WorkingEnvExt)
|
36
|
+
WorkingEnv.send(:include, SyncCodebase::WorkingEnvExt)
|
37
|
+
end
|
data/lib/dtr/master.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'dtr/shared'
|
16
|
+
|
17
|
+
module DTR
|
18
|
+
module Master
|
19
|
+
def with_dtr_master(&block)
|
20
|
+
if defined?(ActiveRecord::Base)
|
21
|
+
ActiveRecord::Base.clear_active_connections! rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
DTR.info ""
|
25
|
+
DTR.info "--------------------beautiful line--------------------------"
|
26
|
+
DTR.info {"Master process started at #{Time.now}"}
|
27
|
+
|
28
|
+
DTR.configuration.with_rinda_server do
|
29
|
+
provide_working_env WorkingEnv.new
|
30
|
+
with_wakeup_agents(&block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
include Adapter::Master
|
35
|
+
include Service::WorkingEnv
|
36
|
+
include SyncCodebase::MasterExt
|
37
|
+
end
|
38
|
+
|
39
|
+
Configuration.send(:include, SyncLogger::Provider)
|
40
|
+
end
|
data/lib/dtr/monitor.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'dtr/master'
|
16
|
+
|
17
|
+
module DTR
|
18
|
+
class Monitor
|
19
|
+
include Adapter::Master
|
20
|
+
include Service::Agent
|
21
|
+
def start
|
22
|
+
DTR.configuration.with_rinda_server do
|
23
|
+
monitor_thread = Thread.new do
|
24
|
+
new_agent_monitor.each { |t| puts t.last.last }
|
25
|
+
end
|
26
|
+
puts "Monitor process started at #{Time.now}"
|
27
|
+
|
28
|
+
with_wakeup_agents do
|
29
|
+
begin
|
30
|
+
monitor_thread.join
|
31
|
+
rescue Interrupt
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/dtr/raketasks.rb
CHANGED
@@ -14,11 +14,15 @@
|
|
14
14
|
|
15
15
|
require "rubygems"
|
16
16
|
require 'dtr'
|
17
|
+
require 'dtr/shared/sync_codebase/package'
|
18
|
+
require 'dtr/shared/ruby_ext'
|
19
|
+
require 'rake'
|
17
20
|
require 'rake/testtask'
|
21
|
+
require 'rake/tasklib'
|
18
22
|
|
19
23
|
module DTR
|
20
|
-
class
|
21
|
-
attr_accessor :processes
|
24
|
+
class TestTask < Rake::TestTask
|
25
|
+
attr_accessor :processes
|
22
26
|
|
23
27
|
def define
|
24
28
|
@libs.unshift DTR.lib_path
|
@@ -26,8 +30,7 @@ module DTR
|
|
26
30
|
|
27
31
|
desc "Run tests" + (@name==:test ? "" : " for #{@name}")
|
28
32
|
task @name do
|
29
|
-
|
30
|
-
start_runners
|
33
|
+
@agent = start_agent
|
31
34
|
run_code = ''
|
32
35
|
begin
|
33
36
|
RakeFileUtils.verbose(@verbose) do
|
@@ -41,9 +44,8 @@ module DTR
|
|
41
44
|
" #{option_list}"
|
42
45
|
end
|
43
46
|
ensure
|
44
|
-
|
45
|
-
|
46
|
-
DTR.stop_server_daemon_mode rescue nil
|
47
|
+
if defined?(@agent)
|
48
|
+
Process.kill 'TERM', @agent rescue nil
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -54,16 +56,75 @@ module DTR
|
|
54
56
|
@processes ? @processes.to_i : 2
|
55
57
|
end
|
56
58
|
|
57
|
-
def start_server?
|
58
|
-
defined?(@start_server) ? @start_server : true
|
59
|
-
end
|
60
|
-
|
61
59
|
private
|
62
|
-
def
|
60
|
+
def start_agent
|
63
61
|
return if self.processes.to_i <= 0
|
64
62
|
runner_names = []
|
65
63
|
self.processes.to_i.times {|i| runner_names << "runner#{i}"}
|
66
|
-
|
64
|
+
|
65
|
+
Process.fork do
|
66
|
+
DTR_AGENT_OPTIONS[:runners] = runner_names if DTR_AGENT_OPTIONS[:runners].empty?
|
67
|
+
DTR.start_agent
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# The following task is copied & modified from 'rake/packagetask'
|
73
|
+
class PackageTask < Rake::TaskLib
|
74
|
+
include SyncCodebase::Package
|
75
|
+
# List of files to be included in the package.
|
76
|
+
attr_accessor :package_files
|
77
|
+
|
78
|
+
# Tar command for gzipped or bzip2ed archives. The default is 'tar'.
|
79
|
+
attr_accessor :tar_command
|
80
|
+
|
81
|
+
# Create a Package Task with the given name and version.
|
82
|
+
def initialize
|
83
|
+
@package_files = Rake::FileList.new
|
84
|
+
@tar_command = 'tar'
|
85
|
+
yield self if block_given?
|
86
|
+
define
|
87
|
+
end
|
88
|
+
|
89
|
+
# Create the tasks defined by this task library.
|
90
|
+
def define
|
91
|
+
desc "Build packages for dtr task"
|
92
|
+
task :dtr_package
|
93
|
+
|
94
|
+
desc "Force a rebuild of the package files for dtr task"
|
95
|
+
task :dtr_repackage => [:dtr_clobber_package, :dtr_package]
|
96
|
+
|
97
|
+
desc "Remove package for dtr task"
|
98
|
+
task :dtr_clobber_package do
|
99
|
+
rm_r package_dir rescue nil
|
100
|
+
end
|
101
|
+
|
102
|
+
file, flag = package_file, 'j'
|
103
|
+
task :dtr_package => ["#{package_dir}/#{file}"]
|
104
|
+
|
105
|
+
file "#{package_dir}/#{file}" => [package_dir_path] do
|
106
|
+
chdir(package_dir) do
|
107
|
+
sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
directory package_dir
|
112
|
+
|
113
|
+
file package_dir_path do
|
114
|
+
mkdir_p package_dir rescue nil
|
115
|
+
@package_files.each do |fn|
|
116
|
+
f = File.join(package_dir_path, fn)
|
117
|
+
fdir = File.dirname(f)
|
118
|
+
mkdir_p(fdir) if !File.exist?(fdir)
|
119
|
+
if File.directory?(fn)
|
120
|
+
mkdir_p(f)
|
121
|
+
else
|
122
|
+
rm_f f
|
123
|
+
safe_ln(fn, f)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
self
|
67
128
|
end
|
68
129
|
end
|
69
130
|
end
|