fmq 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,33 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestFreeMessageQueue < Test::Unit::TestCase
4
- TEST_URL = "http://localhost:5884/fmq_test/test1"
5
- TEST_REQUEST = 'X' * 1200 # 1.2 KB
6
-
7
- def setup
8
- @queue = FreeMessageQueue::ClientQueue.new(TEST_URL)
9
- end
10
-
11
- def test_post_and_get_message
12
- 5.times do |t|
13
- @queue.put(TEST_REQUEST + t.to_s)
14
- end
15
-
16
- assert_equal 5, @queue.size
17
- assert_equal TEST_REQUEST.size * 5 + 5, @queue.bytes
18
-
19
- 5.times do |t|
20
- assert_equal TEST_REQUEST + t.to_s, @queue.poll()
21
- end
22
-
23
- assert_equal 0, @queue.size
24
- assert_equal 0, @queue.bytes
25
- end
26
- end
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestFreeMessageQueue < Test::Unit::TestCase
4
+ TEST_URL = "http://localhost:5884/fmq_test/test1"
5
+ TEST_REQUEST = 'X' * 1200 # 1.2 KB
6
+
7
+ def setup
8
+ @queue = FreeMessageQueue::ClientQueue.new(TEST_URL)
9
+ end
10
+
11
+ def test_post_and_get_message
12
+ 5.times do |t|
13
+ message = new_msg(TEST_REQUEST + t.to_s)
14
+ message.option["ID"] = t
15
+ message.option["application-name"] = "Test"
16
+ @queue.put(message)
17
+ end
18
+
19
+ assert_equal 5, @queue.size
20
+ assert_equal TEST_REQUEST.size * 5 + 5, @queue.bytes
21
+
22
+ 5.times do |t|
23
+ message = @queue.poll()
24
+ assert_equal TEST_REQUEST + t.to_s, message.payload
25
+ assert_equal "text/plain", message.content_type
26
+ assert_equal t, message.option["ID"].to_i
27
+ assert_equal "Test", message.option["APPLICATION_NAME"]
28
+ end
29
+
30
+ assert_equal 0, @queue.size
31
+ assert_equal 0, @queue.bytes
32
+ end
33
+ end
data/test/test_helper.rb CHANGED
@@ -1,2 +1,6 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/fmq'
2
+ require File.dirname(__FILE__) + '/../lib/fmq'
3
+
4
+ def new_msg(payload)
5
+ FreeMessageQueue::Message.new(payload)
6
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ # This is the default test to the message interface
4
+ class TestLinkedQueue < Test::Unit::TestCase
5
+ def setup
6
+ manager = nil # the manager is not needed in this test
7
+ @queue = FreeMessageQueue::LinkedQueue.new(manager)
8
+ end
9
+
10
+ def test_basic_get_poll
11
+ assert_nil @queue.poll
12
+ assert_equal 0, @queue.size
13
+ assert @queue.put(nil) == false
14
+ assert_nil @queue.poll
15
+ td_1 = new_msg("asdasd")
16
+ assert @queue.put(td_1)
17
+ assert_equal 1, @queue.size
18
+ assert_equal td_1.payload, @queue.poll.payload
19
+ end
20
+
21
+ def test_n_messages
22
+ n = 20
23
+ byte_size = 0
24
+ n.times { |t| byte_size += t.to_s.size }
25
+
26
+ assert_equal 0, @queue.bytes
27
+ assert_nil @queue.poll
28
+ n.times do |i|
29
+ assert @queue.put(new_msg(i.to_s))
30
+ end
31
+ assert_equal byte_size, @queue.bytes
32
+ assert_equal n, @queue.size
33
+ n.times do |i|
34
+ assert_equal i.to_s, @queue.poll.payload
35
+ end
36
+ assert_equal 0, @queue.bytes
37
+ assert_nil @queue.poll
38
+ end
39
+
40
+ def test_mam_messages
41
+ @queue.put(new_msg("asd"))
42
+ @queue.put(new_msg("asd"))
43
+ @queue.poll()
44
+ @queue.put(new_msg("asd"))
45
+ @queue.put(new_msg("asd"))
46
+ @queue.poll()
47
+ @queue.put(new_msg("asd"))
48
+ @queue.poll()
49
+ assert_equal 2, @queue.size
50
+ @queue.put(new_msg("asd"))
51
+ @queue.put(new_msg("asd"))
52
+ assert_equal 4, @queue.size
53
+ @queue.clear
54
+ assert_equal 0, @queue.size
55
+ end
56
+
57
+ def test_queue_bytes
58
+ @queue.put(new_msg("XX" * 40))
59
+ @queue.put(new_msg("X" * 40))
60
+ @queue.put(new_msg("XX888" * 40))
61
+ assert_equal 2*40+40+5*40, @queue.bytes
62
+ @queue.clear
63
+ assert_equal 0, @queue.bytes
64
+ end
65
+ end
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ # This is the tests the queue manager interface
4
+ class TestQueueManager < Test::Unit::TestCase
5
+ DEFAULT_QUEUE_NAME = "/fmq_test/test1"
6
+
7
+ def setup
8
+ FreeMessageQueue.create_logger
9
+ FreeMessageQueue.set_log_level "fatal"
10
+
11
+ @working_conf = {
12
+ "auto-create-queues" => false,
13
+ "defined-queues" => {
14
+ "test-queue-1" => {
15
+ "path" => DEFAULT_QUEUE_NAME,
16
+ "max-messages" => 100,
17
+ "max-size" => "100mb"
18
+ }
19
+ }
20
+ }
21
+ @queue_manager = FreeMessageQueue::QueueManager.new(@working_conf)
22
+ end
23
+
24
+ def test_config
25
+ # check constraints
26
+ constraints = { :max_messages => 100, :max_size => 104857600 }
27
+ assert_equal constraints, @queue_manager.queue_constraints[DEFAULT_QUEUE_NAME]
28
+
29
+ # the queue manager can't be created without config
30
+ assert_raise(FreeMessageQueue::QueueManagerException) {
31
+ FreeMessageQueue::QueueManager.new(nil)
32
+ }
33
+
34
+ # check that the simple config will work
35
+ simple = {
36
+ "auto-create-queues" => true,
37
+ "defined-queues" => {}
38
+ }
39
+ FreeMessageQueue::QueueManager.new(simple)
40
+ end
41
+
42
+ def test_poll_and_get
43
+ 10.times do
44
+ @queue_manager.put(DEFAULT_QUEUE_NAME, new_msg("XXX" * 20))
45
+ end
46
+ assert_equal 10, @queue_manager.queue_size(DEFAULT_QUEUE_NAME)
47
+ i = 0
48
+ while message = @queue_manager.poll(DEFAULT_QUEUE_NAME)
49
+ i += 1
50
+ end
51
+ assert_equal 10, i
52
+ assert_equal 0, @queue_manager.queue_size(DEFAULT_QUEUE_NAME)
53
+
54
+ # should raise a exception because of the maximum messages limitation
55
+ i = 0
56
+ assert_raise(FreeMessageQueue::QueueManagerException) {
57
+ 101.times do
58
+ @queue_manager.put(DEFAULT_QUEUE_NAME, new_msg("XXX" * 20))
59
+ i += 1
60
+ end
61
+ }
62
+ @queue_manager.queue[DEFAULT_QUEUE_NAME].clear
63
+ assert_equal 0, @queue_manager.queue_size(DEFAULT_QUEUE_NAME)
64
+ assert i = 100
65
+
66
+ # should raise a exception because of the maximum byte size limitation
67
+ i = 0
68
+ two_mb_message = new_msg("X" * 1024 * 1024 * 2)
69
+ assert_raise(FreeMessageQueue::QueueManagerException) {
70
+ 101.times do
71
+ @queue_manager.put(DEFAULT_QUEUE_NAME, two_mb_message)
72
+ i += 1
73
+ end
74
+ }
75
+ assert i = 50
76
+ end
77
+
78
+ def test_creating_and_deleting
79
+ url = "/XX123"
80
+ @queue_manager.create_queue(url)
81
+ @queue_manager.put(url, new_msg("X_X_X_X_X_X"))
82
+ assert_equal "X_X_X_X_X_X", @queue_manager.poll(url).payload
83
+ @queue_manager.delete_queue(url)
84
+
85
+ # auto queue creation is off
86
+ assert_raise(FreeMessageQueue::QueueManagerException) {
87
+ @queue_manager.put(url, new_msg("Test"))
88
+ }
89
+ end
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Landgraf
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-23 00:00:00 +02:00
12
+ date: 2008-06-28 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,28 +21,43 @@ executables:
21
21
  extensions: []
