stompserver_ng 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. data/History.txt +159 -0
  2. data/Manifest.txt +71 -0
  3. data/README.txt +172 -0
  4. data/Rakefile +38 -0
  5. data/STATUS +5 -0
  6. data/bin/stompserver_ng +63 -0
  7. data/client/README.txt +1 -0
  8. data/client/both.rb +25 -0
  9. data/client/consume.rb +14 -0
  10. data/client/send.rb +17 -0
  11. data/config/stompserver_ng.conf +11 -0
  12. data/etc/19xcompat/notes.txt +223 -0
  13. data/etc/arutils/README-activerecord.txt +78 -0
  14. data/etc/arutils/cre_mysql.rb +34 -0
  15. data/etc/arutils/cre_postgres.rb +33 -0
  16. data/etc/arutils/cre_sqlite3.rb +28 -0
  17. data/etc/arutils/mysql_boot.sql +12 -0
  18. data/etc/arutils/postgres_boot.sql +14 -0
  19. data/etc/database.mysql.yml +9 -0
  20. data/etc/database.postgres.yml +9 -0
  21. data/etc/passwd.example +3 -0
  22. data/etc/ppqinfo.rb +15 -0
  23. data/etc/runserver.sh +17 -0
  24. data/etc/stompserver_ng +50 -0
  25. data/etc/stompserver_ng.conf +13 -0
  26. data/lib/stomp_server_ng.rb +471 -0
  27. data/lib/stomp_server_ng/protocols/http.rb +128 -0
  28. data/lib/stomp_server_ng/protocols/stomp.rb +407 -0
  29. data/lib/stomp_server_ng/qmonitor.rb +58 -0
  30. data/lib/stomp_server_ng/queue.rb +248 -0
  31. data/lib/stomp_server_ng/queue/activerecord_queue.rb +118 -0
  32. data/lib/stomp_server_ng/queue/ar_message.rb +21 -0
  33. data/lib/stomp_server_ng/queue/ar_reconnect.rb +18 -0
  34. data/lib/stomp_server_ng/queue/dbm_queue.rb +72 -0
  35. data/lib/stomp_server_ng/queue/file_queue.rb +56 -0
  36. data/lib/stomp_server_ng/queue/memory_queue.rb +64 -0
  37. data/lib/stomp_server_ng/queue_manager.rb +302 -0
  38. data/lib/stomp_server_ng/stomp_auth.rb +26 -0
  39. data/lib/stomp_server_ng/stomp_frame.rb +32 -0
  40. data/lib/stomp_server_ng/stomp_frame_recognizer.rb +77 -0
  41. data/lib/stomp_server_ng/stomp_id.rb +32 -0
  42. data/lib/stomp_server_ng/stomp_user.rb +17 -0
  43. data/lib/stomp_server_ng/test_server.rb +21 -0
  44. data/lib/stomp_server_ng/topic_manager.rb +46 -0
  45. data/setup.rb +1585 -0
  46. data/stompserver_ng.gemspec +136 -0
  47. data/test/devserver/props.yaml +5 -0
  48. data/test/devserver/runserver.sh +16 -0
  49. data/test/devserver/stompserver_ng.dbm.conf +12 -0
  50. data/test/devserver/stompserver_ng.file.conf +12 -0
  51. data/test/devserver/stompserver_ng.memory.conf +12 -0
  52. data/test/noserver/mocklogger.rb +12 -0
  53. data/test/noserver/test_queue_manager.rb +134 -0
  54. data/test/noserver/test_stomp_frame.rb +138 -0
  55. data/test/noserver/test_topic_manager.rb +79 -0
  56. data/test/noserver/ts_all_no_server.rb +12 -0
  57. data/test/props.yaml +5 -0
  58. data/test/runalltests.sh +14 -0
  59. data/test/runtest.sh +4 -0
  60. data/test/test_0000_base.rb +107 -0
  61. data/test/test_0001_conn.rb +47 -0
  62. data/test/test_0002_conn_sr.rb +94 -0
  63. data/test/test_0006_client.rb +41 -0
  64. data/test/test_0011_send_recv.rb +74 -0
  65. data/test/test_0015_ack_conn.rb +78 -0
  66. data/test/test_0017_ack_client.rb +78 -0
  67. data/test/test_0019_ack_no_ack.rb +145 -0
  68. data/test/test_0022_ack_noack_conn.rb +123 -0
  69. data/test/test_0030_subscr_id.rb +44 -0
  70. data/test/test_0040_receipt_conn.rb +87 -0
  71. data/test/ts_all_server.rb +10 -0
  72. metadata +196 -0
