qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [1/4] qpid-proton git commit: PROTON-1738: [ruby] Fixes to work with ruby 2.0.0
Date Wed, 14 Feb 2018 16:51:19 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 942085256 -> 9a8f9f59a


PROTON-1738: [ruby] Fixes to work with ruby 2.0.0

- old Queue method << does not return Queue, cannot be chained
- old URI parser does not allow empty host name
- fix compile warning in SWIG generated code


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

Branch: refs/heads/master
Commit: 83205db4c5c957588518b9028eb2ca7f5a906441
Parents: 9420852
Author: Alan Conway <aconway@redhat.com>
Authored: Mon Feb 12 18:31:26 2018 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Feb 14 11:29:59 2018 -0500

----------------------------------------------------------------------
 proton-c/bindings/ruby/lib/core/container.rb  |  3 ++-
 proton-c/bindings/ruby/lib/core/ssl_domain.rb |  2 +-
 proton-c/bindings/ruby/lib/core/uri.rb        | 24 ++++++++++-------
 proton-c/bindings/ruby/tests/test_uri.rb      | 30 +++++++++++-----------
 4 files changed, 33 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/83205db4/proton-c/bindings/ruby/lib/core/container.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/container.rb b/proton-c/bindings/ruby/lib/core/container.rb
index 7a69b58..f262ea1 100644
--- a/proton-c/bindings/ruby/lib/core/container.rb
+++ b/proton-c/bindings/ruby/lib/core/container.rb
@@ -125,7 +125,8 @@ module Qpid::Proton
       # - nil on the @work queue makes a #run thread exit
 
       @work = Queue.new
-      @work << :start << self   # Issue start and start start selecting
+      @work << :start
+      @work << self             # Issue start and start start selecting
       @wake = IO.pipe           # Wakes #run thread in IO.select
       @auto_stop = true         # Stop when @active drops to 0
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/83205db4/proton-c/bindings/ruby/lib/core/ssl_domain.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/ssl_domain.rb b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
index 31a472f..813fc1a 100644
--- a/proton-c/bindings/ruby/lib/core/ssl_domain.rb
+++ b/proton-c/bindings/ruby/lib/core/ssl_domain.rb
@@ -48,7 +48,7 @@ module Qpid::Proton
     # @private
     def initialize(mode)
       @impl = Cproton.pn_ssl_domain(mode)
-      raise SSLUnavailable.new if @impl.nil?
+      raise Qpid::Proton::SSLError, "SSL Unavailable" if @impl.nil?
     end
 
     # Set the certificate that identifies the local node to the remote.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/83205db4/proton-c/bindings/ruby/lib/core/uri.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/lib/core/uri.rb b/proton-c/bindings/ruby/lib/core/uri.rb
index e347849..272c2d2 100644
--- a/proton-c/bindings/ruby/lib/core/uri.rb
+++ b/proton-c/bindings/ruby/lib/core/uri.rb
@@ -37,9 +37,15 @@ module URI
 end
 
 module Qpid::Proton
