ElmerFudd 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c77507d5550d32879e421a33c9c667eceed1bb5
4
- data.tar.gz: 7016a77b2fd57fd16f022fd27867e2d68543f93c
3
+ metadata.gz: 6fc3cc1a95abd4ab256ec11a4ac3926ee326ee19
4
+ data.tar.gz: d9932a4afdfe4d8e1565c7db8960a9bd491af4c2
5
5
  SHA512:
6
- metadata.gz: e5e12979ea5778ac402d96698f5d5b73b116fabfc6c840a6ada53efdd2bfd8fed60283abd24a2de0d6c48b2516c897e1d360f93bf581c53cc05dea2a762298a2
7
- data.tar.gz: 7cfede537d36e38d866ca688d8c987327ccaf5765bf859e2078e68f69a732e5af8f7b5d7faa0282c3d9bfe7bd018522522852412e239ae533ec7efb123bf0ae7
6
+ metadata.gz: 1f555023cf6f2bd03d2f6fcb707247bceaa32f6e9be4e47d8fe51692d3c941884613b248e06b2386cd3b8d7312b6b887f41a1bf20ef7453c980d682c08db62e6
7
+ data.tar.gz: eb6ca5e463ffc71e9cecbd549c9a4a8d769f52206e7f06bc22de08f432d8f9cebcd6b1d79ecfbbb44e7a47718fcd83c625d07a25e5310fae7148154c09af5da5
@@ -1,3 +1,3 @@
1
1
  module ElmerFudd
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -7,6 +7,10 @@ module ElmerFudd
7
7
  class << self
8
8
  attr_writer :durable_queues
9
9
  def durable_queues; @durable_queues.nil? ? true : @durable_queues; end
10
+
11
+ # When set to true, every handler will receive a separate channel
12
+ attr_writer :single_channel
13
+ def single_channel; @single_channel.nil? ? true : @single_channel; end
10
14
  end
11
15
 
12
16
  def self.handlers
@@ -91,18 +95,23 @@ module ElmerFudd
91
95
  end
92
96
 
93
97
  def env
94
- @env ||= Env.new(channel, @logger, self.class)
98
+ self.class.single_channel ? @env ||= new_env : new_env
99
+ end
100
+
101
+ def new_env
102
+ Env.new(new_channel, @logger, self.class)
95
103
  end
96
104
 
97
105
  def connection
98
106
  @connection.tap { |c| c.start unless c.connected? }
99
107
  end
100
108
 
101
- def channel
102
- @channel ||= connection.create_channel
103
- @channel.recover_cancelled_consumers!
104
- @channel.tap do |c|
105
- c.prefetch(@concurrency)
109
+ def new_channel
110
+ connection.create_channel.tap do |channel|
111
+ channel.recover_cancelled_consumers!
112
+ channel.tap do |c|
113
+ c.prefetch(@concurrency)
114
+ end
106
115
  end
107
116
  end
108
117
  end
@@ -27,7 +27,7 @@ class CastTest < MiniTest::Test
27
27
  @publisher.cast TEST_QUEUE, message: "hello"
28
28
 
29
29
  Timeout.timeout(0.5) do
30
- assert "hello", $responses.pop
30
+ assert_equal "hello", $responses.pop
31
31
  end
32
32
  end
33
33
 
@@ -45,7 +45,7 @@ class CastTest < MiniTest::Test
45
45
  @publisher.cast TEST_QUEUE, message: "hello2"
46
46
 
47
47
  Timeout.timeout(0.5) do
48
- assert "hello2", $responses.pop
48
+ assert_equal "hello2", $responses.pop
49
49
  end
50
50
  end
51
51
 
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class SingleChannelTest < MiniTest::Test
4
+ include RabbitHelper
5
+ TEST_QUEUE = "test.ElmerFudd.cast"
6
+ TEST_QUEUE_2 = "test.ElmerFudd.cast"
7
+
8
+ class TestWorker < ElmerFudd::Worker
9
+ default_filters ElmerFudd::JsonFilter
10
+ self.single_channel = false
11
+
12
+ handle_cast(Route(TEST_QUEUE)) do |_env, message|
13
+ if delay = message.payload["delay"]
14
+ sleep delay
15
+ end
16
+
17
+ $responses << message.payload["message"]
18
+ end
19
+
20
+ handle_cast(Route(TEST_QUEUE_2)) do |_env, message|
21
+ if delay = message.payload["delay"]
22
+ sleep delay
23
+ end
24
+
25
+ $responses << message.payload["message"]
26
+ end
27
+ end
28
+
29
+ def teardown
30
+ remove_queue TEST_QUEUE
31
+ remove_queue TEST_QUEUE_2
32
+ super
33
+ end
34
+
35
+ def test_basic_cast
36
+ start_worker TestWorker
37
+ @publisher.cast TEST_QUEUE, message: "hello1", delay: 0.9
38
+ @publisher.cast TEST_QUEUE_2, message: "hello2", delay: 0.9
39
+
40
+ Timeout.timeout(1) do
41
+ assert_equal %w(hello1 hello2), [$responses.pop, $responses.pop].sort
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ElmerFudd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrzej Sliwa
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-09 00:00:00.000000000 Z
12
+ date: 2016-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bunny
@@ -121,6 +121,7 @@ files:
121
121
  - test/smoke/cast_test.rb
122
122
  - test/smoke/event_test.rb
123
123
  - test/smoke/external_handlers_test.rb
124
+ - test/smoke/single_channel_test.rb
124
125
  - test/test_helper.rb
125
126
  - test/unit/benchmark_filter_test.rb
126
127
  homepage: https://github.com/bonusboxme/ElmerFudd
@@ -152,5 +153,6 @@ test_files:
152
153
  - test/smoke/cast_test.rb
153
154
  - test/smoke/event_test.rb
154
155
  - test/smoke/external_handlers_test.rb
156
+ - test/smoke/single_channel_test.rb
155
157
  - test/test_helper.rb
156
158
  - test/unit/benchmark_filter_test.rb