activemessaging 0.6.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/jms_test.rb ADDED
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ if defined?(JRUBY_VERSION)
4
+
5
+ class JmsTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @test_txt = 'Yo Homie!'
9
+ @isolation_const = rand(99999999)
10
+ @connection = ActiveMessaging::Adapters::Jms::Connection.new(:url => 'tcp://localhost:61616',
11
+ :login => '',
12
+ :passcode => '',
13
+ :connection_factory => 'org.apache.activemq.ActiveMQConnectionFactory')
14
+ end
15
+
16
+ def test_send
17
+ @connection.send "/queue/TestQueue#{@isolation_const}", @test_txt, {}
18
+ end
19
+
20
+ def test_receive_with_one
21
+ @connection.send "/queue/TestQueue#{@isolation_const}", @test_txt
22
+ @connection.subscribe "/queue/TestQueue#{@isolation_const}"
23
+ message = @connection.receive
24
+ assert_equal @test_txt, message.body
25
+ end
26
+
27
+ def test_receive_multi
28
+ 10.times do |i|
29
+ @connection.send "/queue/MultiQueue#{@isolation_const}", @test_txt
30
+ end
31
+
32
+ counter=0
33
+ @connection.subscribe "/queue/MultiQueue#{@isolation_const}"
34
+ while message = @connection.receive
35
+ assert_equal @test_txt, message.body
36
+ counter += 1
37
+ end
38
+ assert_equal 10, counter
39
+ end
40
+
41
+ def test_one_off_receive
42
+ @connection.send "/queue/OneOff#{@isolation_const}", "one off message"
43
+ message = @connection.receive "/queue/OneOff#{@isolation_const}"
44
+ assert_equal "one off message", message.body
45
+ assert_equal "MESSAGE", message.command
46
+ assert_equal "/queue/OneOff#{@isolation_const}", message.headers['destination']
47
+ end
48
+
49
+ def test_unsubscribe
50
+ @connection.subscribe "/queue/TestSubQueue#{@isolation_const}"
51
+ @connection.unsubscribe "/queue/TestSubQueue#{@isolation_const}"
52
+ assert_nil @connection.consumers["TestSubQueue#{@isolation_const}"]
53
+ end
54
+
55
+ def teardown
56
+ @connection.close unless @connection.nil?
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'activemessaging/adapters/reliable_msg'
3
+
4
+ loaded = true
5
+ begin
6
+ require 'reliable-msg'
7
+ rescue Object => e
8
+ loaded = false
9
+ end
10
+ if loaded
11
+
12
+ class ReliableMsgTest < Test::Unit::TestCase
13
+
14
+ def setup
15
+ @qm = ReliableMsg::QueueManager.new
16
+ @qm.start
17
+ @connection = ActiveMessaging::Adapters::ReliableMsgConnection.new(:reliable=>false, :poll_interval=>2)
18
+ @d = "/queue/reliable.msg.test}."
19
+ @message = "mary had a little lamb"
20
+ @message2 = "whose fleece was white as snow"
21
+ end
22
+
23
+ def teardown
24
+ @connection.disconnect unless @connection.nil?
25
+ @qm.stop unless @qm.nil?
26
+ end
27
+
28
+ def test_subscribe_and_unsubscribe
29
+ assert_nil @connection.subscriptions["#{@d}test_subscribe"]
30
+ @connection.subscribe "#{@d}test_subscribe"
31
+ assert_equal 1, @connection.subscriptions["#{@d}test_subscribe"].count
32
+ @connection.subscribe "#{@d}test_subscribe"
33
+ assert_equal 2, @connection.subscriptions["#{@d}test_subscribe"].count
34
+ @connection.unsubscribe "#{@d}test_subscribe"
35
+ assert_equal 1, @connection.subscriptions["#{@d}test_subscribe"].count
36
+ @connection.unsubscribe "#{@d}test_subscribe"
37
+ assert_nil @connection.subscriptions["#{@d}test_subscribe"]
38
+ end
39
+
40
+ def test_send_and_receive
41
+ @connection.subscribe "#{@d}test_send_and_receive"
42
+ @connection.send "#{@d}test_send_and_receive", @message
43
+ message = @connection.receive
44
+ @connection.received message
45
+ assert_equal @message, message.body
46
+ end
47
+
48
+
49
+ def test_send_and_receive_multiple_subscriptions
50
+ @connection.subscribe "#{@d}test_send_and_receive1"
51
+ @connection.subscribe "#{@d}test_send_and_receive2"
52
+ @connection.subscribe "#{@d}test_send_and_receive3"
53
+
54
+ @connection.send "#{@d}test_send_and_receive2", "message2"
55
+ message = @connection.receive
56
+ @connection.received message
57
+ assert_equal "message2", message.body
58
+
59
+ @connection.send "#{@d}test_send_and_receive3", "message3"
60
+ message = @connection.receive
61
+ @connection.received message
62
+ assert_equal "message3", message.body
63
+
64
+ end
65
+
66
+
67
+ def test_will_cause_sleep
68
+
69
+ begin
70
+ Timeout.timeout 10 do
71
+ @connection.subscribe "#{@d}test_will_cause_sleep"
72
+ message = @connection.receive
73
+ @connection.received message
74
+ assert false
75
+ end
76
+ rescue Timeout::Error=>toe
77
+ assert true
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end # if loaded
@@ -0,0 +1,131 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'activemessaging/adapters/stomp'
3
+
4
+ loaded = true
5
+ begin
6
+ require 'stomp'
7
+ rescue Object => e
8
+ loaded = false
9
+ end
10
+ if loaded #only run these test if stomp gem installed
11
+
12
+
13
+ class FakeTCPSocket
14
+ attr_accessor :sent_messages
15
+ def initialize; @sent_messages=[]; end
16
+ def puts(s=""); @sent_messages << s; end
17
+ def write(s=""); self.puts s; end
18
+ def ready?; true; end
19
+ end
20
+
21
+
22
+ module Stomp
23
+ class Connection
24
+
25
+ attr_accessor :subscriptions
26
+
27
+ def socket
28
+ @socket = FakeTCPSocket.new if @socket.nil?
29
+ @socket
30
+ end
31
+
32
+ def receive=(msg)
33
+ # stomp 1.0.5 code, now no longer works
34
+ # sm = Stomp::Message.new do |m|
35
+ # m.command = 'MESSAGE'
36
+ # m.body = msg
37
+ # m.headers = {'message-id'=>'testmessage1', 'content-length'=>msg.length, 'destination'=>'destination1'}
38
+ # end
39
+
40
+ sm = Stomp::Message.new("MESSAGE\ndestination:/queue/stomp/destination/1\nmessage-id: messageid1\ncontent-length:#{msg.length}\n\n#{msg}\0\n")
41
+
42
+ sm.command = 'MESSAGE'
43
+ sm.headers = {'message-id'=>'testmessage1', 'content-length'=>msg.length, 'destination'=>'destination1'}
44
+
45
+ @test_message = ActiveMessaging::Adapters::Stomp::Message.new(sm)
46
+ end
47
+
48
+ def receive
49
+ @test_message
50
+ end
51
+ end
52
+ end
53
+
54
+ class StompTest < Test::Unit::TestCase
55
+
56
+ def setup
57
+ @connection = ActiveMessaging::Adapters::Stomp::Connection.new({})
58
+ @d = "/queue/stomp/destination/1"
59
+ @message = "mary had a little lamb"
60
+ @connection.stomp_connection.receive = @message
61
+ end
62
+
63
+ def test_initialize
64
+ i = { :retryMax => 4,
65
+ :deadLetterQueue=>'/queue/dlq',
66
+ :login=>"",
67
+ :passcode=> "",
68
+ :host=> "localhost",
69
+ :port=> "61613",
70
+ :reliable=>FALSE,
71
+ :reconnectDelay=> 5,
72
+ :clientId=> 'cid' }
73
+
74
+ @connection = ActiveMessaging::Adapters::Stomp::Connection.new(i)
75
+ assert_equal 4, @connection.retryMax
76
+ assert_equal '/queue/dlq', @connection.deadLetterQueue
77
+ end
78
+
79
+ def test_disconnect
80
+ @connection.disconnect
81
+ assert_equal "DISCONNECT", @connection.stomp_connection.socket.sent_messages[0]
82
+ end
83
+
84
+ def test_subscribe
85
+ @connection.subscribe @d, {}
86
+ assert_equal "SUBSCRIBE", @connection.stomp_connection.socket.sent_messages[0]
87
+ # assert_equal "content-length:0", @connection.stomp_connection.socket.sent_messages[1]
88
+ assert_equal "destination:#{@d}", @connection.stomp_connection.socket.sent_messages[1]
89
+ assert_equal 1, @connection.stomp_connection.subscriptions.count
90
+ assert_equal({'content-length'=>'0', :destination=>@d}, @connection.stomp_connection.subscriptions[@d])
91
+ end
92
+
93
+ def test_unsubscribe
94
+ @connection.subscribe @d, {}
95
+ @connection.stomp_connection.socket.sent_messages = []
96
+ @connection.unsubscribe @d, {}
97
+ assert_equal "UNSUBSCRIBE", @connection.stomp_connection.socket.sent_messages[0]
98
+ # assert_equal "content-length:0", @connection.stomp_connection.socket.sent_messages[1]
99
+ assert_equal "destination:#{@d}", @connection.stomp_connection.socket.sent_messages[1]
100
+ assert_equal 0, @connection.stomp_connection.subscriptions.count
101
+ end
102
+
103
+ def test_send
104
+ @connection.send(@d, @message, {})
105
+ assert_equal 'SEND', @connection.stomp_connection.socket.sent_messages[0]
106
+ # assert_equal "content-length:#{@message.length}", @connection.stomp_connection.socket.sent_messages[1]
107
+ assert_equal "destination:#{@d}", @connection.stomp_connection.socket.sent_messages[1]
108
+ assert_equal @message, @connection.stomp_connection.socket.sent_messages[5]
109
+ end
110
+
111
+ def test_receive
112
+ m = @connection.receive
113
+ assert_equal @message, m.body
114
+ end
115
+
116
+ def test_received
117
+ m = @connection.receive
118
+ m.headers[:transaction] = 'test-transaction'
119
+ @connection.received m, {:ack=>'client'}
120
+ end
121
+
122
+ def test_unreceive
123
+ @connection = ActiveMessaging::Adapters::Stomp::Connection.new({:retryMax=>4, :deadLetterQueue=>'/queue/dlq'})
124
+ @connection.stomp_connection.receive = @message
125
+ m = @connection.receive
126
+ @connection.unreceive m, {:ack=>'client'}
127
+ end
128
+
129
+ end
130
+
131
+ end # if loaded
@@ -0,0 +1,24 @@
1
+ rails_environtment_file = File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
2
+
3
+ if File.exists? rails_environtment_file
4
+ require rails_environment_file
5
+ APP_ROOT = RAILS_ROOT
6
+ else
7
+ ENV['APP_ENV'] = 'test'
8
+ APP_ENV = 'test'
9
+
10
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
11
+ require 'rubygems'
12
+ require 'active_support'
13
+ require 'activemessaging/message_sender'
14
+ require 'activemessaging/processor'
15
+ require 'activemessaging/gateway'
16
+ require 'activemessaging/filter'
17
+ require 'activemessaging/adapters/test'
18
+ APP_ROOT = File.dirname(__FILE__) + '/app'
19
+ end
20
+
21
+ # load other libraries
22
+ require 'test/unit'
23
+
24
+ require File.dirname(__FILE__) + '/../lib/activemessaging/test_helper'
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require 'activemessaging/trace_filter'
3
+
4
+ module ActiveMessaging #:nodoc:
5
+ def self.reload_activemessaging
6
+ end
7
+ end
8
+
9
+ class TestProcessor < ActiveMessaging::Processor
10
+ def on_message message
11
+ end
12
+ end
13
+
14
+ class TestSender < ActiveMessaging::Processor
15
+ end
16
+
17
+ class FakeMessage < ActiveMessaging::BaseMessage
18
+ def initialize
19
+ super("Ni hao ma?", 1, {'destination'=>'/queue/helloWorld'}, '/queue/helloWorld')
20
+ end
21
+ end
22
+
23
+ class TracerTest < Test::Unit::TestCase
24
+ include ActiveMessaging::TestHelper
25
+
26
+ def setup
27
+ ActiveMessaging::Gateway.define do |s|
28
+ s.queue :hello_world, '/queue/helloWorld'
29
+ s.queue :trace, '/queue/trace'
30
+
31
+ s.filter :trace_filter, :queue=>:trace
32
+ end
33
+
34
+ TestProcessor.subscribes_to :hello_world
35
+ TestSender.publishes_to :hello_world
36
+ end
37
+
38
+ def teardown
39
+ ActiveMessaging::Gateway.reset
40
+ end
41
+
42
+ def test_should_trace_sent_messages
43
+ message = "Ni hao ma?"
44
+
45
+ sender = TestSender.new
46
+ sender.publish :hello_world, message
47
+
48
+ assert_message :trace, "<sent><from>TestSender</from><queue>hello_world</queue><message>#{message}</message></sent>"
49
+ assert_message :hello_world, message
50
+ end
51
+
52
+ def test_should_trace_received_messages
53
+ ActiveMessaging::Gateway.dispatch FakeMessage.new
54
+
55
+ assert_message :trace, "<received><by>TestProcessor</by><queue>hello_world</queue><message>Ni hao ma?</message></received>"
56
+ end
57
+ end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemessaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
- - jon.tirsen
8
- - kookster
9
- - olle.jonsson
10
- - sylvain.perez
11
- - anti.god.botherer
12
- - uwe.kubosch
7
+ - Jon Tirsen
8
+ - Andrew Kuklewicz
9
+ - Olle Jonsson
10
+ - Sylvain Perez
11
+ - Cliff Moon
12
+ - Uwe Kubosch
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2008-08-15 00:00:00 +02:00
17
+ date: 2010-04-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -27,77 +27,84 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: 1.0.0
29
29
  version:
