Skip to content
Browse files

Unpack stomp gem; clean up

  • Loading branch information...
1 parent bcc4056 commit 90e59916a1a3b78dfe3ebdc0a2f268a1159463e7 @rsanheim committed Oct 9, 2009
View
24 Rakefile
@@ -6,30 +6,6 @@ require 'rake/rdoctask'
require 'tasks/rails'
-namespace :spec do
- begin
- gem "spicycode-micronaut"
- require "micronaut"
- require "micronaut/rake_task"
-
- desc "Run all specs using rcov"
- Micronaut::RakeTask.new :coverage => ["db:test:prepare"] do |t|
- t.pattern = "spec/**/*_spec.rb"
- t.rcov = true
- t.rcov_opts = %[-Ispec --exclude "features/*,gems/*,lib/authenticated*,db/*,/Library/Ruby/*,config/*" --rails --text-summary --sort coverage --html]
- end
-
- desc "Run all specs"
- Micronaut::RakeTask.new :all => ["db:test:prepare"] do |t|
- t.pattern = "spec/**/*_spec.rb"
- t.ruby_opts = ["-Ispec"]
- end
- task :default => :all
- rescue LoadError => e
- puts "Micronaut not installed - spec tasks not available"
- end
-end
-
Rake::Task[:default].clear
if RUBY_VERSION < "1.9"
View
1 config/environment.rb
@@ -13,6 +13,7 @@
config.gem "chatterbox", :source => "http://gemcutter.org"
config.gem "chatterbox-email", :lib => "chatterbox/email"
config.gem "rosetta_queue", :lib => false
+ config.gem "stomp"
config.frameworks -= [:active_resource]
View
3 lib/producer.rb
@@ -21,7 +21,8 @@ def self.run
end
end
- def self.publish(message)
+ def self.publish(reminder)
+ message = reminder.to_hash
logger.debug { "Submitting reminder: #{reminder.id} msg: #{message.inspect}"}
RosettaQueue::Producer.publish(:requests, message)
end
View
6 lib/tasks/producer.rake
@@ -0,0 +1,6 @@
+namespace :producer do
+ desc "Run the Producer, publishing an reminders ready for processing"
+ task :run => :environment do
+ Producer.run
+ end
+end
View
24 lib/tasks/spec.rake
@@ -0,0 +1,24 @@
+namespace :spec do
+ begin
+ gem "spicycode-micronaut"
+ require "micronaut"
+ require "micronaut/rake_task"
+
+ desc "Run all specs using rcov"
+ Micronaut::RakeTask.new :coverage => ["db:test:prepare"] do |t|
+ t.pattern = "spec/**/*_spec.rb"
+ t.rcov = true
+ t.rcov_opts = %[-Ispec --exclude "features/*,gems/*,lib/authenticated*,db/*,/Library/Ruby/*,config/*" --rails --text-summary --sort coverage --html]
+ end
+
+ desc "Run all specs"
+ Micronaut::RakeTask.new :all => ["db:test:prepare"] do |t|
+ t.pattern = "spec/**/*_spec.rb"
+ t.ruby_opts = ["-Ispec"]
+ end
+ task :default => :all
+ rescue LoadError => e
+ puts "Micronaut not installed - spec tasks not available"
+ end
+end
+
View
2 vendor/gems/justinfrench-formtastic-0.2.4/.specification
@@ -34,7 +34,7 @@ files:
- rails/init.rb
- spec/formtastic_spec.rb
- spec/test_helper.rb
-has_rdoc: false
+has_rdoc: true
homepage: http://github.com/justinfrench/formtastic/tree/master
licenses: []
View
3 vendor/gems/stomp-1.1/.gitignore
@@ -0,0 +1,3 @@
+pkg/*
+doc/*
+coverage/*
View
57 vendor/gems/stomp-1.1/.specification
@@ -0,0 +1,57 @@
+--- !ruby/object:Gem::Specification
+name: stomp
+version: !ruby/object:Gem::Version
+ version: "1.1"
+platform: ruby
+authors: []
+
+autorequire:
+bindir: bin
+cert_chain: []
+
+date: 2009-10-09 00:00:00 -04:00
+default_executable:
+dependencies: []
+
+description:
+email:
+executables: []
+
+extensions: []
+
+extra_rdoc_files: []
+
+files:
+- lib
+- lib/stomp
+- lib/stomp.rb
+has_rdoc: true
+homepage:
+licenses: []
+
+post_install_message:
+rdoc_options: []
+
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: "0"
+ version:
+requirements: []
+
+rubyforge_project:
+rubygems_version: 1.3.5
+signing_key:
+specification_version: 3
+summary:
+test_files: []
+
View
10 vendor/gems/stomp-1.1/AUTHORS
@@ -0,0 +1,10 @@
+The following people have contributed to Stomp (ordered by commits):
+
+Brian McCaliister
+Glenn Rempe <glenn@rempe.us>
+jstrachan
+Marius Mathiesen <marius.mathiesen@gmail.com>
+Johan S√∏rensen <johan@johansorensen.com>
+kookster
+Tony Garnock-Jones <tonyg@lshift.net>
+chirino
View
25 vendor/gems/stomp-1.1/CHANGELOG
@@ -0,0 +1,25 @@
+== 1.1 2009-27-02
+
+* Ruby 1.9 Support
+* Add support for connect_headers, to control the CONNECT command.
+* Refactored lib dir to separate concerns.
+* Better test coverage
+* General code cleanup.
+
+== 1.0.6 2008-05-08
+
+* Whitespace cleanup
+* Refactored Rakefile and added stomp.gemspec for GitHub friendliness.
+* Added .gitignore file
+* Refactored layout of lib dir to separate concerns
+* Cleanup of initializers, and provide Client accessors for reading values (for testing)
+* Removed test/test_url_* files as they only differed from the test_client.rb in their
+ setup. Super UnDry. Added URL tests to cover stomp URL as param.
+* Created initial RSpec specs which stub/mock objects and should not require a running
+ Stomp server instance.
+
+== v1.0.5
+
+SVN rev 86 clone from http://svn.codehaus.org/stomp/ruby/trunk
+
+git-svn-id: http://svn.codehaus.org/stomp/ruby/trunk@86 fd4e7336-3dff-0310-b68a-b6615a75f13b
View
202 vendor/gems/stomp-1.1/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
View
36 vendor/gems/stomp-1.1/README.rdoc
@@ -0,0 +1,36 @@
+==README
+
+http://stomp.rubyforge.org/
+
+===Overview
+
+An implementation of the Stomp protocol (http://stomp.codehaus.org/Protocol) for Ruby.
+
+
+===Example Usage
+
+ client = Stomp::Client.new("test", "user", "localhost", 61613)
+ client.send("/my/queue", "hello world!")
+ client.subscribe("/my/queue") do |msg|
+ p msg
+ end
+
+===Contact info
+
+Up until March 2009 the project was maintained and primarily developed by Brian McCallister.
+
+The project is now maintained by Johan Sørensen <johan@johansorensen.com>
+
+===Source Code
+
+ http://gitorious.org/projects/stomp/
+ http://github.com/js/stomp/
+
+===Project urls
+
+Project Home :
+ http://gitorious.org/projects/stomp/
+ http://rubyforge.org/projects/stomp/
+
+Stomp Protocol Info :
+ http://stomp.codehaus.org/Protocol
View
52 vendor/gems/stomp-1.1/Rakefile
@@ -0,0 +1,52 @@
+# Copyright 2005-2006 Brian McCallister
+#
+# Licensed 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 'rubygems'
+require 'rake/gempackagetask'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'spec/rake/spectask'
+
+# read the contents of the gemspec, eval it, and assign it to 'spec'
+# this lets us maintain all gemspec info in one place. Nice and DRY.
+spec = eval(IO.read("stomp.gemspec"))
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+ pkg.need_tar = true
+end
+
+task :install => [:package] do
+ sh %{sudo gem install pkg/#{GEM}-#{VERSION}}
+end
+
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/test*.rb']
+ t.verbose = true
+end
+
+Rake::RDocTask.new do |rd|
+ rd.main = "README.rdoc"
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
+ rd.rdoc_dir = 'doc'
+ rd.options = spec.rdoc_options
+end
+
+desc "RSpec : run all"
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_files = FileList['spec/**/*.rb']
+ t.spec_opts = ["--color", "--format", "specdoc"]
+end
+
View
55 vendor/gems/stomp-1.1/bin/catstomp
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+#
+# Copyright 2006 LogicBlaze Inc.
+#
+# Licensed 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.
+#
+begin; require 'rubygems'; rescue; end
+require 'stomp'
+
+#
+# This simple script is inspired by the netcat utility. It allows you to send
+# input into this process to stomp destination.
+#
+# Usage: catstomp (destination-name)
+#
+# Example: ls | catstomp /topic/foo
+# Would send the output of the ls command to the stomp destination /topic/foo
+#
+begin
+
+ @port = 61613
+ @host = "localhost"
+ @user = ENV["STOMP_USER"];
+ @password = ENV["STOMP_PASSWORD"]
+
+ @host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != nil
+ @port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != nil
+
+ @destination = "/topic/default"
+ @destination = $*[0] if $*[0] != nil
+
+ $stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
+ @conn = Stomp::Connection.open(@user, @password, @host, @port, true)
+ $stderr.print "Sending input to #{@destination}\n"
+
+ @headers = {'persistent'=>'false'}
+ @headers['reply-to'] = $*[1] if $*[1] != nil
+
+ STDIN.each_line { |line|
+ @conn.send @destination, line, @headers
+ }
+
+rescue
+end
+
View
56 vendor/gems/stomp-1.1/bin/stompcat
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+#
+# Copyright 2006 LogicBlaze Inc.
+#
+# Licensed 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.
+#
+begin; require 'rubygems'; rescue; end
+require 'stomp'
+
+#
+# This simple script is inspired by the netcat utility. It allows you to receive
+# data from a stomp destination and output it.
+#
+# Usage: stompcat (destination-name)
+#
+# Example: stompcat /topic/foo
+# Would display output that arrives at the /topic/foo stomp destination
+#
+begin
+
+ @port = 61613
+ @host = "localhost"
+ @user = ENV["STOMP_USER"];
+ @password = ENV["STOMP_PASSWORD"]
+
+ @host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != nil
+ @port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != nil
+
+ @destination = "/topic/default"
+ @destination = $*[0] if $*[0] != nil
+
+ $stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
+ @conn = Stomp::Connection.open(@user, @password, @host, @port, true)
+ $stderr.print "Getting output from #{@destination}\n"
+
+ @conn.subscribe(@destination, { :ack =>"client" })
+ while true
+ @msg = @conn.receive
+ $stdout.print @msg.body
+ $stdout.flush
+ @conn.ack @msg.headers["message-id"]
+ end
+
+rescue
+end
+
View
25 vendor/gems/stomp-1.1/lib/stomp.rb
@@ -0,0 +1,25 @@
+# Copyright 2005-2006 Brian McCallister
+# Copyright 2006 LogicBlaze Inc.
+#
+# Licensed 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 'io/wait'
+require 'socket'
+require 'thread'
+require 'stomp/connection'
+require 'stomp/client'
+require 'stomp/message'
+
+module Stomp
+end
+
View
207 vendor/gems/stomp-1.1/lib/stomp/client.rb
@@ -0,0 +1,207 @@
+module Stomp
+
+ # Typical Stomp client class. Uses a listener thread to receive frames
+ # from the server, any thread can send.
+ #
+ # Receives all happen in one thread, so consider not doing much processing
+ # in that thread if you have much message volume.
+ class Client
+
+ attr_reader :login, :passcode, :host, :port, :reliable, :running
+
+ # A new Client object can be initialized using two forms:
+ #
+ # Standard positional parameters:
+ # login (String, default : '')
+ # passcode (String, default : '')
+ # host (String, default : 'localhost')
+ # port (Integer, default : 61613)
+ # reliable (Boolean, default : false)
+ #
+ # e.g. c = Client.new('login', 'passcode', 'localhost', 61613, true)
+ #
+ # Stomp URL :
+ # A Stomp URL must begin with 'stomp://' and can be in one of the following forms:
+ #
+ # stomp://host:port
+ # stomp://host.domain.tld:port
+ # stomp://login:passcode@host:port
+ # stomp://login:passcode@host.domain.tld:port
+ #
+ def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
+
+ # Parse stomp:// URL's or set positional params
+ case login
+ when /stomp:\/\/([\w\.]+):(\d+)/ # e.g. stomp://host:port
+ # grabs the matching positions out of the regex which are stored as
+ # $1 (host), $2 (port), etc
+ @login = ''
+ @passcode = ''
+ @host = $1
+ @port = $2.to_i
+ @reliable = false
+ when /stomp:\/\/([\w\.]+):(\w+)@([\w\.]+):(\d+)/ # e.g. stomp://login:passcode@host:port
+ @login = $1
+ @passcode = $2
+ @host = $3
+ @port = $4.to_i
+ @reliable = false
+ else
+ @login = login
+ @passcode = passcode
+ @host = host
+ @port = port.to_i
+ @reliable = reliable
+ end
+
+ raise ArgumentError if @host.nil? || @host.empty?
+ raise ArgumentError if @port.nil? || @port == '' || @port < 1 || @port > 65535
+ raise ArgumentError unless @reliable.is_a?(TrueClass) || @reliable.is_a?(FalseClass)
+
+ @id_mutex = Mutex.new
+ @ids = 1
+ @connection = Connection.new(@login, @passcode, @host, @port, @reliable)
+ @listeners = {}
+ @receipt_listeners = {}
+ @running = true
+ @replay_messages_by_txn = {}
+
+ @listener_thread = Thread.start do
+ while @running
+ message = @connection.receive
+ case
+ when message.nil?
+ break
+ when message.command == 'MESSAGE'
+ if listener = @listeners[message.headers['destination']]
+ listener.call(message)
+ end
+ when message.command == 'RECEIPT'
+ if listener = @receipt_listeners[message.headers['receipt-id']]
+ listener.call(message)
+ end
+ end
+ end
+ end
+
+ end
+
+ # Syntactic sugar for 'Client.new' See 'initialize' for usage.
+ def self.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
+ Client.new(login, passcode, host, port, reliable)
+ end
+
+ # Join the listener thread for this client,
+ # generally used to wait for a quit signal
+ def join
+ @listener_thread.join
+ end
+
+ # Begin a transaction by name
+ def begin(name, headers = {})
+ @connection.begin(name, headers)
+ end
+
+ # Abort a transaction by name
+ def abort(name, headers = {})
+ @connection.abort(name, headers)
+
+ # lets replay any ack'd messages in this transaction
+ replay_list = @replay_messages_by_txn[name]
+ if replay_list
+ replay_list.each do |message|
+ if listener = @listeners[message.headers['destination']]
+ listener.call(message)
+ end
+ end
+ end
+ end
+
+ # Commit a transaction by name
+ def commit(name, headers = {})
+ txn_id = headers[:transaction]
+ @replay_messages_by_txn.delete(txn_id)
+ @connection.commit(name, headers)
+ end
+
+ # Subscribe to a destination, must be passed a block
+ # which will be used as a callback listener
+ #
+ # Accepts a transaction header ( :transaction => 'some_transaction_id' )
+ def subscribe(destination, headers = {})
+ raise "No listener given" unless block_given?
+ @listeners[destination] = lambda {|msg| yield msg}
+ @connection.subscribe(destination, headers)
+ end
+
+ # Unsubecribe from a channel
+ def unsubscribe(name, headers = {})
+ @connection.unsubscribe(name, headers)
+ @listeners[name] = nil
+ end
+
+ # Acknowledge a message, used when a subscription has specified
+ # client acknowledgement ( connection.subscribe "/queue/a", :ack => 'client'g
+ #
+ # Accepts a transaction header ( :transaction => 'some_transaction_id' )
+ def acknowledge(message, headers = {})
+ txn_id = headers[:transaction]
+ if txn_id
+ # lets keep around messages ack'd in this transaction in case we rollback
+ replay_list = @replay_messages_by_txn[txn_id]
+ if replay_list.nil?
+ replay_list = []
+ @replay_messages_by_txn[txn_id] = replay_list
+ end
+ replay_list << message
+ end
+ if block_given?
+ headers['receipt'] = register_receipt_listener lambda {|r| yield r}
+ end
+ @connection.ack message.headers['message-id'], headers
+ end
+
+ # Send message to destination
+ #
+ # If a block is given a receipt will be requested and passed to the
+ # block on receipt
+ #
+ # Accepts a transaction header ( :transaction => 'some_transaction_id' )
+ def send(destination, message, headers = {})
+ if block_given?
+ headers['receipt'] = register_receipt_listener lambda {|r| yield r}
+ end
+ @connection.send(destination, message, headers)
+ end
+
+ # Is this client open?
+ def open?
+ @connection.open?
+ end
+
+ # Is this client closed?
+ def closed?
+ @connection.closed?
+ end
+
+ # Close out resources in use by this client
+ def close
+ @connection.disconnect
+ @running = false
+ end
+
+ private
+
+ def register_receipt_listener(listener)
+ id = -1
+ @id_mutex.synchronize do
+ id = @ids.to_s
+ @ids = @ids.succ
+ end
+ @receipt_listeners[id] = listener
+ id
+ end
+
+ end
+end
+
View
258 vendor/gems/stomp-1.1/lib/stomp/connection.rb
@@ -0,0 +1,258 @@
+module Stomp
+
+ # Low level connection which maps commands and supports
+ # synchronous receives
+ class Connection
+
+
+ # A new Connection object accepts the following parameters:
+ #
+ # login (String, default : '')
+ # passcode (String, default : '')
+ # host (String, default : 'localhost')
+ # port (Integer, default : 61613)
+ # reliable (Boolean, default : false)
+ # reconnect_delay (Integer, default : 5)
+ #
+ # e.g. c = Client.new("username", "password", "localhost", 61613, true)
+ #
+# TODO
+ # Stomp URL :
+ # A Stomp URL must begin with 'stomp://' and can be in one of the following forms:
+ #
+ # stomp://host:port
+ # stomp://host.domain.tld:port
+ # stomp://user:pass@host:port
+ # stomp://user:pass@host.domain.tld:port
+ #
+ def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, reconnect_delay = 5, connect_headers = {})
+ @host = host
+ @port = port
+ @login = login
+ @passcode = passcode
+ @transmit_semaphore = Mutex.new
+ @read_semaphore = Mutex.new
+ @socket_semaphore = Mutex.new
+ @reliable = reliable
+ @reconnect_delay = reconnect_delay
+ @connect_headers = connect_headers
+ @closed = false
+ @subscriptions = {}
+ @failure = nil
+ socket
+ end
+
+ # Syntactic sugar for 'Connection.new' See 'initialize' for usage.
+ def Connection.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, reconnect_delay = 5, connect_headers = {})
+ Connection.new(login, passcode, host, port, reliable, reconnect_delay, connect_headers)
+ end
+
+ def socket
+ # Need to look into why the following synchronize does not work.
+ #@read_semaphore.synchronize do
+ s = @socket;
+ while s.nil? || !@failure.nil?
+ @failure = nil
+ begin
+ s = TCPSocket.open @host, @port
+ headers = @connect_headers.clone
+ headers[:login] = @login
+ headers[:passcode] = @passcode
+ _transmit(s, "CONNECT", headers)
+ @connect = _receive(s)
+ # replay any subscriptions.
+ @subscriptions.each { |k,v| _transmit(s, "SUBSCRIBE", v) }
+ rescue
+ @failure = $!;
+ s=nil;
+ raise unless @reliable
+ $stderr.print "connect failed: " + $! +" will retry in #{@reconnect_delay}\n";
+ sleep(@reconnect_delay);
+ end
+ end
+ @socket = s
+ return s;
+ #end
+ end
+
+ # Is this connection open?
+ def open?
+ !@closed
+ end
+
+ # Is this connection closed?
+ def closed?
+ @closed
+ end
+
+ # Begin a transaction, requires a name for the transaction
+ def begin(name, headers = {})
+ headers[:transaction] = name
+ transmit("BEGIN", headers)
+ end
+
+ # Acknowledge a message, used when a subscription has specified
+ # client acknowledgement ( connection.subscribe "/queue/a", :ack => 'client'g
+ #
+ # Accepts a transaction header ( :transaction => 'some_transaction_id' )
+ def ack(message_id, headers = {})
+ headers['message-id'] = message_id
+ transmit("ACK", headers)
+ end
+
+ # Commit a transaction by name
+ def commit(name, headers = {})
+ headers[:transaction] = name
+ transmit("COMMIT", headers)
+ end
+
+ # Abort a transaction by name
+ def abort(name, headers = {})
+ headers[:transaction] = name
+ transmit("ABORT", headers)
+ end
+
+ # Subscribe to a destination, must specify a name
+ def subscribe(name, headers = {}, subId = nil)
+ headers[:destination] = name
+ transmit("SUBSCRIBE", headers)
+
+ # Store the sub so that we can replay if we reconnect.
+ if @reliable
+ subId = name if subId.nil?
+ @subscriptions[subId] = headers
+ end
+ end
+
+ # Unsubscribe from a destination, must specify a name
+ def unsubscribe(name, headers = {}, subId = nil)
+ headers[:destination] = name
+ transmit("UNSUBSCRIBE", headers)
+ if @reliable
+ subId = name if subId.nil?
+ @subscriptions.delete(subId)
+ end
+ end
+
+ # Send message to destination
+ #
+ # Accepts a transaction header ( :transaction => 'some_transaction_id' )
+ def send(destination, message, headers = {})
+ headers[:destination] = destination
+ transmit("SEND", headers, message)
+ end
+
+ # Close this connection
+ def disconnect(headers = {})
+ transmit("DISCONNECT", headers)
+ @closed = true
+ end
+
+ # Return a pending message if one is available, otherwise
+ # return nil
+ def poll
+ @read_semaphore.synchronize do
+ return nil if @socket.nil? || !@socket.ready?
+ return receive
+ end
+ end
+
+ # Receive a frame, block until the frame is received
+ def __old_receive
+ # The recive my fail so we may need to retry.
+ while TRUE
+ begin
+ s = socket
+ return _receive(s)
+ rescue
+ @failure = $!;
+ raise unless @reliable
+ $stderr.print "receive failed: " + $!;
+ end
+ end
+ end
+
+ def receive
+ super_result = __old_receive()
+ if super_result.nil? && @reliable
+ $stderr.print "connection.receive returning EOF as nil - resetting connection.\n"
+ @socket = nil
+ super_result = __old_receive()
+ end
+ return super_result
+ end
+
+ private
+
+ def _receive( s )
+ line = ' '
+ @read_semaphore.synchronize do
+ line = s.gets while line =~ /^\s*$/
+ return nil if line.nil?
+
+ message = Message.new do |m|
+ m.command = line.chomp
+ m.headers = {}
+ until (line = s.gets.chomp) == ''
+ k = (line.strip[0, line.strip.index(':')]).strip
+ v = (line.strip[line.strip.index(':') + 1, line.strip.length]).strip
+ m.headers[k] = v
+ end
+
+ if (m.headers['content-length'])
+ m.body = s.read m.headers['content-length'].to_i
+ c = RUBY_VERSION > '1.9' ? s.getc.ord : s.getc
+ raise "Invalid content length received" unless c == 0
+ else
+ m.body = ''
+ if RUBY_VERSION > '1.9'
+ until (c = s.getc.ord) == 0
+ m.body << c.chr
+ end
+ else
+ until (c = s.getc) == 0
+ m.body << c.chr
+ end
+ end
+ end
+ #c = s.getc
+ #raise "Invalid frame termination received" unless c == 10
+ end # message
+ return message
+
+ end
+ end
+
+ def transmit(command, headers = {}, body = '')
+ # The transmit may fail so we may need to retry.
+ while TRUE
+ begin
+ s = socket
+ _transmit(s, command, headers, body)
+ return
+ rescue
+ @failure = $!;
+ raise unless @reliable
+ puts "stomp connect fail"
+ puts "transmit failed: " + $!+"\n";
+ $stderr.print "transmit failed: " + $!+"\n";
+ end
+ end
+ end
+
+ def _transmit(s, command, headers = {}, body = '')
+ @transmit_semaphore.synchronize do
+ s.puts command
+ headers.each {|k,v| s.puts "#{k}:#{v}" }
+ s.puts "content-length: #{body.length}"
+ s.puts "content-type: text/plain; charset=UTF-8"
+ s.puts
+ s.write body
+ s.write "\0"
+ end
+ end
+
+ end
+
+end
+
View
17 vendor/gems/stomp-1.1/lib/stomp/message.rb
@@ -0,0 +1,17 @@
+module Stomp
+
+ # Container class for frames, misnamed technically
+ class Message
+ attr_accessor :headers, :body, :command
+
+ def initialize
+ yield(self) if block_given?
+ end
+
+ def to_s
+ "<Stomp::Message headers=#{headers.inspect} body='#{body}' command='#{command}' >"
+ end
+ end
+
+end
+
View
55 vendor/gems/stomp-1.1/spec/client_shared_examples.rb
@@ -0,0 +1,55 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+shared_examples_for "standard Client" do
+
+ before(:each) do
+ @destination = "/queue/test/ruby/client"
+ @message_text = "test_client-#{Time.now.to_i}"
+ end
+
+ describe "the closed? method" do
+ it "should be false when the connection is open" do
+ @mock_connection.stub!(:closed?).and_return(false)
+ @client.closed?.should == false
+ end
+
+ it "should be true when the connection is closed" do
+ @mock_connection.stub!(:closed?).and_return(true)
+ @client.closed?.should == true
+ end
+ end
+
+ describe "the open? method" do
+ it "should be true when the connection is open" do
+ @mock_connection.stub!(:open?).and_return(true)
+ @client.open?.should == true
+ end
+
+ it "should be false when the connection is closed" do
+ @mock_connection.stub!(:open?).and_return(false)
+ @client.open?.should == false
+ end
+ end
+
+ describe "the subscribe method" do
+
+ before(:each) do
+ @mock_connection.stub!(:subscribe).and_return(true)
+ end
+
+ it "should raise RuntimeError if not passed a block" do
+ lambda {
+ @client.subscribe(@destination)
+ }.should raise_error
+ end
+
+ it "should not raise an error when passed a block" do
+ lambda {
+ @client.subscribe(@destination) {|msg| received = msg}
+ }.should_not raise_error
+ end
+
+ end
+
+end
+
View
173 vendor/gems/stomp-1.1/spec/client_spec.rb
@@ -0,0 +1,173 @@
+require File.dirname(__FILE__) + '/spec_helper'
+require File.dirname(__FILE__) + '/client_shared_examples'
+
+describe Stomp::Client do
+
+ before(:each) do
+ @mock_connection = mock('connection')
+ Stomp::Connection.stub!(:new).and_return(@mock_connection)
+ end
+
+ describe "(created with no params)" do
+
+ before(:each) do
+ @client = Stomp::Client.new
+ end
+
+ it "should not return any errors" do
+ lambda {
+ @client = Stomp::Client.new
+ }.should_not raise_error
+ end
+
+ it "should not return any errors when created with the open constructor" do
+ lambda {
+ @client = Stomp::Client.open
+ }.should_not raise_error
+ end
+
+ it_should_behave_like "standard Client"
+
+ end
+
+ describe "(created with invalid params)" do
+
+ it "should return ArgumentError if host is nil" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', nil)
+ }.should raise_error
+ end
+
+ it "should return ArgumentError if host is empty" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', '')
+ }.should raise_error
+ end
+
+ it "should return ArgumentError if port is nil" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', 'localhost', nil)
+ }.should raise_error
+ end
+
+ it "should return ArgumentError if port is < 1" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', 'localhost', 0)
+ }.should raise_error
+ end
+
+ it "should return ArgumentError if port is > 65535" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', 'localhost', 65536)
+ }.should raise_error
+ end
+
+ it "should return ArgumentError if port is empty" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', 'localhost', '')
+ }.should raise_error
+ end
+
+ it "should return ArgumentError if reliable is something other than true or false" do
+ lambda {
+ @client = Stomp::Client.new('login', 'passcode', 'localhost', '12345', 'foo')
+ }.should raise_error
+ end
+
+ end
+
+
+ describe "(created with positional params)" do
+
+ before(:each) do
+ @client = Stomp::Client.new('testlogin', 'testpassword', 'localhost', '12345', false)
+ end
+
+ it "should properly parse the URL provided" do
+ @client.login.should eql('testlogin')
+ @client.passcode.should eql('testpassword')
+ @client.host.should eql('localhost')
+ @client.port.should eql(12345)
+ @client.reliable.should be_false
+ end
+
+ it_should_behave_like "standard Client"
+
+ end
+
+ describe "(created with non-authenticating stomp:// URL and non-TLD host)" do
+
+ before(:each) do
+ @client = Stomp::Client.new('stomp://foobar:12345')
+ end
+
+ it "should properly parse the URL provided" do
+ @client.login.should eql('')
+ @client.passcode.should eql('')
+ @client.host.should eql('foobar')
+ @client.port.should eql(12345)
+ @client.reliable.should be_false
+ end
+
+ it_should_behave_like "standard Client"
+
+ end
+
+ describe "(created with authenticating stomp:// URL and non-TLD host)" do
+
+ before(:each) do
+ @client = Stomp::Client.new('stomp://testlogin:testpasscode@foobar:12345')
+ end
+
+ it "should properly parse the URL provided" do
+ @client.login.should eql('testlogin')
+ @client.passcode.should eql('testpasscode')
+ @client.host.should eql('foobar')
+ @client.port.should eql(12345)
+ @client.reliable.should be_false
+ end
+
+ it_should_behave_like "standard Client"
+
+ end
+
+ describe "(created with non-authenticating stomp:// URL and TLD host)" do
+
+ before(:each) do
+ @client = Stomp::Client.new('stomp://host.foobar.com:12345')
+ end
+
+ after(:each) do
+ end
+
+ it "should properly parse the URL provided" do
+ @client.login.should eql('')
+ @client.passcode.should eql('')
+ @client.host.should eql('host.foobar.com')
+ @client.port.should eql(12345)
+ @client.reliable.should be_false
+ end
+
+ it_should_behave_like "standard Client"
+
+ end
+
+ describe "(created with authenticating stomp:// URL and non-TLD host)" do
+
+ before(:each) do
+ @client = Stomp::Client.new('stomp://testlogin:testpasscode@host.foobar.com:12345')
+ end
+
+ it "should properly parse the URL provided" do
+ @client.login.should eql('testlogin')
+ @client.passcode.should eql('testpasscode')
+ @client.host.should eql('host.foobar.com')
+ @client.port.should eql(12345)
+ @client.reliable.should be_false
+ end
+
+ it_should_behave_like "standard Client"
+
+ end
+
+end
View
14 vendor/gems/stomp-1.1/spec/spec_helper.rb
@@ -0,0 +1,14 @@
+begin
+ require 'spec'
+rescue LoadError
+ require 'rubygems'
+ #gem 'rspec'
+ require 'spec'
+end
+
+dir = File.dirname(__FILE__)
+lib_path = File.expand_path("#{dir}/../lib")
+$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
+
+require 'stomp'
+
View
32 vendor/gems/stomp-1.1/stomp.gemspec
@@ -0,0 +1,32 @@
+GEM = "stomp"
+VER = "1.1"
+AUTHORS = ["Brian McCallister", 'Marius Mathiesen']
+EMAILS = ["brianm@apache.org", 'marius@stones.com']
+HOMEPAGE = "http://stomp.codehaus.org/"
+SUMMARY = "Ruby client for the Stomp messaging protocol"
+
+Gem::Specification.new do |s|
+ s.name = GEM
+ s.version = VER
+ s.authors = AUTHORS
+ s.email = EMAILS
+ s.homepage = HOMEPAGE
+ s.summary = SUMMARY
+ s.description = s.summary
+ s.platform = Gem::Platform::RUBY
+
+ s.require_path = 'lib'
+ s.executables = ["catstomp", "stompcat"]
+
+ # get this easily and accurately by running 'Dir.glob("{lib,test}/**/*")'
+ # in an IRB session. However, GitHub won't allow that command hence
+ # we spell it out.
+ s.files = ["README.rdoc", "LICENSE", "CHANGELOG", "Rakefile", "lib/stomp.rb", "lib/stomp/client.rb", "lib/stomp/connection.rb", "lib/stomp/message.rb", "test/test_client.rb", "test/test_connection.rb", "test/test_helper.rb"]
+ s.test_files = ["test/test_client.rb", "test/test_connection.rb", "test/test_helper.rb"]
+
+ s.has_rdoc = true
+ s.rdoc_options = ["--quiet", "--title", "stomp documentation", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
+ s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "LICENSE"]
+end
+
+
View
182 vendor/gems/stomp-1.1/test/test_client.rb
@@ -0,0 +1,182 @@
+require File.join(File.dirname(__FILE__), 'test_helper.rb')
+
+class TestClient < Test::Unit::TestCase
+
+ def setup
+ @client = Stomp::Client.new("test", "user", "localhost", 61613)
+ end
+
+ def teardown
+ @client.close
+ end
+
+ def message_text
+ "test_client#" + name()
+ end
+
+ def destination
+ "/queue/test/ruby/client/" + name()
+ end
+
+ def test_subscribe_requires_block
+ assert_raise(RuntimeError) do
+ @client.subscribe destination
+ end
+ end
+
+ def test_asynch_subscribe
+ received = false
+ @client.subscribe(destination) {|msg| received = msg}
+ @client.send destination, message_text
+ sleep 0.01 until received
+
+ assert_equal message_text, received.body
+ end
+
+ def test_ack_api_works
+ @client.send destination, message_text
+
+ received = nil
+ @client.subscribe(destination, :ack => 'client') {|msg| received = msg}
+ sleep 0.01 until received
+ assert_equal message_text, received.body
+
+ receipt = nil
+ @client.acknowledge(received) {|r| receipt = r}
+ sleep 0.01 until receipt
+ assert_not_nil receipt.headers['receipt-id']
+ end
+
+ # BROKEN
+ def test_noack
+ @client.send destination, message_text
+
+ received = nil
+ @client.subscribe(destination, :ack => :client) {|msg| received = msg}
+ sleep 0.01 until received
+ assert_equal message_text, received.body
+ @client.close
+
+ # was never acked so should be resent to next client
+
+ @client = Stomp::Client.new("test", "user", "localhost", 61613)
+ received = nil
+ @client.subscribe(destination) {|msg| received = msg}
+ sleep 0.01 until received
+
+ assert_equal message_text, received.body
+ end
+
+ def test_receipts
+ receipt = false
+ @client.send(destination, message_text) {|r| receipt = r}
+ sleep 0.1 until receipt
+
+ message = nil
+ @client.subscribe(destination) {|m| message = m}
+ sleep 0.1 until message
+ assert_equal message_text, message.body
+ end
+
+ def test_send_then_sub
+ @client.send destination, message_text
+ message = nil
+ @client.subscribe(destination) {|m| message = m}
+ sleep 0.01 until message
+
+ assert_equal message_text, message.body
+ end
+
+ def test_transactional_send
+ @client.begin 'tx1'
+ @client.send destination, message_text, :transaction => 'tx1'
+ @client.commit 'tx1'
+
+ message = nil
+ @client.subscribe(destination) {|m| message = m}
+ sleep 0.01 until message
+
+ assert_equal message_text, message.body
+ end
+
+ def test_transaction_send_then_rollback
+ @client.begin 'tx1'
+ @client.send destination, "first_message", :transaction => 'tx1'
+ @client.abort 'tx1'
+
+ @client.begin 'tx1'
+ @client.send destination, "second_message", :transaction => 'tx1'
+ @client.commit 'tx1'
+
+ message = nil
+ @client.subscribe(destination) {|m| message = m}
+ sleep 0.01 until message
+ assert_equal "second_message", message.body
+ end
+
+ def test_transaction_ack_rollback_with_new_client
+ @client.send destination, message_text
+
+ @client.begin 'tx1'
+ message = nil
+ @client.subscribe(destination, :ack => 'client') {|m| message = m}
+ sleep 0.01 until message
+ assert_equal message_text, message.body
+ @client.acknowledge message, :transaction => 'tx1'
+ message = nil
+ @client.abort 'tx1'
+
+ # lets recreate the connection
+ teardown
+ setup
+ @client.subscribe(destination, :ack => 'client') {|m| message = m}
+
+ Timeout::timeout(4) do
+ sleep 0.01 until message
+ end
+ assert_not_nil message
+ assert_equal message_text, message.body
+
+ @client.begin 'tx2'
+ @client.acknowledge message, :transaction => 'tx2'
+ @client.commit 'tx2'
+ end
+
+ def test_unsubscribe
+ message = nil
+ client = Stomp::Client.new("test", "user", "localhost", 61613, true)
+ client.subscribe(destination, :ack => 'client') { |m| message = m }
+ @client.send destination, message_text
+ Timeout::timeout(4) do
+ sleep 0.01 until message
+ end
+ client.unsubscribe destination # was throwing exception on unsub at one point
+
+ end
+
+ def test_transaction_with_client_side_redelivery
+ @client.send destination, message_text
+
+ @client.begin 'tx1'
+ message = nil
+ @client.subscribe(destination, :ack => 'client') { |m| message = m }
+
+ sleep 0.1 while message.nil?
+
+ assert_equal message_text, message.body
+ @client.acknowledge message, :transaction => 'tx1'
+ message = nil
+ @client.abort 'tx1'
+
+ sleep 0.1 while message.nil?
+
+ assert_not_nil message
+ assert_equal message_text, message.body
+
+ @client.begin 'tx2'
+ @client.acknowledge message, :transaction => 'tx2'
+ @client.commit 'tx2'
+ end
+
+
+end
View
95 vendor/gems/stomp-1.1/test/test_connection.rb
@@ -0,0 +1,95 @@
+require File.join(File.dirname(__FILE__), 'test_helper.rb')
+
+class TestStomp < Test::Unit::TestCase
+
+ def setup
+ @conn = Stomp::Connection.open("test", "user", "localhost", 61613)
+ end
+
+ def teardown
+ @conn.disconnect
+ end
+
+ def make_destination
+ "/queue/test/ruby/stomp/" + name()
+ end
+
+ def _test_transaction
+ @conn.subscribe make_destination
+
+ # Drain the destination.
+ sleep 0.01 while
+ sleep 0.01 while @conn.poll!=nil
+
+ @conn.begin "tx1"
+ @conn.send make_destination, "txn message", 'transaction' => "tx1"
+
+ @conn.send make_destination, "first message"
+
+ sleep 0.01
+ msg = @conn.receive
+ assert_equal "first message", msg.body
+
+ @conn.commit "tx1"
+ msg = @conn.receive
+ assert_equal "txn message", msg.body
+ end
+
+ def test_connection_exists
+ assert_not_nil @conn
+ end
+
+ def test_explicit_receive
+ @conn.subscribe make_destination
+ @conn.send make_destination, "test_stomp#test_explicit_receive"
+ msg = @conn.receive
+ assert_equal "test_stomp#test_explicit_receive", msg.body
+ end
+
+ def test_receipt
+ @conn.subscribe make_destination, :receipt => "abc"
+ msg = @conn.receive
+ assert_equal "abc", msg.headers['receipt-id']
+ end
+
+ def test_client_ack_with_symbol
+ @conn.subscribe make_destination, :ack => :client
+ @conn.send make_destination, "test_stomp#test_client_ack_with_symbol"
+ msg = @conn.receive
+ @conn.ack msg.headers['message-id']
+ end
+
+ def test_embedded_null
+ @conn.subscribe make_destination
+ @conn.send make_destination, "a\0"
+ msg = @conn.receive
+ assert_equal "a\0" , msg.body
+ end
+
+ def test_connection_open?
+ assert_equal true , @conn.open?
+ @conn.disconnect
+ assert_equal false, @conn.open?
+ end
+
+ def test_connection_closed?
+ assert_equal false, @conn.closed?
+ @conn.disconnect
+ assert_equal true, @conn.closed?
+ end
+
+ def test_response_is_instance_of_message_class
+ @conn.subscribe make_destination
+ @conn.send make_destination, "a\0"
+ msg = @conn.receive
+ assert_instance_of Stomp::Message , msg
+ end
+
+ def test_message_to_s
+ @conn.subscribe make_destination
+ @conn.send make_destination, "a\0"
+ msg = @conn.receive
+ assert_match /^<Stomp::Message headers=/ , msg.to_s
+ end
+
+end
View
5 vendor/gems/stomp-1.1/test/test_helper.rb
@@ -0,0 +1,5 @@
+require 'test/unit'
+require 'timeout'
+require 'stomp'
+$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
+

0 comments on commit 90e5991

Please sign in to comment.
Something went wrong with that request. Please try again.