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/07 19:26:52 UTC

[10/10] qpid-proton git commit: PROTON-1064: [ruby] use old examples as compatibility auto-test

PROTON-1064: [ruby] use old examples as compatibility auto-test

Added the old reactor examples to the auto-test suite as a basic check
for backwards-compatibility breakage.


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

Branch: refs/heads/master
Commit: 86de6b5896c56b3a26419f839b061a30da3f7f89
Parents: 8155c5a
Author: Alan Conway <ac...@redhat.com>
Authored: Mon Nov 6 16:33:23 2017 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Tue Nov 7 13:31:51 2017 -0500

----------------------------------------------------------------------
 proton-c/bindings/ruby/CMakeLists.txt           |   2 +
 .../bindings/ruby/tests/old_examples/README.md  |   8 +
 .../bindings/ruby/tests/old_examples/broker.rb  | 200 +++++++++++++++++++
 .../bindings/ruby/tests/old_examples/client.rb  |  82 ++++++++
 .../ruby/tests/old_examples/direct_recv.rb      |  60 ++++++
 .../ruby/tests/old_examples/direct_send.rb      |  59 ++++++
 .../ruby/tests/old_examples/helloworld.rb       |  73 +++++++
 .../tests/old_examples/helloworld_direct.rb     |  74 +++++++
 .../ruby/tests/old_examples/lib/debugging.rb    |  26 +++
 .../ruby/tests/old_examples/lib/driver.rb       |  69 +++++++
 .../tests/old_examples/lib/qpid_examples.rb     |  27 +++
 .../ruby/tests/old_examples/lib/selectable.rb   | 120 +++++++++++
 .../tests/old_examples/lib/send_and_receive.rb  |  90 +++++++++
 .../ruby/tests/old_examples/old_example_test.rb |  85 ++++++++
 .../bindings/ruby/tests/old_examples/server.rb  |  76 +++++++
 .../ruby/tests/old_examples/simple_recv.rb      |  58 ++++++
 .../ruby/tests/old_examples/simple_send.rb      |  55 +++++
 17 files changed, 1164 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/CMakeLists.txt b/proton-c/bindings/ruby/CMakeLists.txt
index 3397b43..46b7ba8 100644
--- a/proton-c/bindings/ruby/CMakeLists.txt
+++ b/proton-c/bindings/ruby/CMakeLists.txt
@@ -113,6 +113,8 @@ if (result EQUAL 0)  # Have minitest
     set_tests_properties(${name} PROPERTIES ENVIRONMENT "PATH=${PATH};RUBYLIB=${RUBYLIB}")
   endmacro()
   add_ruby_test(example_test.rb WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/examples/ruby)
+  # Old examples for backwards compatibility testing.
+  add_ruby_test(old_example_test.rb WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/old_examples)
 
   file(GLOB TESTS tests/test_*.rb)
   file(GLOB SPECS spec/*_spec.rb)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/README.md
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/README.md b/proton-c/bindings/ruby/tests/old_examples/README.md
new file mode 100644
index 0000000..1516e86
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/README.md
@@ -0,0 +1,8 @@
+# OLD EXAMPLES FOR BACKWARDS COMPATIBILITY TESTING
+
+These examples are from 0.18.1, before the ruby IO refactoring.
+
+They are run as part of the regression test suite to catch breaks in backwards
+compatibility.
+
+They will be removed when all deprecated features have been removed.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/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
new file mode 100644
index 0000000..e1ababd
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/broker.rb
@@ -0,0 +1,200 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+require 'pathname'
+
+require_relative 'lib/debugging'
+
+class Exchange
+
+  include Debugging
+
+  def initialize(dynamic = false)
+    @dynamic = dynamic
+    @queue = Queue.new
+    @consumers = []
+  end
+
+  def subscribe(consumer)
+    debug("subscribing #{consumer}") if $options[:debug]
+    @consumers << (consumer)
+    debug(" there are #{@consumers.size} consumers") if $options[:debug]
+  end
+
+  def unsubscribe(consumer)
+    debug("unsubscribing #{consumer}") if $options[:debug]
+    if @consumers.include?(consumer)
+      @consumers.delete(consumer)
+    else
+      debug(" consumer doesn't exist") if $options[:debug]
+    end
+    debug("  there are #{@consumers.size} consumers") if $options[:debug]
+    @consumers.empty? && (@dynamic || @queue.empty?)
+  end
+
+  def publish(message)
+    debug("queueing message: #{message.body}") if $options[:debug]
+    @queue << message
+    self.dispatch
+  end
+
+  def dispatch(consumer = nil)
+    debug("dispatching: consumer=#{consumer}") if $options[:debug]
+    if consumer
+      c = [consumer]
+    else
+      c = @consumers
+    end
+
+    while self.deliver_to(c) do
+    end
+  end
+
+  def deliver_to(consumers)
+    debug("delivering to #{consumers.size} consumer(s)") if $options[:debug]
+    result = false
+    consumers.each do |consumer|
+      debug(" current consumer=#{consumer} credit=#{consumer.credit}") if $options[:debug]
+      if consumer.credit > 0 && !@queue.empty?
+        consumer.send(@queue.pop(true))
+        result = true
+      end
+    end
+    return result
+  end
+
+end
+
+class Broker < Qpid::Proton::Handler::MessagingHandler
+
+  include Debugging
+
+  def initialize(url)
+    super()
+    @url = url
+    @queues = {}
+  end
+
+  def on_start(event)
+    debug("on_start event") if $options[:debug]
+    @acceptor = event.container.listen(@url)
+    print "Listening on #{@url}\n"
+  end
+
+  def queue(address)
+    debug("fetching queue for #{address}: (there are #{@queues.size} queues)") if $options[:debug]
+    unless @queues.has_key?(address)
+      debug(" creating new queue") if $options[:debug]
+      @queues[address] = Exchange.new
+    else
+      debug(" using existing queue") if $options[:debug]
+    end
+    result = @queues[address]
+    debug(" returning #{result}") if $options[:debug]
+    return result
+  end
+
+  def on_link_opening(event)
+    debug("processing on_link_opening") if $options[:debug]
+    debug("link is#{event.link.sender? ? '' : ' not'} a sender") if $options[:debug]
+    if event.link.sender?
+      if event.link.remote_source.dynamic?
+        address = SecureRandom.uuid
+        event.link.source.address = address
+        q = Exchange.new(true)
+        @queues[address] = q
+        q.subscribe(event.link)
+      elsif event.link.remote_source.address
+        event.link.source.address = event.link.remote_source.address
+        self.queue(event.link.source.address).subscribe(event.link)
+      end
+    elsif event.link.remote_target.address
+      event.link.target.address = event.link.remote_target.address
+    end
+  end
+
+  def unsubscribe(link)
+    debug("unsubscribing #{link.address}") if $options[:debug]
+    if @queues.has_key?(link.source.address)
+      if @queues[link.source.address].unsubscribe(link)
+        @queues.delete(link.source.address)
+      end
+    end
+  end
+
+  def on_link_closing(event)
+    self.unsubscribe(event.link) if event.link.sender?
+  end
+
+  def on_connection_closing(event)
+    self.remove_stale_consumers(event.connection)
+  end
+
+  def on_disconnected(event)
+    self.remove_stale_consumers(event.connection)
+  end
+
+  def remove_stale_consumers(connection)
+    l = connection.link_head(Qpid::Proton::Endpoint::REMOTE_ACTIVE)
+    while !l.nil?
+      self.unsubscribe(l) if l.sender?
+      l = l.next(Qpid::Proton::Endpoint::REMOTE_ACTIVE)
+    end
+  end
+
+  def on_sendable(event)
+    debug("on_sendable event") if $options[:debug]
+    q = self.queue(event.link.source.address)
+    debug(" dispatching #{event.message} to #{q}") if $options[:debug]
+    q.dispatch(event.link)
+  end
+
+  def on_message(event)
+    debug("on_message event") if $options[:debug]
+    q = self.queue(event.link.target.address)
+    debug(" dispatching #{event.message} to #{q}") if $options[:debug]
+    q.publish(event.message)
+  end
+
+end
+
+$options = {
+  :address => "localhost:5672",
+  :debug => false
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: #{Pathname.new(__FILE__).basename} [$options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{$options[:address]}).") do |address|
+    $options[:address] = address
+  end
+
+  opts.on("-d", "--debug", "Enable debugging output (def. #{$options[:debug]})") do
+    $options[:debug] = true
+  end
+
+end.parse!
+
+begin
+  Qpid::Proton::Reactor::Container.new(Broker.new($options[:address])).run
+rescue Interrupt
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/client.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/client.rb b/proton-c/bindings/ruby/tests/old_examples/client.rb
new file mode 100644
index 0000000..8c38f38
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/client.rb
@@ -0,0 +1,82 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+class Client < Qpid::Proton::Handler::MessagingHandler
+
+  def initialize(url, requests)
+    super()
+    @url = url
+    @requests = requests
+  end
+
+  def on_start(event)
+    @sender = event.container.create_sender(@url)
+    @receiver = event.container.create_receiver(@sender.connection, :dynamic => true)
+  end
+
+  def next_request
+    if @receiver.remote_source.address
+      req = Qpid::Proton::Message.new
+      req.reply_to = @receiver.remote_source.address
+      req.body = @requests.first
+      puts "-> #{req.body}"
+      @sender.send(req)
+    end
+  end
+
+  def on_link_opened(event)
+    if event.receiver == @receiver
+      next_request
+    end
+  end
+
+  def on_message(event)
+    puts "<- #{event.message.body}"
+    @requests.delete_at(0)
+    if !@requests.empty?
+      next_request
+    else
+      event.connection.close
+    end
+  end
+
+  def on_transport_error(event)
+    raise "Connection error: #{event.transport.condition}"
+  end
+
+end
+
+REQUESTS = ["Twas brillig, and the slithy toves",
+            "Did gire and gymble in the wabe.",
+            "All mimsy were the borogroves,",
+            "And the mome raths outgrabe."]
+
+options = {
+  :address => "localhost:5672/examples",
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: client.rb [options]"
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") { |address| options[:address] = address }
+end.parse!
+
+Qpid::Proton::Reactor::Container.new(Client.new(options[:address], REQUESTS)).run

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/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
new file mode 100644
index 0000000..e8b52f3
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/direct_recv.rb
@@ -0,0 +1,60 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+require_relative 'lib/send_and_receive'
+
+class DirectReceive < ExampleReceive
+
+  def initialize(url, expected)
+    super
+  end
+
+  def on_start(event)
+    @acceptor = event.container.listen(self.url)
+  end
+
+  def on_message(event)
+    super(event)
+    @acceptor.close if self.finished?
+  end
+
+end
+
+options = {
+  :address => "localhost:5672/examples",
+  :messages => 100,
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: simple_send.rb [options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+    options[:address] = address
+  end
+
+  opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+    OptionParser::DecimalInteger) do |messages|
+    options[:messages] = messages
+  end
+end.parse!
+
+Qpid::Proton::Reactor::Container.new(DirectReceive.new(options[:address], options[:messages])).run

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/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
new file mode 100644
index 0000000..2164304
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/direct_send.rb
@@ -0,0 +1,59 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+require_relative 'lib/send_and_receive'
+
+options = {
+  :address => "localhost:5672/examples",
+  :messages => 100,
+}
+
+class SimpleSend < ExampleSend
+
+  def initialize(url, messages)
+    super(url, messages)
+  end
+
+  def on_start(event)
+    @acceptor = event.container.listen(url)
+  end
+
+end
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: simple_send.rb [options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+    options[:address] = address
+  end
+
+  opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+    OptionParser::DecimalInteger) do |messages|
+    options[:messages] = messages
+  end
+end.parse!
+
+begin
+  Qpid::Proton::Reactor::Container.new(SimpleSend.new(options[:address], options[:messages])).run
+rescue Interrupt => error
+  puts "ERROR: #{error}"
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/helloworld.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/helloworld.rb b/proton-c/bindings/ruby/tests/old_examples/helloworld.rb
new file mode 100644
index 0000000..9b02e8a
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/helloworld.rb
@@ -0,0 +1,73 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+class HelloWorld < Qpid::Proton::Handler::MessagingHandler
+
+  def initialize(server, address)
+    super()
+    @server = server
+    @address = address
+  end
+
+  def on_start(event)
+    conn = event.container.connect(:address => @server)
+    event.container.create_sender(conn, :target => @address)
+    event.container.create_receiver(conn, :source => @address)
+  end
+
+  def on_sendable(event)
+    msg = Qpid::Proton::Message.new
+    msg.body = "Hello world!"
+    event.sender.send(msg)
+    event.sender.close
+  end
+
+  def on_message(event)
+    puts event.message.body
+    event.connection.close
+  end
+
+  def on_transport_error(event)
+    raise "Connection error: #{event.transport.condition}"
+  end
+end
+
+options = {
+  :address => "localhost:5672",
+  :queue => "examples"
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: helloworld_direct.rb [options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+    options[:address] = address
+  end
+
+  opts.on("-q", "--queue=QUEUE", "Send messages to QUEUE (def. #{options[:queue]})") do |queue|
+    options[:queue] = queue
+  end
+
+end.parse!
+
+hw = HelloWorld.new(options[:address], "examples")
+Qpid::Proton::Reactor::Container.new(hw).run

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/helloworld_direct.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/helloworld_direct.rb b/proton-c/bindings/ruby/tests/old_examples/helloworld_direct.rb
new file mode 100644
index 0000000..e98cc1f
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/helloworld_direct.rb
@@ -0,0 +1,74 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+options = {
+  :address => "localhost:5672/examples",
+}
+
+class HelloWorldDirect < Qpid::Proton::Handler::MessagingHandler
+
+  include Qpid::Proton::Util::Wrapper
+
+  def initialize(url)
+    super()
+    @url = url
+  end
+
+  def on_start(event)
+    @acceptor = event.container.listen(@url)
+    event.container.create_sender(@url)
+  end
+
+  def on_sendable(event)
+    msg = Qpid::Proton::Message.new
+    msg.body = "Hello world!"
+    event.sender.send(msg)
+    event.sender.close
+  end
+
+  def on_message(event)
+    puts "#{event.message.body}"
+  end
+
+  def on_accepted(event)
+    event.connection.close
+  end
+
+  def on_connection_closed(event)
+    @acceptor.close
+  end
+
+end
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: helloworld_direct.rb [options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+    options[:address] = address
+  end
+
+end.parse!
+
+begin
+  Qpid::Proton::Reactor::Container.new(HelloWorldDirect.new(options[:address])).run
+rescue Interrupt => error
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/lib/debugging.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/lib/debugging.rb b/proton-c/bindings/ruby/tests/old_examples/lib/debugging.rb
new file mode 100644
index 0000000..5065d51
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/lib/debugging.rb
@@ -0,0 +1,26 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+module Debugging
+
+  def debug(text)
+    print "[#{Time.now.strftime('%s')}] #{text}\n"
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/lib/driver.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/lib/driver.rb b/proton-c/bindings/ruby/tests/old_examples/lib/driver.rb
new file mode 100644
index 0000000..4e223d0
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/lib/driver.rb
@@ -0,0 +1,69 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+class Driver
+
+  def initialize
+    @selectables = {}
+  end
+
+  def add(selectable)
+    @selectables[selectable.fileno] = selectable
+  end
+
+  def process
+    reading = []
+    writing = []
+
+    @selectables.each_value do |sel|
+      if sel.closed? || sel.fileno.nil?
+        @selectables.delete(sel.fileno)
+      else
+        begin
+          reading << sel.to_io if sel.reading?
+          writing << sel.to_io if sel.writing?
+        rescue Exception => error
+          puts "Error: #{error}"
+          puts error.backtrace.join("\n");
+          # @selectables.delete(sel.fileno)
+        end
+      end
+    end
+
+    read_from, write_to = IO.select(reading, writing, [], 0)
+
+    unless read_from.nil?
+      read_from.each do |r|
+        sel = @selectables[r.fileno]
+        sel.readable unless sel.nil? || sel.closed?
+      end
+    end
+
+    begin
+      unless write_to.nil?
+        write_to.each do |w|
+          sel = @selectables[w.fileno]
+          sel.writable unless sel.nil? || sel.closed?
+        end
+      end
+
+    end
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/lib/qpid_examples.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/lib/qpid_examples.rb b/proton-c/bindings/ruby/tests/old_examples/lib/qpid_examples.rb
new file mode 100644
index 0000000..665812d
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/lib/qpid_examples.rb
@@ -0,0 +1,27 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require "qpid_proton"
+
+require "selectable"
+require "driver"
+require "socket"
+require "monitor"
+
+include Socket::Constants

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/lib/selectable.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/lib/selectable.rb b/proton-c/bindings/ruby/tests/old_examples/lib/selectable.rb
new file mode 100644
index 0000000..779ea24
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/lib/selectable.rb
@@ -0,0 +1,120 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+class Selectable
+
+  attr_reader :transport
+
+  def initialize(transport, socket)
+    @transport = transport
+    @socket = socket
+    @socket.autoclose = true
+    @write_done = false
+    @read_done = false
+  end
+
+  def closed?
+    return true if @socket.closed?
+    return false if !@read_done && !@write_done
+    @socket.close
+    true
+  end
+
+  def fileno
+    @socket.fileno unless @socket.closed?
+  end
+
+  def to_io
+    @socket
+  end
+
+  def reading?
+    return false if @read_done
+    c = @transport.capacity
+    if c > 0
+      return true
+    elsif c < 0
+      @read_done = true
+      return false
+    else
+      return false
+    end
+  end
+
+  def writing?
+    return false if @write_done
+    begin
+      p = @transport.pending
+      if p > 0
+        return true
+      elsif p < 0
+        @write_done = true
+        return false
+      else
+        return false
+      end
+    rescue Qpid::Proton::TransportError => error
+      @write_done = true
+      return false
+    end
+  end
+
+  def readable
+    c = @transport.capacity
+    if c > 0
+      begin
+        data = @socket.recv(c)
+        if data
+          @transport.push(data)
+        else
+          @transport.close_tail
+        end
+      rescue Exception => error
+        puts "read error; #{error}"
+        @transport.close_tail
+        @read_done = true
+      end
+    elsif c < 0
+      @read_done = true
+    end
+  end
+
+  def writable
+    begin
+      p = @transport.pending
+      if p > 0
+        data = @transport.peek(p)
+        n = @socket.send(data, 0)
+        @transport.pop(n)
+      elsif p < 0
+        @write_done = true
+      end
+    rescue Exception => error
+      puts "write error: #{error}"
+      puts error.backtrace.join("\n")
+      @transport.close_head
+      @write_done = true
+    end
+  end
+
+  def tick(now)
+    @transport.tick(now)
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/lib/send_and_receive.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/lib/send_and_receive.rb b/proton-c/bindings/ruby/tests/old_examples/lib/send_and_receive.rb
new file mode 100644
index 0000000..9fd7417
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/lib/send_and_receive.rb
@@ -0,0 +1,90 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+class ExampleSend < Qpid::Proton::Handler::MessagingHandler
+
+  attr_reader :url
+
+  def initialize(url, expected)
+    super()
+    @url = url
+    @sent = 0
+    @confirmed = 0
+    @expected = expected
+  end
+
+  def on_sendable(event)
+    while event.sender.credit > 0 && @sent < @expected
+      msg = Qpid::Proton::Message.new
+      msg.body = "sequence #{@sent}"
+      msg.id = @sent
+      event.sender.send(msg)
+      @sent = @sent + 1
+    end
+  end
+
+  def on_accepted(event)
+    @confirmed = @confirmed + 1
+    if self.finished?
+      puts "#{@expected > 1 ? 'All ' : ''}#{@expected} message#{@expected > 1 ? 's' : ''} confirmed!"
+      event.connection.close
+    end
+  end
+
+  def on_disconnected(event)
+    @sent = @confirmed
+  end
+
+  def finished?
+    @confirmed == @expected
+  end
+
+end
+
+class ExampleReceive < Qpid::Proton::Handler::MessagingHandler
+
+  attr_reader :url
+
+  def initialize(url, expected)
+    super()
+    @url = url
+    @expected = expected
+    @received = 0
+  end
+
+  def on_message(event)
+    if event.message.id.nil? || event.message.id < @received
+      puts "Missing or old message id: id=#{event.message.id}"
+      return
+    end
+    if @expected.zero? || (@received < @expected)
+      puts "Received: #{event.message.body}"
+      @received = @received + 1
+      if finished?
+        event.receiver.close
+        event.connection.close
+      end
+    end
+  end
+
+  def finished?
+    @received == @expected
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/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
new file mode 100755
index 0000000..16c390d
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/old_example_test.rb
@@ -0,0 +1,85 @@
+#!/usr/bin/enc ruby
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+require 'minitest/autorun'
+require 'qpid_proton'
+require 'socket'
+
+class ExampleTest < MiniTest::Test
+
+  def run_script(script, port)
+    assert File.exist? script
+    cmd = [RbConfig.ruby, script]
+    cmd += ["-a", ":#{port}/examples"] if port
+    return IO.popen(cmd)
+  end
+
+
+  def assert_output(script, want, port=nil)
+    out = run_script(script, port)
+    assert_equal want, out.read.strip
+  end
+
+  def test_helloworld
+    assert_output("helloworld.rb", "Hello world!", $port)
+  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)
+  end
+
+  def test_client_server
+    want =  <<EOS
+-> Twas brillig, and the slithy toves
+<- TWAS BRILLIG, AND THE SLITHY TOVES
+-> Did gire and gymble in the wabe.
+<- DID GIRE AND GYMBLE IN THE WABE.
+-> All mimsy were the borogroves,
+<- ALL MIMSY WERE THE BOROGROVES,
+-> And the mome raths outgrabe.
+<- AND THE MOME RATHS OUTGRABE.
+EOS
+    srv = run_script("server.rb", $port)
+    assert_output("client.rb", want.strip, $port)
+
+  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}")
+
+# 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
+end
+
+# Kill the broker after all tests
+MiniTest.after_run do
+  Process.kill(:TERM, $broker) if $broker
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/proton-c/bindings/ruby/tests/old_examples/server.rb
----------------------------------------------------------------------
diff --git a/proton-c/bindings/ruby/tests/old_examples/server.rb b/proton-c/bindings/ruby/tests/old_examples/server.rb
new file mode 100644
index 0000000..9373272
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/server.rb
@@ -0,0 +1,76 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+class Server < Qpid::Proton::Handler::MessagingHandler
+
+  def initialize(url)
+    super()
+    @url = Qpid::Proton::URL.new url
+    @address = @url.path
+    @senders = {}
+  end
+
+  def on_start(event)
+    @container = event.container
+    @conn = @container.connect(:url => @url)
+    @receiver = @container.create_receiver(@conn, :source => @address)
+    @relay = nil
+  end
+
+  def on_connection_opened(event)
+    if event.connection.remote_offered_capabilities &&
+      event.connection.remote_offered_capabilities.contain?("ANONYMOUS-RELAY")
+      @relay = @container.create_sender(@conn, nil)
+    end
+  end
+
+  def on_message(event)
+    msg = event.message
+    puts "<- #{msg.body}"
+    sender = @relay || @senders[msg.reply_to]
+    if sender.nil?
+      sender = @container.create_sender(@conn, :target => msg.reply_to)
+      @senders[msg.reply_to] = sender
+    end
+    reply = Qpid::Proton::Message.new
+    reply.address = msg.reply_to
+    reply.body = msg.body.upcase
+    puts "-> #{reply.body}"
+    reply.correlation_id = msg.correlation_id
+    sender.send(reply)
+  end
+
+  def on_transport_error(event)
+    raise "Connection error: #{event.transport.condition}"
+  end
+end
+
+options = {
+  :address => "localhost:5672/examples",
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: server.rb [options]"
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") { |address| options[:address] = address }
+end.parse!
+
+Qpid::Proton::Reactor::Container.new(Server.new(options[:address])).run()

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/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
new file mode 100644
index 0000000..91cb30c
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/simple_recv.rb
@@ -0,0 +1,58 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+require_relative 'lib/send_and_receive'
+
+class Receiver < ExampleReceive
+
+  def initialize(url, count)
+    super(url, count)
+  end
+
+  def on_start(event)
+    event.container.create_receiver(@url)
+  end
+
+end
+
+options = {
+  :address => "localhost:5672/examples",
+  :messages => 100,
+}
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: simple_send.rb [options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+    options[:address] = address
+  end
+
+  opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+    OptionParser::DecimalInteger) do |messages|
+    options[:messages] = messages
+  end
+end.parse!
+
+begin
+  Qpid::Proton::Reactor::Container.new(Receiver.new(options[:address], options[:messages])).run
+rescue Interrupt
+end

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/86de6b58/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
new file mode 100644
index 0000000..13e40f0
--- /dev/null
+++ b/proton-c/bindings/ruby/tests/old_examples/simple_send.rb
@@ -0,0 +1,55 @@
+#--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#++
+
+require 'qpid_proton'
+require 'optparse'
+
+require_relative 'lib/send_and_receive'
+
+options = {
+  :address => "localhost:5672/examples",
+  :messages => 100,
+}
+
+class SimpleSend < ExampleSend
+
+  def initialize(url, messages)
+    super(url, messages)
+  end
+
+  def on_start(event)
+    event.container.create_sender(url)
+  end
+
+end
+
+OptionParser.new do |opts|
+  opts.banner = "Usage: simple_send.rb [options]"
+
+  opts.on("-a", "--address=ADDRESS", "Send messages to ADDRESS (def. #{options[:address]}).") do |address|
+    options[:address] = address
+  end
+
+  opts.on("-m", "--messages=COUNT", "The number of messages to send (def. #{options[:messages]}",
+    OptionParser::DecimalInteger) do |messages|
+    options[:messages] = messages
+  end
+end.parse!
+
+Qpid::Proton::Reactor::Container.new(SimpleSend.new(options[:address], options[:messages])).run


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