You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/11/27 21:10:41 UTC

[2/3] qpid-proton git commit: PROTON-1699: [ruby] add messenger tests to backward compatibility suite

PROTON-1699: [ruby] add messenger tests to backward compatibility suite

This closes #114, and adds the direct_ examples to the old_examples test suite.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/1bf4a32c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/1bf4a32c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/1bf4a32c

Branch: refs/heads/master
Commit: 1bf4a32ccbadfe3cfe103661f8a87d7fdb4ad4a7
Parents: 4530774
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Nov 27 09:24:44 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Mon Nov 27 16:09:47 2017 -0500

----------------------------------------------------------------------
 examples/ruby/example_test.rb                   |  3 +-
 .../bindings/ruby/tests/old_examples/broker.rb  |  1 +
 .../ruby/tests/old_examples/direct_recv.rb      |  7 +-
 .../ruby/tests/old_examples/direct_send.rb      |  6 +-
 .../ruby/tests/old_examples/old_example_test.rb | 73 ++++++++++++--------
 .../bindings/ruby/tests/old_examples/recv.rb    | 23 ++++++
 .../bindings/ruby/tests/old_examples/send.rb    | 21 ++++++
 .../ruby/tests/old_examples/simple_recv.rb      |  2 +-
 .../ruby/tests/old_examples/simple_send.rb      |  4 +-
 9 files changed, 104 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/examples/ruby/example_test.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/example_test.rb b/examples/ruby/example_test.rb
index 19f1638..dc31a18 100755
--- a/examples/ruby/example_test.rb
+++ b/examples/ruby/example_test.rb
@@ -35,8 +35,7 @@ class ExampleTest < MiniTest::Test
   end
 
   def assert_output(want, *args)
-    p = run_script(*args)
-    assert_equal(want, p.read.strip)
+    assert_equal(want.strip, run_script(*args).read.strip)
   end
 
   def test_helloworld

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/broker.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/broker.rb b/proton-c/bindings/ruby/tests/old_examples/broker.rb
index e1ababd..e7cc9b3 100644
--- a/proton-c/bindings/ruby/tests/old_examples/broker.rb
+++ b/proton-c/bindings/ruby/tests/old_examples/broker.rb
@@ -97,6 +97,7 @@ class Broker < Qpid::Proton::Handler::MessagingHandler
     debug("on_start event") if $options[:debug]
     @acceptor = event.container.listen(@url)
     print "Listening on #{@url}\n"
+    STDOUT.flush
   end
 
   def queue(address)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/direct_recv.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/direct_recv.rb b/proton-c/bindings/ruby/tests/old_examples/direct_recv.rb
index e8b52f3..ff3366a 100644
--- a/proton-c/bindings/ruby/tests/old_examples/direct_recv.rb
+++ b/proton-c/bindings/ruby/tests/old_examples/direct_recv.rb
@@ -30,6 +30,11 @@ class DirectReceive < ExampleReceive
 
   def on_start(event)
     @acceptor = event.container.listen(self.url)
+    puts "Listening"; STDOUT.flush
+  end
+
+  def on_connection_opening(event)
+    @acceptor.close
   end
 
   def on_message(event)
@@ -41,7 +46,7 @@ end
 
 options = {
   :address => "localhost:5672/examples",
-  :messages => 100,
+  :messages => 10,
 }
 
 OptionParser.new do |opts|

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/direct_send.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/direct_send.rb b/proton-c/bindings/ruby/tests/old_examples/direct_send.rb
index 2164304..50543b2 100644
--- a/proton-c/bindings/ruby/tests/old_examples/direct_send.rb
+++ b/proton-c/bindings/ruby/tests/old_examples/direct_send.rb
@@ -24,7 +24,7 @@ require_relative 'lib/send_and_receive'
 
 options = {
   :address => "localhost:5672/examples",
-  :messages => 100,
+  :messages => 10,
 }
 
 class SimpleSend < ExampleSend
@@ -35,8 +35,12 @@ class SimpleSend < ExampleSend
 
   def on_start(event)
     @acceptor = event.container.listen(url)
+    puts "Listening"; STDOUT.flush
   end
 
+  def on_connection_opening(event)
+    @acceptor.close
+  end
 end
 
 OptionParser.new do |opts|

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/old_example_test.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/old_example_test.rb b/proton-c/bindings/ruby/tests/old_examples/old_example_test.rb
index 16c390d..0ade719 100755
--- a/proton-c/bindings/ruby/tests/old_examples/old_example_test.rb
+++ b/proton-c/bindings/ruby/tests/old_examples/old_example_test.rb
@@ -22,29 +22,35 @@ require 'minitest/autorun'
 require 'qpid_proton'
 require 'socket'
 
-class ExampleTest < MiniTest::Test
+def unused_port; TCPServer.open(0) { |s| s.addr[1] } end
+def make_url(port, path) "amqp://:#{port}/${path}"; end # Make a proton pseudo-url
 
-  def run_script(script, port)
-    assert File.exist? script
-    cmd = [RbConfig.ruby, script]
-    cmd += ["-a", ":#{port}/examples"] if port
-    return IO.popen(cmd)
-  end
+class OldExampleTest < MiniTest::Test
 
+  def run_script(*args)
+    IO.popen [RbConfig.ruby, "-W0", *args];
+  end
 
-  def assert_output(script, want, port=nil)
-    out = run_script(script, port)
-    assert_equal want, out.read.strip
+  def assert_output(want, args)
+    assert_equal want.strip, run_script(*args).read.strip
   end
 
   def test_helloworld
-    assert_output("helloworld.rb", "Hello world!", $port)
+    assert_output "Hello world!", ["helloworld.rb", "-a", make_url($port, __method__)]
   end
 
   def test_send_recv
