right_agent 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +78 -0
- data/Rakefile +86 -0
- data/lib/right_agent.rb +66 -0
- data/lib/right_agent/actor.rb +163 -0
- data/lib/right_agent/actor_registry.rb +76 -0
- data/lib/right_agent/actors/agent_manager.rb +189 -0
- data/lib/right_agent/agent.rb +735 -0
- data/lib/right_agent/agent_config.rb +403 -0
- data/lib/right_agent/agent_identity.rb +209 -0
- data/lib/right_agent/agent_tags_manager.rb +213 -0
- data/lib/right_agent/audit_formatter.rb +107 -0
- data/lib/right_agent/broker_client.rb +683 -0
- data/lib/right_agent/command.rb +30 -0
- data/lib/right_agent/command/agent_manager_commands.rb +134 -0
- data/lib/right_agent/command/command_client.rb +136 -0
- data/lib/right_agent/command/command_constants.rb +42 -0
- data/lib/right_agent/command/command_io.rb +128 -0
- data/lib/right_agent/command/command_parser.rb +87 -0
- data/lib/right_agent/command/command_runner.rb +105 -0
- data/lib/right_agent/command/command_serializer.rb +63 -0
- data/lib/right_agent/console.rb +65 -0
- data/lib/right_agent/core_payload_types.rb +42 -0
- data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
- data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
- data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
- data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
- data/lib/right_agent/core_payload_types/dev_repositories.rb +90 -0
- data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
- data/lib/right_agent/core_payload_types/executable_bundle.rb +138 -0
- data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
- data/lib/right_agent/core_payload_types/login_user.rb +62 -0
- data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
- data/lib/right_agent/core_payload_types/recipe_instantiation.rb +60 -0
- data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
- data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
- data/lib/right_agent/core_payload_types/right_script_instantiation.rb +73 -0
- data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
- data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
- data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
- data/lib/right_agent/daemonize.rb +35 -0
- data/lib/right_agent/dispatcher.rb +348 -0
- data/lib/right_agent/enrollment_result.rb +217 -0
- data/lib/right_agent/exceptions.rb +30 -0
- data/lib/right_agent/ha_broker_client.rb +1278 -0
- data/lib/right_agent/idempotent_request.rb +140 -0
- data/lib/right_agent/log.rb +418 -0
- data/lib/right_agent/monkey_patches.rb +29 -0
- data/lib/right_agent/monkey_patches/amqp_patch.rb +274 -0
- data/lib/right_agent/monkey_patches/ruby_patch.rb +49 -0
- data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
- data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
- data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
- data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
- data/lib/right_agent/monkey_patches/ruby_patch/singleton_patch.rb +46 -0
- data/lib/right_agent/monkey_patches/ruby_patch/string_patch.rb +107 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +90 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
- data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
- data/lib/right_agent/multiplexer.rb +91 -0
- data/lib/right_agent/operation_result.rb +270 -0
- data/lib/right_agent/packets.rb +637 -0
- data/lib/right_agent/payload_formatter.rb +104 -0
- data/lib/right_agent/pid_file.rb +159 -0
- data/lib/right_agent/platform.rb +319 -0
- data/lib/right_agent/platform/darwin.rb +227 -0
- data/lib/right_agent/platform/linux.rb +268 -0
- data/lib/right_agent/platform/windows.rb +1204 -0
- data/lib/right_agent/scripts/agent_controller.rb +522 -0
- data/lib/right_agent/scripts/agent_deployer.rb +379 -0
- data/lib/right_agent/scripts/common_parser.rb +153 -0
- data/lib/right_agent/scripts/log_level_manager.rb +193 -0
- data/lib/right_agent/scripts/stats_manager.rb +256 -0
- data/lib/right_agent/scripts/usage.rb +58 -0
- data/lib/right_agent/secure_identity.rb +92 -0
- data/lib/right_agent/security.rb +32 -0
- data/lib/right_agent/security/cached_certificate_store_proxy.rb +63 -0
- data/lib/right_agent/security/certificate.rb +102 -0
- data/lib/right_agent/security/certificate_cache.rb +89 -0
- data/lib/right_agent/security/distinguished_name.rb +56 -0
- data/lib/right_agent/security/encrypted_document.rb +84 -0
- data/lib/right_agent/security/rsa_key_pair.rb +76 -0
- data/lib/right_agent/security/signature.rb +86 -0
- data/lib/right_agent/security/static_certificate_store.rb +69 -0
- data/lib/right_agent/sender.rb +937 -0
- data/lib/right_agent/serialize.rb +29 -0
- data/lib/right_agent/serialize/message_pack.rb +102 -0
- data/lib/right_agent/serialize/secure_serializer.rb +131 -0
- data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
- data/lib/right_agent/serialize/serializable.rb +135 -0
- data/lib/right_agent/serialize/serializer.rb +149 -0
- data/lib/right_agent/stats_helper.rb +731 -0
- data/lib/right_agent/subprocess.rb +38 -0
- data/lib/right_agent/tracer.rb +124 -0
- data/right_agent.gemspec +60 -0
- data/spec/actor_registry_spec.rb +81 -0
- data/spec/actor_spec.rb +99 -0
- data/spec/agent_config_spec.rb +226 -0
- data/spec/agent_identity_spec.rb +75 -0
- data/spec/agent_spec.rb +571 -0
- data/spec/broker_client_spec.rb +961 -0
- data/spec/command/agent_manager_commands_spec.rb +51 -0
- data/spec/command/command_io_spec.rb +93 -0
- data/spec/command/command_parser_spec.rb +79 -0
- data/spec/command/command_runner_spec.rb +72 -0
- data/spec/command/command_serializer_spec.rb +51 -0
- data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
- data/spec/core_payload_types/executable_bundle_spec.rb +59 -0
- data/spec/core_payload_types/login_user_spec.rb +98 -0
- data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
- data/spec/core_payload_types/spec_helper.rb +23 -0
- data/spec/dispatcher_spec.rb +372 -0
- data/spec/enrollment_result_spec.rb +53 -0
- data/spec/ha_broker_client_spec.rb +1673 -0
- data/spec/idempotent_request_spec.rb +136 -0
- data/spec/log_spec.rb +177 -0
- data/spec/monkey_patches/amqp_patch_spec.rb +100 -0
- data/spec/monkey_patches/eventmachine_spec.rb +62 -0
- data/spec/monkey_patches/string_patch_spec.rb +99 -0
- data/spec/multiplexer_spec.rb +48 -0
- data/spec/operation_result_spec.rb +171 -0
- data/spec/packets_spec.rb +418 -0
- data/spec/platform/platform_spec.rb +60 -0
- data/spec/results_mock.rb +45 -0
- data/spec/secure_identity_spec.rb +50 -0
- data/spec/security/cached_certificate_store_proxy_spec.rb +56 -0
- data/spec/security/certificate_cache_spec.rb +71 -0
- data/spec/security/certificate_spec.rb +49 -0
- data/spec/security/distinguished_name_spec.rb +46 -0
- data/spec/security/encrypted_document_spec.rb +55 -0
- data/spec/security/rsa_key_pair_spec.rb +55 -0
- data/spec/security/signature_spec.rb +66 -0
- data/spec/security/static_certificate_store_spec.rb +52 -0
- data/spec/sender_spec.rb +887 -0
- data/spec/serialize/message_pack_spec.rb +131 -0
- data/spec/serialize/secure_serializer_spec.rb +102 -0
- data/spec/serialize/serializable_spec.rb +90 -0
- data/spec/serialize/serializer_spec.rb +174 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +77 -0
- data/spec/stats_helper_spec.rb +681 -0
- data/spec/tracer_spec.rb +114 -0
- metadata +320 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
24
|
+
|
25
|
+
describe RightScale::IdempotentRequest do
|
26
|
+
|
27
|
+
module RightScale
|
28
|
+
class SenderMock
|
29
|
+
include Singleton
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
before(:all) do
|
34
|
+
if @sender_exists = RightScale.const_defined?(:Sender)
|
35
|
+
RightScale.module_eval('OldSender = Sender')
|
36
|
+
end
|
37
|
+
RightScale.module_eval('Sender = SenderMock')
|
38
|
+
end
|
39
|
+
|
40
|
+
after(:all) do
|
41
|
+
if @sender_exists
|
42
|
+
RightScale.module_eval('Sender = OldSender')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context ':targets option' do
|
47
|
+
context 'when :targets=>nil' do
|
48
|
+
it 'should send target-less requests' do
|
49
|
+
request = RightScale::IdempotentRequest.new('type', 'payload')
|
50
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', nil, Proc).
|
51
|
+
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
52
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).once
|
53
|
+
request.run
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when one target is specified' do
|
58
|
+
it 'should send a targeted request' do
|
59
|
+
request = RightScale::IdempotentRequest.new('type', 'payload', :targets=>[1])
|
60
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', 1, Proc).
|
61
|
+
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
62
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).once
|
63
|
+
request.run
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when many targets are specified' do
|
68
|
+
it 'should choose a random target' do
|
69
|
+
request = RightScale::IdempotentRequest.new('type', 'payload', :targets=>[1, 2, 3])
|
70
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).and_return do |type, payload, tgt, block|
|
71
|
+
type.should == 'type'
|
72
|
+
payload.should == 'payload'
|
73
|
+
[1,2,3].should include(tgt)
|
74
|
+
block.call(RightScale::OperationResult.non_delivery('test'))
|
75
|
+
end
|
76
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).once
|
77
|
+
request.run
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should retry non-delivery responses' do
|
83
|
+
request = RightScale::IdempotentRequest.new('type', 'payload')
|
84
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', nil, Proc).
|
85
|
+
and_yield(RightScale::OperationResult.non_delivery('test')).once
|
86
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).once
|
87
|
+
request.run
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should retry retry responses' do
|
91
|
+
request = RightScale::IdempotentRequest.new('type', 'payload')
|
92
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', nil, Proc).
|
93
|
+
and_yield(RightScale::OperationResult.retry('test')).once
|
94
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).once
|
95
|
+
request.run
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should fail in case of error responses by default' do
|
99
|
+
request = RightScale::IdempotentRequest.new('type', 'payload')
|
100
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', nil, Proc).
|
101
|
+
and_yield(RightScale::OperationResult.error('test')).once
|
102
|
+
flexmock(request).should_receive(:fail).once
|
103
|
+
request.run
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should retry error responses when told to' do
|
107
|
+
request = RightScale::IdempotentRequest.new('type', 'payload', :retry_on_error => true)
|
108
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', nil, Proc).
|
109
|
+
and_yield(RightScale::OperationResult.error('test')).once
|
110
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).once
|
111
|
+
request.run
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should ignore responses that arrive post-cancel' do
|
115
|
+
request = RightScale::IdempotentRequest.new('type', 'payload')
|
116
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).with('type', 'payload', nil, Proc).
|
117
|
+
and_yield(RightScale::OperationResult.success('test')).once
|
118
|
+
flexmock(request).should_receive(:fail).once
|
119
|
+
flexmock(request).should_receive(:succeed).never
|
120
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, Proc).never
|
121
|
+
request.cancel('test')
|
122
|
+
request.run
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should ignore duplicate responses' do
|
126
|
+
request = RightScale::IdempotentRequest.new('type', 'payload', :retry_on_error => true)
|
127
|
+
flexmock(RightScale::Sender.instance).should_receive(:send_retryable_request).and_return do |t, p, tgt, b|
|
128
|
+
5.times { b.call(RightScale::OperationResult.success('test')) }
|
129
|
+
end
|
130
|
+
flexmock(request).should_receive(:fail).never
|
131
|
+
flexmock(request).should_receive(:succeed).once
|
132
|
+
flexmock(EM).should_receive(:add_timer).with(RightScale::IdempotentRequest::DEFAULT_RETRY_DELAY, nil, Proc).never
|
133
|
+
request.run
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
|
24
|
+
|
25
|
+
describe RightScale::Log do
|
26
|
+
|
27
|
+
# Count number of lines logged with the specified text
|
28
|
+
# Search is case sensitive and regular expression sensitive
|
29
|
+
#
|
30
|
+
# === Parameters
|
31
|
+
# text(String):: Text to search for
|
32
|
+
#
|
33
|
+
# === Return
|
34
|
+
# (Integer):: Number of lines where text found
|
35
|
+
def log_count(text)
|
36
|
+
# no such animal as egrep in windows, so hacked up an equivalent here.
|
37
|
+
pattern = Regexp.compile(text)
|
38
|
+
File.read(@log_file).each.select { |x| x =~ pattern }.count
|
39
|
+
end
|
40
|
+
|
41
|
+
before(:all) do
|
42
|
+
ENV['RS_LOG'] = 'true'
|
43
|
+
end
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
Singleton.__init__(RightScale::Log)
|
47
|
+
end
|
48
|
+
|
49
|
+
after(:all) do
|
50
|
+
Singleton.__init__(RightScale::Log)
|
51
|
+
ENV['RS_LOG'] = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should set default level to info' do
|
55
|
+
RightScale::Log.level.should == :info
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should change level to debug when force_debug' do
|
59
|
+
RightScale::Log.level.should == :info
|
60
|
+
RightScale::Log.force_debug
|
61
|
+
RightScale::Log.level.should == :debug
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should notify of log level change' do
|
65
|
+
RightScale::Log.level.should == :info
|
66
|
+
notified = nil
|
67
|
+
RightScale::Log.notify(lambda{ |l| notified = l })
|
68
|
+
RightScale::Log.level = :debug
|
69
|
+
notified.should == Logger::DEBUG
|
70
|
+
end
|
71
|
+
|
72
|
+
context "logging" do
|
73
|
+
|
74
|
+
before(:each) do
|
75
|
+
# note that log directory doesn't necessarily exist in Windows dev/test
|
76
|
+
# environment.
|
77
|
+
log_dir = RightScale::Platform.filesystem.log_dir
|
78
|
+
FileUtils.mkdir_p(log_dir) unless File.directory?(log_dir)
|
79
|
+
|
80
|
+
# use a unique name for the test because the file cannot be deleted after
|
81
|
+
# the test in the Windows case (until the process exits) and we need to
|
82
|
+
# avoid any potential conflicts with other tests, etc.
|
83
|
+
@log_name = "log_test-9D9A9CB7-24A1-4093-9F75-D462D373A0D8"
|
84
|
+
@log_file = File.join(log_dir, "#{@log_name}.log")
|
85
|
+
RightScale::Log.program_name = "tester"
|
86
|
+
RightScale::Log.log_to_file_only(true)
|
87
|
+
RightScale::Log.init(@log_name, log_dir)
|
88
|
+
end
|
89
|
+
|
90
|
+
after(:each) do
|
91
|
+
# note that the log is held open in the Windows case by Log so we
|
92
|
+
# cannot delete it after each test. on the other hand, we can truncate the
|
93
|
+
# log to zero size and continue to the next test (ultimately leaving an
|
94
|
+
# empty file after the test, which is acceptable).
|
95
|
+
File.delete(@log_file) if File.file?(@log_file) rescue File.truncate(@log_file, 0)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should log info but not debug by default' do
|
99
|
+
RightScale::Log.debug("Test debug")
|
100
|
+
RightScale::Log.info("Test info")
|
101
|
+
log_count("Test debug$").should == 0
|
102
|
+
log_count("Test info$").should == 1
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should log debug after adjust level to :debug' do
|
106
|
+
RightScale::Log.level = :debug
|
107
|
+
RightScale::Log.debug("Test debug")
|
108
|
+
RightScale::Log.info("Test info")
|
109
|
+
log_count("Test debug$").should == 1
|
110
|
+
log_count("Test info$").should == 1
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should log additional error string when given' do
|
114
|
+
RightScale::Log.warning("Test warning", "Error")
|
115
|
+
RightScale::Log.error("Test error", "Error")
|
116
|
+
log_count("Test warning \\\(Error\\\)$").should == 1
|
117
|
+
log_count("Test error \\\(Error\\\)$").should == 1
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should log without exception when none given' do
|
121
|
+
begin
|
122
|
+
nil + "string"
|
123
|
+
rescue Exception => e
|
124
|
+
RightScale::Log.warning("Test warning")
|
125
|
+
RightScale::Log.error("Test error")
|
126
|
+
end
|
127
|
+
log_count("Test warning$").should == 1
|
128
|
+
log_count("Test error$").should == 1
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should log with exception class, message, and caller appended by default when exception given' do
|
132
|
+
begin
|
133
|
+
nil + "string"
|
134
|
+
rescue Exception => e
|
135
|
+
RightScale::Log.warning("Test warning", e)
|
136
|
+
RightScale::Log.error("Test error", e)
|
137
|
+
end
|
138
|
+
log_count("Test warning \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass in .*log_spec.*\\\)$").should == 1
|
139
|
+
log_count("Test error \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass in .*log_spec.*\\\)$").should == 1
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should log with exception class, message, and caller appended when use :caller' do
|
143
|
+
begin
|
144
|
+
nil + "string"
|
145
|
+
rescue Exception => e
|
146
|
+
RightScale::Log.warning("Test warning", e, :caller)
|
147
|
+
RightScale::Log.error("Test error", e, :caller)
|
148
|
+
end
|
149
|
+
log_count("Test warning \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass in .*log_spec.*\\\)$").should == 1
|
150
|
+
log_count("Test error \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass in .*log_spec.*\\\)$").should == 1
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should log with exception class and message appended when use :no_trace' do
|
154
|
+
begin
|
155
|
+
nil + "string"
|
156
|
+
rescue Exception => e
|
157
|
+
RightScale::Log.warning("Test warning", e, :no_trace)
|
158
|
+
RightScale::Log.error("Test error", e, :no_trace)
|
159
|
+
end
|
160
|
+
log_count("Test warning \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass\\\)$").should == 1
|
161
|
+
log_count("Test error \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass\\\)$").should == 1
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should log with exception class, message, and full backtrace appended when use :trace' do
|
165
|
+
begin
|
166
|
+
nil + "string"
|
167
|
+
rescue Exception => e
|
168
|
+
RightScale::Log.warning("Test warning", e, :trace)
|
169
|
+
RightScale::Log.error("Test error", e, :trace)
|
170
|
+
end
|
171
|
+
log_count("Test warning \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass in$").should == 1
|
172
|
+
log_count("Test error \\\(NoMethodError: undefined method \\\`\\\+\' for nil:NilClass in$").should == 1
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
24
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'right_agent', 'monkey_patches', 'amqp_patch'))
|
25
|
+
|
26
|
+
describe AMQP::Client do
|
27
|
+
context 'with an incorrect AMQP password' do
|
28
|
+
class SUT
|
29
|
+
include AMQP::Client
|
30
|
+
|
31
|
+
attr_accessor :reconnecting, :settings, :channels
|
32
|
+
end
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
@sut = flexmock(SUT.new)
|
36
|
+
@sut.reconnecting = false
|
37
|
+
@sut.settings = {:host => 'testhost', :port=>'12345'}
|
38
|
+
@sut.channels = {}
|
39
|
+
|
40
|
+
@sut.should_receive(:initialize)
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'and no :reconnect_delay' do
|
44
|
+
it 'should reconnect immediately' do
|
45
|
+
flexmock(EM).should_receive(:reconnect).once
|
46
|
+
flexmock(EM).should_receive(:add_timer).never
|
47
|
+
|
48
|
+
@sut.reconnect()
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'and a :reconnect_delay of true' do
|
53
|
+
it 'should reconnect immediately' do
|
54
|
+
@sut.settings[:reconnect_delay] = true
|
55
|
+
|
56
|
+
flexmock(EM).should_receive(:reconnect).once
|
57
|
+
flexmock(EM).should_receive(:add_timer).never
|
58
|
+
|
59
|
+
@sut.reconnect()
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'and a :reconnect_delay of 15 seconds' do
|
64
|
+
it 'should schedule a reconnect attempt in 15s' do
|
65
|
+
@sut.settings[:reconnect_delay] = 15
|
66
|
+
|
67
|
+
flexmock(EM).should_receive(:reconnect).never
|
68
|
+
flexmock(EM).should_receive(:add_timer).with(15, Proc).once
|
69
|
+
|
70
|
+
@sut.reconnect()
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'and a :reconnect_delay containing a Proc that returns 30' do
|
75
|
+
it 'should schedule a reconnect attempt in 30s' do
|
76
|
+
@sut.settings[:reconnect_delay] = Proc.new {30}
|
77
|
+
|
78
|
+
flexmock(EM).should_receive(:reconnect).never
|
79
|
+
flexmock(EM).should_receive(:add_timer).with(30, Proc).once
|
80
|
+
|
81
|
+
@sut.reconnect()
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'and a :reconnect_interval of 5 seconds' do
|
86
|
+
it 'should schedule reconnect attempts on a 5s interval' do
|
87
|
+
@sut.reconnecting = true
|
88
|
+
@sut.settings[:reconnect_delay] = 15
|
89
|
+
@sut.settings[:reconnect_interval] = 5
|
90
|
+
|
91
|
+
flexmock(EM).should_receive(:reconnect).never
|
92
|
+
flexmock(EM).should_receive(:add_timer).with(5, Proc).once
|
93
|
+
|
94
|
+
@sut.reconnect()
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2009-2011 RightScale Inc
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
24
|
+
|
25
|
+
describe EventMachine do
|
26
|
+
|
27
|
+
it "should not repeatedly run deferred task if task raises an exception" do
|
28
|
+
error = nil
|
29
|
+
count = 0
|
30
|
+
EM.error_handler { |e| error = e; raise e if (count += 1) > 1 }
|
31
|
+
|
32
|
+
begin
|
33
|
+
EM.run do
|
34
|
+
EM.add_timer(1) { EM.next_tick { EM.stop } }
|
35
|
+
EM.next_tick { raise 'test' }
|
36
|
+
end
|
37
|
+
rescue Exception => error
|
38
|
+
error.should == nil
|
39
|
+
end
|
40
|
+
|
41
|
+
EM.error_handler(nil)
|
42
|
+
|
43
|
+
error.class.should == RuntimeError
|
44
|
+
error.message.should == 'test'
|
45
|
+
count.should == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should end EM loop if deferred task raises an exception and there is no error handler" do
|
49
|
+
count = 0
|
50
|
+
begin
|
51
|
+
EM.run do
|
52
|
+
EM.add_timer(0) { raise 'test' }
|
53
|
+
end
|
54
|
+
rescue Exception => error
|
55
|
+
error.class.should == RuntimeError
|
56
|
+
error.message.should == 'test'
|
57
|
+
count += 1
|
58
|
+
end
|
59
|
+
count.should == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|