22
22
 
23
23
  extra_rdoc_files:
24
+ - History.txt
25
+ - License.txt
26
+ - PostInstall.txt
27
+ - README.txt
24
28
  - lib/fmq/queues/README.txt
25
29
  files:
30
+ - History.txt
31
+ - License.txt
32
+ - PostInstall.txt
33
+ - README.txt
26
34
  - bin/fmq
35
+ - config/hoe.rb
36
+ - config/requirements.rb
27
37
  - default-server/admin-interface/images/logo.png
28
38
  - default-server/admin-interface/index.html
29
39
  - default-server/admin-interface/prototype.js
30
40
  - default-server/config.yml
31
41
  - default-server/queues/my_test.rb
32
42
  - lib/fmq.rb
33
- - lib/fmq/client.rb
34
43
  - lib/fmq/boot.rb
44
+ - lib/fmq/client.rb
35
45
  - lib/fmq/mongrel_server.rb
36
46
  - lib/fmq/queue_manager.rb
37
47
  - lib/fmq/queues/README.txt
38
48
  - lib/fmq/queues/admin.rb
49
+ - lib/fmq/queues/base.rb
39
50
  - lib/fmq/queues/file.rb
40
51
  - lib/fmq/queues/forward.rb
41
52
  - lib/fmq/queues/linked.rb
42
53
  - lib/fmq/queues/load_balanced.rb
43
54
  - lib/fmq/queues/syncronized.rb
44
55
  - lib/fmq/version.rb
45
- - setup.rb
56
+ - test/test_basic.rb
57
+ - test/test_fmq_client.rb
58
+ - test/test_helper.rb
59
+ - test/test_linked.rb
60
+ - test/test_queue_manager.rb
46
61
  has_rdoc: true
47
62
  homepage: http://fmq.rubyforge.org
48
63
  post_install_message: |-
@@ -74,6 +89,8 @@ signing_key:
74
89
  specification_version: 2
75
90
  summary: The project implements a queue system with a server and some client apis. This project wants to be a fast and lightweight implementation with most of the features of MQS or ActiveMQ.
76
91
  test_files:
92
+ - test/test_basic.rb
77
93
  - test/test_fmq_client.rb
78
- - test/test_fmq_queue.rb
79
94
  - test/test_helper.rb
95
+ - test/test_linked.rb
96
+ - test/test_queue_manager.rb