resque-bus 0.3.2 → 0.7.0
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -3
- data/README.mdown +50 -64
- data/Rakefile +0 -1
- data/lib/resque-bus.rb +21 -283
- data/lib/resque_bus/adapter.rb +66 -0
- data/lib/resque_bus/compatibility/deprecated.rb +38 -0
- data/lib/resque_bus/compatibility/driver.rb +10 -0
- data/lib/resque_bus/compatibility/heartbeat.rb +10 -0
- data/lib/resque_bus/compatibility/publisher.rb +13 -0
- data/lib/resque_bus/compatibility/rider.rb +32 -0
- data/lib/resque_bus/compatibility/subscriber.rb +8 -0
- data/lib/resque_bus/compatibility/task_manager.rb +8 -0
- data/lib/resque_bus/server.rb +6 -5
- data/lib/resque_bus/server/views/bus.erb +2 -2
- data/lib/resque_bus/tasks.rb +46 -46
- data/lib/resque_bus/version.rb +2 -4
- data/resque-bus.gemspec +5 -12
- data/spec/adapter/compatibility_spec.rb +97 -0
- data/spec/adapter/integration_spec.rb +111 -0
- data/spec/adapter/publish_at_spec.rb +50 -0
- data/spec/adapter/retry_spec.rb +47 -0
- data/spec/adapter/support.rb +23 -0
- data/spec/adapter_spec.rb +14 -0
- data/spec/application_spec.rb +62 -62
- data/spec/config_spec.rb +83 -0
- data/spec/dispatch_spec.rb +6 -6
- data/spec/driver_spec.rb +62 -53
- data/spec/heartbeat_spec.rb +4 -4
- data/spec/integration_spec.rb +2 -2
- data/spec/matcher_spec.rb +29 -29
- data/spec/publish_spec.rb +62 -38
- data/spec/publisher_spec.rb +7 -0
- data/spec/rider_spec.rb +14 -66
- data/spec/spec_helper.rb +25 -28
- data/spec/subscriber_spec.rb +194 -176
- data/spec/subscription_list_spec.rb +1 -1
- data/spec/subscription_spec.rb +1 -1
- data/spec/worker_spec.rb +32 -0
- metadata +75 -91
- data/lib/resque_bus/application.rb +0 -115
- data/lib/resque_bus/dispatch.rb +0 -61
- data/lib/resque_bus/driver.rb +0 -30
- data/lib/resque_bus/heartbeat.rb +0 -106
- data/lib/resque_bus/local.rb +0 -34
- data/lib/resque_bus/matcher.rb +0 -81
- data/lib/resque_bus/publisher.rb +0 -12
- data/lib/resque_bus/rider.rb +0 -54
- data/lib/resque_bus/subscriber.rb +0 -63
- data/lib/resque_bus/subscription.rb +0 -55
- data/lib/resque_bus/subscription_list.rb +0 -53
- data/lib/resque_bus/task_manager.rb +0 -52
- data/lib/resque_bus/util.rb +0 -42
- data/lib/tasks/resquebus.rake +0 -2
- data/spec/publish_at_spec.rb +0 -74
- data/spec/redis_spec.rb +0 -13
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module QueueBus
|
4
|
+
module Adapters
|
5
|
+
class TestOne
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "QueueBus config" do
|
12
|
+
it "should set the default app key" do
|
13
|
+
QueueBus.default_app_key.should == nil
|
14
|
+
|
15
|
+
QueueBus.default_app_key = "my_app"
|
16
|
+
QueueBus.default_app_key.should == "my_app"
|
17
|
+
|
18
|
+
QueueBus.default_app_key = "something here"
|
19
|
+
QueueBus.default_app_key.should == "something_here"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set the default queue" do
|
23
|
+
QueueBus.default_queue.should == nil
|
24
|
+
|
25
|
+
QueueBus.default_queue = "my_queue"
|
26
|
+
QueueBus.default_queue.should == "my_queue"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set the local mode" do
|
30
|
+
QueueBus.local_mode.should == nil
|
31
|
+
QueueBus.local_mode = :standalone
|
32
|
+
QueueBus.local_mode.should == :standalone
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set the hostname" do
|
36
|
+
QueueBus.hostname.should_not == nil
|
37
|
+
QueueBus.hostname = "whatever"
|
38
|
+
QueueBus.hostname.should == "whatever"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set before_publish callback" do
|
42
|
+
QueueBus.before_publish = lambda {|attributes| 42 }
|
43
|
+
QueueBus.before_publish_callback({}).should == 42
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
it "should use the default Redis connection" do
|
48
|
+
QueueBus.redis { |redis| redis }.should_not eq(nil)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should default to given adapter" do
|
52
|
+
QueueBus.adapter.is_a?(adapter_under_test_class).should == true
|
53
|
+
|
54
|
+
# and should raise if already set
|
55
|
+
lambda {
|
56
|
+
QueueBus.adapter = :data
|
57
|
+
}.should raise_error
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with a fresh load" do
|
61
|
+
before(:each) do
|
62
|
+
QueueBus.send(:reset)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be able to be set to resque" do
|
66
|
+
QueueBus.adapter = adapter_under_test_symbol
|
67
|
+
QueueBus.adapter.is_a?(adapter_under_test_class).should == true
|
68
|
+
|
69
|
+
# and should raise if already set
|
70
|
+
lambda {
|
71
|
+
QueueBus.adapter = :data
|
72
|
+
}.should raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be able to be set to something else" do
|
76
|
+
|
77
|
+
QueueBus.adapter = :test_one
|
78
|
+
QueueBus.adapter.is_a?(QueueBus::Adapters::TestOne).should == true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
data/spec/dispatch_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module QueueBus
|
4
4
|
describe Dispatch do
|
5
5
|
it "should not start with any applications" do
|
6
6
|
Dispatch.new("d").subscriptions.size.should == 0
|
@@ -29,7 +29,7 @@ module ResqueBus
|
|
29
29
|
|
30
30
|
describe "Top Level" do
|
31
31
|
before(:each) do
|
32
|
-
|
32
|
+
QueueBus.dispatch("testit") do
|
33
33
|
subscribe "event1" do |attributes|
|
34
34
|
Runner2.run(attributes)
|
35
35
|
end
|
@@ -50,16 +50,16 @@ module ResqueBus
|
|
50
50
|
|
51
51
|
it "should register and run" do
|
52
52
|
Runner2.value.should == 0
|
53
|
-
|
53
|
+
QueueBus.dispatcher_execute("testit", "event2", "bus_event_type" => "event2")
|
54
54
|
Runner2.value.should == 1
|
55
|
-
|
55
|
+
QueueBus.dispatcher_execute("testit", "event1", "bus_event_type" => "event1")
|
56
56
|
Runner2.value.should == 2
|
57
|
-
|
57
|
+
QueueBus.dispatcher_execute("testit", "event1", "bus_event_type" => "event1")
|
58
58
|
Runner2.value.should == 3
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return the subscriptions" do
|
62
|
-
dispatcher =
|
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
65
|
tuples.should =~ [ ["event1", "testit_default"],
|
data/spec/driver_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module QueueBus
|
4
4
|
describe Driver do
|
5
5
|
before(:each) do
|
6
6
|
Application.new("app1").subscribe(test_list(test_sub("event1"), test_sub("event2"), test_sub("event3")))
|
@@ -11,90 +11,99 @@ module ResqueBus
|
|
11
11
|
after(:each) do
|
12
12
|
Timecop.return
|
13
13
|
end
|
14
|
-
|
15
|
-
let(:bus_attrs) { {"bus_driven_at" => Time.now.to_i, "bus_rider_class_name"=>"::
|
16
|
-
|
14
|
+
|
15
|
+
let(:bus_attrs) { {"bus_driven_at" => Time.now.to_i, "bus_rider_class_name"=>"::QueueBus::Rider", "bus_class_proxy" => "::QueueBus::Rider"} }
|
16
|
+
|
17
17
|
describe ".subscription_matches" do
|
18
18
|
it "return empty array when none" do
|
19
19
|
Driver.subscription_matches("bus_event_type" => "else").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should == []
|
20
20
|
Driver.subscription_matches("bus_event_type" => "event").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should == []
|
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]}.should =~ [["app1", "event1", "default", "::
|
24
|
-
Driver.subscription_matches("bus_event_type" => "event6").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["app3", "event6", "default", "::
|
23
|
+
Driver.subscription_matches("bus_event_type" => "event1").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["app1", "event1", "default", "::QueueBus::Rider"]]
|
24
|
+
Driver.subscription_matches("bus_event_type" => "event6").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["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]}.should =~ [["app1", "event2", "default", "::
|
27
|
+
Driver.subscription_matches("bus_event_type" => "event2").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["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]}.should =~ [["app3", "event[45]", "default", "::
|
30
|
+
Driver.subscription_matches("bus_event_type" => "event4").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["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]}.should =~ [["app3", "event[45]", "default", "::
|
33
|
+
Driver.subscription_matches("bus_event_type" => "event5").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.should =~ [["app3", "event[45]", "default", "::QueueBus::Rider"], ["app3", "event5", "default", "::QueueBus::Rider"]]
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
describe ".perform" do
|
38
38
|
let(:attributes) { {"x" => "y"} }
|
39
|
-
|
39
|
+
|
40
40
|
before(:each) do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
QueueBus.redis { |redis| redis.smembers("queues") }.should == []
|
42
|
+
QueueBus.redis { |redis| redis.lpop("queue:app1_default") }.should be_nil
|
43
|
+
QueueBus.redis { |redis| redis.lpop("queue:app2_default") }.should be_nil
|
44
|
+
QueueBus.redis { |redis| redis.lpop("queue:app3_default") }.should 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
|
-
|
49
|
+
QueueBus.redis { |redis| redis.smembers("queues") }.should == []
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it "should queue up the riders in redis" do
|
53
|
-
|
53
|
+
QueueBus.redis { |redis| redis.lpop("queue:app1_default") }.should be_nil
|
54
54
|
Driver.perform(attributes.merge("bus_event_type" => "event1"))
|
55
|
-
|
55
|
+
QueueBus.redis { |redis| redis.smembers("queues") }.should =~ ["default"]
|
56
56
|
|
57
|
-
hash = JSON.parse(
|
58
|
-
hash["class"].should == "::
|
59
|
-
hash["args"].should ==
|
57
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
58
|
+
hash["class"].should == "QueueBus::Worker"
|
59
|
+
hash["args"].size.should == 1
|
60
|
+
JSON.parse(hash["args"].first).should == {"bus_rider_app_key"=>"app1", "x" => "y", "bus_event_type" => "event1", "bus_rider_sub_key"=>"event1", "bus_rider_queue" => "default"}.merge(bus_attrs)
|
60
61
|
end
|
61
|
-
|
62
|
+
|
62
63
|
it "should queue up to multiple" do
|
63
64
|
Driver.perform(attributes.merge("bus_event_type" => "event4"))
|
64
|
-
|
65
|
-
|
66
|
-
hash = JSON.parse(
|
67
|
-
hash["class"].should == "::
|
68
|
-
hash["args"].should ==
|
69
|
-
|
70
|
-
|
71
|
-
hash
|
72
|
-
hash["
|
65
|
+
QueueBus.redis { |redis| redis.smembers("queues") }.should =~ ["default", "more"]
|
66
|
+
|
67
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:more") })
|
68
|
+
hash["class"].should == "QueueBus::Worker"
|
69
|
+
hash["args"].size.should == 1
|
70
|
+
JSON.parse(hash["args"].first).should == {"bus_rider_app_key"=>"app2", "x" => "y", "bus_event_type" => "event4", "bus_rider_sub_key"=>"event4", "bus_rider_queue" => "more"}.merge(bus_attrs)
|
71
|
+
|
72
|
+
hash = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
73
|
+
hash["class"].should == "QueueBus::Worker"
|
74
|
+
hash["args"].size.should == 1
|
75
|
+
JSON.parse(hash["args"].first).should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event4", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs)
|
73
76
|
end
|
74
|
-
|
77
|
+
|
75
78
|
it "should queue up to the same" do
|
76
79
|
Driver.perform(attributes.merge("bus_event_type" => "event5"))
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
if first == "event[45]"
|
92
|
-
second.should == "event5"
|
80
|
+
QueueBus.redis { |redis| redis.smembers("queues") }.should =~ ["default"]
|
81
|
+
|
82
|
+
QueueBus.redis { |redis| redis.llen("queue:default") }.should == 2
|
83
|
+
|
84
|
+
pop1 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
85
|
+
pop2 = JSON.parse(QueueBus.redis { |redis| redis.lpop("queue:default") })
|
86
|
+
|
87
|
+
pargs1 = JSON.parse(pop1["args"].first)
|
88
|
+
pargs2 = JSON.parse(pop2["args"].first)
|
89
|
+
if pargs1["bus_rider_sub_key"] == "event5"
|
90
|
+
hash1 = pop1
|
91
|
+
hash2 = pop2
|
92
|
+
args1 = pargs1
|
93
|
+
args2 = pargs2
|
93
94
|
else
|
94
|
-
|
95
|
-
|
95
|
+
hash1 = pop2
|
96
|
+
hash2 = pop1
|
97
|
+
args1 = pargs2
|
98
|
+
args2 = pargs1
|
96
99
|
end
|
100
|
+
|
101
|
+
hash1["class"].should == "QueueBus::Worker"
|
102
|
+
args1.should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event5", "bus_rider_queue" => "default"}.merge(bus_attrs)
|
103
|
+
|
104
|
+
hash2["class"].should == "QueueBus::Worker"
|
105
|
+
args2.should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs)
|
97
106
|
end
|
98
107
|
end
|
99
108
|
end
|
100
|
-
end
|
109
|
+
end
|
data/spec/heartbeat_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module QueueBus
|
4
4
|
describe Heartbeat do
|
5
5
|
def now_attributes
|
6
6
|
{
|
@@ -20,7 +20,7 @@ module ResqueBus
|
|
20
20
|
|
21
21
|
it "should publish the current time once" do
|
22
22
|
Timecop.freeze "12/12/2013 12:01:19" do
|
23
|
-
|
23
|
+
QueueBus.should_receive(:publish).with("heartbeat_minutes", now_attributes)
|
24
24
|
Heartbeat.perform
|
25
25
|
end
|
26
26
|
|
@@ -31,12 +31,12 @@ module ResqueBus
|
|
31
31
|
|
32
32
|
it "should publish a minute later" do
|
33
33
|
Timecop.freeze "12/12/2013 12:01:19" do
|
34
|
-
|
34
|
+
QueueBus.should_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
|
-
|
39
|
+
QueueBus.should_receive(:publish).with("heartbeat_minutes", now_attributes)
|
40
40
|
Heartbeat.perform
|
41
41
|
end
|
42
42
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module QueueBus
|
4
4
|
describe "Integration" do
|
5
5
|
it "should round trip attributes" do
|
6
6
|
write1 = Subscription.new("default", "key1", "MyClass1", {"bus_event_type" => "event_one"})
|
@@ -23,7 +23,7 @@ module ResqueBus
|
|
23
23
|
app = Application.new("test")
|
24
24
|
app.subscribe(write)
|
25
25
|
|
26
|
-
|
26
|
+
reset_test_adapter # reset to make sure we read from redis
|
27
27
|
app = Application.new("test")
|
28
28
|
read = app.send(:subscriptions)
|
29
29
|
|
data/spec/matcher_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module QueueBus
|
4
4
|
describe Matcher do
|
5
5
|
it "should already return false on empty filters" do
|
6
6
|
matcher = Matcher.new({})
|
@@ -8,19 +8,19 @@ module ResqueBus
|
|
8
8
|
matcher.matches?(nil).should == false
|
9
9
|
matcher.matches?("name" => "val").should == false
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "should not crash if nil inputs" do
|
13
13
|
matcher = Matcher.new("name" => "val")
|
14
14
|
matcher.matches?(nil).should == false
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "string filter to/from redis" do
|
18
18
|
matcher = Matcher.new("name" => "val")
|
19
19
|
matcher.matches?("name" => "val").should == true
|
20
20
|
matcher.matches?("name" => " val").should == false
|
21
21
|
matcher.matches?("name" => "zval").should == false
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "regex filter" do
|
25
25
|
matcher = Matcher.new("name" => /^[cb]a+t/)
|
26
26
|
matcher.matches?("name" => "cat").should == true
|
@@ -29,7 +29,7 @@ module ResqueBus
|
|
29
29
|
matcher.matches?("name" => "ct").should == false
|
30
30
|
matcher.matches?("name" => "bcat").should == false
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "present filter" do
|
34
34
|
matcher = Matcher.new("name" => :present)
|
35
35
|
matcher.matches?("name" => "").should == false
|
@@ -37,7 +37,7 @@ module ResqueBus
|
|
37
37
|
matcher.matches?("name" => "bear").should == true
|
38
38
|
matcher.matches?("other" => "bear").should == false
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "blank filter" do
|
42
42
|
matcher = Matcher.new("name" => :blank)
|
43
43
|
matcher.matches?("name" => nil).should == true
|
@@ -47,7 +47,7 @@ module ResqueBus
|
|
47
47
|
matcher.matches?("name" => "bear").should == false
|
48
48
|
matcher.matches?("name" => " s ").should == false
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "nil filter" do
|
52
52
|
matcher = Matcher.new("name" => :nil)
|
53
53
|
matcher.matches?("name" => nil).should == true
|
@@ -56,7 +56,7 @@ module ResqueBus
|
|
56
56
|
matcher.matches?("name" => " ").should == false
|
57
57
|
matcher.matches?("name" => "bear").should == false
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "key filter" do
|
61
61
|
matcher = Matcher.new("name" => :key)
|
62
62
|
matcher.matches?("name" => nil).should == true
|
@@ -65,7 +65,7 @@ module ResqueBus
|
|
65
65
|
matcher.matches?("name" => " ").should == true
|
66
66
|
matcher.matches?("name" => "bear").should == true
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "empty filter" do
|
70
70
|
matcher = Matcher.new("name" => :empty)
|
71
71
|
matcher.matches?("name" => nil).should == false
|
@@ -75,7 +75,7 @@ module ResqueBus
|
|
75
75
|
matcher.matches?("name" => "bear").should == false
|
76
76
|
matcher.matches?("name" => " s ").should == false
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "value filter" do
|
80
80
|
matcher = Matcher.new("name" => :value)
|
81
81
|
matcher.matches?("name" => nil).should == false
|
@@ -85,7 +85,7 @@ module ResqueBus
|
|
85
85
|
matcher.matches?("name" => "bear").should == true
|
86
86
|
matcher.matches?("name" => " s ").should == true
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "multiple filters" do
|
90
90
|
matcher = Matcher.new("name" => /^[cb]a+t/, "state" => "sleeping")
|
91
91
|
matcher.matches?("state" => "sleeping", "name" => "cat").should == true
|
@@ -94,7 +94,7 @@ module ResqueBus
|
|
94
94
|
matcher.matches?("state" => "sleeping", "name" => "bear").should == false
|
95
95
|
matcher.matches?("state" => "awake", "name" => "bear").should == 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
100
|
matcher.matches?("name" => "cat").should == true
|
@@ -102,40 +102,40 @@ module ResqueBus
|
|
102
102
|
matcher.matches?("name" => "caaaaat").should == true
|
103
103
|
matcher.matches?("name" => "ct").should == false
|
104
104
|
matcher.matches?("name" => "bcat").should == false
|
105
|
-
|
106
|
-
|
107
|
-
redis =
|
108
|
-
matcher = Matcher.new(
|
105
|
+
|
106
|
+
QueueBus.redis { |redis| redis.set("temp1", QueueBus::Util.encode(matcher.to_redis) ) }
|
107
|
+
redis = QueueBus.redis { |redis| redis.get("temp1") }
|
108
|
+
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
109
109
|
matcher.matches?("name" => "cat").should == true
|
110
110
|
matcher.matches?("name" => "bat").should == true
|
111
111
|
matcher.matches?("name" => "caaaaat").should == true
|
112
112
|
matcher.matches?("name" => "ct").should == false
|
113
113
|
matcher.matches?("name" => "bcat").should == false
|
114
|
-
|
115
|
-
|
116
|
-
redis =
|
117
|
-
matcher = Matcher.new(
|
114
|
+
|
115
|
+
QueueBus.redis { |redis| redis.set("temp2", QueueBus::Util.encode(matcher.to_redis) ) }
|
116
|
+
redis = QueueBus.redis { |redis| redis.get("temp2") }
|
117
|
+
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
118
118
|
matcher.matches?("name" => "cat").should == true
|
119
119
|
matcher.matches?("name" => "bat").should == true
|
120
120
|
matcher.matches?("name" => "caaaaat").should == true
|
121
121
|
matcher.matches?("name" => "ct").should == false
|
122
122
|
matcher.matches?("name" => "bcat").should == 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
127
|
matcher.matches?("name" => "cat").should == false
|
128
128
|
matcher.matches?("name" => "").should == true
|
129
|
-
|
130
|
-
|
131
|
-
redis
|
132
|
-
matcher = Matcher.new(
|
129
|
+
|
130
|
+
QueueBus.redis { |redis| redis.set("temp1", QueueBus::Util.encode(matcher.to_redis) ) }
|
131
|
+
redis= QueueBus.redis { |redis| redis.get("temp1") }
|
132
|
+
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
133
133
|
matcher.matches?("name" => "cat").should == false
|
134
134
|
matcher.matches?("name" => "").should == true
|
135
|
-
|
136
|
-
|
137
|
-
redis
|
138
|
-
matcher = Matcher.new(
|
135
|
+
|
136
|
+
QueueBus.redis { |redis| redis.set("temp2", QueueBus::Util.encode(matcher.to_redis) ) }
|
137
|
+
redis= QueueBus.redis { |redis| redis.get("temp2") }
|
138
|
+
matcher = Matcher.new(QueueBus::Util.decode(redis))
|
139
139
|
matcher.matches?("name" => "cat").should == false
|
140
140
|
matcher.matches?("name" => "").should == true
|
141
141
|
end
|