30
- - !ruby/object:Gem::Dependency
31
- name: rubigen
32
- type: :runtime
33
- version_requirement:
34
- version_requirements: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - ">="
37
- - !ruby/object:Gem::Version
38
- version: 1.5.2
39
- version:
40
30
  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.
41
31
  email: activemessaging-discuss@googlegroups.com
42
32
  executables: []
43
33
 
44
34
  extensions: []
45
35
 
46
- extra_rdoc_files: []
47
-
36
+ extra_rdoc_files:
37
+ - README
48
38
  files:
39
+ - README
40
+ - Rakefile
41
+ - VERSION
42
+ - activemessaging.gemspec
49
43
  - generators/a13g_test_harness/a13g_test_harness_generator.rb
50
44
  - generators/a13g_test_harness/templates/active_messaging_test.rhtml
51
45
  - generators/a13g_test_harness/templates/active_messaging_test_controller.rb
52
46
  - generators/a13g_test_harness/templates/index.rhtml
47
+ - generators/filter/USAGE
48
+ - generators/filter/filter_generator.rb
49
+ - generators/filter/templates/filter.rb
50
+ - generators/filter/templates/filter_test.rb
51
+ - generators/processor/USAGE
52
+ - generators/processor/processor_generator.rb
53
53
  - generators/processor/templates/application.rb
