qs 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/bench/config.qs +4 -27
  2. data/bench/dispatcher.qs +24 -0
  3. data/bench/report.rb +80 -10
  4. data/bench/report.txt +10 -3
  5. data/bench/setup.rb +55 -0
  6. data/lib/qs.rb +75 -15
  7. data/lib/qs/client.rb +73 -22
  8. data/lib/qs/daemon.rb +21 -21
  9. data/lib/qs/daemon_data.rb +4 -4
  10. data/lib/qs/dispatch_job.rb +36 -0
  11. data/lib/qs/dispatch_job_handler.rb +79 -0
  12. data/lib/qs/dispatcher_queue.rb +19 -0
  13. data/lib/qs/error_handler.rb +12 -12
  14. data/lib/qs/event.rb +82 -0
  15. data/lib/qs/event_handler.rb +34 -0
  16. data/lib/qs/event_handler_test_helpers.rb +17 -0
  17. data/lib/qs/job.rb +19 -31
  18. data/lib/qs/job_handler.rb +6 -63
  19. data/lib/qs/{test_helpers.rb → job_handler_test_helpers.rb} +2 -2
  20. data/lib/qs/message.rb +29 -0
  21. data/lib/qs/message_handler.rb +84 -0
  22. data/lib/qs/payload.rb +98 -0
  23. data/lib/qs/payload_handler.rb +106 -54
  24. data/lib/qs/queue.rb +39 -6
  25. data/lib/qs/queue_item.rb +33 -0
  26. data/lib/qs/route.rb +7 -7
  27. data/lib/qs/runner.rb +6 -5
  28. data/lib/qs/test_runner.rb +41 -13
  29. data/lib/qs/version.rb +1 -1
  30. data/qs.gemspec +1 -1
  31. data/test/helper.rb +1 -1
  32. data/test/support/app_daemon.rb +77 -11
  33. data/test/support/factory.rb +34 -0
  34. data/test/system/daemon_tests.rb +146 -77
  35. data/test/system/queue_tests.rb +87 -0
  36. data/test/unit/client_tests.rb +184 -45
  37. data/test/unit/daemon_data_tests.rb +4 -4
  38. data/test/unit/daemon_tests.rb +32 -32
  39. data/test/unit/dispatch_job_handler_tests.rb +163 -0
  40. data/test/unit/dispatch_job_tests.rb +75 -0
  41. data/test/unit/dispatcher_queue_tests.rb +42 -0
  42. data/test/unit/error_handler_tests.rb +9 -9
  43. data/test/unit/event_handler_test_helpers_tests.rb +55 -0
  44. data/test/unit/event_handler_tests.rb +63 -0
  45. data/test/unit/event_tests.rb +162 -0
  46. data/test/unit/{test_helper_tests.rb → job_handler_test_helper_tests.rb} +13 -19
  47. data/test/unit/job_handler_tests.rb +17 -210
  48. data/test/unit/job_tests.rb +49 -79
  49. data/test/unit/message_handler_tests.rb +235 -0
  50. data/test/unit/message_tests.rb +64 -0
  51. data/test/unit/payload_handler_tests.rb +285 -86
  52. data/test/unit/payload_tests.rb +139 -0
  53. data/test/unit/qs_runner_tests.rb +6 -6
  54. data/test/unit/qs_tests.rb +167 -28
  55. data/test/unit/queue_item_tests.rb +51 -0
  56. data/test/unit/queue_tests.rb +126 -18
  57. data/test/unit/route_tests.rb +12 -13
  58. data/test/unit/runner_tests.rb +10 -10
  59. data/test/unit/test_runner_tests.rb +117 -24
  60. metadata +51 -21
  61. data/bench/queue.rb +0 -8
  62. data/lib/qs/redis_item.rb +0 -33
  63. data/test/unit/redis_item_tests.rb +0 -49
@@ -13,11 +13,11 @@ class Qs::ErrorHandler
13
13
  @daemon_data = Qs::DaemonData.new
14
14
  @queue_redis_key = Qs::Queue::RedisKey.new(Factory.string)