-    assert_output("simple_send.rb", "All 100 messages confirmed!", $port)
-    want = (0..99).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
-    assert_output("simple_recv.rb", want.strip, $port)
+    assert_output "All 10 messages confirmed!", ["simple_send.rb", "-a", make_url($port, __method__)]
+    want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
+    assert_output want, ["simple_recv.rb", "-a", make_url($port, __method__)]
+  end
+
+  def test_smoke
+    url = "127.0.0.1:#{unused_port}"
+    recv = run_script("recv.rb", "~#{url}")
+    recv.readline               # Wait for "Listening"
+    assert_output("Status: ACCEPTED", ["send.rb", url])
+    assert_equal "Got: Hello World!", recv.read.strip
   end
 
   def test_client_server
@@ -58,28 +64,37 @@ class ExampleTest < MiniTest::Test
 -> And the mome raths outgrabe.
 <- AND THE MOME RATHS OUTGRABE.
 EOS
-    srv = run_script("server.rb", $port)
-    assert_output("client.rb", want.strip, $port)
-
+    srv = run_script("server.rb", "-a", make_url($port, __method__))
+    assert_output(want, ["client.rb", "-a", make_url($port, __method__)])
   ensure
     Process.kill :TERM, srv.pid if srv
   end
-end
 
-# Start the broker before all tests.
-$port = TCPServer.open(0) do |s| s.addr[1]; end # find an unused port
-$broker = spawn("#{RbConfig.ruby} broker.rb -a :#{$port}")
+  def test_direct_recv
+    url = make_url unused_port, __method__
+    p = run_script("direct_recv.rb", "-a", url)
+    p.readline                # Wait till ready
+    assert_output("All 10 messages confirmed!", ["simple_send.rb", "-a", url])
+    want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
+    assert_equal(want.strip, p.read.strip)
+  end
 
-# Wait for the broker to be listening
-deadline = Time.now + 5
-begin
-  TCPSocket.open("", $port).close
-rescue Errno::ECONNREFUSED
-  retry if Time.now < deadline
-  raise
+  def test_direct_send
+    url = make_url unused_port, __method__
+    p = run_script("direct_send.rb", "-a", url)
+    p.readline                # Wait till ready
+    want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
+    assert_output(want, ["simple_recv.rb", "-a", url])
+    assert_equal("All 10 messages confirmed!", p.read.strip)
+  end
 end
 
+# Start the broker before all tests.
+$port = unused_port
+$broker = IO.popen [RbConfig.ruby, "-W0", "broker.rb", "-a", ":#{$port}"]
+$broker.readline                # Wait for "Listening"
+
 # Kill the broker after all tests
 MiniTest.after_run do
-  Process.kill(:TERM, $broker) if $broker
+  Process.kill(:TERM, $broker.pid) if $broker
 end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/recv.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/recv.rb b/proton-c/bindings/ruby/tests/old_examples/recv.rb
new file mode 100755
index 0000000..a29f123
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/recv.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+
+require 'qpid_proton.rb'
+
+messenger = Qpid::Proton::Messenger::Messenger.new()
+messenger.incoming_window = 1
+message = Qpid::Proton::Message.new()
+
+address = ARGV[0]
+if not address then
+  address = "~0.0.0.0"
+end
+messenger.subscribe(address)
+
+messenger.start()
+
+puts "Listening"; STDOUT.flush
+messenger.receive()
+messenger.get(message)
+puts "Got: #{message.body}"
+messenger.accept()
+
+messenger.stop()

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/send.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/send.rb b/proton-c/bindings/ruby/tests/old_examples/send.rb
new file mode 100755
index 0000000..73016d0
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/send.rb
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+require 'qpid_proton.rb'
+
+messenger = Qpid::Proton::Messenger::Messenger.new()
+messenger.outgoing_window = 10
+message = Qpid::Proton::Message.new()
+
+address = ARGV[0]
+if not address then
+  address = "0.0.0.0"
+end
+
+message.address = address
+message.body = "Hello World!"
+
+messenger.start()
+tracker = messenger.put(message)
+messenger.send()
+print "Status: ", messenger.status(tracker), "\n"
+messenger.stop()

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/simple_recv.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/simple_recv.rb b/proton-c/bindings/ruby/tests/old_examples/simple_recv.rb
index 91cb30c..136e332 100644
--- a/proton-c/bindings/ruby/tests/old_examples/simple_recv.rb
+++ b/proton-c/bindings/ruby/tests/old_examples/simple_recv.rb
@@ -36,7 +36,7 @@ end
 
 options = {
   :address => "localhost:5672/examples",
-  :messages => 100,
+  :messages => 10,
 }
 
 OptionParser.new do |opts|

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/1bf4a32c/proton-c/bindings/ruby/tests/old_examples/simple_send.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/simple_send.rb b/proton-c/bindings/ruby/tests/old_examples/simple_send.rb
index 13e40f0..5e5d0a6 100644
--- a/proton-c/bindings/ruby/tests/old_examples/simple_send.rb
+++ b/proton-c/bindings/ruby/tests/old_examples/simple_send.rb
@@ -24,7 +24,7 @@ require_relative 'lib/send_and_receive'
 
 options = {
   :address => "localhost:5672/examples",
-  :messages => 100,
+  :messages => 10,
 }
 
 class SimpleSend < ExampleSend
@@ -47,7 +47,7 @@ OptionParser.new do |opts|
   end
 
   opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
-    OptionParser::DecimalInteger) do |messages|
+     OptionParser::DecimalInteger) do |messages|
     options[:messages] = messages
   end
 end.parse!


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org