action_subscriber 2.5.0.pre2 → 3.0.0.pre1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/action_subscriber.gemspec +1 -0
  3. data/lib/action_subscriber/babou.rb +2 -29
  4. data/lib/action_subscriber/base.rb +0 -4
  5. data/lib/action_subscriber/bunny/subscriber.rb +14 -4
  6. data/lib/action_subscriber/configuration.rb +1 -11
  7. data/lib/action_subscriber/default_routing.rb +6 -4
  8. data/lib/action_subscriber/march_hare/subscriber.rb +14 -4
  9. data/lib/action_subscriber/message_retry.rb +1 -1
  10. data/lib/action_subscriber/middleware/env.rb +3 -1
  11. data/lib/action_subscriber/middleware/error_handler.rb +11 -4
  12. data/lib/action_subscriber/rabbit_connection.rb +23 -34
  13. data/lib/action_subscriber/route.rb +5 -1
  14. data/lib/action_subscriber/route_set.rb +12 -11
  15. data/lib/action_subscriber/router.rb +13 -2
  16. data/lib/action_subscriber/version.rb +1 -1
  17. data/lib/action_subscriber.rb +11 -24
  18. data/spec/integration/around_filters_spec.rb +1 -1
  19. data/spec/integration/at_least_once_spec.rb +1 -1
  20. data/spec/integration/at_most_once_spec.rb +1 -1
  21. data/spec/integration/automatic_reconnect_spec.rb +3 -4
  22. data/spec/integration/basic_subscriber_spec.rb +2 -2
  23. data/spec/integration/custom_actions_spec.rb +1 -1
  24. data/spec/integration/custom_headers_spec.rb +2 -2
  25. data/spec/integration/decoding_payloads_spec.rb +2 -2
  26. data/spec/integration/manual_acknowledgement_spec.rb +1 -1
  27. data/spec/integration/multiple_connections_spec.rb +36 -0
  28. data/spec/integration/multiple_threadpools_spec.rb +3 -3
  29. data/spec/lib/action_subscriber/configuration_spec.rb +1 -5
  30. data/spec/spec_helper.rb +7 -4
  31. metadata +18 -14
  32. data/lib/action_subscriber/publisher/async/in_memory_adapter.rb +0 -153
  33. data/lib/action_subscriber/publisher/async.rb +0 -31
  34. data/lib/action_subscriber/publisher.rb +0 -46
  35. data/lib/action_subscriber/synchronizer.rb +0 -15
  36. data/spec/integration/inferred_routes_spec.rb +0 -53
  37. data/spec/lib/action_subscriber/publisher/async/in_memory_adapter_spec.rb +0 -135
  38. data/spec/lib/action_subscriber/publisher/async_spec.rb +0 -40
  39. data/spec/lib/action_subscriber/publisher_spec.rb +0 -35
