qpid_proton 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/README.md +76 -0
- data/examples/broker.rb +167 -0
- data/examples/client.rb +79 -0
- data/examples/direct_recv.rb +61 -0
- data/examples/direct_send.rb +67 -0
- data/examples/example_test.rb +109 -0
- data/examples/helloworld.rb +57 -0
- data/examples/server.rb +70 -0
- data/examples/simple_recv.rb +57 -0
- data/examples/simple_send.rb +63 -0
- data/examples/ssl_certs/README.txt +24 -0
- data/examples/ssl_certs/tclient-certificate.p12 +0 -0
- data/examples/ssl_certs/tclient-certificate.pem +19 -0
- data/examples/ssl_certs/tclient-full.p12 +0 -0
- data/examples/ssl_certs/tclient-private-key.pem +30 -0
- data/examples/ssl_certs/tserver-certificate.p12 +0 -0
- data/examples/ssl_certs/tserver-certificate.pem +19 -0
- data/examples/ssl_certs/tserver-full.p12 +0 -0
- data/examples/ssl_certs/tserver-private-key.pem +30 -0
- data/examples/ssl_send.rb +70 -0
- data/ext/cproton/cproton.c +105 -74
- data/lib/core/container.rb +2 -1
- data/lib/core/ssl_domain.rb +1 -1
- data/lib/core/uri.rb +15 -9
- data/lib/handler/messaging_adapter.rb +20 -5
- data/tests/old_examples/broker.rb +200 -0
- data/tests/old_examples/client.rb +81 -0
- data/tests/old_examples/direct_recv.rb +64 -0
- data/tests/old_examples/direct_send.rb +63 -0
- data/tests/old_examples/helloworld.rb +72 -0
- data/tests/old_examples/helloworld_direct.rb +73 -0
- data/tests/old_examples/lib/debugging.rb +25 -0
- data/tests/old_examples/lib/driver.rb +68 -0
- data/tests/old_examples/lib/qpid_examples.rb +26 -0
- data/tests/old_examples/lib/selectable.rb +119 -0
- data/tests/old_examples/lib/send_and_receive.rb +89 -0
- data/tests/old_examples/old_example_test.rb +107 -0
- data/tests/old_examples/recv.rb +23 -0
- data/tests/old_examples/send.rb +21 -0
- data/tests/old_examples/server.rb +75 -0
- data/tests/old_examples/simple_recv.rb +57 -0
- data/tests/old_examples/simple_send.rb +54 -0
- data/tests/test_connection_driver.rb +134 -0
- data/tests/test_container.rb +319 -0
- data/tests/test_data.rb +66 -0
- data/tests/test_delivery.rb +110 -0
- data/tests/test_interop.rb +131 -0
- data/tests/test_messaging_adapter.rb +223 -0
- data/tests/test_old_adapter.rb +228 -0
- data/tests/test_tools.rb +147 -0
- data/tests/test_uri.rb +83 -0
- metadata +49 -3
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test_tools'
|
4
|
+
require 'qpid_proton'
|
5
|
+
|
6
|
+
if ((RUBY_VERSION.split(".").map {|x| x.to_i} <=> [1, 9]) < 0)
|
7
|
+
require 'pathname'
|
8
|
+
class File
|
9
|
+
def self.absolute_path(name)
|
10
|
+
return Pathname.new(name).realpath
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class InteropTest < MiniTest::Test
|
16
|
+
include Qpid::Proton
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@data = Codec::Data.new
|
20
|
+
@message = Message.new
|
21
|
+
end
|
22
|
+
|
23
|
+
# Walk up the directory tree to find the tests directory.
|
24
|
+
def get_data(name)
|
25
|
+
path = File.join(File.dirname(__FILE__), "../../../../tests/interop/#{name}.amqp")
|
26
|
+
raise "Can't find test/interop directory from #{__FILE__}" unless File.exists?(path)
|
27
|
+
File.open(path, "rb") { |f| f.read }
|
28
|
+
end
|
29
|
+
|
30
|
+
# Decode encoded bytes as a Data object
|
31
|
+
def decode_data(encoded)
|
32
|
+
buffer = encoded
|
33
|
+
while buffer.size > 0
|
34
|
+
n = @data.decode(buffer)
|
35
|
+
buffer = buffer[n..-1]
|
36
|
+
end
|
37
|
+
@data.rewind
|
38
|
+
reencoded = @data.encode
|
39
|
+
# Test the round-trip re-encoding gives the same result.
|
40
|
+
assert_equal(encoded, reencoded)
|
41
|
+
end
|
42
|
+
|
43
|
+
def decode_data_file(name) decode_data(get_data(name)); end
|
44
|
+
|
45
|
+
def decode_message_file(name)
|
46
|
+
message = Message.new()
|
47
|
+
message.decode(self.get_data(name))
|
48
|
+
self.decode_data(message.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_next(type, value)
|
52
|
+
assert @data.next
|
53
|
+
assert_equal(type, @data.type)
|
54
|
+
assert_equal(value, @data.object)
|
55
|
+
end
|
56
|
+
|
57
|
+
def assert_array_next(expected)
|
58
|
+
result = @data.next_object
|
59
|
+
assert_equal(expected, result)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_message
|
63
|
+
decode_message_file("message")
|
64
|
+
assert_next(Codec::STRING, "hello")
|
65
|
+
assert !@data.next
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_primitives
|
69
|
+
decode_data_file("primitives")
|
70
|
+
assert_next(Codec::BOOL, true)
|
71
|
+
assert_next(Codec::BOOL, false)
|
72
|
+
assert_next(Codec::UBYTE, 42)
|
73
|
+
assert_next(Codec::USHORT, 42)
|
74
|
+
assert_next(Codec::SHORT, -42)
|
75
|
+
assert_next(Codec::UINT, 12345)
|
76
|
+
assert_next(Codec::INT, -12345)
|
77
|
+
assert_next(Codec::ULONG, 12345)
|
78
|
+
assert_next(Codec::LONG, -12345)
|
79
|
+
assert_next(Codec::FLOAT, 0.125)
|
80
|
+
assert_next(Codec::DOUBLE, 0.125)
|
81
|
+
assert !@data.next
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_strings
|
85
|
+
decode_data_file("strings")
|
86
|
+
assert_next(Codec::BINARY, "abc\0defg")
|
87
|
+
assert_next(Codec::STRING, "abcdefg")
|
88
|
+
assert_next(Codec::SYMBOL, :abcdefg)
|
89
|
+
assert_next(Codec::BINARY, "")
|
90
|
+
assert_next(Codec::STRING, "")
|
91
|
+
assert_next(Codec::SYMBOL, :"")
|
92
|
+
assert !@data.next
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_described
|
96
|
+
decode_data_file("described")
|
97
|
+
assert_next(Codec::DESCRIBED, Types::Described.new(:"foo-descriptor", "foo-value"))
|
98
|
+
assert(@data.described?)
|
99
|
+
assert_next(Codec::DESCRIBED, Types::Described.new(12, 13))
|
100
|
+
assert(@data.described?)
|
101
|
+
assert !@data.next
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_described_array
|
105
|
+
decode_data_file("described_array")
|
106
|
+
assert_array_next(Types::UniformArray.new(Types::INT, (0...10).to_a, :"int-array"))
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_arrays
|
110
|
+
decode_data_file("arrays")
|
111
|
+
assert_array_next(Types::UniformArray.new(Codec::INT, (0...100).to_a))
|
112
|
+
assert_array_next(Types::UniformArray.new(Codec::STRING, ["a", "b", "c"]))
|
113
|
+
assert_array_next(Types::UniformArray.new(Codec::INT))
|
114
|
+
assert !@data.next
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_lists
|
118
|
+
decode_data_file("lists")
|
119
|
+
assert_next(Codec::LIST, [32, "foo", true])
|
120
|
+
assert_next(Codec::LIST, [])
|
121
|
+
assert !@data.next
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_maps
|
125
|
+
decode_data_file("maps")
|
126
|
+
assert_next(Codec::MAP, {"one" => 1, "two" => 2, "three" => 3 })
|
127
|
+
assert_next(Codec::MAP, {1 => "one", 2 => "two", 3 => "three"})
|
128
|
+
assert_next(Codec::MAP, {})
|
129
|
+
assert !@data.next
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require 'minitest/autorun'
|
20
|
+
require 'qpid_proton'
|
21
|
+
require 'test_tools'
|
22
|
+
include Qpid::Proton
|
23
|
+
|
24
|
+
# Records every call, never provokes "on_unhandled"
|
25
|
+
class RecordingHandler < Qpid::Proton::MessagingHandler
|
26
|
+
|
27
|
+
def initialize(*args) super(*args); @calls = []; end
|
28
|
+
|
29
|
+
attr_accessor :calls
|
30
|
+
|
31
|
+
def names() @calls.collect { |c| c[0] }; end
|
32
|
+
|
33
|
+
def clear() @calls.clear; end
|
34
|
+
|
35
|
+
def method_missing(name, *args)
|
36
|
+
respond_to_missing?(name) ? (@calls << [name, *args]) : super;
|
37
|
+
end
|
38
|
+
def respond_to_missing?(name, private=false); (/^on_/ =~ name); end
|
39
|
+
def respond_to?(name, all=false) super || respond_to_missing?(name); end # For ruby < 1.9.2
|
40
|
+
end
|
41
|
+
|
42
|
+
class NoAutoOpenClose < RecordingHandler
|
43
|
+
def initialize() super; @endpoints = []; end
|
44
|
+
def on_connection_open(x) @connection = x; super; raise StopAutoResponse; end
|
45
|
+
def on_session_open(x) @session = x; super; raise StopAutoResponse; end
|
46
|
+
def on_sender_open(x) @link = x; super; raise StopAutoResponse; end
|
47
|
+
def on_receiver_open(x) @link = x; super; raise StopAutoResponse; end
|
48
|
+
def on_connection_close(x) super; raise StopAutoResponse; end
|
49
|
+
def on_session_close(x) super; raise StopAutoResponse; end
|
50
|
+
def on_sender_close(x) super; raise StopAutoResponse; end
|
51
|
+
def on_receiver_close(x) super; raise StopAutoResponse; end
|
52
|
+
attr_reader :connection, :session, :link
|
53
|
+
end
|
54
|
+
|
55
|
+
class TestMessagingHandler < MiniTest::Test
|
56
|
+
|
57
|
+
def test_auto_open_close
|
58
|
+
d = DriverPair.new(RecordingHandler.new, RecordingHandler.new)
|
59
|
+
d.client.connection.open; d.client.connection.open_sender; d.run
|
60
|
+
assert_equal [:on_connection_open, :on_session_open, :on_sender_open, :on_sendable], d.client.handler.names
|
61
|
+
assert_equal [:on_connection_open, :on_session_open, :on_receiver_open], d.server.handler.names
|
62
|
+
d.clear
|
63
|
+
d.client.connection.close; d.run
|
64
|
+
assert_equal [:on_connection_close, :on_transport_close], d.server.handler.names
|
65
|
+
assert_equal [:on_connection_close, :on_transport_close], d.client.handler.names
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_no_auto_open_close
|
69
|
+
d = DriverPair.new(NoAutoOpenClose.new, NoAutoOpenClose.new)
|
70
|
+
d.client.connection.open; d.run
|
71
|
+
assert_equal [:on_connection_open], d.server.handler.names
|
72
|
+
assert_equal [], d.client.handler.names
|
73
|
+
d.server.connection.open; d.run
|
74
|
+
assert_equal [:on_connection_open], d.client.handler.names
|
75
|
+
assert_equal [:on_connection_open], d.server.handler.names
|
76
|
+
d.clear
|
77
|
+
d.client.connection.open_session; d.run
|
78
|
+
assert_equal [:on_session_open], d.server.handler.names
|
79
|
+
assert_equal [], d.client.handler.names
|
80
|
+
d.clear
|
81
|
+
d.client.connection.close;
|
82
|
+
3.times { d.process }
|
83
|
+
assert_equal [:on_connection_close], d.server.handler.names
|
84
|
+
assert_equal [], d.client.handler.names
|
85
|
+
d.server.connection.close; d.run
|
86
|
+
assert_equal [:on_connection_close, :on_transport_close], d.client.handler.names
|
87
|
+
assert_equal [:on_connection_close, :on_transport_close], d.server.handler.names
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_transport_error
|
91
|
+
d = DriverPair.new(RecordingHandler.new, RecordingHandler.new)
|
92
|
+
d.client.connection.open; d.run
|
93
|
+
d.clear
|
94
|
+
d.client.close "stop that"; d.run
|
95
|
+
assert_equal [:on_transport_close], d.client.handler.names
|
96
|
+
assert_equal [:on_transport_error, :on_transport_close], d.server.handler.names
|
97
|
+
assert_equal Condition.new("proton:io", "stop that (connection aborted)"), d.client.transport.condition
|
98
|
+
assert_equal Condition.new("amqp:connection:framing-error", "connection aborted"), d.server.transport.condition
|
99
|
+
end
|
100
|
+
|
101
|
+
# Close on half-open
|
102
|
+
def test_connection_error
|
103
|
+
d = DriverPair.new(NoAutoOpenClose.new, NoAutoOpenClose.new)
|
104
|
+
d.client.connection.open; d.run
|
105
|
+
d.server.connection.close "bad dog"; d.run
|
106
|
+
d.client.connection.close; d.run
|
107
|
+
assert_equal [:on_connection_open, :on_connection_error, :on_connection_close, :on_transport_close], d.client.handler.names
|
108
|
+
assert_equal "bad dog", d.client.handler.calls[1][1].condition.description
|
109
|
+
assert_equal [:on_connection_open, :on_connection_error, :on_connection_close, :on_transport_close], d.server.handler.names
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_session_error
|
113
|
+
d = DriverPair.new(RecordingHandler.new, RecordingHandler.new)
|
114
|
+
d.client.connection.open
|
115
|
+
s = d.client.connection.session; s.open; d.run
|
116
|
+
assert_equal [:on_connection_open, :on_session_open], d.client.handler.names
|
117
|
+
assert_equal [:on_connection_open, :on_session_open], d.server.handler.names
|
118
|
+
d.clear
|
119
|
+
s.close "bad dog"; d.run
|
120
|
+
assert_equal [:on_session_error, :on_session_close], d.client.handler.names
|
121
|
+
assert_equal [:on_session_error, :on_session_close], d.server.handler.names
|
122
|
+
assert_equal "bad dog", d.server.handler.calls[0][1].condition.description
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_sender_receiver_error
|
126
|
+
d = DriverPair.new(RecordingHandler.new, RecordingHandler.new)
|
127
|
+
d.client.connection.open
|
128
|
+
s = d.client.connection.open_sender; d.run
|
129
|
+
assert_equal [:on_connection_open, :on_session_open, :on_sender_open, :on_sendable], d.client.handler.names
|
130
|
+
assert_equal [:on_connection_open, :on_session_open, :on_receiver_open], d.server.handler.names
|
131
|
+
d.clear
|
132
|
+
s.close "bad dog"; d.run
|
133
|
+
assert_equal [:on_sender_error, :on_sender_close], d.client.handler.names
|
134
|
+
assert_equal [:on_receiver_error, :on_receiver_close], d.server.handler.names
|
135
|
+
assert_equal "bad dog", d.server.handler.calls[0][1].condition.description
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_options_off
|
139
|
+
linkopts = {:credit_window=>0, :auto_settle=>false, :auto_accept=>false}
|
140
|
+
d = DriverPair.new(NoAutoOpenClose.new, NoAutoOpenClose.new)
|
141
|
+
d.client.connection.open; d.run
|
142
|
+
assert_equal [[], [:on_connection_open]], d.names
|
143
|
+
d.server.connection.open; d.run
|
144
|
+
assert_equal [[:on_connection_open], [:on_connection_open]], d.names
|
145
|
+
d.clear
|
146
|
+
s = d.client.connection.open_sender(linkopts); d.run
|
147
|
+
assert_equal [[], [:on_session_open, :on_receiver_open]], d.names
|
148
|
+
d.server.handler.session.open # Return session open
|
149
|
+
d.server.handler.link.open(linkopts) # Return link open
|
150
|
+
d.run
|
151
|
+
assert_equal [[:on_session_open, :on_sender_open], [:on_session_open, :on_receiver_open]], d.names
|
152
|
+
d.clear
|
153
|
+
d.server.handler.link.flow(1); d.run
|
154
|
+
assert_equal [[:on_sendable], []], d.names
|
155
|
+
assert_equal 1, s.credit
|
156
|
+
d.clear
|
157
|
+
s.send Message.new("foo"); d.run
|
158
|
+
assert_equal [[], [:on_message]], d.names
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_message
|
162
|
+
handler_class = Class.new(MessagingHandler) do
|
163
|
+
def on_message(delivery, message) @message = message; end
|
164
|
+
def on_tracker_accept(event) @accepted = true; end
|
165
|
+
attr_accessor :message, :accepted
|
166
|
+
end
|
167
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
168
|
+
d.client.connection.open;
|
169
|
+
s = d.client.connection.open_sender; d.run
|
170
|
+
assert_equal 10, s.credit # Default prefetch
|
171
|
+
s.send(Message.new("foo")); d.run
|
172
|
+
assert_equal "foo", d.server.handler.message.body
|
173
|
+
assert d.client.handler.accepted
|
174
|
+
end
|
175
|
+
|
176
|
+
# Verify on_unhandled is called
|
177
|
+
def test_unhandled
|
178
|
+
handler_class = Class.new(MessagingHandler) do
|
179
|
+
def initialize() super; @unhandled = []; end
|
180
|
+
def on_unhandled(method, *args) @unhandled << method; end
|
181
|
+
attr_accessor :unhandled
|
182
|
+
end
|
183
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
184
|
+
d.client.connection.open; d.run
|
185
|
+
assert_equal [:on_connection_open], d.client.handler.unhandled
|
186
|
+
assert_equal [:on_connection_open], d.server.handler.unhandled
|
187
|
+
end
|
188
|
+
|
189
|
+
# Verify on_error is called
|
190
|
+
def test_on_error
|
191
|
+
handler_class = Class.new(MessagingHandler) do
|
192
|
+
def initialize() super; @error = []; @unhandled = []; end
|
193
|
+
def on_error(condition) @error << condition; end
|
194
|
+
def on_unhandled(method, *args) @unhandled << method; end
|
195
|
+
attr_accessor :error, :unhandled
|
196
|
+
end
|
197
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
198
|
+
d.client.connection.open
|
199
|
+
r = d.client.connection.open_receiver; d.run
|
200
|
+
assert_equal [:on_connection_open, :on_session_open, :on_receiver_open], d.client.handler.unhandled
|
201
|
+
assert_equal [:on_connection_open, :on_session_open, :on_sender_open, :on_sendable], d.server.handler.unhandled
|
202
|
+
r.close Condition.new("goof", "oops"); d.run
|
203
|
+
|
204
|
+
assert_equal [Condition.new("goof", "oops")], d.client.handler.error
|
205
|
+
assert_equal [:on_connection_open, :on_session_open, :on_sender_open, :on_sendable, :on_sender_close], d.server.handler.unhandled
|
206
|
+
assert_equal [Condition.new("goof", "oops")], d.server.handler.error
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
# Verify on_unhandled is called for errors if there is no on_error
|
211
|
+
def test_unhandled_error
|
212
|
+
handler_class = Class.new(MessagingHandler) do
|
213
|
+
def on_unhandled(method, *args)
|
214
|
+
@error = args[0].condition if method == :on_connection_error;
|
215
|
+
end
|
216
|
+
attr_accessor :error
|
217
|
+
end
|
218
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
219
|
+
d.client.connection.open; d.run
|
220
|
+
d.client.connection.close "oops"; d.run
|
221
|
+
assert_equal [Condition.new("error", "oops")]*2, d.collect { |x| x.handler.error }
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
|
19
|
+
require 'minitest/autorun'
|
20
|
+
require 'qpid_proton'
|
21
|
+
require 'test_tools'
|
22
|
+
include Qpid::Proton
|
23
|
+
|
24
|
+
OldMessagingHandler = Qpid::Proton::Handler::MessagingHandler #Use the old handler.
|
25
|
+
|
26
|
+
# Records every call
|
27
|
+
class AllHandler < OldMessagingHandler
|
28
|
+
def initialize(*args)
|
29
|
+
super(*args)
|
30
|
+
@calls = []
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :calls
|
34
|
+
|
35
|
+
def names; @calls.map { |c| c[0] }; end
|
36
|
+
def events; @calls.map { |c| c[1] }; end
|
37
|
+
|
38
|
+
def method_missing(name, *args) (/^on_/ =~ name) ? (@calls << [name] + args) : super; end
|
39
|
+
def respond_to_missing?(name, private=false); (/^on_/ =~ name); end
|
40
|
+
def respond_to?(name, all=false) super || respond_to_missing?(name); end # For ruby < 1.9.2
|
41
|
+
end
|
42
|
+
|
43
|
+
# Tests with Mock handler that handles all methods, expect both old and new calls
|
44
|
+
class TestOldHandler < MiniTest::Test
|
45
|
+
def setup
|
46
|
+
@h = [AllHandler.new, AllHandler.new]
|
47
|
+
@ch, @sh = *@h
|
48
|
+
@d = DriverPair.new(*@h)
|
49
|
+
end
|
50
|
+
|
51
|
+
def clear; @d.each { |d| h = d.handler; h.calls.clear }; end
|
52
|
+
|
53
|
+
def test_handler_defaults
|
54
|
+
want = { :prefetch => 10, :auto_settle => true, :auto_accept => true, :auto_open => true, :auto_close => true, :peer_close_is_error => false }
|
55
|
+
assert_equal want, @ch.options
|
56
|
+
assert_equal want, @sh.options
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_auto_open_close
|
60
|
+
@d.client.connection.open; @d.client.connection.open_sender; @d.run
|
61
|
+
assert_equal [:on_connection_opened, :on_session_opened, :on_link_opened, :on_sendable], @ch.names
|
62
|
+
assert_equal [:on_connection_opening, :on_session_opening, :on_link_opening, :on_connection_opened, :on_session_opened, :on_link_opened], @sh.names
|
63
|
+
clear
|
64
|
+
@d.client.connection.close; @d.run
|
65
|
+
assert_equal [:on_connection_closed, :on_transport_closed], @ch.names
|
66
|
+
assert_equal [:on_connection_closing, :on_connection_closed, :on_transport_closed], @sh.names
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_no_auto_open_close
|
70
|
+
[:auto_close, :auto_open].each { |k| @ch.options[k] = @sh.options[k] = false }
|
71
|
+
@d.client.connection.open; @d.run
|
72
|
+
assert_equal [:on_connection_opening], @sh.names
|
73
|
+
assert_equal [], @ch.names
|
74
|
+
@d.server.connection.open; @d.run
|
75
|
+
assert_equal [:on_connection_opened], @ch.names
|
76
|
+
assert_equal [:on_connection_opening, :on_connection_opened], @sh.names
|
77
|
+
clear
|
78
|
+
@d.client.connection.session.open; @d.run
|
79
|
+
assert_equal [:on_session_opening], @sh.names
|
80
|
+
assert_equal [], @ch.names
|
81
|
+
clear
|
82
|
+
@d.client.connection.close;
|
83
|
+
3.times { @d.process }
|
84
|
+
assert_equal [:on_connection_closing], @sh.names
|
85
|
+
assert_equal [], @ch.names
|
86
|
+
@d.server.connection.close; @d.run
|
87
|
+
assert_equal [:on_connection_closed, :on_transport_closed], @ch.names
|
88
|
+
assert_equal [:on_connection_closing, :on_connection_closed, :on_transport_closed], @sh.names
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_transport_error
|
92
|
+
@d.client.connection.open; @d.run
|
93
|
+
clear
|
94
|
+
@d.client.close "stop that"; @d.run
|
95
|
+
assert_equal [:on_transport_closed], @ch.names
|
96
|
+
assert_equal [:on_transport_error, :on_transport_closed], @sh.names
|
97
|
+
assert_equal Condition.new("proton:io", "stop that (connection aborted)"), @d.client.transport.condition
|
98
|
+
assert_equal Condition.new("amqp:connection:framing-error", "connection aborted"), @d.server.transport.condition
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_connection_error
|
102
|
+
@ch.options[:auto_open] = @sh.options[:auto_open] = false
|
103
|
+
@d.client.connection.open; @d.run
|
104
|
+
@d.server.connection.close "bad dog"; @d.run
|
105
|
+
assert_equal [:on_connection_opened, :on_connection_error, :on_connection_closed, :on_transport_closed], @ch.names
|
106
|
+
assert_equal "bad dog", @ch.calls[2][1].condition.description
|
107
|
+
assert_equal [:on_connection_opening, :on_connection_closed, :on_transport_closed], @sh.names
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_session_error
|
111
|
+
@d.client.connection.open
|
112
|
+
s = @d.client.connection.session; s.open; @d.run
|
113
|
+
s.close "bad dog"; @d.run
|
114
|
+
assert_equal [:on_connection_opened, :on_session_opened, :on_session_closed], @ch.names
|
115
|
+
assert_equal [:on_connection_opening, :on_session_opening, :on_connection_opened, :on_session_opened, :on_session_error, :on_session_closed], @sh.names
|
116
|
+
assert_equal "bad dog", @sh.calls[-3][1].condition.description
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_link_error
|
120
|
+
@d.client.connection.open
|
121
|
+
s = @d.client.connection.open_sender; @d.run
|
122
|
+
s.close "bad dog"; @d.run
|
123
|
+
assert_equal [:on_connection_opened, :on_session_opened, :on_link_opened, :on_sendable, :on_link_closed], @ch.names
|
124
|
+
assert_equal [:on_connection_opening, :on_session_opening, :on_link_opening,
|
125
|
+
:on_connection_opened, :on_session_opened, :on_link_opened,
|
126
|
+
:on_link_error, :on_link_closed], @sh.names
|
127
|
+
assert_equal "bad dog", @sh.calls[-3][1].condition.description
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_options_off
|
131
|
+
off = {:prefetch => 0, :auto_settle => false, :auto_accept => false, :auto_open => false, :auto_close => false}
|
132
|
+
@ch.options.replace(off)
|
133
|
+
@sh.options.replace(off)
|
134
|
+
@d.client.connection.open; @d.run
|
135
|
+
assert_equal [[], [:on_connection_opening]], [@ch.names, @sh.names]
|
136
|
+
@d.server.connection.open; @d.run
|
137
|
+
assert_equal [[:on_connection_opened], [:on_connection_opening, :on_connection_opened]], [@ch.names, @sh.names]
|
138
|
+
clear
|
139
|
+
s = @d.client.connection.open_sender; @d.run
|
140
|
+
assert_equal [[], [:on_session_opening, :on_link_opening]], [@ch.names, @sh.names]
|
141
|
+
@sh.events[1].session.open
|
142
|
+
r = @sh.events[1].link
|
143
|
+
r.open; @d.run
|
144
|
+
assert_equal [[:on_session_opened, :on_link_opened], [:on_session_opening, :on_link_opening, :on_session_opened, :on_link_opened]], [@ch.names, @sh.names]
|
145
|
+
clear
|
146
|
+
r.flow(1); @d.run
|
147
|
+
assert_equal [[:on_sendable], []], [@ch.names, @sh.names]
|
148
|
+
assert_equal 1, s.credit
|
149
|
+
clear
|
150
|
+
s.send Message.new("foo"); @d.run
|
151
|
+
assert_equal [[], [:on_message]], [@ch.names, @sh.names]
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_peer_close_is_error
|
155
|
+
@ch.options[:peer_close_is_error] = true
|
156
|
+
@d.client.connection.open; @d.run
|
157
|
+
@d.server.connection.close; @d.run
|
158
|
+
assert_equal [:on_connection_opened, :on_connection_error, :on_connection_closed, :on_transport_closed], @ch.names
|
159
|
+
assert_equal [:on_connection_opening, :on_connection_opened, :on_connection_closed, :on_transport_closed], @sh.names
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Test with real handlers that implement a few methods
|
164
|
+
class TestOldUnhandled < MiniTest::Test
|
165
|
+
|
166
|
+
def test_message
|
167
|
+
handler_class = Class.new(OldMessagingHandler) do
|
168
|
+
def on_message(event) @message = event.message; end
|
169
|
+
def on_accepted(event) @accepted = true; end
|
170
|
+
attr_accessor :message, :accepted, :sender
|
171
|
+
end
|
172
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
173
|
+
d.client.connection.open;
|
174
|
+
s = d.client.connection.open_sender; d.run
|
175
|
+
assert_equal 10, s.credit # Default prefetch
|
176
|
+
s.send(Message.new("foo")); d.run
|
177
|
+
assert_equal "foo", d.server.handler.message.body
|
178
|
+
assert d.client.handler.accepted
|
179
|
+
end
|
180
|
+
|
181
|
+
# Verify on_unhandled is called
|
182
|
+
def test_unhandled
|
183
|
+
handler_class = Class.new(OldMessagingHandler) do
|
184
|
+
def initialize() super; @unhandled = []; end
|
185
|
+
def on_unhandled(event) @unhandled << event.method; end
|
186
|
+
attr_accessor :unhandled
|
187
|
+
end
|
188
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
189
|
+
d.client.connection.open; d.run
|
190
|
+
assert_equal [:on_connection_opened], d.client.handler.unhandled
|
191
|
+
assert_equal [:on_connection_opening, :on_connection_opened], d.server.handler.unhandled
|
192
|
+
end
|
193
|
+
|
194
|
+
# Verify on_error is called
|
195
|
+
def test_on_error
|
196
|
+
handler_class = Class.new(OldMessagingHandler) do
|
197
|
+
def initialize() super; @error = []; @unhandled = []; end
|
198
|
+
def on_error(event) @error << event.method; end
|
199
|
+
def on_unhandled(event) @unhandled << event.method; end
|
200
|
+
attr_accessor :error, :unhandled
|
201
|
+
end
|
202
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
203
|
+
d.client.connection.open
|
204
|
+
r = d.client.connection.open_receiver; d.run
|
205
|
+
r.close "oops"; d.run
|
206
|
+
assert_equal [:on_connection_opened, :on_session_opened, :on_link_opened,
|
207
|
+
:on_link_closed], d.client.handler.unhandled
|
208
|
+
assert_equal [:on_connection_opening, :on_session_opening, :on_link_opening,
|
209
|
+
:on_connection_opened, :on_session_opened, :on_link_opened, :on_sendable,
|
210
|
+
:on_link_closed], d.server.handler.unhandled
|
211
|
+
assert_equal [:on_link_error], d.server.handler.error
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
# Verify on_unhandled is called even for errors if there is no on_error
|
216
|
+
def test_unhandled_error
|
217
|
+
handler_class = Class.new(OldMessagingHandler) do
|
218
|
+
def initialize() super; @unhandled = []; end
|
219
|
+
def on_unhandled(event) @unhandled << event.method; end
|
220
|
+
attr_accessor :unhandled
|
221
|
+
end
|
222
|
+
d = DriverPair.new(handler_class.new, handler_class.new)
|
223
|
+
d.client.connection.open; d.run
|
224
|
+
d.client.connection.close "oops"; d.run
|
225
|
+
assert_equal [:on_connection_opened, :on_connection_closed, :on_transport_closed], d.client.handler.unhandled
|
226
|
+
assert_equal [:on_connection_opening, :on_connection_opened, :on_connection_error, :on_connection_closed, :on_transport_closed], d.server.handler.unhandled
|
227
|
+
end
|
228
|
+
end
|