-  # Returns +s+ converted to a {URI::AMQP} or {URI::AMQPS} object
+  private
+  # Make sure to allow empty hostnames, Ruby 2.0.0 does not.
+  DEFAULT_URI_PARSER = URI::Parser.new(:HOSTNAME => /(?:#{URI::PATTERN::HOSTNAME})|/)
+
+  public
+
+  # Convert +s+ to a {URI::AMQP} or {URI::AMQPS} object
   #
-  # Shortcut strings are allowed: an "amqp://" prefix is added if +s+ does
+  # Shortcut strings like "host:port" are allowed: an "amqp://" prefix is added if +s+ does
   # not already look like an 'amqp:', 'amqps:' URI.
   #
   # @note this does not give the same result as a standard URI parser in all cases.
@@ -54,19 +60,19 @@ module Qpid::Proton
   #
   def self.uri(s)
     case s
-      when URI::AMQP then s     # Pass-thru
-    when URI::Generic
-      s.scheme ||= 'amqp'
-      u = URI.parse(s.to_s)      # Re-parse as amqp
+    when URI::AMQP then s       # This is already an AMQP or AMQPS URL.
+    when URI::Generic           # Re-parse a generic URI that was not parsed as AMQP/AMQPS
class
+      s.scheme ||= 'amqp'       # Default to amqp: scheme
+      u = DEFAULT_URI_PARSER.parse(s.to_s)
       raise URI::BadURIError, "Not an AMQP URI: '#{u}'" unless u.is_a? URI::AMQP
       u
     else
       s = String.try_convert s
       raise ::ArgumentError, "bad argument (expected URI object or URI string)" unless s
       case s
-      when %r{^amqps?:} then URI.parse(s)      # Looks like an AMQP URI
-      when %r{^//} then URI.parse("amqp:#{s}") # Looks like a scheme-less URI
-      else URI.parse("amqp://#{s}")            # Treat as a bare host:port/path string
+      when %r{^amqps?:} then DEFAULT_URI_PARSER.parse(s)      # Looks like an AMQP URI
+      when %r{^//} then DEFAULT_URI_PARSER.parse("amqp:#{s}") # Looks like an authority with
no scheme
+      else DEFAULT_URI_PARSER.parse("amqp://#{s}")            # Treat as a bare host:port/path
string
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/83205db4/proton-c/bindings/ruby/tests/test_uri.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/test_uri.rb b/proton-c/bindings/ruby/tests/test_uri.rb
index 95887b1..7af2ea2 100644
--- a/proton-c/bindings/ruby/tests/test_uri.rb
+++ b/proton-c/bindings/ruby/tests/test_uri.rb
@@ -21,41 +21,40 @@ require 'qpid_proton'
 
 class TestURI < Minitest::Test
 
+  PARTS=[:scheme, :userinfo, :host, :port, :path] # Interesting URI components
   def uri(u) Qpid::Proton::uri(u); end
+  def uri_parts(u) uri(u).select(*PARTS); end
 
   # Extension to standard URI parser
   def test_standard
     u = URI("amqp://u:p@h/x")
     assert_equal URI::AMQP, u.class
-    assert_equal ['amqp', 'u:p', 'h', 5672, '/x'], u.select(:scheme, :userinfo, :host, :port,
:path)
+    assert_equal ['amqp', 'u:p', 'h', 5672, '/x'], u.select(*PARTS)
 
     u = URI("amqps://u:p@h/x")
     assert_equal URI::AMQPS, u.class
-    assert_equal ['amqps', 'u:p', 'h', 5671, '/x'], u.select(:scheme, :userinfo, :host, :port,
:path)
+    assert_equal ['amqps', 'u:p', 'h', 5671, '/x'], u.select(*PARTS)
 
-    assert_equal ['amqp', '[::1:2:3]', 5672], URI('amqp://[::1:2:3]').select(:scheme, :host,
:port)
+    assert_equal ['amqp', nil, '[::1:2:3]', 5672, ""], URI('amqp://[::1:2:3]').select(*PARTS)
   end
 
   # Proton::uri on valid URIs
   def test_valid
     u = uri("amqp://u:p@h:1/x")
     assert_equal URI::AMQP, u.class
-    assert_equal u.select(:scheme, :userinfo, :host, :port, :path), ['amqp', 'u:p', 'h',
1, '/x']
+    assert_equal ['amqp', 'u:p', 'h', 1, '/x'], u.select(*PARTS)
 
     u = uri("amqps://u:p@h:1/x")
     assert_equal URI::AMQPS, u.class
-    assert_equal u.select(:scheme, :userinfo, :host, :port, :path), ['amqps', 'u:p', 'h',
1, '/x']
+    assert_equal ['amqps', 'u:p', 'h', 1, '/x'], u.select(*PARTS)
 
     # Schemeless string -> amqp
-    assert_equal URI("amqp://h:1/x"), uri("//h:1/x")
-    assert_equal URI("amqp:/x"), uri("/x")
-    assert_equal URI("amqp:"), uri("//")
-    assert_equal URI("amqp:"), uri("")
-    assert_equal URI("amqp://[::1]"), uri("//[::1]")
+    assert_equal ["amqp", nil, "h", 1, "/x"], uri_parts("//h:1/x")
+    assert_equal ["amqp", nil, "", 5672, "/x"], uri_parts("/x")
+    assert_equal ["amqp", nil, "[::1]", 5672, ""], uri_parts("//[::1]")
 
-    # Schemeless URI -> amqp, no re-parse for ambiguous case of path only
-    assert_equal URI("amqp:x"), uri(URI("x"))
-    assert_equal URI("amqp:/x"), uri(URI("/x"))
+    # Schemeless URI gets amqp: scheme
+    assert_equal ["amqp", nil, nil, 5672, "/x"], uri_parts(URI("/x"))
 
     # Pass-through
     u = uri('')
@@ -68,14 +67,15 @@ class TestURI < Minitest::Test
     assert_equal URI("amqp://h:1"), uri("h:1")
     assert_equal URI("amqp://h"), uri("h")
     assert_equal URI("amqp://h"), uri("h:")
-    assert_equal URI("amqp://:1"), uri(":1")
+    assert_equal ["amqp", nil, "", 1, ""], uri_parts(":1")
+    assert_equal ["amqp", nil, "", 1, ""], uri_parts("amqp://:1")
     assert_equal URI("amqp://[::1:2]:1"), uri("[::1:2]:1")
     assert_equal URI("amqp://[::1:2]"), uri("[::1:2]")
   end
 
   def test_error
     assert_raises(::ArgumentError) { uri(nil) }
-    assert_raises(URI::BadURIError) { uri(URI("http:x")) } # Don't re-parse a URI with wrong
scheme
+    assert_raises(URI::BadURIError) { uri(URI("http://x")) } # Don't re-parse a URI with
wrong scheme
     assert_raises(URI::InvalidURIError) { uri("x:y:z") } # Nonsense
     assert_raises(URI::InvalidURIError) { uri("amqp://[foobar]") } # Bad host
   end


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


Mime
View raw message