kestrel-client 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/kestrel-client.gemspec +5 -2
- data/lib/kestrel/client.rb +2 -0
- data/lib/kestrel/client/namespace.rb +11 -6
- data/lib/kestrel/client/partitioning.rb +35 -0
- data/spec/kestrel/client/blocking_spec.rb +0 -1
- data/spec/kestrel/client/envelope_spec.rb +0 -1
- data/spec/kestrel/client/json_spec.rb +1 -1
- data/spec/kestrel/client/namespace_spec.rb +41 -12
- data/spec/kestrel/client/partitioning_spec.rb +29 -0
- data/spec/kestrel/client/unmarshal_spec.rb +0 -1
- data/spec/kestrel/client_spec.rb +2 -2
- data/spec/kestrel/config_spec.rb +0 -3
- data/spec/spec_helper.rb +13 -0
- metadata +7 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/kestrel-client.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{kestrel-client}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Freels", "Rael Dornfest"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-18}
|
13
13
|
s.description = %q{Ruby client for the Kestrel queue server}
|
14
14
|
s.email = %q{rael@twitter.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/kestrel/client/envelope.rb",
|
29
29
|
"lib/kestrel/client/json.rb",
|
30
30
|
"lib/kestrel/client/namespace.rb",
|
31
|
+
"lib/kestrel/client/partitioning.rb",
|
31
32
|
"lib/kestrel/client/proxy.rb",
|
32
33
|
"lib/kestrel/client/unmarshal.rb",
|
33
34
|
"lib/kestrel/config.rb",
|
@@ -35,6 +36,7 @@ Gem::Specification.new do |s|
|
|
35
36
|
"spec/kestrel/client/envelope_spec.rb",
|
36
37
|
"spec/kestrel/client/json_spec.rb",
|
37
38
|
"spec/kestrel/client/namespace_spec.rb",
|
39
|
+
"spec/kestrel/client/partitioning_spec.rb",
|
38
40
|
"spec/kestrel/client/unmarshal_spec.rb",
|
39
41
|
"spec/kestrel/client_spec.rb",
|
40
42
|
"spec/kestrel/config/kestrel.yml",
|
@@ -52,6 +54,7 @@ Gem::Specification.new do |s|
|
|
52
54
|
"spec/kestrel/client/envelope_spec.rb",
|
53
55
|
"spec/kestrel/client/json_spec.rb",
|
54
56
|
"spec/kestrel/client/namespace_spec.rb",
|
57
|
+
"spec/kestrel/client/partitioning_spec.rb",
|
55
58
|
"spec/kestrel/client/unmarshal_spec.rb",
|
56
59
|
"spec/kestrel/client_spec.rb",
|
57
60
|
"spec/kestrel/config_spec.rb",
|
data/lib/kestrel/client.rb
CHANGED
@@ -3,10 +3,12 @@ module Kestrel
|
|
3
3
|
autoload :Proxy, 'kestrel/client/proxy'
|
4
4
|
autoload :Envelope, 'kestrel/client/envelope'
|
5
5
|
autoload :Blocking, 'kestrel/client/blocking'
|
6
|
+
autoload :Partitioning, 'kestrel/client/partitioning'
|
6
7
|
autoload :Unmarshal, 'kestrel/client/unmarshal'
|
7
8
|
autoload :Namespace, 'kestrel/client/namespace'
|
8
9
|
autoload :Json, 'kestrel/client/json'
|
9
10
|
|
11
|
+
|
10
12
|
QUEUE_STAT_NAMES = %w{items bytes total_items logsize expired_items mem_items mem_bytes age discarded}
|
11
13
|
|
12
14
|
def flush(queue)
|
@@ -3,22 +3,27 @@ module Kestrel
|
|
3
3
|
class Namespace < Proxy
|
4
4
|
def initialize(namespace, client)
|
5
5
|
@namespace = namespace
|
6
|
+
@matcher = /\A#{Regexp.escape(@namespace)}:(.+)/
|
6
7
|
super(client)
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
-
client
|
10
|
+
%w(set get delete flush stat).each do |method|
|
11
|
+
class_eval "def #{method}(key, *args); client.#{method}(namespace(key), *args) end", __FILE__, __LINE__
|
11
12
|
end
|
12
13
|
|
13
|
-
def
|
14
|
-
client.
|
14
|
+
def available_queues
|
15
|
+
client.available_queues.map {|q| in_namespace(q) }.compact
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
def in_namespace(key)
|
19
|
+
if match = @matcher.match(key)
|
20
|
+
match[1]
|
21
|
+
end
|
22
|
+
end
|
18
23
|
|
19
24
|
def namespace(key)
|
20
25
|
"#{@namespace}:#{key}"
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
|
-
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Kestrel
|
2
|
+
class Client
|
3
|
+
class Partitioning < Proxy
|
4
|
+
|
5
|
+
def initialize(client_map)
|
6
|
+
@clients = client_map.inject({}) do |clients, (keys, client)|
|
7
|
+
Array(keys).inject(clients) do |_, key|
|
8
|
+
clients.update(key => client)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def clients
|
14
|
+
@clients.values.uniq
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_client
|
18
|
+
@clients[:default]
|
19
|
+
end
|
20
|
+
alias client default_client
|
21
|
+
|
22
|
+
%w(set get delete flush stat).each do |method|
|
23
|
+
class_eval "def #{method}(key, *args); client_for(key).#{method}(key, *args) end", __FILE__, __LINE__
|
24
|
+
end
|
25
|
+
|
26
|
+
def stats
|
27
|
+
merge_stats(clients.map {|c| c.stats })
|
28
|
+
end
|
29
|
+
|
30
|
+
def client_for(key)
|
31
|
+
@clients[key.to_s] || default_client
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -3,7 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe "Kestrel::Client::Blocking" do
|
4
4
|
describe "Instance Methods" do
|
5
5
|
before do
|
6
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
7
6
|
@raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
|
8
7
|
@kestrel = Kestrel::Client::Blocking.new(@raw_kestrel_client)
|
9
8
|
end
|
@@ -5,7 +5,6 @@ class Envelope; end
|
|
5
5
|
describe Kestrel::Client::Envelope do
|
6
6
|
describe "Instance Methods" do
|
7
7
|
before do
|
8
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
9
8
|
@raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
|
10
9
|
@kestrel = Kestrel::Client::Envelope.new(Envelope, @raw_kestrel_client)
|
11
10
|
end
|
@@ -5,7 +5,6 @@ require 'kestrel/client/json'
|
|
5
5
|
describe Kestrel::Client::Json do
|
6
6
|
describe "Instance Methods" do
|
7
7
|
before do
|
8
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
9
8
|
@raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
|
10
9
|
@kestrel = Kestrel::Client::Json.new(@raw_kestrel_client)
|
11
10
|
end
|
@@ -16,6 +15,7 @@ describe Kestrel::Client::Json do
|
|
16
15
|
@kestrel.get('a_queue').should == {"a" => 1, "b" => ["c" => 2]}
|
17
16
|
end
|
18
17
|
|
18
|
+
# wtf is up with this test?
|
19
19
|
it "uses a HashWithIndifferentAccess" do
|
20
20
|
mock(@raw_kestrel_client).get('a_queue') { '{"a": 1, "b": [{"c": 2}]}' }
|
21
21
|
@kestrel.get('a_queue').class.should == HashWithIndifferentAccess
|
@@ -3,22 +3,51 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe Kestrel::Client::Namespace do
|
4
4
|
describe "Instance Methods" do
|
5
5
|
before do
|
6
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
7
6
|
@raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
|
8
7
|
@kestrel = Kestrel::Client::Namespace.new('some_namespace', @raw_kestrel_client)
|
9
8
|
end
|
10
9
|
|
11
|
-
describe "#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
describe "#set" do
|
11
|
+
it "prepends a namespace to the key" do
|
12
|
+
mock(@raw_kestrel_client).set('some_namespace:a_queue', :mcguffin)
|
13
|
+
@kestrel.set('a_queue', :mcguffin)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#get" do
|
18
|
+
it "prepends a namespace to the key" do
|
19
|
+
mock(@raw_kestrel_client).get('some_namespace:a_queue')
|
20
|
+
@kestrel.get('a_queue')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#delete" do
|
25
|
+
it "prepends a namespace to the key" do
|
26
|
+
mock(@raw_kestrel_client).delete('some_namespace:a_queue')
|
27
|
+
@kestrel.delete('a_queue')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#flush" do
|
32
|
+
it "prepends a namespace to the key" do
|
33
|
+
mock(@raw_kestrel_client).flush('some_namespace:a_queue')
|
34
|
+
@kestrel.flush('a_queue')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#stat" do
|
39
|
+
it "prepends a namespace to the key" do
|
40
|
+
mock(@raw_kestrel_client).stat('some_namespace:a_queue')
|
41
|
+
@kestrel.stat('a_queue')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#available_queues" do
|
46
|
+
it "only returns namespaced queues" do
|
47
|
+
@raw_kestrel_client.set('some_namespace:namespaced_queue', 'foo')
|
48
|
+
@raw_kestrel_client.set('unnamespaced_queue', 'foo')
|
49
|
+
|
50
|
+
@kestrel.available_queues.should == ['namespaced_queue']
|
22
51
|
end
|
23
52
|
end
|
24
53
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Kestrel::Client::Partitioning do
|
4
|
+
before do
|
5
|
+
@client_1 = Kestrel::Client.new(*Kestrel::Config.default)
|
6
|
+
@client_2 = Kestrel::Client.new(*Kestrel::Config.default)
|
7
|
+
@default_client = Kestrel::Client.new(*Kestrel::Config.default)
|
8
|
+
|
9
|
+
@kestrel = Kestrel::Client::Partitioning.new('queue1' => @client_1, ['queue2', 'queue3'] => @client_2, :default => @default_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
%w(set get delete flush stat).each do |method|
|
13
|
+
describe "##{method}" do
|
14
|
+
it "routes to the correct client" do
|
15
|
+
mock(@client_1).__send__(method, 'queue1')
|
16
|
+
@kestrel.send(method, 'queue1')
|
17
|
+
|
18
|
+
mock(@client_2).__send__(method, 'queue2')
|
19
|
+
@kestrel.send(method, 'queue2')
|
20
|
+
|
21
|
+
mock(@client_2).__send__(method, 'queue3')
|
22
|
+
@kestrel.send(method, 'queue3')
|
23
|
+
|
24
|
+
mock(@default_client).__send__(method, 'queue4')
|
25
|
+
@kestrel.send(method, 'queue4')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -3,7 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe Kestrel::Client::Unmarshal do
|
4
4
|
describe "Instance Methods" do
|
5
5
|
before do
|
6
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
7
6
|
@raw_kestrel_client = Kestrel::Client.new(*Kestrel::Config.default)
|
8
7
|
@kestrel = Kestrel::Client::Unmarshal.new(@raw_kestrel_client)
|
9
8
|
end
|
data/spec/kestrel/client_spec.rb
CHANGED
@@ -3,7 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe Kestrel::Client do
|
4
4
|
describe "Instance Methods" do
|
5
5
|
before do
|
6
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
7
6
|
@kestrel = Kestrel::Client.new(*Kestrel::Config.default)
|
8
7
|
stub(@kestrel).with_timing(anything) { |_, block| block.call }
|
9
8
|
end
|
@@ -45,13 +44,14 @@ describe Kestrel::Client do
|
|
45
44
|
|
46
45
|
describe "#stats" do
|
47
46
|
it "retrieves stats" do
|
47
|
+
@kestrel.set("test-queue-name", 97)
|
48
|
+
|
48
49
|
stats = @kestrel.stats
|
49
50
|
%w{uptime time version curr_items total_items bytes curr_connections total_connections
|
50
51
|
cmd_get cmd_set get_hits get_misses bytes_read bytes_written queues}.each do |stat|
|
51
52
|
stats[stat].should_not be_nil
|
52
53
|
end
|
53
54
|
|
54
|
-
@kestrel.set("test-queue-name", 97)
|
55
55
|
stats['queues']["test-queue-name"].should_not be_nil
|
56
56
|
Kestrel::Client::QUEUE_STAT_NAMES.each do |queue_stat|
|
57
57
|
stats['queues']['test-queue-name'][queue_stat].should_not be_nil
|
data/spec/kestrel/config_spec.rb
CHANGED
@@ -2,9 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe Kestrel::Config do
|
4
4
|
before do
|
5
|
-
Kestrel::Config.environment = nil
|
6
|
-
Kestrel::Config.load TEST_CONFIG_FILE
|
7
|
-
|
8
5
|
# to sniff namespace foo_space
|
9
6
|
Kestrel::Config.config['foo_space']['development']['connect_timeout'] = 8
|
10
7
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,4 +12,17 @@ TEST_CONFIG_FILE = File.expand_path("#{spec_dir}/kestrel/config/kestrel.yml")
|
|
12
12
|
|
13
13
|
Spec::Runner.configure do |config|
|
14
14
|
config.mock_with :rr
|
15
|
+
|
16
|
+
config.before do
|
17
|
+
Kestrel::Config.environment = nil
|
18
|
+
Kestrel::Config.load TEST_CONFIG_FILE
|
19
|
+
end
|
20
|
+
|
21
|
+
config.after do
|
22
|
+
c = Kestrel::Client.new(*Kestrel::Config.default)
|
23
|
+
c.available_queues.uniq.each do |q|
|
24
|
+
c.delete(q) rescue nil
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
28
|
+
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matt Freels
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-18 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/kestrel/client/envelope.rb
|
52
52
|
- lib/kestrel/client/json.rb
|
53
53
|
- lib/kestrel/client/namespace.rb
|
54
|
+
- lib/kestrel/client/partitioning.rb
|
54
55
|
- lib/kestrel/client/proxy.rb
|
55
56
|
- lib/kestrel/client/unmarshal.rb
|
56
57
|
- lib/kestrel/config.rb
|
@@ -58,6 +59,7 @@ files:
|
|
58
59
|
- spec/kestrel/client/envelope_spec.rb
|
59
60
|
- spec/kestrel/client/json_spec.rb
|
60
61
|
- spec/kestrel/client/namespace_spec.rb
|
62
|
+
- spec/kestrel/client/partitioning_spec.rb
|
61
63
|
- spec/kestrel/client/unmarshal_spec.rb
|
62
64
|
- spec/kestrel/client_spec.rb
|
63
65
|
- spec/kestrel/config/kestrel.yml
|
@@ -99,6 +101,7 @@ test_files:
|
|
99
101
|
- spec/kestrel/client/envelope_spec.rb
|
100
102
|
- spec/kestrel/client/json_spec.rb
|
101
103
|
- spec/kestrel/client/namespace_spec.rb
|
104
|
+
- spec/kestrel/client/partitioning_spec.rb
|
102
105
|
- spec/kestrel/client/unmarshal_spec.rb
|
103
106
|
- spec/kestrel/client_spec.rb
|
104
107
|
- spec/kestrel/config_spec.rb
|