15
15
  @context_hash = {
16
- :daemon_data => @daemon_data,
17
- :queue_redis_key => @queue_redis_key,
18
- :serialized_payload => Factory.string,
19
- :job => Factory.string,
20
- :handler_class => Factory.string
16
+ :daemon_data => @daemon_data,
17
+ :queue_redis_key => @queue_redis_key,
18
+ :encoded_payload => Factory.string,
19
+ :message => Factory.string,
20
+ :handler_class => Factory.string
21
21
  }
22
22
 
23
23
  @handler_class = Qs::ErrorHandler
@@ -107,15 +107,15 @@ class Qs::ErrorHandler
107
107
  subject{ @context }
108
108
 
109
109
  should have_readers :daemon_data
110
- should have_readers :queue_name, :serialized_payload
111
- should have_readers :job, :handler_class
110
+ should have_readers :queue_name, :encoded_payload
111
+ should have_readers :message, :handler_class
112
112
 
113
113
  should "know its attributes" do
114
114
  assert_equal @context_hash[:daemon_data], subject.daemon_data
115
115
  exp = Qs::Queue::RedisKey.parse_name(@context_hash[:queue_redis_key])
116
116
  assert_equal exp, subject.queue_name
117
- assert_equal @context_hash[:serialized_payload], subject.serialized_payload
118
- assert_equal @context_hash[:job], subject.job
117
+ assert_equal @context_hash[:encoded_payload], subject.encoded_payload
118
+ assert_equal @context_hash[:message], subject.message
119
119
  assert_equal @context_hash[:handler_class], subject.handler_class
120
120
  end
121
121
 
