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 2018/03/06 15:47:13 UTC

[4/4] qpid-proton git commit: PROTON-1784 [ruby] Connection#each_sender/each_receiver take a block

PROTON-1784 [ruby] Connection#each_sender/each_receiver take a block


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

Branch: refs/heads/master
Commit: d4241caa003c2449a531811b626c8b5728f26af4
Parents: daaf092
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Mar 6 09:57:15 2018 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Mar 6 10:29:42 2018 -0500

----------------------------------------------------------------------
 examples/ruby/example_test.rb                 | 22 +++++++++++-----------
 proton-c/bindings/ruby/lib/core/connection.rb | 13 ++++++++++---
 2 files changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d4241caa/examples/ruby/example_test.rb
----------------------------------------------------------------------
diff --git a/examples/ruby/example_test.rb b/examples/ruby/example_test.rb
index 80a20db..7008dd1 100755
--- a/examples/ruby/example_test.rb
+++ b/examples/ruby/example_test.rb
@@ -46,7 +46,7 @@ class ExampleTest < MiniTest::Test
   end
 
   def test_helloworld
-    assert_output("Hello world!", "helloworld.rb", $url, __method__)
+    assert_output("Hello world!", "helloworld.rb", $url, "examples")
   end
 
   def test_client_server
@@ -60,40 +60,40 @@ class ExampleTest < MiniTest::Test
 -> And the mome raths outgrabe.
 <- AND THE MOME RATHS OUTGRABE.
 EOS
-    server = run_script("server.rb", $url, __method__)
-    assert_output(want.strip, "client.rb", $url, __method__)
+    server = run_script("server.rb", $url, "examples")
+    assert_output(want.strip, "client.rb", $url, "examples")
   ensure
     Process.kill :TERM, server.pid if server
   end
 
   def test_send_recv
-    assert_output("All 10 messages confirmed!", "simple_send.rb", $url, __method__)
+    assert_output("All 10 messages confirmed!", "simple_send.rb", $url, "examples")
     want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
-    assert_output(want.strip, "simple_recv.rb", $url, __method__)
+    assert_output(want.strip, "simple_recv.rb", $url, "examples")
   end
 
   def test_ssl_send_recv
-    out = run_script("ssl_send.rb", $url, __method__).read.strip
+    out = run_script("ssl_send.rb", $url, "examples").read.strip
     assert_match(/Connection secured with "...*\"\nAll 10 messages confirmed!/, out)
     want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
-    assert_output(want.strip, "simple_recv.rb", $url, __method__)
+    assert_output(want.strip, "simple_recv.rb", $url, "examples")
   end
 
   def test_direct_recv
     url = test_url
-      p = run_script("direct_recv.rb", url, __method__)
+      p = run_script("direct_recv.rb", url, "examples")
       p.readline                # Wait till ready
-      assert_output("All 10 messages confirmed!", "simple_send.rb", url, __method__)
+      assert_output("All 10 messages confirmed!", "simple_send.rb", url, "examples")
       want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
       assert_equal(want.strip, p.read.strip)
   end
 
   def test_direct_send
     url = test_url
-    p = run_script("direct_send.rb", url, __method__)
+    p = run_script("direct_send.rb", url, "examples")
     p.readline                # Wait till ready
     want = (0..9).reduce("") { |x,y| x << "Received: sequence #{y}\n" }
-    assert_output(want.strip, "simple_recv.rb", url, __method__)
+    assert_output(want.strip, "simple_recv.rb", url, "examples")
     assert_equal("All 10 messages confirmed!", p.read.strip)
   end
 end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/d4241caa/proton-c/bindings/ruby/lib/core/connection.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/connection.rb b/proton-c/bindings/ruby/lib/core/connection.rb
index b94eaff..8adc259 100644
--- a/proton-c/bindings/ruby/lib/core/connection.rb
+++ b/proton-c/bindings/ruby/lib/core/connection.rb
@@ -253,17 +253,24 @@ module Qpid::Proton
       return enum_for(:each_link) unless block_given?
       l = Cproton.pn_link_head(@impl, 0);
       while l
-        yield Link.wrap(l)
+        l2 = l                  #  get next before yield, in case yield closes l and unlinks it
         l = Cproton.pn_link_next(l, 0)
+        yield Link.wrap(l2)
       end
       self
     end
 
     # Get the {Sender} links - see {#each_link}
-    def each_sender() each_link.select { |l| l.sender? }; end
+    def each_sender()
+      return enum_for(:each_sender) unless block_given?
+      each_link.select { |l| yield l if l.sender? }
+    end
 
     # Get the {Receiver} links - see {#each_link}
-    def each_receiver() each_link.select { |l| l.receiver? }; end
+      def each_receiver()
+        return enum_for(:each_receiver) unless block_given?
+        each_link.select { |l| yield l if l.receiver? }
+      end
 
     # @deprecated use {#MessagingHandler} to handle work
     def work_head


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