qpid_proton 0.27.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,99 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- require 'minitest/autorun'
22
- require 'qpid_proton'
23
- require 'socket'
24
- require 'rbconfig'
25
-
26
- begin
27
- MiniTest::Test
28
- rescue NameError # For older versions of MiniTest
29
- MiniTest::Test = MiniTest::Unit::TestCase
30
- end
31
-
32
- def unused_port; TCPServer.open(0) { |s| s.addr[1] } end
33
- def make_url(port, path) "amqp://:#{port}/#{path}"; end
34
-
35
- class OldExampleTest < MiniTest::Test
36
-
37
- def run_script(*args)
38
- IO.popen [RbConfig.ruby, *args];
39
- end
40
-
41
- def assert_output(want, args)
42
- assert_equal want.strip, run_script(*args).read.strip
43
- end
44
-
45
- def test_helloworld
46
- assert_output "Hello world!", ["helloworld.rb", "-a", make_url($port, __method__)]
47
- end
48
-
49
- def test_send_recv
50
- assert_output "All 10 messages confirmed!", ["simple_send.rb", "-a", make_url($port, __method__)]
51
- want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
52
- assert_output want, ["simple_recv.rb", "-a", make_url($port, __method__)]
53
- end
54
-
55
- def test_client_server
56
- want = <<EOS
57
- -> Twas brillig, and the slithy toves
58
- <- TWAS BRILLIG, AND THE SLITHY TOVES
59
- -> Did gire and gymble in the wabe.
60
- <- DID GIRE AND GYMBLE IN THE WABE.
61
- -> All mimsy were the borogroves,
62
- <- ALL MIMSY WERE THE BOROGROVES,
63
- -> And the mome raths outgrabe.
64
- <- AND THE MOME RATHS OUTGRABE.
65
- EOS
66
- srv = run_script("server.rb", "-a", make_url($port, __method__))
67
- assert_output(want, ["client.rb", "-a", make_url($port, __method__)])
68
- ensure
69
- Process.kill :TERM, srv.pid if srv
70
- end
71
-
72
- def test_direct_recv
73
- url = make_url unused_port, __method__
74
- p = run_script("direct_recv.rb", "-a", url)
75
- p.readline # Wait till ready
76
- assert_output("All 10 messages confirmed!", ["simple_send.rb", "-a", url])
77
- want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
78
- assert_equal(want.strip, p.read.strip)
79
- end
80
-
81
- def test_direct_send
82
- url = make_url unused_port, __method__
83
- p = run_script("direct_send.rb", "-a", url)
84
- p.readline # Wait till ready
85
- want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
86
- assert_output(want, ["simple_recv.rb", "-a", url])
87
- assert_equal("All 10 messages confirmed!", p.read.strip)
88
- end
89
- end
90
-
91
- # Start the broker before all tests.
92
- $port = unused_port
93
- $broker = IO.popen [RbConfig.ruby, "broker.rb", "-a", ":#{$port}"]
94
- $broker.readline # Wait for "Listening"
95
-
96
- # Kill the broker after all tests
97
- MiniTest.after_run do
98
- Process.kill(:TERM, $broker.pid) if $broker
99
- end
@@ -1,75 +0,0 @@
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 'qpid_proton'
20
- require 'optparse'
21
-
22
- class Server < Qpid::Proton::Handler::MessagingHandler
23
-
24
- def initialize(url)
25
- super()
26
- @url = Qpid::Proton::URL.new url
27
- @address = @url.path
28
- @senders = {}
29
- end
30
-
31
- def on_start(event)
32
- @container = event.container
33
- @conn = @container.connect(:url => @url)
34
- @receiver = @container.create_receiver(@conn, :source => @address)
35
- @relay = nil
36
- end
37
-
38
- def on_connection_opened(event)
39
- if event.connection.offered_capabilities &&
40
- event.connection.offered_capabilities.contain?("ANONYMOUS-RELAY")
41
- @relay = @container.create_sender(@conn, nil)
42
- end
43
- end
44
-
45
- def on_message(event)
46
- msg = event.message
47
- puts "<- #{msg.body}"
48
- sender = @relay || @senders[msg.reply_to]
49
- if sender.nil?
50
- sender = @container.create_sender(@conn, :target => msg.reply_to)
51
- @senders[msg.reply_to] = sender
52
- end
53
- reply = Qpid::Proton::Message.new
54
- reply.address = msg.reply_to
55
- reply.body = msg.body.upcase
56
- puts "-> #{reply.body}"
57
- reply.correlation_id = msg.correlation_id
58
- sender.send(reply)
59
- end
60
-
61
- def on_transport_error(event)
62
- raise "Connection error: #{event.transport.condition}"
63
- end
64
- end
65
-
66
- options = {
67
- :address => "localhost:5672/examples",
68
- }
69
-
70
- OptionParser.new do |opts|
71
- opts.banner = "Usage: server.rb [options]"
72
- opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") { |address| options[:address] = address }
73
- end.parse!
74
-
75
- Qpid::Proton::Reactor::Container.new(Server.new(options[:address])).run()
@@ -1,57 +0,0 @@
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 'qpid_proton'
20
- require 'optparse'
21
-
22
- require_relative 'lib/send_and_receive'
23
-
24
- class Receiver < ExampleReceive
25
-
26
- def initialize(url, count)
27
- super(url, count)
28
- end
29
-
30
- def on_start(event)
31
- event.container.create_receiver(@url)
32
- end
33
-
34
- end
35
-
36
- options = {
37
- :address => "localhost:5672/examples",
38
- :messages => 10,
39
- }
40
-
41
- OptionParser.new do |opts|
42
- opts.banner = "Usage: simple_send.rb [options]"
43
-
44
- opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
45
- options[:address] = address
46
- end
47
-
48
- opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
49
- OptionParser::DecimalInteger) do |messages|
50
- options[:messages] = messages
51
- end
52
- end.parse!
53
-
54
- begin
55
- Qpid::Proton::Reactor::Container.new(Receiver.new(options[:address], options[:messages])).run
56
- rescue Interrupt
57
- end
@@ -1,54 +0,0 @@
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 'qpid_proton'
20
- require 'optparse'
21
-
22
- require_relative 'lib/send_and_receive'
23
-
24
- options = {
25
- :address => "localhost:5672/examples",
26
- :messages => 10,
27
- }
28
-
29
- class SimpleSend < ExampleSend
30
-
31
- def initialize(url, messages)
32
- super(url, messages)
33
- end
34
-
35
- def on_start(event)
36
- event.container.create_sender(url)
37
- end
38
-
39
- end
40
-
41
- OptionParser.new do |opts|
42
- opts.banner = "Usage: simple_send.rb [options]"
43
-
44
- opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
45
- options[:address] = address
46
- end
47
-
48
- opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
49
- OptionParser::DecimalInteger) do |messages|
50
- options[:messages] = messages
51
- end
52
- end.parse!
53
-
54
- Qpid::Proton::Reactor::Container.new(SimpleSend.new(options[:address], options[:messages])).run