@@ -0,0 +1,55 @@
1
+ require 'assert'
2
+ require 'qs/event_handler_test_helpers'
3
+
4
+ require 'qs/event_handler'
5
+ require 'qs/test_runner'
6
+ require 'test/support/runner_spy'
7
+
8
+ module Qs::EventHandler::TestHelpers
9
+
10
+ class UnitTests < Assert::Context
11
+ desc "Qs::TestHelpers"
12
+ setup do
13
+ @test_helpers = Qs::EventHandler::TestHelpers
14
+ end
15
+ subject{ @test_helpers }
16
+
17
+ end
18
+
19
+ class MixinTests < UnitTests
20
+ desc "as a mixin"
21
+ setup do
22
+ @handler_class = Class.new
23
+ @args = { Factory.string => Factory.string }
24
+
25
+ @runner_spy = nil
26
+ Assert.stub(Qs::EventTestRunner, :new) do |*args|
27
+ @runner_spy = RunnerSpy.new(*args)
28
+ end
29
+
30
+ context_class = Class.new{ include Qs::EventHandler::TestHelpers }
31
+ @context = context_class.new
32
+ end
33
+ subject{ @context }
34
+
35
+ should have_imeths :test_runner, :test_handler
36
+
37
+ should "build an event test runner for a given handler using `test_runner`" do
38
+ result = subject.test_runner(@handler_class, @args)
39
+
40
+ assert_not_nil @runner_spy
41
+ assert_equal @handler_class, @runner_spy.handler_class
42
+ assert_equal @args, @runner_spy.args
43
+ assert_equal @runner_spy, result
44
+ end
45
+
46
+ should "return an initialized handler instance using `test_handler`" do
47
+ result = subject.test_handler(@handler_class, @args)
48
+
49
+ assert_not_nil @runner_spy
50
+ assert_equal @runner_spy.handler, result
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,63 @@
1
+ require 'assert'
2
+ require 'qs/event_handler'
3
+
4
+ require 'qs/event'
5
+ require 'qs/message_handler'
6
+
7
+ module Qs::EventHandler
8
+
9
+ class UnitTests < Assert::Context
10
+ desc "Qs::EventHandler"
11
+ setup do
12
+ @handler_class = Class.new{ include Qs::EventHandler }
13
+ end
14
+ subject{ @handler_class }
15
+
16
+ should "be a message handler" do
17
+ assert_includes Qs::MessageHandler, subject
18
+ end
19
+
20
+ end
21
+
22
+ class InitTests < UnitTests
23
+ desc "when init"
24
+ setup do
25
+ @runner = FakeRunner.new
26
+ @handler = TestEventHandler.new(@runner)
27
+ end
28
+ subject{ @handler }
29
+
30
+ should "know its event, channel, name and published at" do
31
+ assert_equal @runner.message, subject.public_event
32
+ assert_equal subject.public_event.channel, subject.public_event_channel
33
+ assert_equal subject.public_event.name, subject.public_event_name
34
+ assert_equal subject.public_event.published_at, subject.public_event_published_at
35
+ end
36
+
37
+ should "have a custom inspect" do
38
+ reference = '0x0%x' % (subject.object_id << 1)
39
+ expected = "#<#{subject.class}:#{reference} " \
40
+ "@event=#{@handler.public_event.inspect}>"
41
+ assert_equal expected, subject.inspect
42
+ end
43
+
44
+ end
45
+
46
+ class TestEventHandler
47
+ include Qs::EventHandler
48
+
49
+ def public_event; event; end
50
+ def public_event_channel; event_channel; end
51
+ def public_event_name; event_name; end
52
+ def public_event_published_at; event_published_at; end
53
+ end
54
+
55
+ class FakeRunner
56
+ attr_accessor :message
57
+
58
+ def initialize
59
+ @message = Factory.event
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,162 @@
1
+ require 'assert'
2
+ require 'qs/event'
3
+
4
+ require 'qs/message'
5
+
6
+ class Qs::Event
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Qs::Event"
10
+ setup do
11
+ @channel = Factory.string
12
+ @name = Factory.string
13
+ @params = { Factory.string => Factory.string }
14
+ @publisher = Factory.string
15
+ @published_at = Factory.time
16
+
17
+ @event_class = Qs::Event
18
+ end
19
+ subject{ @event_class }
20
+
21
+ should "know its payload type" do
22
+ assert_equal 'event', PAYLOAD_TYPE
23
+ end
24
+
25
+ should "be a message" do
26
+ assert subject < Qs::Message
27
+ end
28
+
29
+ end
30
+
31
+ class InitTests < UnitTests
32
+ desc "when init"
33
+ setup do
34
+ @current_time = Factory.time
35
+ Assert.stub(Time, :now).with{ @current_time }
36
+
37
+ @event = @event_class.new(@channel, @name, {
38
+ :params => @params,
39
+ :publisher => @publisher,
40
+ :published_at => @published_at
41
+ })
42
+ end
43
+ subject{ @event }
44
+
45
+ should have_readers :channel, :name, :publisher, :published_at
46
+ should have_imeths :route_name, :subscribers_redis_key
47
+
48
+ should "know its attributes" do
49
+ assert_equal PAYLOAD_TYPE, subject.payload_type
50
+ assert_equal @channel, subject.channel
51
+ assert_equal @name, subject.name
52
+ assert_equal @params, subject.params
53
+ assert_equal @publisher, subject.publisher
54
+ assert_equal @published_at, subject.published_at
55
+ end
56
+
57
+ should "default its params and published at to the current time" do
58
+ event = @event_class.new(@channel, @name)
59
+ assert_equal({}, event.params)
60
+ assert_equal @current_time, event.published_at
61
+ end
62
+
63
+ should "know its route name" do
64
+ exp = RouteName.new(@channel, @name)
65
+ result = subject.route_name
66
+ assert_equal exp, result
67
+ assert_same result, subject.route_name
68
+ end
69
+
70
+ should "know its subscribers redis key" do
71
+ exp = SubscribersRedisKey.new(subject.route_name)
72
+ assert_equal exp, subject.subscribers_redis_key
73
+ end
74
+
75
+ should "have a custom inspect" do
76
+ reference = '0x0%x' % (subject.object_id << 1)
77
+ exp = "#<Qs::Event:#{reference} " \
78
+ "@channel=#{subject.channel.inspect} " \
79
+ "@name=#{subject.name.inspect} " \
80
+ "@params=#{subject.params.inspect} " \
81
+ "@publisher=#{subject.publisher.inspect} " \
82
+ "@published_at=#{subject.published_at.inspect}>"
83
+ assert_equal exp, subject.inspect
84
+ end
85
+
86
+ should "be comparable" do
87
+ matching = @event_class.new(@channel, @name, {
88
+ :params => @params,
89
+ :publisher => @publisher,
90
+ :published_at => @published_at
91
+ })
92
+ assert_equal matching, subject
93
+
94
+ non_matching = @event_class.new(Factory.string, @name, {
95
+ :params => @params,
96
+ :publisher => @publisher,
97
+ :published_at => @published_at
98
+ })
99
+ assert_not_equal non_matching, subject
100
+ non_matching = @event_class.new(@channel, Factory.string, {
101
+ :params => @params,
102
+ :publisher => @publisher,
103
+ :published_at => @published_at
104
+ })
105
+ assert_not_equal non_matching, subject
106
+ non_matching = @event_class.new(@channel, @name, {
107
+ :params => { Factory.string => Factory.string },
108
+ :publisher => @publisher,
109
+ :published_at => @published_at
110
+ })
111
+ assert_not_equal non_matching, subject
112
+ non_matching = @event_class.new(@channel, @name, {
113
+ :params => @params,
114
+ :publisher => Factory.string,
115
+ :published_at => @published_at
116
+ })
117
+ assert_not_equal non_matching, subject
118
+ non_matching = @event_class.new(@channel, @name, {
119
+ :params => @params,
120
+ :publisher => @publisher,
121
+ :published_at => Factory.time
122
+ })
123
+ assert_not_equal non_matching, subject
124
+ end
125
+
126
+ should "raise an error when given invalid attributes" do
127
+ assert_raises(InvalidError){ @event_class.new(nil, @name) }
128
+ assert_raises(InvalidError){ @event_class.new(@channel, nil) }
129
+ assert_raises(InvalidError) do
130
+ @event_class.new(@channel, @name, :params => Factory.string)
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+ class RouteNameTests < UnitTests
137
+ desc "RouteName"
138
+ subject{ RouteName }
139
+
140
+ should have_imeths :new
141
+
142
+ should "return an event route name given an event channel and event name" do
143
+ assert_equal "#{@channel}:#{@name}", subject.new(@channel, @name)
144
+ end
145
+
146
+ end
147
+
148
+ class SubscribersRedisKeyTests < UnitTests
149
+ desc "SubscribersRedisKey"
150
+ subject{ SubscribersRedisKey }
151
+
152
+ should have_imeths :new
153
+
154
+ should "return an event subscribers redis key given an event route name" do
155
+ event_route_name = RouteName.new(@channel, @name)
156
+ exp = "events:#{event_route_name}:subscribers"
157
+ assert_equal exp, subject.new(event_route_name)
158
+ end
159
+
160
+ end
161
+
162
+ end
@@ -1,15 +1,16 @@
1
1
  require 'assert'
