modern_times 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/LICENSE.txt +201 -0
  2. data/README.rdoc +143 -0
  3. data/Rakefile +28 -0
  4. data/VERSION +1 -0
  5. data/examples/simple/.gitignore +2 -0
  6. data/examples/simple/README +24 -0
  7. data/examples/simple/bar_worker.rb +6 -0
  8. data/examples/simple/baz_worker.rb +8 -0
  9. data/examples/simple/hornetq.yml +14 -0
  10. data/examples/simple/manager.rb +17 -0
  11. data/examples/simple/publish.rb +35 -0
  12. data/lib/modern_times/base/supervisor.rb +97 -0
  13. data/lib/modern_times/base/supervisor_mbean.rb +30 -0
  14. data/lib/modern_times/base/worker.rb +55 -0
  15. data/lib/modern_times/base.rb +3 -0
  16. data/lib/modern_times/exception.rb +4 -0
  17. data/lib/modern_times/hornetq/client.rb +53 -0
  18. data/lib/modern_times/hornetq/marshal_strategy/json.rb +17 -0
  19. data/lib/modern_times/hornetq/marshal_strategy/ruby.rb +17 -0
  20. data/lib/modern_times/hornetq/marshal_strategy/string.rb +17 -0
  21. data/lib/modern_times/hornetq/marshal_strategy.rb +3 -0
  22. data/lib/modern_times/hornetq/publisher.rb +72 -0
  23. data/lib/modern_times/hornetq/supervisor.rb +19 -0
  24. data/lib/modern_times/hornetq/supervisor_mbean.rb +12 -0
  25. data/lib/modern_times/hornetq/worker.rb +121 -0
  26. data/lib/modern_times/hornetq.rb +11 -0
  27. data/lib/modern_times/loggable.rb +23 -0
  28. data/lib/modern_times/manager.rb +92 -0
  29. data/lib/modern_times/manager_mbean.rb +36 -0
  30. data/lib/modern_times/railsable.rb +132 -0
  31. data/lib/modern_times/thread.rb +16 -0
  32. data/lib/modern_times.rb +13 -0
  33. data/test/base/worker_test.rb +38 -0
  34. data/test/messaging/worker_manager_test.rb +58 -0
  35. data/test/messaging/worker_test.rb +58 -0
  36. data/test/worker_manager_test.rb +48 -0
  37. metadata +123 -0