54
- - generators/processor/templates/poller.rb
55
54
  - generators/processor/templates/broker.yml
56
- - generators/processor/templates/processor.rb
57
55
  - generators/processor/templates/jruby_poller
58
- - generators/processor/templates/poller
59
56
  - generators/processor/templates/messaging.rb
57
+ - generators/processor/templates/poller
58
+ - generators/processor/templates/poller.rb
59
+ - generators/processor/templates/processor.rb
60
60
  - generators/processor/templates/processor_test.rb
61
- - generators/processor/processor_generator.rb
62
- - generators/processor/USAGE
63
- - generators/tracer/tracer_generator.rb
64
- - generators/tracer/templates/helper.rb
61
+ - generators/tracer/USAGE
65
62
  - generators/tracer/templates/controller.rb
66
- - generators/tracer/templates/layout.rhtml
63
+ - generators/tracer/templates/helper.rb
67
64
  - generators/tracer/templates/index.rhtml
65
+ - generators/tracer/templates/layout.rhtml
68
66
  - generators/tracer/templates/trace_processor.rb
69
- - generators/tracer/USAGE
70
- - generators/filter/filter_generator.rb
71
- - generators/filter/templates/filter_test.rb
72
- - generators/filter/templates/filter.rb
73
- - generators/filter/USAGE
74
- - lib/activemessaging/message_sender.rb
75
- - lib/activemessaging/support.rb
76
- - lib/activemessaging/adapters/reliable_msg.rb
77
- - lib/activemessaging/adapters/test.rb
78
- - lib/activemessaging/adapters/jms.rb
67
+ - generators/tracer/tracer_generator.rb
68
+ - init.rb
69
+ - lib/activemessaging.rb
70
+ - lib/activemessaging/adapter.rb
79
71
  - lib/activemessaging/adapters/asqs.rb
