This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
forked from ruby-amqp/march_hare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange_declare_spec.rb
131 lines (92 loc) · 3.22 KB
/
exchange_declare_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
RSpec.describe "Direct exchange" do
let(:connection) { MarchHare.connect }
let(:channel) { connection.create_channel }
after :each do
channel.close
connection.close
end
it "can be declared" do
exchange = channel.exchange("march.hare.exchanges.direct1", :type => :direct)
queue = channel.queue("", :exclusive => true)
queue.bind(exchange, :routing_key => "abc")
exchange.publish("", :routing_key => "xyz")
exchange.publish("", :routing_key => "abc")
sleep(0.3)
mc, cc = queue.status
expect(mc).to eq(1)
end
end
RSpec.describe "Fanout exchange" do
let(:connection) { MarchHare.connect }
let(:channel) { connection.create_channel }
after :each do
channel.close
connection.close
end
it "can be declared" do
exchange = channel.exchange("march.hare.exchanges.fanout1", :type => :fanout)
expect(exchange).not_to be_internal
queue = channel.queue("", :exclusive => true)
queue.bind(exchange)
exchange.publish("")
exchange.publish("", :routing_key => "xyz")
exchange.publish("", :routing_key => "abc")
sleep(0.5)
mc, cc = queue.status
expect(mc).to eq(3)
end
end
RSpec.describe "Topic exchange" do
let(:connection) { MarchHare.connect }
let(:channel) { connection.create_channel }
after :each do
channel.close
connection.close
end
it "can be declared" do
exchange = channel.exchange("march.hare.exchanges.topic1", :type => :topic)
queue = channel.queue("", :exclusive => true)
queue.bind(exchange, :routing_key => "log.*")
exchange.publish("")
exchange.publish("", :routing_key => "accounts.signup")
exchange.publish("", :routing_key => "log.info")
exchange.publish("", :routing_key => "log.warn")
sleep(0.5)
mc, cc = queue.status
expect(mc).to eq(2)
end
end
RSpec.describe "Headers exchange" do
let(:connection) { MarchHare.connect }
let(:channel) { connection.create_channel }
after :each do
channel.close
connection.close
end
it "can be declared" do
exchange = channel.exchange("march.hare.exchanges.headers1", :type => :headers)
queue = channel.queue("", :exclusive => true)
queue.bind(exchange, :arguments => { 'x-match' => 'all', 'arch' => "x86_64", 'os' => "linux" })
exchange.publish "For linux/IA64", :properties => { :headers => { 'arch' => "x86_64", 'os' => 'linux' } }
exchange.publish "For linux/x86", :properties => { :headers => { 'arch' => "x86", 'os' => 'linux' } }
exchange.publish "For any linux", :properties => { :headers => { 'os' => 'linux' } }
exchange.publish "For OS X", :properties => { :headers => { 'os' => 'macosx' } }
exchange.publish "For solaris/IA64", :properties => { :headers => { 'os' => 'solaris', 'arch' => 'x86_64' } }
sleep(0.3)
mc, cc = queue.status
expect(mc).to eq(1)
end
end
RSpec.describe "Internal exchange" do
let(:connection) { MarchHare.connect }
let(:channel) { connection.create_channel }
after :each do
channel.close
connection.close
end
it "can be declared" do
exchange = channel.topic("march.hare.exchanges.topic.internal", :internal => true)
expect(exchange).to be_internal
exchange.delete
end
end