@@ -0,0 +1,38 @@
1
+ require 'modern_times'
2
+ require 'shoulda'
3
+ require 'test/unit'
4
+
5
+ class DummyWorker < ModernTimes::Base::Worker
6
+ end
7
+
8
+ module Base
9
+ class WorkerTest < Test::Unit::TestCase
10
+
11
+ context 'a worker with no name specified' do
12
+ setup do
13
+ @worker = DummyWorker.new
14
+ @worker.index = 2
15
+ @worker.thread = 'dummy thread'
16
+ @supervisor = DummyWorker.create_supervisor('dummy_manager')
17
+ end
18
+
19
+ should "have default name and proper supervisor and attributes" do
20
+ assert_equal('Dummy', @worker.name)
21
+ assert_equal(2, @worker.index)
22
+ assert_equal('dummy thread', @worker.thread)
23
+ assert_equal(ModernTimes::Base::Supervisor, @supervisor.class)
24
+ assert_equal('dummy_manager', @supervisor.manager)
25
+ end
26
+ end
27
+
28
+ context 'a worker with name specified' do
29
+ setup do
30
+ @worker = DummyWorker.new(:name => 'Foo')
31
+ end
32
+
33
+ should "have name specified and proper supervisor and attributes" do
34
+ assert_equal('Foo', @worker.name)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class DummyDefaultWorker < Messaging::Worker
4
+ end
5
+
6
+ module Dummy
7
+ class DefaultWorker < Messaging::Worker
8
+ end
9
+ end
10
+
11
+ class DummyDefaultWorkerWithSpecifiedNames < Messaging::Worker
12
+ address :MyAddressName
13
+ queue :MyQueueName
14
+ end
15
+
16
+ module Messaging
17
+ class WorkerManagerTest < ActiveSupport::TestCase
18
+
19
+ context 'a default worker' do
20
+ setup do
21
+ @worker = DummyDefaultWorker.new
22
+ @worker.message = 'foo'
23
+ @worker.session = 'dummy session'
24
+ @worker.thread_number = 4
25
+ end
26
+
27
+ should "have address and queue names derived from it's class name" do
28
+ assert_equal(@worker.address_name, 'DummyDefault')
29
+ assert_equal(@worker.queue_name, 'DummyDefault')
30
+ assert_equal(@worker.message, 'foo')
31
+ assert_equal(@worker.session, 'dummy session')
32
+ assert_equal(@worker.thread_number, 4)
33
+ end
34
+ end
35
+
36
+ context 'a default worker in a namespace' do
37
+ setup do
38
+ @worker = Dummy::DefaultWorker.new
39
+ end
40
+
41
+ should "have address and queue names derived from it's class name" do
42
+ assert_equal(@worker.address_name, 'Dummy_Default')
43
+ assert_equal(@worker.queue_name, 'Dummy_Default')
44
+ end
45
+ end
46
+
47
+ context 'a worker with specified names' do
48
+ setup do
49
+ @worker = DummyDefaultWorkerWithSpecifiedNames.new
50
+ end
51
+
52
+ should "have address and queue names matching the specified names" do
53
+ assert_equal(@worker.address_name, 'MyAddressName')
54
+ assert_equal(@worker.queue_name, 'MyQueueName')
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class DummyDefaultWorker < Messaging::Worker
4
+ end
5
+
6
+ module Dummy
7
+ class DefaultWorker < Messaging::Worker
8
+ end
9
+ end
10
+
11
+ class DummyDefaultWorkerWithSpecifiedNames < Messaging::Worker
12
+ address :MyAddressName
13
+ queue :MyQueueName
14
+ end
15
+
16
+ module Messaging
17
+ class WorkerTest < ActiveSupport::TestCase
18
+
19
+ context 'a default worker' do
20
+ setup do
21
+ @worker = DummyDefaultWorker.new
22
+ @worker.message = 'foo'
23
+ @worker.session = 'dummy session'
24
+ @worker.thread_number = 4
25
+ end
26
+
27
+ should "have address and queue names derived from it's class name" do
28
+ assert_equal(@worker.address_name, 'DummyDefault')
29
+ assert_equal(@worker.queue_name, 'DummyDefault')
30
+ assert_equal(@worker.message, 'foo')
31
+ assert_equal(@worker.session, 'dummy session')
32
+ assert_equal(@worker.thread_number, 4)
33
+ end
34
+ end
35
+
36
+ context 'a default worker in a namespace' do
37
+ setup do
38
+ @worker = Dummy::DefaultWorker.new
39
+ end
40
+
41
+ should "have address and queue names derived from it's class name" do
42
+ assert_equal(@worker.address_name, 'Dummy_Default')
43
+ assert_equal(@worker.queue_name, 'Dummy_Default')
44
+ end
45
+ end
46
+
47
+ context 'a worker with specified names' do
48
+ setup do
49
+ @worker = DummyDefaultWorkerWithSpecifiedNames.new
50
+ end
51
+
52
+ should "have address and queue names matching the specified names" do
53
+ assert_equal(@worker.address_name, 'MyAddressName')
54
+ assert_equal(@worker.queue_name, 'MyQueueName')
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'modern_times'
5
+ require 'range_queue_strategy'
6
+ require 'range_queue_worker'
7
+
8
+ class WorkerManagerTest < Test::Unit::TestCase
9
+ context 'on single strategy' do
10
+ setup do
11
+ @range = 1..100
12
+ end
13
+
14
+ should 'work' do
15
+ strategy = RangeQueueStrategy.new(@range)
16
+ manager = ModernTimes::WorkerManager.new
17
+ worker = RangeQueueWorker.new
18
+ thread_count = 10
19
+ manager.add(strategy, worker, thread_count, 1)
20
+ sleep(2)
21
+ manager.stop
22
+ assert_equal @range.to_a, worker.results.sort
23
+ end
24
+ end
25
+
26
+ context 'on multiple strategies' do
27
+ setup do
28
+ @ranges = [1..100, 101..200, 201..300]
29
+ end
30
+
31
+ should 'work' do
32
+ [nil, 1].each do |poll_sleep|
33
+ strategies = @ranges.map {|range| RangeQueueStrategy.new(range) }
34
+ manager = ModernTimes::WorkerManager.new
35
+ workers = [RangeQueueWorker.new, RangeQueueWorker.new, RangeQueueWorker.new]
36
+ thread_count = 10
37
+ strategies.each_index do |i|
38
+ manager.add(strategies[i], workers[i], thread_count, poll_sleep)
39
+ end
40
+ sleep(2)
41
+ manager.stop
42
+ strategies.each_index do |i|
43
+ assert_equal @ranges[i].to_a, workers[i].results.sort
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modern_times
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Brad Pardee
9
+ - Reid Morrison
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-03-14 00:00:00 -04:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: jruby-hornetq
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.3.2
26
+ type: :runtime
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: jmx
30
+ prerelease: false
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0"
37
+ type: :runtime
38
+ version_requirements: *id002
39
+ description: Generic asynchronous task library
40
+ email:
41
+ - bradpardee@gmail.com
42
+ - rubywmq@gmail.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files:
48
+ - LICENSE.txt
49
+ - README.rdoc
50
+ files:
51
+ - LICENSE.txt
52
+ - README.rdoc
53
+ - Rakefile
54
+ - VERSION
55
+ - examples/simple/.gitignore
56
+ - examples/simple/README
57
+ - examples/simple/bar_worker.rb
58
+ - examples/simple/baz_worker.rb
59
+ - examples/simple/hornetq.yml
60
+ - examples/simple/manager.rb
61
+ - examples/simple/publish.rb
62
+ - lib/modern_times.rb
63
+ - lib/modern_times/base.rb
64
+ - lib/modern_times/base/supervisor.rb
65
+ - lib/modern_times/base/supervisor_mbean.rb
66
+ - lib/modern_times/base/worker.rb
67
+ - lib/modern_times/exception.rb
68
+ - lib/modern_times/hornetq.rb
69
+ - lib/modern_times/hornetq/client.rb
70
+ - lib/modern_times/hornetq/marshal_strategy.rb
71
+ - lib/modern_times/hornetq/marshal_strategy/json.rb
72
+ - lib/modern_times/hornetq/marshal_strategy/ruby.rb
73
+ - lib/modern_times/hornetq/marshal_strategy/string.rb
74
+ - lib/modern_times/hornetq/publisher.rb
75
+ - lib/modern_times/hornetq/supervisor.rb
76
+ - lib/modern_times/hornetq/supervisor_mbean.rb
77
+ - lib/modern_times/hornetq/worker.rb
78
+ - lib/modern_times/loggable.rb
79
+ - lib/modern_times/manager.rb
80
+ - lib/modern_times/manager_mbean.rb
81
+ - lib/modern_times/railsable.rb
82
+ - lib/modern_times/thread.rb
83
+ - test/base/worker_test.rb
84
+ - test/worker_manager_test.rb
85
+ - test/messaging/worker_manager_test.rb
86
+ - test/messaging/worker_test.rb
87
+ has_rdoc: true
88
+ homepage: http://github.com/ClarityServices/modern_times
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.5.1
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Asynchronous task library
115
+ test_files:
116
+ - examples/simple/bar_worker.rb
117
+ - examples/simple/baz_worker.rb
118
+ - examples/simple/manager.rb
119
+ - examples/simple/publish.rb
120
+ - test/base/worker_test.rb
121
+ - test/messaging/worker_manager_test.rb
122
+ - test/messaging/worker_test.rb
123
+ - test/worker_manager_test.rb