diff --git a/.gitignore b/.gitignore index 6b1fad1..a955cfa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,18 @@ -queues -activemq-data +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp .DS_Store -*.gemfile.lock -Gemfile.lock diff --git a/.travis.yml b/.travis.yml index c1b4b01..0c228e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,10 @@ language: ruby -gemfile: - - gemfiles/activesupport23.gemfile - - gemfiles/activesupport30.gemfile - - gemfiles/activesupport31.gemfile - - gemfiles/activesupport32.gemfile +branches: + only: + - feat/rails5 rvm: - - 1.8.7 - - 1.9.2 - - 1.9.3 - - ruby-head - - ree - - jruby-18mode - - jruby-19mode - - jruby-head - - rbx-18mode - - rbx-19mode -matrix: - allow_failures: - - rvm: jruby-18mode - - rvm: jruby-19mode - - rvm: jruby-head - - rvm: rbx-18mode - - rvm: rbx-19mode - - rvm: ruby-head - exclude: - - rvm: 1.9.3 - gemfile: gemfiles/activesupport23.gemfile - - rvm: ruby-head - gemfile: gemfiles/activesupport23.gemfile - - rvm: jruby-19mode - gemfile: gemfiles/activesupport23.gemfile - - rvm: jruby-head - gemfile: gemfiles/activesupport23.gemfile - - rvm: rbx-19mode - gemfile: gemfiles/activesupport23.gemfile + - 2.1.10 + - 2.5.0 notifications: - recipients: - - kookster@gmail.com + email: + - andrew@beginsinwonder.com diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..3f4976f --- /dev/null +++ b/Guardfile @@ -0,0 +1,10 @@ +guard 'bundler' do + watch('Gemfile') + watch(/^.+\.gemspec/) +end + +guard :minitest do + watch(%r{^test/(.*)\/?test_(.*)\.rb}) + watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } + watch(%r{^test/test_helper\.rb}) { 'test' } +end diff --git a/README.md b/README.md index da094b2..5f8bec1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc. -ActiveMessaging is a generic framework to ease using messaging, but is not tied to any particular messaging system - in fact, it now has support for Stomp, AMQP, beanstalk, Amazon Simple Queue Service (SQS), JMS (using StompConnect or direct on JRuby), WebSphere MQ, the all-Ruby ReliableMessaging, a mock 'test' adapter, and a 'synch' adapter for use in development that processes calls synchronously (of course) and so requires no broker or additional processes to be running. +ActiveMessaging is a generic framework to ease using messaging, but is not tied to any particular messaging system - in fact, it now has support for Stomp, AMQP, beanstalk, Amazon Simple Queue Service (SQS), JMS (using StompConnect or direct on JRuby), WebSphere MQ, a mock 'test' adapter, and a 'synch' adapter for use in development that processes calls synchronously (of course) and so requires no broker or additional processes to be running. Here's a sample of a processor class that handles incoming messages: diff --git a/Rakefile b/Rakefile index 0c60209..4548b69 100644 --- a/Rakefile +++ b/Rakefile @@ -1,25 +1,12 @@ -require "rubygems" -require "bundler/gem_tasks" -require "bundler/setup" - -require 'rake' +require 'bundler/gem_tasks' require 'rake/testtask' -require 'rdoc/rdoc' - require 'appraisal' -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the ActiveMessaging plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.pattern = 'test/**/*_test.rb' +Rake::TestTask.new do |t| + t.libs.push 'lib' + t.libs.push 'test' + t.test_files = FileList['test/**/*_test.rb'] t.verbose = true end -desc 'Generate documentation for the ActiveMessaging plugin.' -task :rdoc do - rm_rf 'doc' - RDoc::RDoc.new.document(%w(--line-numbers --inline-source --title ActiveMessaging README lib)) -end +task :default => :test diff --git a/activemessaging.gemspec b/activemessaging.gemspec index a022983..1b438d1 100644 --- a/activemessaging.gemspec +++ b/activemessaging.gemspec @@ -4,26 +4,35 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'activemessaging/version' Gem::Specification.new do |spec| - spec.name = "activemessaging" - spec.version = ActiveMessaging::VERSION - spec.authors = ["Jon Tirsen", "Andrew Kuklewicz", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", "Uwe Kubosch", "Lance Cooper", "Matt Campbell"] - spec.email = ["activemessaging-discuss@googlegroups.com"] - - spec.summary = "Official activemessaging gem, now hosted on github.com/kookster. (kookster prefix temporary)" - spec.description = "ActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc. Now supporting Rails 3 as of version 0.8.0." - spec.homepage = "http://github.com/kookster/activemessaging" + spec.name = "activemessaging" + spec.version = ActiveMessaging::VERSION + spec.authors = ["Andrew Kuklewicz", "Jon Tirsen", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", "Uwe Kubosch", "Lance Cooper", "Matt Campbell"] + spec.email = ["activemessaging-discuss@googlegroups.com"] + spec.description = "ActiveMessaging is an attempt to bring the simplicity and elegance of Rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc." + spec.summary = "ActiveMessaging is an attempt to bring the simplicity and elegance of Rails development to the world of messaging." + spec.homepage = "http://github.com/kookster/activemessaging" spec.license = "MIT" - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_development_dependency "bundler" - spec.add_development_dependency "test-unit" - spec.add_development_dependency "stomp" - spec.add_development_dependency "appraisal" + spec.add_runtime_dependency 'activesupport' + spec.add_runtime_dependency 'celluloid' + + spec.add_development_dependency 'bundler', '~> 1.3' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'appraisal' + + spec.add_development_dependency 'minitest' + spec.add_development_dependency 'webmock' + spec.add_development_dependency 'pry' + + spec.add_development_dependency 'guard' + spec.add_development_dependency 'guard-bundler' + spec.add_development_dependency 'guard-minitest' - spec.add_runtime_dependency "activesupport" - spec.add_runtime_dependency "rake" + spec.add_development_dependency 'simplecov' + spec.add_development_dependency 'coveralls' end diff --git a/generators/filter/templates/filter_test.rb b/generators/filter/templates/filter_test.rb index 31c4bc4..75b501f 100644 --- a/generators/filter/templates/filter_test.rb +++ b/generators/filter/templates/filter_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../../vendor/plugins/activemessaging/lib/activemessaging/test_helper' -class <%= class_name %>FilterTest < Test::Unit::TestCase +class <%= class_name %>FilterTest < Minitest::Test include ActiveMessaging::TestHelper def setup diff --git a/generators/processor/templates/processor_test.rb b/generators/processor/templates/processor_test.rb index 0bcab52..083a2b9 100644 --- a/generators/processor/templates/processor_test.rb +++ b/generators/processor/templates/processor_test.rb @@ -2,7 +2,7 @@ require 'activemessaging/test_helper' require File.dirname(__FILE__) + '/../../app/processors/application' -class <%= class_name %>ProcessorTest < Test::Unit::TestCase +class <%= class_name %>ProcessorTest < Minitest::Test include ActiveMessaging::TestHelper def setup diff --git a/lib/activemessaging.rb b/lib/activemessaging.rb index f6f1747..baa3bbf 100644 --- a/lib/activemessaging.rb +++ b/lib/activemessaging.rb @@ -64,15 +64,15 @@ def self.load_extensions end def self.load_config - # Skip loading config if there are no custom processors as the generator + # Skip loading config if there are no custom processors as the generator # is likely running since application_processor.rb and another processor - # should exist when running rails. + # should exist when running rails. if Dir["#{app_root}/app/processors/*.rb"].size() <= 1 - return + return end path = File.expand_path("#{app_root}/config/messaging.rb") begin - load path + load path rescue raise $!, " ActiveMessaging: problems trying to load '#{path}': \n\t#{$!.message}" end diff --git a/lib/activemessaging/adapters/asqs.rb b/lib/activemessaging/adapters/asqs.rb index 599d1f3..fddbb95 100644 --- a/lib/activemessaging/adapters/asqs.rb +++ b/lib/activemessaging/adapters/asqs.rb @@ -266,7 +266,7 @@ def make_request(action, url=nil, params = {}) # Sign the string sorted_params = params.sort_by { |key,value| key.downcase } string_to_sign = sorted_params.collect { |key, value| key.to_s + value.to_s }.join() - digest = OpenSSL::Digest::Digest.new('sha1') + digest = OpenSSL::Digest.new('sha1') hmac = OpenSSL::HMAC.digest(digest, @secret_access_key, string_to_sign) params['Signature'] = Base64.encode64(hmac).chomp diff --git a/lib/activemessaging/adapters/reliable_msg.rb b/lib/activemessaging/adapters/reliable_msg.rb deleted file mode 100644 index 7b2fadc..0000000 --- a/lib/activemessaging/adapters/reliable_msg.rb +++ /dev/null @@ -1,186 +0,0 @@ -require 'reliable-msg' - -require 'activemessaging/adapters/base' - -# add access to the queue_manager to use for adding transactions -module ReliableMsg - - class Client - - def queue_manager - qm - end - - end -end - - -module ActiveMessaging - module Adapters - class ReliableMsgConnection < ActiveMessaging::Adapters::BaseConnection - - THREAD_OLD_TXS = :a13g_reliable_msg_old_txs - - QUEUE_PARAMS = [:expires,:delivery,:priority,:max_deliveries,:drb_uri,:tx_timeout,:connect_count] - TOPIC_PARAMS = [:expires,:drb_uri,:tx_timeout,:connect_count] - - register :reliable_msg - - #configurable params - attr_accessor :subscriptions, :destinations, :poll_interval, :current_subscription, :tx_timeout - - #generic init method needed by a13g - def initialize cfg - @poll_interval = cfg[:poll_interval] || 1 - @reliable = cfg[:reliable] || true - @tx_timeout = cfg[:tx_timeout] || ::ReliableMsg::Client::DEFAULT_TX_TIMEOUT - - @subscriptions = {} - @destinations = {} - @current_subscription = 0 - end - - # called to cleanly get rid of connection - def disconnect - nil - end - - # destination_name string, headers hash - # subscribe to listen on a destination - # use '/destination-type/name' convetion, like stomp - def subscribe destination_name, message_headers={} - get_or_create_destination(destination_name, message_headers) - if subscriptions.has_key? destination_name - subscriptions[destination_name].add - else - subscriptions[destination_name] = Subscription.new(destination_name, message_headers) - end - end - - # destination_name string, headers hash - # unsubscribe to listen on a destination - def unsubscribe destination_name, message_headers={} - subscriptions[destination_name].remove - subscriptions.delete(destination_name) if subscriptions[destination_name].count <= 0 - end - - # destination_name string, body string, headers hash - # send a single message to a destination - def send destination_name, message_body, message_headers={} - dest = get_or_create_destination(destination_name) - begin - dest.put message_body, message_headers - rescue Object=>err - raise err unless reliable - puts "send failed, will retry in #{@poll_interval} seconds" - sleep @poll_interval - end - end - - def get_or_create_destination destination_name, message_headers={} - return destinations[destination_name] if destinations.has_key? destination_name - dd = /^\/(queue|topic)\/(.*)$/.match(destination_name) - rm_class = dd[1].titleize - message_headers.delete("id") - dest_headers = message_headers.reject {|k,v| rm_class == 'Queue' ? !QUEUE_PARAMS.include?(k) : !TOPIC_PARAMS.include?(k)} - rm_dest = "ReliableMsg::#{rm_class}".constantize.new(dd[2], dest_headers) - destinations[destination_name] = rm_dest - end - - # receive a single message from any of the subscribed destinations - # check each destination once, then sleep for poll_interval - def receive(options={}) - - raise "No subscriptions to receive messages from." if (subscriptions.nil? || subscriptions.empty?) - start = current_subscription - while true - self.current_subscription = ((current_subscription < subscriptions.length-1) ? current_subscription + 1 : 0) - sleep poll_interval if (current_subscription == start) - destination_name = subscriptions.keys.sort[current_subscription] - destination = destinations[destination_name] - unless destination.nil? - # from the way we use this, assume this is the start of a transaction, - # there should be no current transaction - ctx = Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] - raise "There should not be an existing reliable-msg transaction. #{ctx.inspect}" if ctx - - # start a new transaction - @tx = {:qm=>destination.queue_manager} - @tx[:tid] = @tx[:qm].begin @tx_timeout - Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = @tx - begin - - # now call a get on the destination - it will use the transaction - #the commit or the abort will occur in the received or unreceive methods - reliable_msg = destination.get subscriptions[destination_name].headers[:selector] - @tx[:qm].commit(@tx[:tid]) if reliable_msg.nil? - - rescue Object=>err - #abort the transaction on error - @tx[:qm].abort(@tx[:tid]) - - raise err unless reliable - puts "receive failed, will retry in #{@poll_interval} seconds" - sleep poll_interval - end - return Message.new(reliable_msg.object, reliable_msg.id, reliable_msg.headers, destination_name, @tx) if reliable_msg - - Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = nil - end - end - end - - # called after a message is successfully received and processed - def received message, headers={} - begin - message.transaction[:qm].commit(message.transaction[:tid]) - rescue Object=>ex - puts "received failed: #{ex.message}" - ensure - Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = nil - end - - end - - # called after a message is successfully received and processed - def unreceive message, headers={} - begin - message.transaction[:qm].abort(message.transaction[:tid]) - rescue Object=>ex - puts "unreceive failed: #{ex.message}" - ensure - Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = nil - end - end - - end - - class Subscription - attr_accessor :name, :headers, :count - - def initialize(destination, headers={}, count=1) - @destination, @headers, @count = destination, headers, count - end - - def add - @count += 1 - end - - def remove - @count -= 1 - end - - end - - class Message < ActiveMessaging::BaseMessage - attr_accessor :transaction - - def initialize body, id, headers, destination, transaction=nil - super(body, id, headers, destination) - @transaction = transaction - end - - end - - end -end \ No newline at end of file diff --git a/lib/activemessaging/gateway.rb b/lib/activemessaging/gateway.rb index 1b9ba89..523200f 100644 --- a/lib/activemessaging/gateway.rb +++ b/lib/activemessaging/gateway.rb @@ -201,12 +201,12 @@ def create_filter(filter, options) end def prepare_application - return unless defined?(ActiveRecord) - - if ActiveRecord::VERSION::MAJOR >= 4 - ActiveRecord::Base.connection_pool.connections.map(&:verify!) - else - ActiveRecord::Base.verify_active_connections! + if defined?(ActiveRecord) + if ActiveRecord::VERSION::MAJOR >= 4 + ActiveRecord::Base.connection_pool.connections.map(&:verify!) + else + ActiveRecord::Base.verify_active_connections! + end end end diff --git a/lib/activemessaging/railtie.rb b/lib/activemessaging/railtie.rb index 3398cac..4567d1a 100644 --- a/lib/activemessaging/railtie.rb +++ b/lib/activemessaging/railtie.rb @@ -4,23 +4,29 @@ module ActiveMessaging class Railtie < Rails::Railtie - initializer 'activemessaging.initialize' do ActiveMessaging.load_activemessaging - + + # Add a to_prepare block which is executed once in production + # and before each request in development if defined? Rails ActiveMessaging.logger.info "ActiveMessaging: Rails available: Adding dispatcher prepare callback." - ActionDispatch::Callbacks.to_prepare do - ActiveMessaging.reload_activemessaging + case + when Gem::Version.new(Rails.version) < Gem::Version.new('3.0.0') + ActionDispatch::Callbacks.to_prepare do + ActiveMessaging.reload_activemessaging + end + else + config.to_prepare do + ActiveMessaging.reload_activemessaging + end end end - end rake_tasks do load "tasks/start_consumers.rake" end - end end diff --git a/lib/activemessaging/test_helper.rb b/lib/activemessaging/test_helper.rb index 70b5571..781d35c 100644 --- a/lib/activemessaging/test_helper.rb +++ b/lib/activemessaging/test_helper.rb @@ -37,8 +37,8 @@ def publish_with_reset(destination_name, message, headers={}, timeout=10) publish_without_reset(destination_name, message, headers, timeout) end - alias_method_chain :publish, :reset - + alias_method :publish_without_reset, :publish + alias_method :publish, :publish_with_reset end class TestMessage < ActiveMessaging::BaseMessage diff --git a/lib/activemessaging/version.rb b/lib/activemessaging/version.rb index 939261f..427a7a1 100644 --- a/lib/activemessaging/version.rb +++ b/lib/activemessaging/version.rb @@ -1,3 +1,3 @@ module ActiveMessaging - VERSION = "0.13.3" + VERSION = "0.14.0" end diff --git a/lib/generators/active_messaging/processor/templates/processor_test.rb b/lib/generators/active_messaging/processor/templates/processor_test.rb index 6d4ad73..b2a4c4a 100644 --- a/lib/generators/active_messaging/processor/templates/processor_test.rb +++ b/lib/generators/active_messaging/processor/templates/processor_test.rb @@ -2,7 +2,7 @@ require 'activemessaging/test_helper' require File.dirname(__FILE__) + '/../../app/processors/application_processor' -class <%= class_name %>ProcessorTest < Test::Unit::TestCase +class <%= class_name %>ProcessorTest < Minitest::Test include ActiveMessaging::TestHelper def setup diff --git a/test/all_tests.rb b/test/all_tests.rb deleted file mode 100644 index 7f92b72..0000000 --- a/test/all_tests.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'rubygems' -require 'test/unit' - -# tests -require 'config_test' -require 'filter_test' -require 'tracer_test' -require 'jms_test' -require 'asqs_test' diff --git a/test/asqs_test.rb b/test/asqs_test.rb index 92843a9..a1f3929 100644 --- a/test/asqs_test.rb +++ b/test/asqs_test.rb @@ -1,7 +1,7 @@ -require File.dirname(__FILE__) + '/test_helper' +require "#{File.dirname(__FILE__)}/test_helper" require 'activemessaging/adapters/asqs' -class AsqsTest < Test::Unit::TestCase +class AsqsTest < Minitest::Test class FakeHTTPResponse attr_accessor :headers, :body @@ -54,18 +54,14 @@ def test_message_size @connection = ActiveMessaging::Adapters::AmazonSqs::Connection.new(:reliable=>false, :access_key_id=>'access_key_id', :secret_access_key=>'secret_access_key', :max_message_size => 10) - assert_nothing_raised do - @connection.send @d, @message - end + @connection.send @d, @message large_message = "m" * 1024 * 9 - assert_nothing_raised do - @connection.send @d, large_message - end + @connection.send @d, large_message large_message = nil large_message = "m" * 1024 * 11 - assert_raise(RuntimeError) do + assert_raises(RuntimeError) do @connection.send @d, large_message end large_message = nil @@ -73,10 +69,9 @@ def test_message_size end def test_allow_underscore_and_dash - assert_nothing_raised do - @connection.subscribe 'name-name_dash' - end - assert_raise(RuntimeError) do + @connection.subscribe 'name-name_dash' + + assert_raises(RuntimeError) do @connection.subscribe '!@#$%^&' end end @@ -111,15 +106,14 @@ def test_receive_timeout @connection.send @d, @message @connection.test_headers = {:destination=>@d} - @connection.test_response = TimeoutError.new('test timeout error') + @connection.test_response = Timeout::Error.new('test timeout error') @connection.reliable = true begin Timeout.timeout 2 do @connection.receive end rescue Timeout::Error=>toe - assert_not_equal toe.message, 'test timeout error' + refute_equal toe.message, 'test timeout error' end end - end diff --git a/test/config_test.rb b/test/config_test.rb index 28d6608..5b0fec1 100644 --- a/test/config_test.rb +++ b/test/config_test.rb @@ -1,10 +1,9 @@ -require File.dirname(__FILE__) + '/test_helper' +require "#{File.dirname(__FILE__)}/test_helper" class TestProcessor < ActiveMessaging::Processor end -class ConfigTest < Test::Unit::TestCase - +class ConfigTest < Minitest::Test def setup ActiveMessaging::Gateway.define do |s| s.destination :hello_world, '/queue/helloWorld' @@ -38,5 +37,4 @@ def test_should_raise_error_if_publishes_to_queue_that_does_not_exist TestProcessor.publishes_to :queue_that_does_not_exist end end - end diff --git a/test/filter_test.rb b/test/filter_test.rb index 2e5eb79..46deb50 100644 --- a/test/filter_test.rb +++ b/test/filter_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/test_helper' +require "#{File.dirname(__FILE__)}/test_helper" require 'activemessaging/filter' module ActiveMessaging #:nodoc: @@ -6,8 +6,7 @@ def self.reload_activemessaging end end -class FilterTest < Test::Unit::TestCase - +class FilterTest < Minitest::Test class MockFilter < ActiveMessaging::Filter @@called = {} @@ -24,22 +23,20 @@ def process(message, details={}) end class << self - include Test::Unit::Assertions - def reset @@called = {} end def assert_was_called(name=nil) - assert @@called.has_key?(name) + raise unless @@called.has_key?(name) end def assert_was_not_called(name=nil) - assert !@@called.has_key?(name) + raise if @@called.has_key?(name) end def assert_routing(name, routing) - assert_equal routing, @@called[name][:details] + raise unless routing == @@called[name][:details] end end end @@ -50,10 +47,8 @@ class TestProcessor < ActiveMessaging::Processor @@was_called = false class<ActiveMessaging::Gateway.find_queue(:testqueue), :receiver=>FilterTest::TestProcessor, :direction=>:incoming}) end - end diff --git a/test/gateway_test.rb b/test/gateway_test.rb index 79ebf76..01e3be7 100644 --- a/test/gateway_test.rb +++ b/test/gateway_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/test_helper' +require "#{File.dirname(__FILE__)}/test_helper" class InitializeFilter @@ -13,7 +13,7 @@ def process(message, details={}) end end -class GatewayTest < Test::Unit::TestCase +class GatewayTest < Minitest::Test class ClassFilter def initialize raise "Don't try and construct one of these please" @@ -127,7 +127,7 @@ def test_subscribe_and_unsubscribe assert_equal TestProcessor, sub.processor_class ActiveMessaging::Gateway.subscribe - assert_not_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value) + refute_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value) ActiveMessaging::Gateway.unsubscribe assert_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value) @@ -149,12 +149,12 @@ def test_disconnect def test_publish ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld' ActiveMessaging::Gateway.publish :hello_world, "test_publish body", self.class, headers={}, timeout=10 - assert_not_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body") + refute_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body") - assert_raise(RuntimeError) do + assert_raises(RuntimeError) do ActiveMessaging::Gateway.publish :hello_world, nil, self.class, headers={}, timeout=10 end - assert_raise(RuntimeError) do + assert_raises(RuntimeError) do ActiveMessaging::Gateway.publish :hello_world, '', self.class, headers={}, timeout=10 end end @@ -200,7 +200,7 @@ def test_receive ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld' ActiveMessaging::Gateway.publish :hello_world, "test_publish body", self.class, headers={}, timeout=10 msg = ActiveMessaging::Gateway.receive :hello_world, self.class, headers={}, timeout=10 - assert_not_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body") + refute_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body") end # def test_reload diff --git a/test/jms_test.rb b/test/jms_test.rb index fee7391..4473596 100644 --- a/test/jms_test.rb +++ b/test/jms_test.rb @@ -1,10 +1,10 @@ -require File.dirname(__FILE__) + '/test_helper' +require "#{File.dirname(__FILE__)}/test_helper" if defined?(JRUBY_VERSION) require 'activemessaging/adapters/jms' -class JmsTest < Test::Unit::TestCase +class JmsTest < Minitest::Test def setup @test_txt = 'Yo Homie!' diff --git a/test/reliable_msg_test.rb b/test/reliable_msg_test.rb deleted file mode 100644 index 8fbe65d..0000000 --- a/test/reliable_msg_test.rb +++ /dev/null @@ -1,83 +0,0 @@ -require File.dirname(__FILE__) + '/test_helper' -loaded = true -begin - require 'reliable-msg' -rescue Object => e - loaded = false -end -if loaded - -require 'activemessaging/adapters/reliable_msg' - -class ReliableMsgTest < Test::Unit::TestCase - - def setup - @qm = ReliableMsg::QueueManager.new - @qm.start - @connection = ActiveMessaging::Adapters::ReliableMsgConnection.new(:reliable=>false, :poll_interval=>2) - @d = "/queue/reliable.msg.test}." - @message = "mary had a little lamb" - @message2 = "whose fleece was white as snow" - end - - def teardown - @connection.disconnect unless @connection.nil? - @qm.stop unless @qm.nil? - end - - def test_subscribe_and_unsubscribe - assert_nil @connection.subscriptions["#{@d}test_subscribe"] - @connection.subscribe "#{@d}test_subscribe" - assert_equal 1, @connection.subscriptions["#{@d}test_subscribe"].count - @connection.subscribe "#{@d}test_subscribe" - assert_equal 2, @connection.subscriptions["#{@d}test_subscribe"].count - @connection.unsubscribe "#{@d}test_subscribe" - assert_equal 1, @connection.subscriptions["#{@d}test_subscribe"].count - @connection.unsubscribe "#{@d}test_subscribe" - assert_nil @connection.subscriptions["#{@d}test_subscribe"] - end - - def test_send_and_receive - @connection.subscribe "#{@d}test_send_and_receive" - @connection.send "#{@d}test_send_and_receive", @message - message = @connection.receive - @connection.received message - assert_equal @message, message.body - end - - - def test_send_and_receive_multiple_subscriptions - @connection.subscribe "#{@d}test_send_and_receive1" - @connection.subscribe "#{@d}test_send_and_receive2" - @connection.subscribe "#{@d}test_send_and_receive3" - - @connection.send "#{@d}test_send_and_receive2", "message2" - message = @connection.receive - @connection.received message - assert_equal "message2", message.body - - @connection.send "#{@d}test_send_and_receive3", "message3" - message = @connection.receive - @connection.received message - assert_equal "message3", message.body - - end - - - def test_will_cause_sleep - - begin - Timeout.timeout 10 do - @connection.subscribe "#{@d}test_will_cause_sleep" - message = @connection.receive - @connection.received message - assert false - end - rescue Timeout::Error=>toe - assert true - end - end - -end - -end # if loaded diff --git a/test/stomp_test.rb b/test/stomp_test.rb index 5637b5f..a9bffd1 100644 --- a/test/stomp_test.rb +++ b/test/stomp_test.rb @@ -1,5 +1,4 @@ -require File.dirname(__FILE__) + '/test_helper' -require 'activemessaging/adapters/stomp' +require "#{File.dirname(__FILE__)}/test_helper" loaded = true begin @@ -9,6 +8,8 @@ end if loaded #only run these test if stomp gem installed +require 'activemessaging/adapters/stomp' + class FakeTCPSocket attr_accessor :sent_messages @@ -51,7 +52,7 @@ def receive end end -class StompTest < Test::Unit::TestCase +class StompTest < Minitest::Test def setup @connection = ActiveMessaging::Adapters::Stomp::Connection.new({}) diff --git a/test/test_helper.rb b/test/test_helper.rb index 66acbfb..0ed1465 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,18 @@ +require 'simplecov' +require 'coveralls' + +SimpleCov.command_name 'Unit Tests' +SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +] +SimpleCov.start + +require 'minitest/autorun' +require 'minitest/spec' +require 'minitest/mock' +require 'webmock/minitest' + rails_environtment_file = File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment") if File.exists? rails_environtment_file @@ -31,6 +46,6 @@ def self.app_env end # load other libraries -require 'test/unit' +require 'minitest' require File.dirname(__FILE__) + '/../lib/activemessaging/test_helper' diff --git a/test/tracer_test.rb b/test/tracer_test.rb index 5bf151d..7684a1b 100644 --- a/test/tracer_test.rb +++ b/test/tracer_test.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/test_helper' +require "#{File.dirname(__FILE__)}/test_helper" require 'activemessaging/trace_filter' module ActiveMessaging #:nodoc: @@ -20,7 +20,7 @@ def initialize end end -class TracerTest < Test::Unit::TestCase +class TracerTest < Minitest::Test include ActiveMessaging::TestHelper def setup