queue-bus 0.5.9 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +16 -0
- data/lib/queue-bus.rb +2 -1
- data/lib/queue_bus/config.rb +4 -0
- data/lib/queue_bus/middleware.rb +54 -0
- data/lib/queue_bus/version.rb +1 -1
- data/lib/queue_bus/worker.rb +3 -1
- data/spec/adapter/publish_at_spec.rb +10 -10
- data/spec/adapter_spec.rb +2 -2
- data/spec/application_spec.rb +48 -48
- data/spec/config_spec.rb +18 -18
- data/spec/dispatch_spec.rb +13 -13
- data/spec/driver_spec.rb +30 -30
- data/spec/heartbeat_spec.rb +3 -3
- data/spec/integration_spec.rb +23 -23
- data/spec/matcher_spec.rb +70 -70
- data/spec/middleware_spec.rb +112 -0
- data/spec/publish_spec.rb +20 -20
- data/spec/rider_spec.rb +7 -7
- data/spec/spec_helper.rb +2 -2
- data/spec/subscriber_spec.rb +98 -98
- data/spec/subscription_list_spec.rb +15 -15
- data/spec/subscription_spec.rb +17 -17
- data/spec/worker_spec.rb +30 -25
- metadata +7 -3
data/spec/dispatch_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module QueueBus
|
4
4
|
describe Dispatch do
|
5
5
|
it "should not start with any applications" do
|
6
|
-
Dispatch.new("d").subscriptions.size.
|
6
|
+
expect(Dispatch.new("d").subscriptions.size).to eq(0)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should register code to run and execute it" do
|
@@ -12,19 +12,19 @@ module QueueBus
|
|
12
12
|
Runner1.run(attrs)
|
13
13
|
end
|
14
14
|
sub = dispatch.subscriptions.key("my_event")
|
15
|
-
sub.send(:executor).is_a?(Proc).
|
15
|
+
expect(sub.send(:executor).is_a?(Proc)).to eq(true)
|
16
16
|
|
17
|
-
Runner.value.
|
17
|
+
expect(Runner.value).to eq(0)
|
18
18
|
dispatch.execute("my_event", {"bus_event_type" => "my_event", "ok" => true})
|
19
|
-
Runner1.value.
|
20
|
-
Runner1.attributes.
|
19
|
+
expect(Runner1.value).to eq(1)
|
20
|
+
expect(Runner1.attributes).to eq({"bus_event_type" => "my_event", "ok" => true})
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should not crash if not there" do
|
25
|
-
|
25
|
+
expect {
|
26
26
|
Dispatch.new("d").execute("fdkjh", "bus_event_type" => "fdkjh")
|
27
|
-
}.
|
27
|
+
}.not_to raise_error
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "Top Level" do
|
@@ -49,24 +49,24 @@ module QueueBus
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should register and run" do
|
52
|
-
Runner2.value.
|
52
|
+
expect(Runner2.value).to eq(0)
|
53
53
|
QueueBus.dispatcher_execute("testit", "event2", "bus_event_type" => "event2")
|
54
|
-
Runner2.value.
|
54
|
+
expect(Runner2.value).to eq(1)
|
55
55
|
QueueBus.dispatcher_execute("testit", "event1", "bus_event_type" => "event1")
|
56
|
-
Runner2.value.
|
56
|
+
expect(Runner2.value).to eq(2)
|
57
57
|
QueueBus.dispatcher_execute("testit", "event1", "bus_event_type" => "event1")
|
58
|
-
Runner2.value.
|
58
|
+
expect(Runner2.value).to eq(3)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return the subscriptions" do
|
62
62
|
dispatcher = QueueBus.dispatcher_by_key("testit")
|
63
63
|
subs = dispatcher.subscriptions.all
|
64
64
|
tuples = subs.collect{ |sub| [sub.key, sub.queue_name]}
|
65
|
-
tuples.
|
65
|
+
expect(tuples).to match_array([ ["event1", "testit_default"],
|
66
66
|
["event2", "testit_default"],
|
67
67
|
["event3", "testit_high"],
|
68
68
|
[ "(?-mix:^patt.+ern)", "testit_low"]
|
69
|
-
]
|
69
|
+
])
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
data/spec/driver_spec.rb
CHANGED
@@ -16,21 +16,21 @@ module QueueBus
|
|
16
16
|
|
17
17
|
describe ".subscription_matches" do
|
18
18
|
it "return empty array when none" do
|
19
|
-
Driver.subscription_matches("bus_event_type" => "else").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
20
|
-
Driver.subscription_matches("bus_event_type" => "event").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
19
|
+
expect(Driver.subscription_matches("bus_event_type" => "else").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
|
20
|
+
expect(Driver.subscription_matches("bus_event_type" => "event").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
|
21
21
|
end
|
22
22
|
it "should return a match" do
|
23
|
-
Driver.subscription_matches("bus_event_type" => "event1").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
24
|
-
Driver.subscription_matches("bus_event_type" => "event6").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
23
|
+
expect(Driver.subscription_matches("bus_event_type" => "event1").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app1", "event1", "default", "::QueueBus::Rider"]])
|
24
|
+
expect(Driver.subscription_matches("bus_event_type" => "event6").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app3", "event6", "default", "::QueueBus::Rider"]])
|
25
25
|
end
|
26
26
|
it "should match multiple apps" do
|
27
|
-
Driver.subscription_matches("bus_event_type" => "event2").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
27
|
+
expect(Driver.subscription_matches("bus_event_type" => "event2").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app1", "event2", "default", "::QueueBus::Rider"], ["app2", "event2", "other", "::QueueBus::Rider"]])
|
28
28
|
end
|
29
29
|
it "should match multiple apps with patterns" do
|
30
|
-
Driver.subscription_matches("bus_event_type" => "event4").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
30
|
+
expect(Driver.subscription_matches("bus_event_type" => "event4").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app3", "event[45]", "default", "::QueueBus::Rider"], ["app2", "event4", "more", "::QueueBus::Rider"]])
|
31
31
|
end
|
32
32
|
it "should match multiple events in same app" do
|
33
|
-
Driver.subscription_matches("bus_event_type" => "event5").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
33
|
+
expect(Driver.subscription_matches("bus_event_type" => "event5").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["app3", "event[45]", "default", "::QueueBus::Rider"], ["app3", "event5", "default", "::QueueBus::Rider"]])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,48 +38,48 @@ module QueueBus
|
|
38
38
|
let(:attributes) { {"x" => "y", "bus_class_proxy" => "ResqueBus::Driver"} }
|
39
39
|
|
40
40
|
before(:each) do
|
41
|
-
QueueBus.redis { |redis| redis.smembers("queues") }.
|
42
|
-
QueueBus.redis { |redis| redis.lpop("queue:app1_default") }.
|
43
|
-
QueueBus.redis { |redis| redis.lpop("queue:app2_default") }.
|
44
|
-
QueueBus.redis { |redis| redis.lpop("queue:app3_default") }.
|
41
|
+
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to eq([])
|
42
|
+
expect(QueueBus.redis { |redis| redis.lpop("queue:app1_default") }).to be_nil
|
43
|
+
expect(QueueBus.redis { |redis| redis.lpop("queue:app2_default") }).to be_nil
|
44
|
+
expect(QueueBus.redis { |redis| redis.lpop("queue:app3_default") }).to be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should do nothing when empty" do
|
48
48
|
Driver.perform(attributes.merge("bus_event_type" => "else"))
|
49
|
-
QueueBus.redis { |redis| redis.smembers("queues") }.
|
49
|
+
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to eq([])
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should queue up the riders in redis" do
|
53
|
-
QueueBus.redis { |redis| redis.lpop("queue:app1_default") }.
|
53
|
+
expect(QueueBus.redis { |redis| redis.lpop("queue:app1_default") }).to be_nil
|
54
54
|
Driver.perform(attributes.merge("bus_event_type" => "event1"))
|
55
|
-
QueueBus.redis { |redis| redis.smembers("queues") }.
|
55
|
+
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["default"])
|
56
56
|
|
57
57
|
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
58
|
-
hash["class"].
|
59
|
-
hash["args"].size.
|
60
|
-
JSON.parse(hash["args"].first).
|
58
|
+
expect(hash["class"]).to eq("QueueBus::Worker")
|
59
|
+
expect(hash["args"].size).to eq(1)
|
60
|
+
expect(JSON.parse(hash["args"].first)).to eq({"bus_rider_app_key"=>"app1", "x" => "y", "bus_event_type" => "event1", "bus_rider_sub_key"=>"event1", "bus_rider_queue" => "default"}.merge(bus_attrs))
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should queue up to multiple" do
|
64
64
|
Driver.perform(attributes.merge("bus_event_type" => "event4"))
|
65
|
-
QueueBus.redis { |redis| redis.smembers("queues") }.
|
65
|
+
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["default", "more"])
|
66
66
|
|
67
67
|
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:more") })
|
68
|
-
hash["class"].
|
69
|
-
hash["args"].size.
|
70
|
-
JSON.parse(hash["args"].first).
|
68
|
+
expect(hash["class"]).to eq("QueueBus::Worker")
|
69
|
+
expect(hash["args"].size).to eq(1)
|
70
|
+
expect(JSON.parse(hash["args"].first)).to eq({"bus_rider_app_key"=>"app2", "x" => "y", "bus_event_type" => "event4", "bus_rider_sub_key"=>"event4", "bus_rider_queue" => "more"}.merge(bus_attrs))
|
71
71
|
|
72
72
|
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
73
|
-
hash["class"].
|
74
|
-
hash["args"].size.
|
75
|
-
JSON.parse(hash["args"].first).
|
73
|
+
expect(hash["class"]).to eq("QueueBus::Worker")
|
74
|
+
expect(hash["args"].size).to eq(1)
|
75
|
+
expect(JSON.parse(hash["args"].first)).to eq({"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event4", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs))
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should queue up to the same" do
|
79
79
|
Driver.perform(attributes.merge("bus_event_type" => "event5"))
|
80
|
-
QueueBus.redis { |redis| redis.smembers("queues") }.
|
80
|
+
expect(QueueBus.redis { |redis| redis.smembers("queues") }).to match_array(["default"])
|
81
81
|
|
82
|
-
QueueBus.redis { |redis| redis.llen("queue:default") }.
|
82
|
+
expect(QueueBus.redis { |redis| redis.llen("queue:default") }).to eq(2)
|
83
83
|
|
84
84
|
pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
85
85
|
pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
@@ -98,11 +98,11 @@ module QueueBus
|
|
98
98
|
args2 = pargs1
|
99
99
|
end
|
100
100
|
|
101
|
-
hash1["class"].
|
102
|
-
args1.
|
101
|
+
expect(hash1["class"]).to eq("QueueBus::Worker")
|
102
|
+
expect(args1).to eq({"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event5", "bus_rider_queue" => "default"}.merge(bus_attrs))
|
103
103
|
|
104
|
-
hash2["class"].
|
105
|
-
args2.
|
104
|
+
expect(hash2["class"]).to eq("QueueBus::Worker")
|
105
|
+
expect(args2).to eq({"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs))
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
data/spec/heartbeat_spec.rb
CHANGED
@@ -20,7 +20,7 @@ module QueueBus
|
|
20
20
|
|
21
21
|
it "should publish the current time once" do
|
22
22
|
Timecop.freeze "12/12/2013 12:01:19" do
|
23
|
-
QueueBus.
|
23
|
+
expect(QueueBus).to receive(:publish).with("heartbeat_minutes", now_attributes)
|
24
24
|
Heartbeat.perform
|
25
25
|
end
|
26
26
|
|
@@ -31,12 +31,12 @@ module QueueBus
|
|
31
31
|
|
32
32
|
it "should publish a minute later" do
|
33
33
|
Timecop.freeze "12/12/2013 12:01:19" do
|
34
|
-
QueueBus.
|
34
|
+
expect(QueueBus).to receive(:publish).with("heartbeat_minutes", now_attributes)
|
35
35
|
Heartbeat.perform
|
36
36
|
end
|
37
37
|
|
38
38
|
Timecop.freeze "12/12/2013 12:02:01" do
|
39
|
-
QueueBus.
|
39
|
+
expect(QueueBus).to receive(:publish).with("heartbeat_minutes", now_attributes)
|
40
40
|
Heartbeat.perform
|
41
41
|
end
|
42
42
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -6,15 +6,15 @@ module QueueBus
|
|
6
6
|
write1 = Subscription.new("default", "key1", "MyClass1", {"bus_event_type" => "event_one"})
|
7
7
|
write2 = Subscription.new("else_ok", "key2", "MyClass2", {"bus_event_type" => /^[ab]here/}) #regex
|
8
8
|
|
9
|
-
write1.matches?("bus_event_type" => "event_one").
|
10
|
-
write1.matches?("bus_event_type" => "event_one1").
|
11
|
-
write1.matches?("bus_event_type" => "aevent_one").
|
9
|
+
expect(write1.matches?("bus_event_type" => "event_one")).to eq(true)
|
10
|
+
expect(write1.matches?("bus_event_type" => "event_one1")).to eq(false)
|
11
|
+
expect(write1.matches?("bus_event_type" => "aevent_one")).to eq(false)
|
12
12
|
|
13
|
-
write2.matches?("bus_event_type" => "ahere").
|
14
|
-
write2.matches?("bus_event_type" => "bhere").
|
15
|
-
write2.matches?("bus_event_type" => "qhere").
|
16
|
-
write2.matches?("bus_event_type" => "abhere").
|
17
|
-
write2.matches?("bus_event_type" => "[ab]here").
|
13
|
+
expect(write2.matches?("bus_event_type" => "ahere")).to eq(true)
|
14
|
+
expect(write2.matches?("bus_event_type" => "bhere")).to eq(true)
|
15
|
+
expect(write2.matches?("bus_event_type" => "qhere")).to eq(false)
|
16
|
+
expect(write2.matches?("bus_event_type" => "abhere")).to eq(false)
|
17
|
+
expect(write2.matches?("bus_event_type" => "[ab]here")).to eq(false)
|
18
18
|
|
19
19
|
write = SubscriptionList.new
|
20
20
|
write.add(write1)
|
@@ -27,26 +27,26 @@ module QueueBus
|
|
27
27
|
app = Application.new("test")
|
28
28
|
read = app.send(:subscriptions)
|
29
29
|
|
30
|
-
read.size.
|
30
|
+
expect(read.size).to eq(2)
|
31
31
|
read1 = read.key("key1")
|
32
32
|
read2 = read.key("key2")
|
33
|
-
read1.
|
34
|
-
read2.
|
33
|
+
expect(read1).not_to be_nil
|
34
|
+
expect(read2).not_to be_nil
|
35
35
|
|
36
|
-
read1.queue_name.
|
37
|
-
read1.class_name.
|
38
|
-
read2.queue_name.
|
39
|
-
read2.class_name.
|
36
|
+
expect(read1.queue_name).to eq("default")
|
37
|
+
expect(read1.class_name).to eq("MyClass1")
|
38
|
+
expect(read2.queue_name).to eq("else_ok")
|
39
|
+
expect(read2.class_name).to eq("MyClass2")
|
40
40
|
|
41
|
-
read1.matches?("bus_event_type" => "event_one").
|
42
|
-
read1.matches?("bus_event_type" => "event_one1").
|
43
|
-
read1.matches?("bus_event_type" => "aevent_one").
|
41
|
+
expect(read1.matches?("bus_event_type" => "event_one")).to eq(true)
|
42
|
+
expect(read1.matches?("bus_event_type" => "event_one1")).to eq(false)
|
43
|
+
expect(read1.matches?("bus_event_type" => "aevent_one")).to eq(false)
|
44
44
|
|
45
|
-
read2.matches?("bus_event_type" => "ahere").
|
46
|
-
read2.matches?("bus_event_type" => "bhere").
|
47
|
-
read2.matches?("bus_event_type" => "qhere").
|
48
|
-
read2.matches?("bus_event_type" => "abhere").
|
49
|
-
read2.matches?("bus_event_type" => "[ab]here").
|
45
|
+
expect(read2.matches?("bus_event_type" => "ahere")).to eq(true)
|
46
|
+
expect(read2.matches?("bus_event_type" => "bhere")).to eq(true)
|
47
|
+
expect(read2.matches?("bus_event_type" => "qhere")).to eq(false)
|
48
|
+
expect(read2.matches?("bus_event_type" => "abhere")).to eq(false)
|
49
|
+
expect(read2.matches?("bus_event_type" => "[ab]here")).to eq(false)
|
50
50
|
|
51
51
|
end
|
52
52
|
end
|
data/spec/matcher_spec.rb
CHANGED
@@ -4,140 +4,140 @@ module QueueBus
|
|
4
4
|
describe Matcher do
|
5
5
|
it "should already return false on empty filters" do
|
6
6
|
matcher = Matcher.new({})
|
7
|
-
matcher.matches?({}).
|
8
|
-
matcher.matches?(nil).
|
9
|
-
matcher.matches?("name" => "val").
|
7
|
+
expect(matcher.matches?({})).to eq(false)
|
8
|
+
expect(matcher.matches?(nil)).to eq(false)
|
9
|
+
expect(matcher.matches?("name" => "val")).to eq(false)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should not crash if nil inputs" do
|
13
13
|
matcher = Matcher.new("name" => "val")
|
14
|
-
matcher.matches?(nil).
|
14
|
+
expect(matcher.matches?(nil)).to eq(false)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "string filter to/from redis" do
|
18
18
|
matcher = Matcher.new("name" => "val")
|
19
|
-
matcher.matches?("name" => "val").
|
20
|
-
matcher.matches?("name" => " val").
|
21
|
-
matcher.matches?("name" => "zval").
|
19
|
+
expect(matcher.matches?("name" => "val")).to eq(true)
|
20
|
+
expect(matcher.matches?("name" => " val")).to eq(false)
|
21
|
+
expect(matcher.matches?("name" => "zval")).to eq(false)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "regex filter" do
|
25
25
|
matcher = Matcher.new("name" => /^[cb]a+t/)
|
26
|
-
matcher.matches?("name" => "cat").
|
27
|
-
matcher.matches?("name" => "bat").
|
28
|
-
matcher.matches?("name" => "caaaaat").
|
29
|
-
matcher.matches?("name" => "ct").
|
30
|
-
matcher.matches?("name" => "bcat").
|
26
|
+
expect(matcher.matches?("name" => "cat")).to eq(true)
|
27
|
+
expect(matcher.matches?("name" => "bat")).to eq(true)
|
28
|
+
expect(matcher.matches?("name" => "caaaaat")).to eq(true)
|
29
|
+
expect(matcher.matches?("name" => "ct")).to eq(false)
|
30
|
+
expect(matcher.matches?("name" => "bcat")).to eq(false)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "present filter" do
|
34
34
|
matcher = Matcher.new("name" => :present)
|
35
|
-
matcher.matches?("name" => "").
|
36
|
-
matcher.matches?("name" => "cat").
|
37
|
-
matcher.matches?("name" => "bear").
|
38
|
-
matcher.matches?("other" => "bear").
|
35
|
+
expect(matcher.matches?("name" => "")).to eq(false)
|
36
|
+
expect(matcher.matches?("name" => "cat")).to eq(true)
|
37
|
+
expect(matcher.matches?("name" => "bear")).to eq(true)
|
38
|
+
expect(matcher.matches?("other" => "bear")).to eq(false)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "blank filter" do
|
42
42
|
matcher = Matcher.new("name" => :blank)
|
43
|
-
matcher.matches?("name" => nil).
|
44
|
-
matcher.matches?("other" => "bear").
|
45
|
-
matcher.matches?("name" => "").
|
46
|
-
matcher.matches?("name" => " ").
|
47
|
-
matcher.matches?("name" => "bear").
|
48
|
-
matcher.matches?("name" => " s ").
|
43
|
+
expect(matcher.matches?("name" => nil)).to eq(true)
|
44
|
+
expect(matcher.matches?("other" => "bear")).to eq(true)
|
45
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
46
|
+
expect(matcher.matches?("name" => " ")).to eq(true)
|
47
|
+
expect(matcher.matches?("name" => "bear")).to eq(false)
|
48
|
+
expect(matcher.matches?("name" => " s ")).to eq(false)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "nil filter" do
|
52
52
|
matcher = Matcher.new("name" => :nil)
|
53
|
-
matcher.matches?("name" => nil).
|
54
|
-
matcher.matches?("other" => "bear").
|
55
|
-
matcher.matches?("name" => "").
|
56
|
-
matcher.matches?("name" => " ").
|
57
|
-
matcher.matches?("name" => "bear").
|
53
|
+
expect(matcher.matches?("name" => nil)).to eq(true)
|
54
|
+
expect(matcher.matches?("other" => "bear")).to eq(true)
|
55
|
+
expect(matcher.matches?("name" => "")).to eq(false)
|
56
|
+
expect(matcher.matches?("name" => " ")).to eq(false)
|
57
|
+
expect(matcher.matches?("name" => "bear")).to eq(false)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "key filter" do
|
61
61
|
matcher = Matcher.new("name" => :key)
|
62
|
-
matcher.matches?("name" => nil).
|
63
|
-
matcher.matches?("other" => "bear").
|
64
|
-
matcher.matches?("name" => "").
|
65
|
-
matcher.matches?("name" => " ").
|
66
|
-
matcher.matches?("name" => "bear").
|
62
|
+
expect(matcher.matches?("name" => nil)).to eq(true)
|
63
|
+
expect(matcher.matches?("other" => "bear")).to eq(false)
|
64
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
65
|
+
expect(matcher.matches?("name" => " ")).to eq(true)
|
66
|
+
expect(matcher.matches?("name" => "bear")).to eq(true)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "empty filter" do
|
70
70
|
matcher = Matcher.new("name" => :empty)
|
71
|
-
matcher.matches?("name" => nil).
|
72
|
-
matcher.matches?("other" => "bear").
|
73
|
-
matcher.matches?("name" => "").
|
74
|
-
matcher.matches?("name" => " ").
|
75
|
-
matcher.matches?("name" => "bear").
|
76
|
-
matcher.matches?("name" => " s ").
|
71
|
+
expect(matcher.matches?("name" => nil)).to eq(false)
|
72
|
+
expect(matcher.matches?("other" => "bear")).to eq(false)
|
73
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
74
|
+
expect(matcher.matches?("name" => " ")).to eq(false)
|
75
|
+
expect(matcher.matches?("name" => "bear")).to eq(false)
|
76
|
+
expect(matcher.matches?("name" => " s ")).to eq(false)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "value filter" do
|
80
80
|
matcher = Matcher.new("name" => :value)
|
81
|
-
matcher.matches?("name" => nil).
|
82
|
-
matcher.matches?("other" => "bear").
|
83
|
-
matcher.matches?("name" => "").
|
84
|
-
matcher.matches?("name" => " ").
|
85
|
-
matcher.matches?("name" => "bear").
|
86
|
-
matcher.matches?("name" => " s ").
|
81
|
+
expect(matcher.matches?("name" => nil)).to eq(false)
|
82
|
+
expect(matcher.matches?("other" => "bear")).to eq(false)
|
83
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
84
|
+
expect(matcher.matches?("name" => " ")).to eq(true)
|
85
|
+
expect(matcher.matches?("name" => "bear")).to eq(true)
|
86
|
+
expect(matcher.matches?("name" => " s ")).to eq(true)
|
87
87
|
end
|
88
88
|
|
89
89
|
it "multiple filters" do
|
90
90
|
matcher = Matcher.new("name" => /^[cb]a+t/, "state" => "sleeping")
|
91
|
-
matcher.matches?("state" => "sleeping", "name" => "cat").
|
92
|
-
matcher.matches?("state" => "awake", "name" => "cat").
|
93
|
-
matcher.matches?("state" => "sleeping", "name" => "bat").
|
94
|
-
matcher.matches?("state" => "sleeping", "name" => "bear").
|
95
|
-
matcher.matches?("state" => "awake", "name" => "bear").
|
91
|
+
expect(matcher.matches?("state" => "sleeping", "name" => "cat")).to eq(true)
|
92
|
+
expect(matcher.matches?("state" => "awake", "name" => "cat")).to eq(false)
|
93
|
+
expect(matcher.matches?("state" => "sleeping", "name" => "bat")).to eq(true)
|
94
|
+
expect(matcher.matches?("state" => "sleeping", "name" => "bear")).to eq(false)
|
95
|
+
expect(matcher.matches?("state" => "awake", "name" => "bear")).to eq(false)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "regex should go back and forth into redis" do
|
99
99
|
matcher = Matcher.new("name" => /^[cb]a+t/)
|
100
|
-
matcher.matches?("name" => "cat").
|
101
|
-
matcher.matches?("name" => "bat").
|
102
|
-
matcher.matches?("name" => "caaaaat").
|
103
|
-
matcher.matches?("name" => "ct").
|
104
|
-
matcher.matches?("name" => "bcat").
|
100
|
+
expect(matcher.matches?("name" => "cat")).to eq(true)
|
101
|
+
expect(matcher.matches?("name" => "bat")).to eq(true)
|
102
|
+
expect(matcher.matches?("name" => "caaaaat")).to eq(true)
|
103
|
+
expect(matcher.matches?("name" => "ct")).to eq(false)
|
104
|
+
expect(matcher.matches?("name" => "bcat")).to eq(false)
|
105
105
|
|
106
106
|
QueueBus.redis { |redis| redis.set("temp1", QueueBus::Util.encode(matcher.to_redis) ) }
|
107
107
|
redis = QueueBus.redis { |redis| redis.get("temp1") }
|
108
108
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
109
|
-
matcher.matches?("name" => "cat").
|
110
|
-
matcher.matches?("name" => "bat").
|
111
|
-
matcher.matches?("name" => "caaaaat").
|
112
|
-
matcher.matches?("name" => "ct").
|
113
|
-
matcher.matches?("name" => "bcat").
|
109
|
+
expect(matcher.matches?("name" => "cat")).to eq(true)
|
110
|
+
expect(matcher.matches?("name" => "bat")).to eq(true)
|
111
|
+
expect(matcher.matches?("name" => "caaaaat")).to eq(true)
|
112
|
+
expect(matcher.matches?("name" => "ct")).to eq(false)
|
113
|
+
expect(matcher.matches?("name" => "bcat")).to eq(false)
|
114
114
|
|
115
115
|
QueueBus.redis { |redis| redis.set("temp2", QueueBus::Util.encode(matcher.to_redis) ) }
|
116
116
|
redis = QueueBus.redis { |redis| redis.get("temp2") }
|
117
117
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
118
|
-
matcher.matches?("name" => "cat").
|
119
|
-
matcher.matches?("name" => "bat").
|
120
|
-
matcher.matches?("name" => "caaaaat").
|
121
|
-
matcher.matches?("name" => "ct").
|
122
|
-
matcher.matches?("name" => "bcat").
|
118
|
+
expect(matcher.matches?("name" => "cat")).to eq(true)
|
119
|
+
expect(matcher.matches?("name" => "bat")).to eq(true)
|
120
|
+
expect(matcher.matches?("name" => "caaaaat")).to eq(true)
|
121
|
+
expect(matcher.matches?("name" => "ct")).to eq(false)
|
122
|
+
expect(matcher.matches?("name" => "bcat")).to eq(false)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "special value should go back and forth into redis" do
|
126
126
|
matcher = Matcher.new("name" => :blank)
|
127
|
-
matcher.matches?("name" => "cat").
|
128
|
-
matcher.matches?("name" => "").
|
127
|
+
expect(matcher.matches?("name" => "cat")).to eq(false)
|
128
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
129
129
|
|
130
130
|
QueueBus.redis { |redis| redis.set("temp1", QueueBus::Util.encode(matcher.to_redis) ) }
|
131
131
|
redis= QueueBus.redis { |redis| redis.get("temp1") }
|
132
132
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
133
|
-
matcher.matches?("name" => "cat").
|
134
|
-
matcher.matches?("name" => "").
|
133
|
+
expect(matcher.matches?("name" => "cat")).to eq(false)
|
134
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
135
135
|
|
136
136
|
QueueBus.redis { |redis| redis.set("temp2", QueueBus::Util.encode(matcher.to_redis) ) }
|
137
137
|
redis= QueueBus.redis { |redis| redis.get("temp2") }
|
138
138
|
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
139
|
-
matcher.matches?("name" => "cat").
|
140
|
-
matcher.matches?("name" => "").
|
139
|
+
expect(matcher.matches?("name" => "cat")).to eq(false)
|
140
|
+
expect(matcher.matches?("name" => "")).to eq(true)
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|