reliable-msg 1.0.0
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.
- data/MIT-LICENSE +20 -0
- data/README +123 -0
- data/Rakefile +164 -0
- data/bin/queues +8 -0
- data/lib/reliable-msg.rb +12 -0
- data/lib/reliable-msg/cli.rb +170 -0
- data/lib/reliable-msg/message-store.rb +509 -0
- data/lib/reliable-msg/mysql.sql +8 -0
- data/lib/reliable-msg/queue-manager.rb +409 -0
- data/lib/reliable-msg/queue.rb +500 -0
- data/lib/reliable-msg/selector.rb +109 -0
- data/lib/uuid.rb +384 -0
- data/test/test-queue.rb +144 -0
- data/test/test-uuid.rb +48 -0
- metadata +63 -0
data/test/test-queue.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
#
|
2
|
+
# = test-queue.rb - Queue manager test cases
|
3
|
+
#
|
4
|
+
# Author:: Assaf Arkin assaf@labnotes.org
|
5
|
+
# Documentation:: http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/RubyReliableMessaging
|
6
|
+
# Copyright:: Copyright (c) 2005 Assaf Arkin
|
7
|
+
# License:: MIT and/or Creative Commons Attribution-ShareAlike
|
8
|
+
#
|
9
|
+
#--
|
10
|
+
#++
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
require 'reliable-msg'
|
14
|
+
|
15
|
+
class TestQueue < Test::Unit::TestCase
|
16
|
+
|
17
|
+
class AbortTransaction < Exception
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@queue = ReliableMsg::Queue.new 'test-queue'
|
22
|
+
@dlq = ReliableMsg::Queue.new ReliableMsg::Queue::DLQ
|
23
|
+
@manager = ReliableMsg::QueueManager.new
|
24
|
+
@manager.start
|
25
|
+
clear
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@manager.stop
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_order
|
33
|
+
clear
|
34
|
+
# Put two messages, test that they are retrieved in order.
|
35
|
+
id1 = @queue.put 'first test message'
|
36
|
+
id2 = @queue.put 'second test message'
|
37
|
+
msg = @queue.get
|
38
|
+
assert msg && msg.id == id1, "Failed to retrieve message in order"
|
39
|
+
msg = @queue.get
|
40
|
+
assert msg && msg.id == id2, "Failed to retrieve message in order"
|
41
|
+
assert @queue.get.nil?, "Phantom message in queue"
|
42
|
+
|
43
|
+
# Put three messages with priority, test that they are retrieved in order.
|
44
|
+
id1 = @queue.put 'priority one message', :priority=>1
|
45
|
+
id2 = @queue.put 'priority three message', :priority=>3
|
46
|
+
id3 = @queue.put 'priority two message', :priority=>2
|
47
|
+
msg = @queue.get
|
48
|
+
assert msg && msg.id == id2, "Failed to retrieve message in order"
|
49
|
+
msg = @queue.get
|
50
|
+
assert msg && msg.id == id3, "Failed to retrieve message in order"
|
51
|
+
msg = @queue.get
|
52
|
+
assert msg && msg.id == id1, "Failed to retrieve message in order"
|
53
|
+
assert @queue.get.nil?, "Phantom message in queue"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_selector
|
57
|
+
clear
|
58
|
+
# Test that we can retrieve message based on specific header value,
|
59
|
+
# contrary to queue order.
|
60
|
+
id1 = @queue.put 'first test message', :name=>"foo"
|
61
|
+
id2 = @queue.put 'second test message', :name=>"bar"
|
62
|
+
msg = @queue.get(ReliableMsg::Queue.selector { name == 'bar' })
|
63
|
+
assert msg && msg.id == id2, "Failed to retrieve message by selector"
|
64
|
+
msg = @queue.get(ReliableMsg::Queue.selector { name == 'foo' })
|
65
|
+
assert msg && msg.id == id1, "Failed to retrieve message by selector"
|
66
|
+
assert @queue.get.nil?, "Phantom message in queue"
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_non_delivered
|
70
|
+
clear
|
71
|
+
# Test that we can receive message that has not yet expired (30 second delay),
|
72
|
+
# but cannot receive message that has expires (1 second, we wait for 2), and
|
73
|
+
# that message has been moved to the DLQ.
|
74
|
+
id1 = @queue.put 'first test message', :expires=>30, :delivery=>:repeated
|
75
|
+
id2 = @queue.put 'second test message', :expires=>1, :delivery=>:repeated
|
76
|
+
msg = @queue.get :id=>id1
|
77
|
+
assert msg, "Failed to retrieve message that did not expire"
|
78
|
+
sleep 2
|
79
|
+
msg = @queue.get :id=>id2
|
80
|
+
assert msg.nil?, "Incorrectly retrieved expired message"
|
81
|
+
msg = @dlq.get
|
82
|
+
assert msg && msg.id == id2, "Message not moved to DLQ"
|
83
|
+
|
84
|
+
# Test that we can receive message more than once, but once we try more than
|
85
|
+
# max_deliveries, the message moves to the DLQ.
|
86
|
+
id1 = @queue.put 'test message', :max_retries=>1, :delivery=>:repeated
|
87
|
+
begin
|
88
|
+
@queue.get do |msg|
|
89
|
+
assert msg && msg.id == id1, "Block called without the message"
|
90
|
+
raise AbortTransaction
|
91
|
+
end
|
92
|
+
flunk "Message not found in queue, or exception not propagated"
|
93
|
+
rescue AbortTransaction
|
94
|
+
end
|
95
|
+
begin
|
96
|
+
@queue.get do |msg|
|
97
|
+
assert msg && msg.id == id1, "Block called without the message"
|
98
|
+
raise AbortTransaction
|
99
|
+
end
|
100
|
+
flunk "Message not found in queue, or exception not propagated"
|
101
|
+
rescue AbortTransaction
|
102
|
+
end
|
103
|
+
assert @queue.get.nil?, "Incorrectly retrieved expired message"
|
104
|
+
msg = @dlq.get
|
105
|
+
assert msg && msg.id == id1, "Message not moved to DLQ"
|
106
|
+
|
107
|
+
# Test that message discarded when delivery mode is best_effort.
|
108
|
+
id1 = @queue.put 'test message', :max_retries=>0, :delivery=>:best_effort
|
109
|
+
begin
|
110
|
+
@queue.get do |msg|
|
111
|
+
assert msg && msg.id == id1, "Block called without the message"
|
112
|
+
raise AbortTransaction
|
113
|
+
end
|
114
|
+
flunk "Message not found in queue, or exception not propagated"
|
115
|
+
rescue AbortTransaction
|
116
|
+
end
|
117
|
+
assert @queue.get.nil?, "Incorrectly retrieved expired message"
|
118
|
+
assert @dlq.get.nil?, "Message incorrectly moved to DLQ"
|
119
|
+
|
120
|
+
# Test that message is moved to DLQ when delivery mode is exactly_once.
|
121
|
+
id1 = @queue.put 'test message', :max_retries=>2, :delivery=>:once
|
122
|
+
begin
|
123
|
+
@queue.get do |msg|
|
124
|
+
assert msg && msg.id == id1, "Block called without the message"
|
125
|
+
assert @dlq.get.nil?, "Message prematurely found in DLQ"
|
126
|
+
raise AbortTransaction
|
127
|
+
end
|
128
|
+
flunk "Message not found in queue, or exception not propagated"
|
129
|
+
rescue AbortTransaction
|
130
|
+
end
|
131
|
+
assert @queue.get.nil?, "Incorrectly retrieved expired message"
|
132
|
+
msg = @dlq.get
|
133
|
+
assert msg && msg.id == id1, "Message not moved to DLQ"
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
def clear
|
138
|
+
# Empty test queue and DLQ.
|
139
|
+
while @queue.get ; end
|
140
|
+
while @dlq.get ; end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
data/test/test-uuid.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# = test-uuid.rb - UUID generator test cases
|
3
|
+
#
|
4
|
+
# Author:: Assaf Arkin assaf@labnotes.org
|
5
|
+
# Documentation:: http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/RubyReliableMessaging
|
6
|
+
# Copyright:: Copyright (c) 2005 Assaf Arkin
|
7
|
+
# License:: MIT and/or Creative Commons Attribution-ShareAlike
|
8
|
+
#
|
9
|
+
#--
|
10
|
+
#++
|
11
|
+
|
12
|
+
|
13
|
+
require 'test/unit'
|
14
|
+
require 'uuid'
|
15
|
+
|
16
|
+
class TestUUID < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def setup
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_format
|
25
|
+
10.times do
|
26
|
+
uuid = UUID.new :compact
|
27
|
+
assert uuid =~ /^[0-9a-fA-F]{32}$/, "UUID does not conform to :compact format"
|
28
|
+
uuid = UUID.new :default
|
29
|
+
assert uuid =~ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/, "UUID does not conform to :default format"
|
30
|
+
uuid = UUID.new :urn
|
31
|
+
assert uuid =~ /^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i, "UUID does not conform to :urn format"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_monotonic
|
36
|
+
count = 100000
|
37
|
+
seen = {}
|
38
|
+
count.times do |i|
|
39
|
+
uuid = UUID.new
|
40
|
+
assert !seen.has_key?(uuid), "UUID repeated"
|
41
|
+
seen[uuid] = true
|
42
|
+
print '.' if (i % 10000) == 0
|
43
|
+
STDOUT.flush
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
!ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: reliable-msg
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2005-11-10 00:00:00 -08:00
|
8
|
+
summary: Reliable messaging and persistent queues for building asynchronous applications in Ruby
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: assaf@labnotes.org
|
12
|
+
homepage: http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/RubyReliableMessaging
|
13
|
+
rubyforge_project:
|
14
|
+
description: This package provides reliable messaging and persistent queues for building asynchronous applications in Ruby. It supports transaction processing, message selectors, priorities, delivery semantics, remote queue managers, disk-based and MySQL message stores and more.
|
15
|
+
autorequire: reliable-msg.rb
|
16
|
+
default_executable: queues
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Assaf Arkin
|
30
|
+
files:
|
31
|
+
- bin/queues
|
32
|
+
- test/test-queue.rb
|
33
|
+
- test/test-uuid.rb
|
34
|
+
- lib/reliable-msg
|
35
|
+
- lib/reliable-msg.rb
|
36
|
+
- lib/uuid.rb
|
37
|
+
- lib/reliable-msg/cli.rb
|
38
|
+
- lib/reliable-msg/message-store.rb
|
39
|
+
- lib/reliable-msg/mysql.sql
|
40
|
+
- lib/reliable-msg/queue-manager.rb
|
41
|
+
- lib/reliable-msg/queue.rb
|
42
|
+
- lib/reliable-msg/selector.rb
|
43
|
+
- README
|
44
|
+
- MIT-LICENSE
|
45
|
+
- Rakefile
|
46
|
+
test_files: []
|
47
|
+
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
- --title
|
52
|
+
- Reliable Messaging for Ruby
|
53
|
+
- --line-numbers
|
54
|
+
extra_rdoc_files:
|
55
|
+
- README
|
56
|
+
executables:
|
57
|
+
- queues
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
requirements:
|
61
|
+
- MySQL for database store, otherwise uses the file system
|
62
|
+
dependencies: []
|
63
|
+
|