2
- require 'qs/test_helpers'
2
+ require 'qs/job_handler_test_helpers'
3
3
 
4
4
  require 'qs/job_handler'
5
+ require 'qs/test_runner'
5
6
  require 'test/support/runner_spy'
6
7
 
7
- module Qs::TestHelpers
8
+ module Qs::JobHandler::TestHelpers
8
9
 
9
10
  class UnitTests < Assert::Context
10
11
  desc "Qs::TestHelpers"
11
12
  setup do
12
- @test_helpers = Qs::TestHelpers
13
+ @test_helpers = Qs::JobHandler::TestHelpers
13
14
  end
14
15
  subject{ @test_helpers }
15
16
 
@@ -17,29 +18,23 @@ module Qs::TestHelpers
17
18
 
18
19
  class MixinTests < UnitTests
19
20
  desc "as a mixin"
20
- setup do
21
- context_class = Class.new{ include Qs::TestHelpers }
22
- @context = context_class.new
23
- end
24
- subject{ @context }
25
-
26
- should have_imeths :test_runner, :test_handler
27
-
28
- end
29
-
30
- class HandlerTestRunnerTests < MixinTests
31
- desc "for handler testing"
32
21
  setup do
33
22
  @handler_class = Class.new
34
23
  @args = { Factory.string => Factory.string }