@@ -0,0 +1,79 @@
1
+ require 'logger'
2
+ $:.unshift File.dirname(__FILE__)
3
+ require 'mocklogger'
4
+ #
5
+ require 'stomp_server/topic_manager'
6
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
7
+
8
+ class TestTopics < Test::Unit::TestCase
9
+
10
+ class UserMock
11
+ attr_accessor :data
12
+ def initialize ; @data = '' ; end
13
+ def stomp_send_data(data); @data += data.to_s ; end
14
+ end
15
+
16
+ class MessageMock
17
+ attr_accessor :headers, :data, :command
18
+ def initialize(dest, msg)
19
+ @headers = { 'destination' => dest }
20
+ @data = msg
21
+ end
22
+ def to_s ; @data ; end
23
+ end
24
+
25
+ def setup
26
+ @t = StompServer::TopicManager.new
27
+ @log = Logger.new(STDOUT)
28
+ @log.level = Logger::DEBUG
29
+ end
30
+
31
+ def test_subscribe
32
+ @log.debug("test_subscribe starts")
33
+ u = UserMock.new
34
+ t = 'foo'
35
+ @t.subscribe(t, u)
36
+
37
+ m1 = MessageMock.new('foo', 'foomsg')
38
+ m2 = MessageMock.new('bar', 'barmsg')
39
+ @t.sendmsg(m1)
40
+ assert_equal(m1.data, u.data)
41
+
42
+ u.data = ''
43
+ @t.sendmsg(m2)
44
+ assert_equal('', u.data)
45
+ @log.debug("test_subscribe ends")
46
+ end
47
+
48
+ def test_unsubscribe
49
+ @log.debug("test_unsubscribe starts")
50
+ u = UserMock.new
51
+ t = 'foo'
52
+ @t.subscribe(t, u)
53
+
54
+ m1 = MessageMock.new('foo', 'foomsg')
55
+ @t.sendmsg(m1)
56
+ assert_equal(m1.data, u.data)
57
+
58
+ @t.unsubscribe(t,u)
59
+ u.data = ''
60
+ @t.sendmsg(m1)
61
+ assert_equal('', u.data)
62
+ @log.debug("test_unsubscribe ends")
63
+ end
64
+
65
+ def test_sendmsg
66
+ @log.debug("test_sendmsg starts")
67
+ u = UserMock.new
68
+ t = 'foo'
69
+ @t.subscribe(t, u)
70
+
71
+ m1 = MessageMock.new('foo', 'foomsg')
72
+ @t.sendmsg(m1)
73
+ assert_equal(m1.data, u.data)
74
+ assert_equal('MESSAGE', m1.command)
75
+ @log.debug("test_sendmsg ends")
76
+ end
77
+
78
+ end
79
+
@@ -0,0 +1,12 @@
1
+ #
2
+ # Run all tests which do not require a server instance to be up.
3
+ #
4
+ here=File.dirname(__FILE__)
5
+ $:.unshift File.join(here,"..","..", "lib")
6
+ $:.unshift File.join(here)
7
+ Dir.glob("#{here}/test_*.rb").each do |file|
8
+ # next if file =~ /test_0/
9
+ puts "Will require unit test file: #{file}"
10
+ require file
11
+ end
12
+
@@ -0,0 +1,5 @@
1
+ ---
2
+ :userid: login
3
+ :password: passcode
4
+ :host: localhost
5
+ :port: 51613
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ #
3
+ for backup in $(ls $(pwd)/test/*~)
4
+ do
5
+ rm $backup
6
+ done
7
+ #
8
+ echo "==== Run All Tests ===="
9
+ for test in $(ls $(pwd)/test/test_0*)
10
+ do
11
+ echo $test
12
+ ruby -I $(pwd)/lib $test $*
13
+ done
14
+
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ #
3
+ ruby -I $(pwd)/lib $*
4
+
@@ -0,0 +1,107 @@
1
+ require 'rubygems'
2
+ require 'stomp'
3
+ require 'test/unit'
4
+ require 'yaml'
5
+ require 'timeout'
6
+ require 'digest/sha1'
7
+ #
8
+ class Test_0000_Base < Test::Unit::TestCase
9
+
10
+ # Base setup.
11
+ # * Load configuration parameters
12
+ # * Initialize connection and client instances.
13
+ # * Override sleep time from environment
14
+ def setup
15
+ @runparms = load_config()
16
+ @conn = nil
17
+ @client = nil
18
+ @sleep_time = ENV['TEST_SLEEP'] ? ENV['TEST_SLEEP'].to_f : 0.0
19
+ end # of setup
20
+
21
+ # Default test for the base class. Will always pass.
22
+ # Required by the test framework.
23
+ def test_0000_default
24
+ assert(true)
25
+ end
26
+
27
+ private
28
+
29
+ # Load yaml configuration file
30
+ def load_config()
31
+ yfname = File.join(File.dirname(__FILE__), "props.yaml")
32
+ parms = YAML.load(File.open(yfname))
33
+ # Allow override of:
34
+ # * host
35
+ # * port
36
+ # * user name
37
+ # * user password
38
+ # from the environment.
39
+ parms[:host] = ENV['STOMP_HOST'] if ENV['STOMP_HOST']
40
+ parms[:port] = ENV['STOMP_PORT'] if ENV['STOMP_PORT']
41
+ parms[:userid] = ENV['STOMP_USER'] if ENV['STOMP_USER']
42
+ parms[:password] = ENV['STOMP_PASS'] if ENV['STOMP_PASS']
43
+ parms
44
+ end
45
+
46
+ protected
47
+
48
+ # Sanity check that required parms are present
49
+ def check_parms()
50
+ assert_not_nil(@runparms[:userid],"userid must be present")
51
+ assert_not_nil(@runparms[:password],"password must be present")
52
+ assert_not_nil(@runparms[:host],"host must be present")
53
+ assert_not_nil(@runparms[:port],"port must be present")
54
+ end
55
+
56
+ # Open a Stomp Connection
57
+ def open_conn()
58
+ assert_nothing_raised() {
59
+ @conn = Stomp::Connection.open(@runparms[:userid],
60
+ @runparms[:password],
61
+ @runparms[:host],
62
+ @runparms[:port])
63
+ }
64
+ end
65
+
66
+ # Disconnect a Stomp Connection
67
+ def disconnect_conn()
68
+ if @conn
69
+ assert_nothing_raised() {
70
+ @conn.disconnect
71
+ }
72
+ end
73
+ @conn = nil
74
+ end
75
+
76
+ # Open a Stomp Client
77
+ def open_client()
78
+ assert_nothing_raised() {
79
+ @client = Stomp::Client.open(@runparms[:userid],
80
+ @runparms[:password],
81
+ @runparms[:host],
82
+ @runparms[:port])
83
+ }
84
+ end
85
+
86
+ # Close a Stomp Client
87
+ def close_client()
88
+ assert_nothing_raised() {
89
+ @client.close if @client
90
+ }
91
+ @client = nil
92
+ end
93
+
94
+ # Convenience method for subscribing to a destination given a
95
+ # Stomp Connection.
96
+ def connection_subscribe(qname, headers = {}, subId = nil)
97
+ @conn.subscribe(qname, headers, subId)
98
+ end
99
+
100
+ #
101
+ def name
102
+ tstr = Time.now.to_f.to_s
103
+ "19x_name_" + Digest::SHA1.hexdigest(tstr)
104
+ end if RUBY_VERSION =~ /1\.9/
105
+
106
+ end # of class
107
+
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'stomp'
3
+ #
4
+ require 'test/unit'
5
+ $:.unshift File.dirname(__FILE__)
6
+ require 'test_0000_base'
7
+ #
8
+ # Basic connection tests.
9
+ #
10
+ class Test_0001_Conn < Test_0000_Base
11
+
12
+ #
13
+ def setup
14
+ super
15
+ @times = 10
16
+ end
17
+
18
+ # Sanity check parameters
19
+ def test_0000_params
20
+ check_parms()
21
+ end
22
+
23
+ # Single connect
24
+ def test_0010_connect
25
+ open_conn()
26
+ assert_not_nil(@conn, "connection should not be nil")
27
+ sleep @sleep_time if @sleep_time > 0
28
+ end
29
+
30
+ # Single disconnect
31
+ def test_0015_disconnect
32
+ disconnect_conn()
33
+ assert_nil(@conn, "connection should be nil after disconnect")
34
+ end
35
+
36
+ # Show that multiple connect/disconnect sequences in a row can be issued.
37
+ def test_0020_connect_disc_mult
38
+ @times.times do |n|
39
+ open_conn()
40
+ assert_not_nil(@conn, "connection should not be nil, try #{n}")
41
+ disconnect_conn()
42
+ assert_nil(@conn, "connection should be nil after disconnect, try #{n}")
43
+ end
44
+ end
45
+
46
+ end # of class
47
+
@@ -0,0 +1,94 @@
1
+ require 'rubygems'
2
+ require 'stomp'
3
+ #
4
+ require 'test/unit'
5
+ $:.unshift File.dirname(__FILE__)
6
+ require 'test_0000_base'
7
+ #
8
+ # Test a basic send and receive over a Stomp Connection.
9
+ #
10
+ class Test_0002_Conn_SR < Test_0000_Base
11
+
12
+ # Setup.
13
+ # * Open the connection
14
+ # * Generate queue name for this test
15
+ # * Specify the message
16
+ def setup
17
+ super
18
+ open_conn()
19
+ @queuename = "/queue/connsr/" + name()
20
+ @test_message = "Abracadabra!"
21
+ end
22
+
23
+ # Teardown.
24
+ # * Disconnect
25
+ def teardown
26
+ disconnect_conn()
27
+ end
28
+
29
+ # Test a single send and receive over the same connection.
30
+ def test_0010_send_receive
31
+ received = nil
32
+ mtosend = @test_message + "-0010"
33
+ assert_nothing_raised() {
34
+ @conn.publish(@queuename, mtosend)
35
+ connection_subscribe(@queuename)
36
+ received = @conn.receive
37
+ }
38
+ assert_not_nil(received, "something should be received")
39
+ assert_equal(mtosend, received.body, "received should match sent")
40
+ end
41
+
42
+ # Test a single send and receive over different connections.
43
+ def test_0020_send_receive
44
+ received = nil
45
+ queuename = "/queue/connsr_0020/" + name()
46
+ mtosend = @test_message + "-0020"
47
+ assert_nothing_raised() {
48
+ @conn.publish(queuename, mtosend)
49
+ sleep 3
50
+ }
51
+ teardown
52
+ setup
53
+ assert_nothing_raised() {
54
+ connection_subscribe(queuename)
55
+ Timeout::timeout(4) do
56
+ received = @conn.receive
57
+ end
58
+ }
59
+ assert_not_nil(received, "something should be received 20")
60
+ assert_equal(mtosend, received.body, "received should match sent 20")
61
+ end
62
+
63
+ # Test a single send and receive over different connections,
64
+ # issue subscribe before send:
65
+ # stompserver - fail
66
+ # AMQ - fail
67
+ # Note: 'fail' means that the second connection will issue 'receive', and
68
+ # no message will ever be received.
69
+ def test_0030_send_receive
70
+ received = nil
71
+ queuename = "/queue/connsr_0030/" + name()
72
+ mtosend = @test_message + "-0030"
73
+ assert_nothing_raised() {
74
+ connection_subscribe(queuename) # This
75
+ @conn.publish(queuename, mtosend)
76
+ sleep 4 # plus this cause fail
77
+ # NOTE!!! - without the above 'sleep':
78
+ # AMQ will sometimes fail, and sometimes succeed. It seems to
79
+ # depend on timing, current system load, .....
80
+ }
81
+ teardown
82
+ setup
83
+ assert_nothing_raised() {
84
+ connection_subscribe(queuename)
85
+ }
86
+ assert_raise(Timeout::Error) {
87
+ Timeout::timeout(4) do
88
+ received = @conn.receive
89
+ end
90
+ }
91
+ end
92
+
93
+ end # of class
94
+
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'stomp'
3
+ #
4
+ require 'test/unit'
5
+ $:.unshift File.dirname(__FILE__)
6
+ require 'test_0000_base'
7
+ #
8
+ # Test client open and close sequences.
9
+ #
10
+ class Test_0006_Client < Test_0000_Base
11
+
12
+ # Setup
13
+ # * Define number of loops for multiple tests.
14
+ def setup
15
+ super
16
+ @times = 10
17
+ end
18
+
19
+ # Teardown.
20
+ def teardown
21
+ end
22
+
23
+ # Single client open then close.
24
+ def test_0010_open_then_close
25
+ open_client()
26
+ assert_not_nil(@client, "client should not be nil")
27
+ close_client()
28
+ assert_nil(@client, "client should be nil after close")
29
+ end
30
+
31
+ # Multiple client open/close sequences.
32
+ def test_0020_open_then_close_mult
33
+ @times.times do |n|
34
+ open_client()
35
+ assert_not_nil(@client, "client should not be nil, try #{n}")
36
+ close_client()
37
+ assert_nil(@client, "client should be nil after close, try #{n}")
38
+ end
39
+ end
40
+ end # of class
41
+
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+ require 'stomp'
3
+ #
4
+ require 'test/unit'
5
+ $:.unshift File.dirname(__FILE__)
6
+ require 'test_0000_base'
7
+ #
8
+ # Test send and receive using a Stomp Client.
9
+ #
10
+ class Test_0011_Send_Recv < Test_0000_Base
11
+
12
+ # Setup
13
+ # * Specify test queue name
14
+ # * Specify message content
15
+ # * Loop count for multiple times tests
16
+ # * Open a Stomp Client
17
+ def setup
18
+ super
19
+ @queue_name = "/queue/sendrecv/" + name()
20
+ @test_message = "This is a test message."
21
+ @times = 10
22
+ open_client()
23
+ end
24
+
25
+ # Teardown.
26
+ # * Close the Stomp Client
27
+ def teardown
28
+ close_client()
29
+ end
30
+
31
+ # Test single message send and receive.
32
+ def test_0010_send_receive
33
+ assert_nothing_raised() {
34
+ received = nil
35
+ #
36
+ @client.publish(@queue_name, @test_message,
37
+ {"persistent" => true,
38
+ "client-id" => "0011_sr1send",
39
+ "reply-to" => @queue_name} )
40
+ #
41
+ @client.subscribe(@queue_name,
42
+ {"persistent" => true, "client-id" => "0011_sr1recv"} ) do |message|
43
+ received = message
44
+ end
45
+ sleep 0.1 until received
46
+ assert_equal(@test_message, received.body, "what is sent should be received")
47
+ }
48
+ end
49
+
50
+ # Test send and receive of multiple messages.
51
+ def test_0020_send_mult_receive
52
+ assert_nothing_raised() {
53
+ received = nil
54
+ #
55
+ @times.times do |n|
56
+ @client.publish(@queue_name, @test_message + " #{n}",
57
+ {"persistent" => true,
58
+ "client-id" => "0011_srXsend",
59
+ "reply-to" => @queue_name} )
60
+ end
61
+ #
62
+ count = 0
63
+ @client.subscribe(@queue_name,
64
+ {"persistent" => true, "client-id" => "0011_srXrecv"} ) do |message|
65
+ count += 1
66
+ received = message
67
+ end
68
+ sleep 0.25 until received
69
+ assert_equal(@times,count,"0011 counts should match")
70
+ }
71
+ end
72
+
73
+ end # of class
74
+