philotic 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -1
  3. data/Gemfile +0 -7
  4. data/README.md +2 -0
  5. data/Rakefile +1 -1
  6. data/examples/README.md +1 -1
  7. data/examples/creating_named_queues/manually.rb +8 -21
  8. data/examples/creating_named_queues/with_rake.rb +2 -2
  9. data/examples/publishing/publish.rb +26 -33
  10. data/examples/subscribing/acks.rb +25 -0
  11. data/examples/subscribing/anonymous_queue.rb +6 -10
  12. data/examples/subscribing/multiple_named_queues.rb +9 -24
  13. data/examples/subscribing/named_queue.rb +7 -17
  14. data/lib/philotic.rb +37 -81
  15. data/lib/philotic/config.rb +63 -24
  16. data/lib/philotic/connection.rb +35 -51
  17. data/lib/philotic/constants.rb +49 -0
  18. data/lib/philotic/event.rb +27 -14
  19. data/lib/philotic/logging.rb +8 -0
  20. data/lib/philotic/logging/event.rb +18 -0
  21. data/lib/philotic/logging/logger.rb +39 -0
  22. data/lib/philotic/publisher.rb +28 -31
  23. data/lib/philotic/routable.rb +40 -40
  24. data/lib/philotic/subscriber.rb +61 -42
  25. data/lib/philotic/tasks/init_queues.rb +4 -14
  26. data/lib/philotic/version.rb +1 -1
  27. data/philotic.gemspec +21 -10
  28. data/spec/philotic/config_spec.rb +40 -0
  29. data/spec/philotic/connection_spec.rb +58 -0
  30. data/spec/philotic/event_spec.rb +69 -0
  31. data/spec/philotic/logging/logger_spec.rb +26 -0
  32. data/spec/philotic/publisher_spec.rb +99 -0
  33. data/spec/{routable_spec.rb → philotic/routable_spec.rb} +15 -14
  34. data/spec/philotic/subscriber_spec.rb +111 -0
  35. data/spec/philotic_spec.rb +66 -0
  36. data/spec/spec_helper.rb +12 -4
  37. data/tasks/bump.rake +10 -10
  38. metadata +173 -36
  39. data/spec/connection_spec.rb +0 -19
  40. data/spec/event_spec.rb +0 -44
  41. data/spec/publisher_spec.rb +0 -102
  42. data/spec/subscriber_spec.rb +0 -72
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Philotic::Connection do
4
- let(:connection){ Philotic::Connection }
5
- subject { connection }
6
-
7
- describe "config" do
8
- it "should return the Philotic::Config singleton" do
9
- subject.config.should == Philotic::Config
10
- end
11
- end
12
-
13
- describe "exchange" do
14
- #TODO make sure rabbit is running for CI to run this
15
- xit "should return an instance of AMQP::Exchange" do
16
- subject.exchange.should be_a AMQP::Exchange
17
- end
18
- end
19
- end
data/spec/event_spec.rb DELETED
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # create 'deep' inheritance to test self.inherited
4
- class TestEventParent < Philotic::Event
5
- end
6
- class TestEvent < TestEventParent
7
- end
8
-
9
- describe Philotic::Event do
10
- let(:event){ TestEvent.new }
11
- subject { event }
12
-
13
- Philotic::Routable::ClassMethods.instance_methods.sort.each do |method_name|
14
- specify { subject.class.methods.should include method_name.to_sym }
15
- end
16
-
17
- Philotic::MESSAGE_OPTIONS.each do |method_name|
18
- specify { subject.methods.should include method_name.to_sym }
19
- specify { subject.methods.should include "#{method_name}=".to_sym }
20
- end
21
-
22
- Philotic::PHILOTIC_HEADERS.each do |method_name|
23
- specify { subject.methods.should include method_name.to_sym }
24
- specify { subject.methods.should include "#{method_name}=".to_sym }
25
- end
26
-
27
- describe "message_metadata" do
28
- it "should have a timestamp" do
29
- Timecop.freeze
30
- subject.message_metadata.should == {timestamp: Time.now.to_i}
31
- end
32
-
33
- it "should reflect changes in the event properties" do
34
- subject.message_metadata[:app_id]. should == nil
35
- subject.app_id = 'ANSIBLE'
36
- subject.message_metadata[:app_id]. should == 'ANSIBLE'
37
- end
38
- end
39
- describe "headers" do
40
- it "should include :philotic_product" do
41
- subject.headers.keys.should include :philotic_product
42
- end
43
- end
44
- end
@@ -1,102 +0,0 @@
1
- require 'spec_helper'
2
- require 'philotic/dummy_event'
3
-
4
- describe Philotic::Publisher do
5
- before(:each) do
6
- @event = Philotic::DummyEvent.new
7
- @event.subject = "Hello"
8
- @event.message = "How are you?"
9
- @event.gender = :M
10
- @event.available = true
11
- end
12
- let(:publisher) { Philotic::Publisher }
13
- subject { publisher }
14
-
15
- describe "config" do
16
- it "should return the Philotic::Config singleton" do
17
- subject.config.should == Philotic::Config
18
- end
19
- end
20
-
21
- describe "exchange" do
22
- #TODO make sure rabbit is running for CI to run this
23
- xit "should return an instance of AMQP::Exchange" do
24
- subject.exchange.should be_a AMQP::Exchange
25
- end
26
- end
27
-
28
- describe "publish" do
29
- it "should call raw_publish with the right values" do
30
- Timecop.freeze
31
- subject.should_receive(:raw_publish).with(
32
- {
33
- subject: 'Hello',
34
- message: "How are you?"
35
- },
36
- {
37
- headers: {
38
- philotic_firehose: true,
39
- philotic_product: nil,
40
- philotic_component: nil,
41
- philotic_event_type: nil,
42
- gender: :M,
43
- available: true
44
- },
45
- timestamp: Time.now.to_i
46
- }
47
- )
48
- subject.publish(@event)
49
- end
50
-
51
- end
52
-
53
- describe "raw_publish" do
54
-
55
- xit "should call exchange.publish with the right values" do
56
- Timecop.freeze
57
- Philotic::Connection.instance.should_receive(:connected?).and_return { true }
58
-
59
- AMQP::Exchange.any_instance.should_receive(:publish).with(
60
- {
61
- subject: 'Hello',
62
- message: "How are you?"
63
- }.to_json,
64
- {
65
- routing_key: nil,
66
- persistent: true,
67
- mandatory: true,
68
- content_type: nil,
69
- content_encoding: nil,
70
- priority: nil,
71
- message_id: nil,
72
- correlation_id: nil,
73
- reply_to: nil,
74
- type: nil,
75
- user_id: nil,
76
- app_id: nil,
77
- expiration: nil,
78
- headers: {
79
- philotic_firehose: true,
80
- philotic_product: nil,
81
- philotic_component: nil,
82
- philotic_event_type: nil,
83
- gender: :M,
84
- available: true
85
- },
86
- timestamp: Time.now.to_i
87
- }
88
- )
89
- subject.publish(@event)
90
- end
91
-
92
- xit "should log an error when there is no connection" do
93
-
94
- 4.times do
95
- Philotic::Connection.instance.should_receive(:connected?).and_return { false }
96
- end
97
- Philotic.logger.should_receive(:error)
98
- subject.publish(@event)
99
- end
100
-
101
- end
102
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
- require 'philotic/dummy_event'
3
-
4
- describe Philotic::Subscriber do
5
- let(:subscriber) do
6
- subscriber = Philotic::Subscriber.new(arguments: {'x-match' => 'any', philotic_firehose: true}) do |metadata, payload|
7
- true
8
- end
9
- subscriber
10
- end
11
-
12
- describe "subscribe" do
13
- xit "should call AMQP.channel.queue with the right values" do
14
- queue = double(AMQP::Queue)
15
- queue.stub(:bind) { queue }
16
- queue.stub(:subscribe) { queue }
17
- channel = double(AMQP::Channel)
18
- exchange = double(AMQP::Exchange)
19
- channel.stub(:queue) { queue }
20
- channel.stub(:headers) { exchange }
21
- AMQP.stub(:channel) { channel }
22
-
23
- channel.should_receive(:queue).with("", {auto_delete: true, durable: false})
24
- queue.should_receive(:bind).with(exchange, {arguments: {"x-match" => "any", philotic_firehose: true}})
25
- queue.should_receive(:subscribe).with({})
26
- Philotic::Subscriber.subscribe(arguments: {'x-match' => 'any', philotic_firehose: true}) do |metadata, payload|
27
- true
28
- end
29
- end
30
- end
31
-
32
- describe "subscribe_to_any_of" do
33
- xit "should call AMQP.channel.queue with the right values" do
34
- queue = double(AMQP::Queue)
35
- queue.stub(:bind) { queue }
36
- queue.stub(:subscribe) { queue }
37
- channel = double(AMQP::Channel)
38
- exchange = double(AMQP::Exchange)
39
- channel.stub(:queue) { queue }
40
- channel.stub(:headers) { exchange }
41
- AMQP.stub(:channel) { channel }
42
-
43
- channel.should_receive(:queue).with("", {auto_delete: true, durable: false})
44
- queue.should_receive(:bind).with(exchange, {arguments: {"x-match" => "any", philotic_firehose: true}})
45
- queue.should_receive(:subscribe).with({})
46
- Philotic::Subscriber.subscribe_to_any_of(arguments: {philotic_firehose: true}) do |metadata, payload|
47
- true
48
- end
49
- end
50
- end
51
-
52
- describe "subscribe_to_all_of" do
53
- xit "should call AMQP.channel.queue with the right values" do
54
- queue = double(AMQP::Queue)
55
- queue.stub(:bind) { queue }
56
- queue.stub(:subscribe) { queue }
57
- channel = double(AMQP::Channel)
58
- exchange = double(AMQP::Exchange)
59
- channel.stub(:queue) { queue }
60
- channel.stub(:headers) { exchange }
61
- AMQP.stub(:channel) { channel }
62
-
63
- channel.should_receive(:queue).with("", {auto_delete: true, durable: false})
64
- queue.should_receive(:bind).with(exchange, {arguments: {"x-match" => "all", philotic_firehose: true}})
65
- queue.should_receive(:subscribe).with({})
66
- Philotic::Subscriber.subscribe_to_all_of(arguments: {philotic_firehose: true}) do |metadata, payload|
67
- true
68
- end
69
- end
70
- end
71
-
72
- end