35
24
 
36
25
  @runner_spy = nil
37
- Assert.stub(Qs::TestRunner, :new) do |*args|
26
+ Assert.stub(Qs::JobTestRunner, :new) do |*args|
38
27
  @runner_spy = RunnerSpy.new(*args)
39
28
  end
29
+
30
+ context_class = Class.new{ include Qs::JobHandler::TestHelpers }
31
+ @context = context_class.new
40
32
  end
33
+ subject{ @context }
41
34
 
42
- should "build a test runner for a given handler" do
35
+ should have_imeths :test_runner, :test_handler
36
+
37
+ should "build a job test runner for a given handler using `test_runner`" do
43
38
  result = subject.test_runner(@handler_class, @args)
44
39
 
45
40
  assert_not_nil @runner_spy
@@ -48,7 +43,7 @@ module Qs::TestHelpers
48
43
  assert_equal @runner_spy, result
49
44
  end
50
45
 
51
- should "return an initialized handler instance" do
46
+ should "return an initialized handler instance using `test_handler`" do
52
47
  result = subject.test_handler(@handler_class, @args)
53
48
 
54
49
  assert_not_nil @runner_spy
@@ -58,4 +53,3 @@ module Qs::TestHelpers
58
53
  end
59
54
 
60
55
  end
61
-
@@ -1,6 +1,8 @@
1
1
  require 'assert'
2
2
  require 'qs/job_handler'
3
3
 
4
+ require 'qs/message_handler'
5
+
4
6
  module Qs::JobHandler
5
7
 
6
8
  class UnitTests < Assert::Context
@@ -10,136 +12,8 @@ module Qs::JobHandler
10
12
  end
11
13
  subject{ @handler_class }
12
14
 
