kestrel-client 0.6.0 → 0.6.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kestrel-client}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
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-10-07}
12
+ s.date = %q{2011-01-19}
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 = [
@@ -22,6 +22,22 @@ module Kestrel
22
22
  :get_timeout_ms => 10
23
23
  }.freeze
24
24
 
25
+ # Exceptions which are connection failures we retry after
26
+ RECOVERABLE_ERRORS = [
27
+ Memcached::ServerIsMarkedDead,
28
+ Memcached::ATimeoutOccurred,
29
+ Memcached::ConnectionBindFailure,
30
+ Memcached::ConnectionFailure,
31
+ Memcached::ConnectionSocketCreateFailure,
32
+ Memcached::Failure,
33
+ Memcached::MemoryAllocationFailure,
34
+ Memcached::ReadFailure,
35
+ Memcached::ServerError,
36
+ Memcached::SystemError,
37
+ Memcached::UnknownReadFailure,
38
+ Memcached::WriteFailure
39
+ ]
40
+
25
41
  include StatsHelper
26
42
  include RetryHelper
27
43
 
@@ -115,7 +131,7 @@ module Kestrel
115
131
  val =
116
132
  begin
117
133
  send(select_get_method(key), key + commands, raw)
118
- rescue Memcached::ATimeoutOccurred, Memcached::ServerIsMarkedDead
134
+ rescue *RECOVERABLE_ERRORS
119
135
  # we can't tell the difference between a server being down
120
136
  # and an empty queue, so just return nil. our sticky server
121
137
  # logic should eliminate piling on down servers
@@ -1,26 +1,10 @@
1
1
  module Kestrel::Client::RetryHelper
2
2
 
3
- # Exceptions which are connection failures we retry after
4
- RECOVERABLE_ERRORS = [
5
- Memcached::ServerIsMarkedDead,
6
- Memcached::ATimeoutOccurred,
7
- Memcached::ConnectionBindFailure,
8
- Memcached::ConnectionFailure,
9
- Memcached::ConnectionSocketCreateFailure,
10
- Memcached::Failure,
11
- Memcached::MemoryAllocationFailure,
12
- Memcached::ReadFailure,
13
- Memcached::ServerError,
14
- Memcached::SystemError,
15
- Memcached::UnknownReadFailure,
16
- Memcached::WriteFailure
17
- ]
18
-
19
3
  private
20
4
 
21
5
  def with_retries #:nodoc:
22
6
  yield
23
- rescue *RECOVERABLE_ERRORS
7
+ rescue *Kestrel::Client::RECOVERABLE_ERRORS
24
8
  tries ||= @exception_retry_limit + 1
25
9
  tries -= 1
26
10
  tries > 0 ? retry : raise
@@ -69,9 +69,9 @@ module Kestrel::Client::StatsHelper
69
69
 
70
70
  def deserialize_stat_value(value)
71
71
  case value
72
- when /^\d+\.\d+$/:
72
+ when /^\d+\.\d+$/
73
73
  value.to_f
74
- when /^\d+$/:
74
+ when /^\d+$/
75
75
  value.to_i
76
76
  else
77
77
  value
@@ -11,11 +11,21 @@ module Kestrel
11
11
  response
12
12
  end
13
13
  end
14
-
15
- def is_marshaled?(object)
16
- object.to_s[0] == Marshal::MAJOR_VERSION && object.to_s[1] == Marshal::MINOR_VERSION
17
- rescue Exception
18
- false
14
+
15
+ if RUBY_VERSION.respond_to?(:getbyte)
16
+ def is_marshaled?(object)
17
+ o = object.to_s
18
+ o.getbyte(0) == Marshal::MAJOR_VERSION && o.getbyte(1) == Marshal::MINOR_VERSION
19
+ rescue Exception
20
+ false
21
+ end
22
+ else
23
+ def is_marshaled?(object)
24
+ o = object.to_s
25
+ o[0] == Marshal::MAJOR_VERSION && o[1] == Marshal::MINOR_VERSION
26
+ rescue Exception
27
+ false
28
+ end
19
29
  end
20
30
  end
21
31
  end
@@ -30,6 +30,16 @@ describe Kestrel::Client do
30
30
 
31
31
  3.times { @kestrel.get("a_queue") }
32
32
  end
33
+
34
+ it "returns nil if there is a recoverable exception" do
35
+ mock(@kestrel).select_get_method(@queue) { raise Memcached::SystemError }
36
+ @kestrel.get(@queue).should == nil
37
+ end
38
+
39
+ it "raises the exception if the exception is not recoverable" do
40
+ mock(@kestrel).select_get_method(@queue) { raise ArgumentError }
41
+ lambda { @kestrel.get(@queue) }.should raise_error(ArgumentError)
42
+ end
33
43
  end
34
44
 
35
45
  describe "retry behavior" do
@@ -20,7 +20,7 @@ describe Kestrel::Client do
20
20
  x.report("set:") { for i in 1..times; @kestrel.set(@queue, @value); end }
21
21
  x.report("get:") { for i in 1..times; @kestrel.get(@queue); end }
22
22
  x.report("set (raw):") { for i in 1..times; @kestrel.set(@queue, @raw_value, 0, true); end }
23
- x.report("get (raw):") { for i in 1..times; @kestrel.get(@queue, true); end }
23
+ x.report("get (raw):") { for i in 1..times; @kestrel.get(@queue, :raw => true); end }
24
24
  end
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kestrel-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Freels
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-07 00:00:00 -07:00
19
+ date: 2011-01-19 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency