http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/examples/ruby/simple_send.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/simple_send.rb b/examples/ruby/simple_send.rb new file mode 100644 index 0000000..38857f3 --- /dev/null +++ b/examples/ruby/simple_send.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' + +options = { + :address => "localhost:5672/examples", + :messages => 100, +} + +class SimpleSend < Qpid::Proton::Handler::MessagingHandler + + def initialize(url, expected) + super() + @url = url + @sent = 0 + @confirmed = 0 + @expected = expected + end + + def on_start(event) + event.container.create_sender(@url) + end + + def on_sendable(event) + while event.sender.credit > 0 && @sent < @expected + msg = Qpid::Proton::Message.new("sequence #{@sent}", { :id => @sent } ) + event.sender.send(msg) + @sent = @sent + 1 + end + end + + def on_accepted(event) + @confirmed = @confirmed + 1 + if @confirmed == @expected + puts "All #{@expected} messages confirmed!" + event.connection.close + end + 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
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/examples/ruby/wrapper_test.rb ---------------------------------------------------------------------- diff --git a/examples/ruby/wrapper_test.rb b/examples/ruby/wrapper_test.rb deleted file mode 100644 index ca7e250..0000000 --- a/examples/ruby/wrapper_test.rb +++ /dev/null @@ -1,82 +0,0 @@ -#-- -# 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' - -def how_many_transports?(expected) - count = ObjectSpace.each_object(Qpid::Proton::Transport).count - if expected.min == expected.max - expectation = "#{expected.min}" - else - expectation = "#{expected.min} <= count <= #{expected.max}" - end - puts "Transport count: found #{count}, expected #{expectation} (#{expected.include?(count) ? 'Good' : 'Bad'})" -end - -transport = Qpid::Proton::Transport.new -timpl = transport.impl - -puts "=================================" -puts "= Storing my original transport =" -puts "=================================" -puts " Stored transport=#{transport} (#{Cproton.pni_address_of(timpl).to_s(16)})" -how_many_transports?(1..1) -puts "=================================" -transport.instance_eval { @first_name = "Darryl"; @last_name = "Pierce", @instance_id = 717 } -transport = nil - - -puts "" -max = 1000 -puts "Creating #{max} instances of Transport" -(0...max).each do |which| - t = Qpid::Proton::Transport.new - t.instance_eval { @instance_id = which } - t = nil -end - -puts "" -puts "====================================" -puts "= Retrieving my original transport =" -puts "====================================" -transport = Qpid::Proton::Transport.wrap(timpl) -puts "Retrieved transport=#{transport} (#{Cproton.pni_address_of(timpl).to_s(16)})" -how_many_transports?(1..1001) -puts "====================================" -puts "My transport attributes:" -puts transport - -transport = nil -GC.start -how_many_transports?(1..1) - -puts "" -puts "======================================" -puts "= Throwing away the Transport object =" -puts "======================================" -transport = nil -timpl.instance_eval { @proton_wrapper = nil } -GC.start -begin - transport = Qpid::Proton::Transport.wrap(timpl) - puts "!!! This should fail!" -rescue Qpid::Proton::ProtonError => error - puts "Good, it failed..." -end -how_many_transports?(0..0) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/proton-c/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/proton-c/CMakeLists.txt b/proton-c/CMakeLists.txt index b6ce4a7..3f79af6 100644 --- a/proton-c/CMakeLists.txt +++ b/proton-c/CMakeLists.txt @@ -559,6 +559,21 @@ elseif (PROACTOR AND NOT PROACTOR STREQUAL "none") message(FATAL_ERROR "Cannot build the ${PROACTOR} proactor") endif() +if (CMAKE_SYSTEM_NAME STREQUAL Windows) + # No change needed for windows already use correct separator + function(to_native_path path result) + file (TO_NATIVE_PATH "${path}" path) + set (${result} ${path} PARENT_SCOPE) + endfunction() +else (CMAKE_SYSTEM_NAME STREQUAL Windows) + # Just change ';'->':' + function(to_native_path path result) + file (TO_NATIVE_PATH "${path}" path) + string (REGEX REPLACE ";" ":" path "${path}") + set (${result} ${path} PARENT_SCOPE) + endfunction() +endif (CMAKE_SYSTEM_NAME STREQUAL Windows) + # note: process bindings after the source lists have been defined so # the bindings can reference them add_subdirectory(bindings) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/proton-c/bindings/ruby/lib/core/message.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/core/message.rb b/proton-c/bindings/ruby/lib/core/message.rb index f31ce29..d84e795 100644 --- a/proton-c/bindings/ruby/lib/core/message.rb +++ b/proton-c/bindings/ruby/lib/core/message.rb @@ -129,13 +129,21 @@ module Qpid::Proton end # Creates a new +Message+ instance. - def initialize(body = nil) + # @param body the body of the message, equivalent to calling m.body=(body) + # @param set [Hash] additional settings, equivalent to m.key=value for each key=>value in settings + def initialize(body = nil, settings={}) @impl = Cproton.pn_message ObjectSpace.define_finalizer(self, self.class.finalize!(@impl)) @properties = {} @instructions = {} @annotations = {} self.body = body unless body.nil? + if !settings.nil? then + settings.each do |k, v| + setter = (k.to_s+"=").to_sym() + self.send setter, v + end + end end def to_s http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/proton-c/bindings/ruby/lib/messenger/messenger.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/lib/messenger/messenger.rb b/proton-c/bindings/ruby/lib/messenger/messenger.rb index 8c4714a..06ce031 100644 --- a/proton-c/bindings/ruby/lib/messenger/messenger.rb +++ b/proton-c/bindings/ruby/lib/messenger/messenger.rb @@ -18,6 +18,7 @@ # module Qpid::Proton::Messenger + # @deprecated use {Qpid::Proton::Container} # # The +Messenger+ class defines a high level interface for # sending and receiving Messages. Every Messenger contains @@ -72,6 +73,7 @@ module Qpid::Proton::Messenger # * name - the name (def. nil) # def initialize(name = nil) + warn "[DEPRECATION] `Qpid::Proton::Messenger` is deprecated, use `Qpid::Proton::Container`" @impl = Cproton.pn_messenger(name) @selectables = {} ObjectSpace.define_finalizer(self, self.class.finalize!(@impl)) http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/proton-c/bindings/ruby/spec/messenger_spec.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/spec/messenger_spec.rb b/proton-c/bindings/ruby/spec/messenger_spec.rb deleted file mode 100644 index 0fec6b9..0000000 --- a/proton-c/bindings/ruby/spec/messenger_spec.rb +++ /dev/null @@ -1,393 +0,0 @@ -# -# 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 "spec_helper" - -module Qpid - - module Proton - - describe "A messenger" do - - before (:each) do - @messenger = Qpid::Proton::Messenger::Messenger.new - end - - after (:each) do - begin - @messenger.stop - rescue ProtonError => error - # ignore this error - end - end - - it "will generate a name if one is not provided" do - expect(@messenger.name).wont_be_nil - end - - it "will accept an assigned name" do - name = random_string(16) - msgr = Qpid::Proton::Messenger::Messenger.new(name) - expect(msgr.name).must_equal(name) - end - - it "raises an error on a nil timeout" do - expect { - @messenger.timeout = nil - }.must_raise(TypeError) - end - - it "can have a negative timeout" do - timeout = (0 - rand(65535)) - @messenger.timeout = timeout - expect(@messenger.timeout).must_equal(timeout) - end - - it "has a timeout" do - timeout = rand(65535) - @messenger.timeout = timeout - expect(@messenger.timeout).must_equal(timeout) - end - - it "has an error number" do - expect(@messenger.error?).must_equal(false) - expect(@messenger.errno).must_equal(0) - # force an error - expect { - @messenger.subscribe("amqp://~#{random_string}") - }.must_raise(ProtonError) - expect(@messenger.error?).must_equal(true) - expect(@messenger.errno).wont_equal(0) - end - - it "has an error message" do - expect(@messenger.error?).must_equal(false) - expect(@messenger.error).must_be_nil - # force an error - expect { - @messenger.subscribe("amqp://~#{random_string}") - }.must_raise(ProtonError) - expect(@messenger.error?).must_equal(true) - expect(@messenger.errno).wont_be_nil - end - - it "can be started" do - @messenger.start - end - - it "can be stopped" do - @messenger.stop - end - - it "raises an error when subscribing to a nil address" do - expect { - @messenger.subscribe(nil) - }.must_raise(TypeError) - end - - it "raises an error when subscribing to an invalid address" do - expect { - @messenger.subscribe("amqp://~#{random_string}") - }.must_raise(ProtonError) - expect(@messenger.error?).must_equal(true) - expect(@messenger.errno).wont_equal(nil) - end - - it "can have a nil certificate" do - @messenger.certificate = nil - expect(@messenger.certificate).must_be_nil - end - - it "can have a certificate" do - cert = random_string(128) - @messenger.certificate = cert - expect(@messenger.certificate).must_equal(cert) - end - - it "can have a nil private key" do - @messenger.private_key = nil - expect(@messenger.private_key).must_be_nil - end - - it "can have a private key" do - key = random_string(128) - @messenger.private_key = key - expect(@messenger.private_key).must_equal(key) - end - - it "can have a nil trusted certificates" do - @messenger.trusted_certificates = nil - expect(@messenger.trusted_certificates).must_be_nil - end - - it "has a list of trusted certificates" do - certs = random_string(128) - @messenger.trusted_certificates = certs - expect(@messenger.trusted_certificates).must_equal(certs) - end - - it "raises an error on a nil outgoing window" do - expect { - @messenger.outgoing_window = nil - }.must_raise(TypeError) - end - - it "raises an error on a non-numeric outgoing window" do - expect { - @messenger.outgoing_window = random_string(16) - }.must_raise(TypeError) - end - - it "can have a negative outgoing window" do - window = 0 - (rand(256) + 1) - @messenger.outgoing_window = window - expect(@messenger.outgoing_window).must_equal(window) - end - - it "can have a positive outgoing window" do - window = (rand(256) + 1) - @messenger.outgoing_window = window - expect(@messenger.outgoing_window).must_equal(window) - end - - it "can have a zero outgoing window" do - window = 0 - @messenger.outgoing_window = window - expect(@messenger.outgoing_window).must_equal(window) - end - - it "raises an error on a nil incoming window" do - expect { - @messenger.incoming_window = nil - }.must_raise(TypeError) - end - - it "raises an error on a non-numeric incoming window" do - expect { - @messenger.incoming_window = random_string(16) - }.must_raise(TypeError) - end - - it "can have a negative incoming window" do - window = 0 - (rand(256) + 1) - @messenger.incoming_window = window - expect(@messenger.incoming_window).must_equal(window) - end - - it "can have a positive incoming window" do - window = (rand(256) + 1) - @messenger.incoming_window = window - expect(@messenger.incoming_window).must_equal(window) - end - - it "can have a zero incoming window" do - window = 0 - @messenger.incoming_window = window - expect(@messenger.incoming_window).must_equal(window) - end - - it "can be put into passive mode" do - @messenger.passive = true - expect(@messenger.passive?).must_equal(true) - end - - it "can be taken out of passive mode" do - @messenger.passive = false - expect(@messenger.passive?).must_equal(false) - end - - it "can clear non-existent errors with failing" do - @messenger.clear_error - end - - it "can clear errors" do - begin - @messenger.accept # should cause an error - rescue; end - - expect(@messenger.error).wont_be_nil - @messenger.clear_error - expect(@messenger.error).must_be_nil - end - - describe "once started" do - - before (:each) do - @messenger.start - end - - after (:each) do - begin - @messenger.stop - rescue ProtonError => error - # ignore this error - end - end - - it "can subscribe to an address" do - expect(@messenger.subscribe("amqp://~0.0.0.0:#{5700+rand(1024)}")).wont_be_nil - end - - it "returns a tracker's status" - - describe "and subscribed to an address" do - - before (:each) do - # create a receiver - @port = 5700 + rand(1024) - @receiver = Qpid::Proton::Messenger::Messenger.new("receiver") - @receiver.subscribe("amqp://~0.0.0.0:#{@port}") - @messenger.timeout = 0 - @receiver.timeout = 0 - @receiver.start - - Thread.new do - @receiver.receive(10) - end - - @msg = Qpid::Proton::Message.new - @msg.address = "amqp://0.0.0.0:#{@port}" - @msg.body = "Test sent #{Time.new}" - end - - after (:each) do - begin - @messenger.stop - rescue ProtonError => error - # ignore this error - end - begin - @receiver.stop - rescue - end - end - - it "raises an error when queueing a nil message" do - expect { - @messenger.put(nil) - }.must_raise(TypeError) - end - - it "raises an error when queueing an invalid object" do - expect { - @messenger.put("This is not a message") - }.must_raise(::ArgumentError) - end - - it "can place a message in the outgoing queue" do - @messenger.put(@msg) - end - - it "can send with an empty queue" - - describe "with a an outgoing tracker" do - - before(:each) do - @messenger.put(@msg) - @tracker = @messenger.outgoing_tracker - end - - it "has an outgoing tracker" do - expect(@tracker).wont_be_nil - end - - it "returns a tracker's status" - - it "raises an error when settling with a nil tracker" do - expect { - @messenger.settle(nil) - }.must_raise(TypeError) - end - - it "can settle a tracker's status" do - @messenger.settle(@tracker) - end - - it "raises an error when checking status on a nil tracker" do - expect { - @messenger.status(nil) - }.must_raise(TypeError) - end - - it "raises an error when checking status on an invalid tracker" do - expect { - @messenger.status(random_string(16)) - }.must_raise(TypeError) - end - - it "can check the status of a tracker" do - expect(@messenger.status(@tracker)).wont_be_nil - end - - end - - it "has an incoming tracker" - it "can reject an incoming message" - - it "raises an error when accepting with an invalid tracker" do - expect { - @messenger.accept(random_string(16)) - }.must_raise(TypeError) - end - - it "can accept a message" - - it "raises an error when rejecting with an invalid tracker" do - expect { - @messenger.accept(random_string(16)) - }.must_raise(TypeError) - end - - describe "with messages sent" do - - before (:each) do - @messenger.put(@msg) - end - - it "can send messages" - - it "raises an error when receiving with a nil max" do - expect { - @messenger.receive(nil) - }.must_raise(TypeError) - end - - it "raises an error when receiving with a non-numeric max" do - expect { - @messenger.receive("farkle") - }.must_raise(TypeError) - end - - it "can receive messages" - it "and create a new message when one wasn't provided" - it "can get a message from the incoming queue" - it "can tell how many outgoing messages are pending" - it "can tell how many incoming messages are queued" - - end - - end - - end - - end - - end - -end http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3d258158/proton-c/bindings/ruby/tests/test_tools.rb ---------------------------------------------------------------------- diff --git a/proton-c/bindings/ruby/tests/test_tools.rb b/proton-c/bindings/ruby/tests/test_tools.rb index 22a9040..8de86e2 100644 --- a/proton-c/bindings/ruby/tests/test_tools.rb +++ b/proton-c/bindings/ruby/tests/test_tools.rb @@ -35,7 +35,7 @@ def wait_port(port, timeout=5) TCPSocket.open("", $port).close rescue Errno::ECONNREFUSED if Time.now > deadline then - raise TestError("timed out waiting for port #{port}") + raise TestError, "timed out waiting for port #{port}" end sleep(0.1) retry @@ -113,15 +113,15 @@ end class TestServer < TestHandler def initialize super - @port = TCPServer.open(0) do |s| s.addr[1]; end # find an unused port + @server = TCPServer.open(0) end def host() ""; end - def port() @port; end + def port() @server.addr[1]; end def addr() "#{host}:#{port}"; end def on_start(e) super - @listener = e.container.listen(addr) + @listener = e.container.listen_io(@server) end end --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org