13
- should have_imeths :timeout
14
- should have_imeths :before_callbacks, :after_callbacks
15
- should have_imeths :before_init_callbacks, :after_init_callbacks
16
- should have_imeths :before_run_callbacks, :after_run_callbacks
17
- should have_imeths :before, :after
18
- should have_imeths :before_init, :after_init
19
- should have_imeths :before_run, :after_run
20
- should have_imeths :prepend_before, :prepend_after
21
- should have_imeths :prepend_before_init, :prepend_after_init
22
- should have_imeths :prepend_before_run, :prepend_after_run
23
-
24
- should "allow reading/writing its timeout" do
25
- assert_nil subject.timeout
26
- value = Factory.integer
27
- subject.timeout(value)
28
- assert_equal value, subject.timeout
29
- end
30
-
31
- should "convert timeout values to floats" do
32
- value = Factory.float.to_s
33
- subject.timeout(value)
34
- assert_equal value.to_f, subject.timeout
35
- end
36
-
37
- should "return an empty array by default using `before_callbacks`" do
38
- assert_equal [], subject.before_callbacks
39
- end
40
-
41
- should "return an empty array by default using `after_callbacks`" do
42
- assert_equal [], subject.after_callbacks
43
- end
44
-
45
- should "return an empty array by default using `before_init_callbacks`" do
46
- assert_equal [], subject.before_init_callbacks
47
- end
48
-
49
- should "return an empty array by default using `after_init_callbacks`" do
50
- assert_equal [], subject.after_init_callbacks
51
- end
52
-
53
- should "return an empty array by default using `before_run_callbacks`" do
54
- assert_equal [], subject.before_run_callbacks
55
- end
56
-
57
- should "return an empty array by default using `after_run_callbacks`" do
58
- assert_equal [], subject.after_run_callbacks
59
- end
60
-
61
- should "append a block to the before callbacks using `before`" do
62
- subject.before_callbacks << proc{ Factory.string }
63
- block = Proc.new{ Factory.string }
64
- subject.before(&block)
65
- assert_equal block, subject.before_callbacks.last
66
- end
67
-
68
- should "append a block to the after callbacks using `after`" do
69
- subject.after_callbacks << proc{ Factory.string }
70
- block = Proc.new{ Factory.string }
71
- subject.after(&block)
72
- assert_equal block, subject.after_callbacks.last
73
- end
74
-
75
- should "append a block to the before init callbacks using `before_init`" do
76
- subject.before_init_callbacks << proc{ Factory.string }
77
- block = Proc.new{ Factory.string }
78
- subject.before_init(&block)
79
- assert_equal block, subject.before_init_callbacks.last
80
- end
81
-
82
- should "append a block to the after init callbacks using `after_init`" do
83
- subject.after_init_callbacks << proc{ Factory.string }
84
- block = Proc.new{ Factory.string }
85
- subject.after_init(&block)
86
- assert_equal block, subject.after_init_callbacks.last
87
- end
88
-
89
- should "append a block to the before run callbacks using `before_run`" do
90
- subject.before_run_callbacks << proc{ Factory.string }
91
- block = Proc.new{ Factory.string }
92
- subject.before_run(&block)
93
- assert_equal block, subject.before_run_callbacks.last
94
- end
95
-
96
- should "append a block to the after run callbacks using `after_run`" do
97
- subject.after_run_callbacks << proc{ Factory.string }
98
- block = Proc.new{ Factory.string }
99
- subject.after_run(&block)
100
- assert_equal block, subject.after_run_callbacks.last
101
- end
102
-
103
- should "prepend a block to the before callbacks using `prepend_before`" do
104
- subject.before_callbacks << proc{ Factory.string }
105
- block = Proc.new{ Factory.string }
106
- subject.prepend_before(&block)
107
- assert_equal block, subject.before_callbacks.first
108
- end
109
-
110
- should "prepend a block to the after callbacks using `prepend_after`" do
111
- subject.after_callbacks << proc{ Factory.string }
112
- block = Proc.new{ Factory.string }
113
- subject.prepend_after(&block)
114
- assert_equal block, subject.after_callbacks.first
115
- end
116
-
117
- should "prepend a block to the before init callbacks using `prepend_before_init`" do
118
- subject.before_init_callbacks << proc{ Factory.string }
119
- block = Proc.new{ Factory.string }
120
- subject.prepend_before_init(&block)
121
- assert_equal block, subject.before_init_callbacks.first
122
- end
123
-
124
- should "prepend a block to the after init callbacks using `prepend_after_init`" do
125
- subject.after_init_callbacks << proc{ Factory.string }
126
- block = Proc.new{ Factory.string }
127
- subject.prepend_after_init(&block)
128
- assert_equal block, subject.after_init_callbacks.first
129
- end
130
-
131
- should "prepend a block to the before run callbacks using `prepend_before_run`" do
132
- subject.before_run_callbacks << proc{ Factory.string }
133
- block = Proc.new{ Factory.string }
134
- subject.prepend_before_run(&block)
135
- assert_equal block, subject.before_run_callbacks.first
136
- end
137
-
138
- should "prepend a block to the after run callbacks using `prepend_after_run`" do
139
- subject.after_run_callbacks << proc{ Factory.string }
140
- block = Proc.new{ Factory.string }
141
- subject.prepend_after_run(&block)
142
- assert_equal block, subject.after_run_callbacks.first
15
+ should "be a message handler" do
16
+ assert_includes Qs::MessageHandler, subject
143
17
  end
144
18
 
145
19
  end
@@ -147,46 +21,22 @@ module Qs::JobHandler
147
21
  class InitTests < UnitTests
148
22
  desc "when init"
149
23
  setup do
150
- @runner = FakeRunner.new
24
+ @runner = FakeRunner.new
151
25
  @handler = TestJobHandler.new(@runner)
152
26
  end
153
27
  subject{ @handler }
154
28
 