72
+ - lib/activemessaging/adapters/base.rb
73
+ - lib/activemessaging/adapters/beanstalk.rb
74
+ - lib/activemessaging/adapters/jms.rb
75
+ - lib/activemessaging/adapters/reliable_msg.rb
80
76
  - lib/activemessaging/adapters/stomp.rb
77
+ - lib/activemessaging/adapters/test.rb
81
78
  - lib/activemessaging/adapters/wmq.rb
82
- - lib/activemessaging/adapters/base.rb
79
+ - lib/activemessaging/base_message.rb
80
+ - lib/activemessaging/filter.rb
83
81
  - lib/activemessaging/gateway.rb
84
- - lib/activemessaging/adapter.rb
82
+ - lib/activemessaging/message_sender.rb
85
83
  - lib/activemessaging/named_base.rb
86
84
  - lib/activemessaging/processor.rb
87
- - lib/activemessaging/trace_filter.rb
85
+ - lib/activemessaging/support.rb
88
86
  - lib/activemessaging/test_helper.rb
89
- - lib/activemessaging/filter.rb
90
- - lib/activemessaging.rb
87
+ - lib/activemessaging/trace_filter.rb
88
+ - poller.rb
91
89
  - tasks/start_consumers.rake
92
- - Rakefile
93
- - messaging.rb.example
90
+ - test/all_tests.rb
91
+ - test/app/config/broker.yml
92
+ - test/asqs_test.rb
93
+ - test/config_test.rb
94
+ - test/filter_test.rb
95
+ - test/gateway_test.rb
96
+ - test/jms_test.rb
97
+ - test/reliable_msg_test.rb
98
+ - test/stomp_test.rb
99
+ - test/test_helper.rb
100
+ - test/tracer_test.rb
94
101
  has_rdoc: true
95
- homepage: http://code.google.com/p/activemessaging/
102
+ homepage: http://github.com/kookster/activemessaging
96
103
  licenses: []
97
104
 
98
105
  post_install_message:
99
- rdoc_options: []
100
-
106
+ rdoc_options:
107
+ - --charset=UTF-8
101
108
  require_paths:
102
109
  - lib
103
110
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -115,9 +122,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
122
  requirements: []
116
123
 
117
124
  rubyforge_project:
118
- rubygems_version: 1.3.2
125
+ rubygems_version: 1.3.5
119
126
  signing_key:
120
- specification_version: 2
121
- summary: 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.
122
- test_files: []
123
-
127
+ specification_version: 3
128
+ summary: Official activemessaging gem, now hosted on github.com/kookster. (kookster prefix temporary)
129
+ test_files:
130
+ - test/all_tests.rb
131
+ - test/asqs_test.rb
132
+ - test/config_test.rb
133
+ - test/filter_test.rb
134
+ - test/gateway_test.rb
135
+ - test/jms_test.rb
136
+ - test/reliable_msg_test.rb
137
+ - test/stomp_test.rb
138
+ - test/test_helper.rb
139
+ - test/tracer_test.rb