@@ -1,135 +0,0 @@
1
- describe ::ActionSubscriber::Publisher::Async::InMemoryAdapter do
2
- let(:route) { "test" }
3
- let(:payload) { "message" }
4
- let(:exchange_name) { "place" }
5
- let(:options) { { :test => :ok } }
6
- let(:message) { described_class::Message.new(route, payload, exchange_name, options) }
7
- let(:mock_queue) { double(:push => nil, :size => 0) }
8
-
9
- describe "#publish" do
10
- before do
11
- allow(described_class::Message).to receive(:new).with(route, payload, exchange_name, options).and_return(message)
12
- allow(described_class::AsyncQueue).to receive(:new).and_return(mock_queue)
13
- end
14
-
15
- it "can publish a message to the queue" do
16
- expect(mock_queue).to receive(:push).with(message)
17
- subject.publish(route, payload, exchange_name, options)
18
- end
19
- end
20
-
21
- describe "#shutdown!" do
22
- # This is called when the rspec finishes. I'm sure we can make this a better test.
23
- end
24
-
25
- describe "::ActionSubscriber::Publisher::Async::InMemoryAdapter::Message" do
26
- specify { expect(message.route).to eq(route) }
27
- specify { expect(message.payload).to eq(payload) }
28
- specify { expect(message.exchange_name).to eq(exchange_name) }
29
- specify { expect(message.options).to eq(options) }
30
- end
31
-
32
- describe "::ActionSubscriber::Publisher::Async::InMemoryAdapter::AsyncQueue" do
33
- subject { described_class::AsyncQueue.new }
34
-
35
- describe ".initialize" do
36
- it "creates a supervisor" do
37
- expect_any_instance_of(described_class::AsyncQueue).to receive(:create_and_supervise_consumer!)
38
- subject
39
- end
40
- end
41
-
42
- describe "#create_and_supervise_consumer!" do
43
- it "creates a supervisor" do
44
- expect_any_instance_of(described_class::AsyncQueue).to receive(:create_consumer)
45
- subject
46
- end
47
-
48
- it "restarts the consumer when it dies" do
49
- consumer = subject.consumer
50
- consumer.kill
51
-
52
- verify_expectation_within(0.1) do
53
- expect(consumer).to_not be_alive
54
- end
55
-
56
- verify_expectation_within(0.3) do
57
- expect(subject.consumer).to be_alive
58
- end
59
- end
60
- end
61
-
62
- describe "#create_consumer" do
63
- it "can successfully publish a message" do
64
- expect(::ActionSubscriber::Publisher).to receive(:publish).with(route, payload, exchange_name, options)
65
- subject.push(message)
66
- sleep 0.1 # Await results
67
- end
68
-
69
- context "when network error occurs" do
70
- let(:error) { described_class::AsyncQueue::NETWORK_ERRORS.first }
71
- before { allow(::ActionSubscriber::Publisher).to receive(:publish).and_raise(error) }
72
-
73
- it "requeues the message" do
74
- consumer = subject.consumer
75
- expect(consumer).to be_alive
76
- expect(subject).to receive(:await_network_reconnect).at_least(:once)
77
- subject.push(message)
78
- sleep 0.1 # Await results
79
- end
80
- end
81
-
82
- context "when an unknown error occurs" do
83
- before { allow(::ActionSubscriber::Publisher).to receive(:publish).and_raise(ArgumentError) }
84
-
85
- it "kills the consumer" do
86
- consumer = subject.consumer
87
- expect(consumer).to be_alive
88
- subject.push(message)
89
- sleep 0.1 # Await results
90
- expect(consumer).to_not be_alive
91
- end
92
- end
93
- end
94
-
95
- describe "#push" do
96
- after { ::ActionSubscriber.configuration.async_publisher_max_queue_size = 1000 }
97
- after { ::ActionSubscriber.configuration.async_publisher_drop_messages_when_queue_full = false }
98
-
99
- context "when the queue has room" do
100
- before { allow(::Queue).to receive(:new).and_return(mock_queue) }
101
-
102
- it "successfully adds to the queue" do
103
- expect(mock_queue).to receive(:push).with(message)
104
- subject.push(message)
105
- end
106
- end
107
-
108
- context "when the queue is full" do
109
- before { ::ActionSubscriber.configuration.async_publisher_max_queue_size = -1 }
110
-
111
- context "and we're dropping messages" do
112
- before { ::ActionSubscriber.configuration.async_publisher_drop_messages_when_queue_full = true }
113
-
114
- it "adding to the queue should not raise an error" do
115
- expect { subject.push(message) }.to_not raise_error
116
- end
117
- end
118
-
119
- context "and we're not dropping messages" do
120
- before { ::ActionSubscriber.configuration.async_publisher_drop_messages_when_queue_full = false }
121
-
122
- it "adding to the queue should raise error back to caller" do
123
- expect { subject.push(message) }.to raise_error(described_class::UnableToPersistMessageError)
124
- end
125
- end
126
- end
127
- end
128
-
129
- describe "#size" do
130
- it "can return the size of the queue" do
131
- expect(subject.size).to eq(0)
132
- end
133
- end
134
- end
135
- end
@@ -1,40 +0,0 @@
1
- describe ::ActionSubscriber::Publisher::Async do
2
-
3
- before { described_class.instance_variable_set(:@publisher_adapter, nil) }
4
- after { ::ActionSubscriber.configuration.async_publisher = "memory" }
5
-
6
- let(:mock_adapter) { double(:publish => nil) }
7
-
8
- describe ".publish_async" do
9
- before { allow(described_class).to receive(:publisher_adapter).and_return(mock_adapter) }
10
-
11
- it "calls through the adapter" do
12
- expect(mock_adapter).to receive(:publish).with("1", "2", "3", { "four" => "five" })
13
- ::ActionSubscriber::Publisher.publish_async("1", "2", "3", { "four" => "five" })
14
- end
15
- end
16
-
17
- context "when an in-memory adapter is selected" do
18
- before { ::ActionSubscriber.configuration.async_publisher = "memory" }
19
-
20
- it "Creates an in-memory publisher" do
21
- expect(described_class.publisher_adapter).to be_an(::ActionSubscriber::Publisher::Async::InMemoryAdapter)
22
- end
23
- end
24
-
25
- context "when an redis adapter is selected" do
26
- before { ::ActionSubscriber.configuration.async_publisher = "redis" }
27
-
28
- it "raises an error" do
29
- expect { described_class.publisher_adapter }.to raise_error("Not yet implemented")
30
- end
31
- end
32
-
33
- context "when some random adapter is selected" do
34
- before { ::ActionSubscriber.configuration.async_publisher = "yolo" }
35
-
36
- it "raises an error" do
37
- expect { described_class.publisher_adapter }.to raise_error("Unknown adapter 'yolo' provided")
38
- end
39
- end
40
- end
@@ -1,35 +0,0 @@
1
- describe ::ActionSubscriber::Publisher do
2
- let(:exchange) { double("Rabbit Exchange") }
3
- let(:exchange_name) { "events" }
4
- let(:payload) { "Yo Dawg" }
5
- let(:route) { "bob.users.created" }
6
-
7
- before { allow(described_class).to receive(:with_exchange).with(exchange_name).and_yield(exchange) }
8
-
9
- describe '.publish' do
10
-
11
- if ::RUBY_PLATFORM == "java"
12
- it "publishes to the exchange with default options for march_hare" do
13
- expect(exchange).to receive(:publish) do |published_payload, published_options|
14
- expect(published_payload).to eq(payload)
15
- expect(published_options[:routing_key]).to eq(route)
16
- expect(published_options[:mandatory]).to eq(false)
17
- expect(published_options[:properties][:persistent]).to eq(false)
18
- end
19
-
20
- described_class.publish(route, payload, exchange_name)
21
- end
22
- else
23
- it "publishes to the exchange with default options for bunny" do
24
- expect(exchange).to receive(:publish) do |published_payload, published_options|
25
- expect(published_payload).to eq(payload)
26
- expect(published_options[:routing_key]).to eq(route)
27
- expect(published_options[:persistent]).to eq(false)
28
- expect(published_options[:mandatory]).to eq(false)
29
- end
30
-
31
- described_class.publish(route, payload, exchange_name)
32
- end
33
- end
34
- end
35
- end