155
- should have_imeths :init, :init!, :run, :run!
156
-
157
- should "know its job, params and logger" do
158
- assert_equal @runner.job, subject.public_job
159
- assert_equal @runner.params, subject.public_params
160
- assert_equal @runner.logger, subject.public_logger
161
- end
162
-
163
- should "call `init!` and its before/after init callbacks using `init`" do
164
- subject.init
165
- assert_equal 1, subject.first_before_init_call_order
166
- assert_equal 2, subject.second_before_init_call_order
167
- assert_equal 3, subject.init_call_order
168
- assert_equal 4, subject.first_after_init_call_order
169
- assert_equal 5, subject.second_after_init_call_order
170
- end
171
-
172
- should "call `run!` and its before/after run callbacks using `run`" do
173
- subject.run
174
- assert_equal 1, subject.first_before_run_call_order
175
- assert_equal 2, subject.second_before_run_call_order
176
- assert_equal 3, subject.run_call_order
177
- assert_equal 4, subject.first_after_run_call_order
178
- assert_equal 5, subject.second_after_run_call_order
29
+ should "know its job, job name and job created at" do
30
+ assert_equal @runner.message, subject.public_job
31
+ assert_equal subject.public_job.name, subject.public_job_name
32
+ assert_equal subject.public_job.created_at, subject.public_job_created_at
179
33
  end
180
34
 
181
35
  should "have a custom inspect" do
182
36
  reference = '0x0%x' % (subject.object_id << 1)
183
- expected = "#<#{subject.class}:#{reference} " \
184
- "@job=#{@runner.job.inspect}>"
185
- assert_equal expected, subject.inspect
186
- end
187
-
188
- should "raise a not implemented error when `run!` by default" do
189
- assert_raises(NotImplementedError){ @handler_class.new(@runner).run! }
37
+ exp = "#<#{subject.class}:#{reference} " \
38
+ "@job=#{@handler.public_job.inspect}>"
39
+ assert_equal exp, subject.inspect
190
40
  end
191
41
 
192
42
  end
@@ -194,59 +44,16 @@ module Qs::JobHandler
194
44
  class TestJobHandler
195
45
  include Qs::JobHandler
196
46
 
197
- attr_reader :first_before_init_call_order, :second_before_init_call_order
198
- attr_reader :first_after_init_call_order, :second_after_init_call_order
199
- attr_reader :first_before_run_call_order, :second_before_run_call_order
200
- attr_reader :first_after_run_call_order, :second_after_run_call_order
201
- attr_reader :init_call_order, :run_call_order
202
-
203
- before_init{ @first_before_init_call_order = next_call_order }
204
- before_init{ @second_before_init_call_order = next_call_order }
205
-
206
- after_init{ @first_after_init_call_order = next_call_order }
207
- after_init{ @second_after_init_call_order = next_call_order }
208
-
209
- before_run{ @first_before_run_call_order = next_call_order }
210
- before_run{ @second_before_run_call_order = next_call_order }
211
-
212
- after_run{ @first_after_run_call_order = next_call_order }
213
- after_run{ @second_after_run_call_order = next_call_order }
214
-
215
- def init!
216
- @init_call_order = next_call_order
217
- end
218
-
219
- def run!
220
- @run_call_order = next_call_order
221
- end
222
-
223
- def public_job
224
- job
225
- end
226
-
227
- def public_params
228
- params
229
- end
230
-
231
- def public_logger
232
- logger
233
- end
234
-
235
- private
236
-
237
- def next_call_order
238
- @order ||= 0
239
- @order += 1
240
- end
47
+ def public_job; job; end
48
+ def public_job_name; job_name; end
49
+ def public_job_created_at; job_created_at; end
241
50
  end
242
51
 
243
52
  class FakeRunner
244
- attr_accessor :job, :params, :logger
53
+ attr_accessor :message
245
54
 
246
55
  def initialize
247
- @job = Factory.string
248
- @params = Factory.string
249
- @logger = Factory.string
56
+ @message = Factory.job
250
57
  end
251
58
  end
252
59