dalli 2.6.3 → 2.6.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

data/History.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ HEAD
5
+ =======
6
+
7
+ - Fix ADD command, aka `write(unless_exist: true)` (pitr, #365)
8
+ - Upgrade test suite from mini_shoulda to minitest.
9
+ - Even more performance improvements for get\_multi (xaop, #331)
10
+
4
11
  2.6.3
5
12
  =======
6
13
 
data/README.md CHANGED
@@ -55,11 +55,14 @@ On Ubuntu you can install it by running:
55
55
 
56
56
  You can verify your installation using this piece of code:
57
57
 
58
- ```ruby
58
+ ```bash
59
59
  gem install dalli
60
+ ```
60
61
 
62
+ ```ruby
61
63
  require 'dalli'
62
- dc = Dalli::Client.new('localhost:11211')
64
+ options = { :namespace => "app_v1", :compress => true }
65
+ dc = Dalli::Client.new('localhost:11211', options)
63
66
  dc.set('abc', 123)
64
67
  value = dc.get('abc')
65
68
  ```
@@ -141,7 +144,7 @@ Default is Marshal.
141
144
 
142
145
  **password**: The password to use for authenticating this client instance against a SASL-enabled memcached server. Heroku users should not need to use this normally.
143
146
 
144
- **keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is false.
147
+ **keepalive**: Boolean. If true, Dalli will enable keep-alive for socket connections. Default is true.
145
148
 
146
149
  **compressor**: The compressor to use for objects being stored.
147
150
  Default is zlib, implemented under `Dalli::Compressor`.
data/dalli.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.require_paths = ["lib"]
23
23
  s.summary = %q{High performance memcached client for Ruby}
24
24
  s.test_files = Dir.glob("test/**/*")
25
- s.add_development_dependency(%q<mini_shoulda>, [">= 0"])
25
+ s.add_development_dependency(%q<minitest>, [">= 5.0.0"])
26
26
  s.add_development_dependency(%q<mocha>, [">= 0"])
27
27
  s.add_development_dependency(%q<rails>, ["~> 3"])
28
28
  end
@@ -201,6 +201,10 @@ module ActiveSupport
201
201
  nil
202
202
  end
203
203
 
204
+ # Clear any local cache
205
+ def cleanup(options=nil)
206
+ end
207
+
204
208
  # Get the statistics from the memcached servers.
205
209
  def stats
206
210
  @data.stats
@@ -233,6 +237,8 @@ module ActiveSupport
233
237
 
234
238
  # Write an entry to the cache.
235
239
  def write_entry(key, value, options) # :nodoc:
240
+ # cleanup LocalCache
241
+ cleanup if options[:unless_exist]
236
242
  method = options[:unless_exist] ? :add : :set
237
243
  expires_in = options[:expires_in]
238
244
  @data.send(method, key, value, expires_in, options)
data/lib/dalli/client.rb CHANGED
@@ -67,82 +67,98 @@ module Dalli
67
67
  # Fetch multiple keys efficiently.
68
68
  # Returns a hash of { 'key' => 'value', 'key2' => 'value1' }
69
69
  def get_multi(*keys)
70
- return {} if keys.empty?
71
- options = nil
72
- options = keys.pop if keys.last.is_a?(Hash) || keys.last.nil?
73
- ring.lock do
74
- begin
75
- servers = self.servers_in_use = Set.new
76
-
77
- keys.flatten.each do |key|
78
- begin
79
- perform(:getkq, key)
80
- rescue DalliError, NetworkError => e
81
- Dalli.logger.debug { e.inspect }
82
- Dalli.logger.debug { "unable to get key #{key}" }
70
+ perform do
71
+ return {} if keys.empty?
72
+ options = nil
73
+ options = keys.pop if keys.last.is_a?(Hash) || keys.last.nil?
74
+ ring.lock do
75
+ begin
76
+ mapped_keys = keys.flatten.map {|a| validate_key(a.to_s)}
77
+ groups = mapped_keys.flatten.group_by do |key|
78
+ begin
79
+ ring.server_for_key(key)
80
+ rescue Dalli::RingError
81
+ Dalli.logger.debug { "unable to get key #{key}" }
82
+ nil
83
+ end
84
+ end
85
+ if unfound_keys = groups.delete(nil)
86
+ Dalli.logger.debug { "unable to get keys for #{unfound_keys.length} keys because no matching server was found" }
83
87
  end
84
- end
85
88
 
86
- values = {}
87
- return values if servers.empty?
88
-
89
- servers.each do |server|
90
- next unless server.alive?
91
- begin
92
- server.multi_response_start
93
- rescue DalliError, NetworkError => e
94
- Dalli.logger.debug { e.inspect }
95
- Dalli.logger.debug { "results from this server will be missing" }
96
- servers.delete(server)
89
+ groups.each do |server, keys_for_server|
90
+ begin
91
+ # TODO: do this with the perform chokepoint?
92
+ # But given the fact that fetching the response doesn't take place
93
+ # in that slot it's misleading anyway. Need to move all of this method
94
+ # into perform to be meaningful
95
+ server.request(:send_multiget, keys_for_server)
96
+ rescue DalliError, NetworkError => e
97
+ Dalli.logger.debug { e.inspect }
98
+ Dalli.logger.debug { "unable to get keys for server #{server.hostname}:#{server.port}" }
99
+ end
97
100
  end
98
- end
99
101
 
100
- start = Time.now
101
- loop do
102
- # remove any dead servers
103
- servers.delete_if { |s| s.sock.nil? }
104
- break if servers.empty?
105
-
106
- # calculate remaining timeout
107
- elapsed = Time.now - start
108
- timeout = servers.first.options[:socket_timeout]
109
- if elapsed > timeout
110
- readable = nil
111
- else
112
- sockets = servers.map(&:sock)
113
- readable, _ = IO.select(sockets, nil, nil, timeout - elapsed)
102
+ servers = groups.keys
103
+ values = {}
104
+ return values if servers.empty?
105
+
106
+ servers.each do |server|
107
+ next unless server.alive?
108
+ begin
109
+ server.multi_response_start
110
+ rescue DalliError, NetworkError => e
111
+ Dalli.logger.debug { e.inspect }
112
+ Dalli.logger.debug { "results from this server will be missing" }
113
+ servers.delete(server)
114
+ end
114
115
  end
115
116
 
116
- if readable.nil?
117
- # no response within timeout; abort pending connections
118
- servers.each do |server|
119
- puts "Abort!"
120
- server.multi_response_abort
117
+ start = Time.now
118
+ loop do
119
+ # remove any dead servers
120
+ servers.delete_if { |s| s.sock.nil? }
121
+ break if servers.empty?
122
+
123
+ # calculate remaining timeout
124
+ elapsed = Time.now - start
125
+ timeout = servers.first.options[:socket_timeout]
126
+ if elapsed > timeout
127
+ readable = nil
128
+ else
129
+ sockets = servers.map(&:sock)
130
+ readable, _ = IO.select(sockets, nil, nil, timeout - elapsed)
121
131
  end
122
- break
123
132
 
124
- else
125
- readable.each do |sock|
126
- server = sock.server
133
+ if readable.nil?
134
+ # no response within timeout; abort pending connections
135
+ servers.each do |server|
136
+ Dalli.logger.debug { "memcached at #{server.name} did not response within timeout" }
137
+ server.multi_response_abort
138
+ end
139
+ break
127
140
 
128
- begin
129
- server.multi_response_nonblock.each do |key, value|
130
- values[key_without_namespace(key)] = value
131
- end
141
+ else
142
+ readable.each do |sock|
143
+ server = sock.server
132
144
 
133
- if server.multi_response_completed?
145
+ begin
146
+ server.multi_response_nonblock.each do |key, value|
147
+ values[key_without_namespace(key)] = value
148
+ end
149
+
150
+ if server.multi_response_completed?
151
+ servers.delete(server)
152
+ end
153
+ rescue NetworkError
134
154
  servers.delete(server)
135
155
  end
136
- rescue NetworkError
137
- servers.delete(server)
138
156
  end
139
157
  end
140
158
  end
141
- end
142
159
 
143
- values
144
- ensure
145
- self.servers_in_use = nil
160
+ values
161
+ end
146
162
  end
147
163
  end
148
164
  end
@@ -321,13 +337,15 @@ module Dalli
321
337
  end
322
338
 
323
339
  # Chokepoint method for instrumentation
324
- def perform(op, key, *args)
340
+ def perform(*all_args, &blk)
341
+ return blk.call if blk
342
+ op, key, *args = *all_args
343
+
325
344
  key = key.to_s
326
345
  key = validate_key(key)
327
346
  begin
328
347
  server = ring.server_for_key(key)
329
348
  ret = server.request(op, key, *args)
330
- servers_in_use << server if servers_in_use
331
349
  ret
332
350
  rescue NetworkError => e
333
351
  Dalli.logger.debug { e.inspect }
@@ -336,14 +354,6 @@ module Dalli
336
354
  end
337
355
  end
338
356
 
339
- def servers_in_use
340
- Thread.current[:"#{object_id}-servers"]
341
- end
342
-
343
- def servers_in_use=(value)
344
- Thread.current[:"#{object_id}-servers"] = value
345
- end
346
-
347
357
  def validate_key(key)
348
358
  raise ArgumentError, "key cannot be blank" if !key || key.length == 0
349
359
  key = key_with_namespace(key)
data/lib/dalli/server.rb CHANGED
@@ -48,6 +48,10 @@ module Dalli
48
48
  @inprogress = nil
49
49
  end
50
50
 
51
+ def name
52
+ "#{@hostname}:#{@port}"
53
+ end
54
+
51
55
  # Chokepoint method for instrumentation
52
56
  def request(op, *args)
53
57
  verify_state
@@ -252,44 +256,42 @@ module Dalli
252
256
  generic_response(true)
253
257
  end
254
258
 
255
- def getkq(key)
256
- req = [REQUEST, OPCODES[:getkq], key.bytesize, 0, 0, 0, key.bytesize, 0, 0, key].pack(FORMAT[:getkq])
259
+ def send_multiget(keys)
260
+ req = ""
261
+ keys.each do |key|
262
+ req << [REQUEST, OPCODES[:getkq], key.bytesize, 0, 0, 0, key.bytesize, 0, 0, key].pack(FORMAT[:getkq])
263
+ end
264
+ # Could send noop here instead of in multi_response_start
257
265
  write(req)
258
266
  end
259
267
 
260
268
  def set(key, value, ttl, cas, options)
261
269
  (value, flags) = serialize(key, value, options)
262
270
 
263
- if under_max_value_size?(key, value)
271
+ guard_max_value(key, value) do
264
272
  req = [REQUEST, OPCODES[multi? ? :setq : :set], key.bytesize, 8, 0, 0, value.bytesize + key.bytesize + 8, 0, cas, flags, ttl, key, value].pack(FORMAT[:set])
265
273
  write(req)
266
274
  generic_response unless multi?
267
- else
268
- false
269
275
  end
270
276
  end
271
277
 
272
278
  def add(key, value, ttl, options)
273
279
  (value, flags) = serialize(key, value, options)
274
280
 
275
- if under_max_value_size?(key, value)
281
+ guard_max_value(key, value) do
276
282
  req = [REQUEST, OPCODES[multi? ? :addq : :add], key.bytesize, 8, 0, 0, value.bytesize + key.bytesize + 8, 0, 0, flags, ttl, key, value].pack(FORMAT[:add])
277
283
  write(req)
278
284
  generic_response unless multi?
279
- else
280
- false
281
285
  end
282
286
  end
283
287
 
284
288
  def replace(key, value, ttl, options)
285
289
  (value, flags) = serialize(key, value, options)
286
290
 
287
- if under_max_value_size?(key, value)
291
+ guard_max_value(key, value) do
288
292
  req = [REQUEST, OPCODES[multi? ? :replaceq : :replace], key.bytesize, 8, 0, 0, value.bytesize + key.bytesize + 8, 0, 0, flags, ttl, key, value].pack(FORMAT[:replace])
289
293
  write(req)
290
294
  generic_response unless multi?
291
- else
292
- false
293
295
  end
294
296
  end
295
297
 
@@ -451,11 +453,11 @@ module Dalli
451
453
  NORMAL_HEADER = '@4CCnN'
452
454
  KV_HEADER = '@2n@6nN'
453
455
 
454
- def under_max_value_size?(key, value)
456
+ def guard_max_value(key, value)
455
457
  if value.bytesize <= @options[:value_max_bytes]
456
- true
458
+ yield
457
459
  else
458
- Dalli.logger.warn "Value for #{key} over max size"
460
+ Dalli.logger.warn "Value for #{key} over max size: #{@options[:value_max_bytes]} <= #{value.bytesize}"
459
461
  false
460
462
  end
461
463
  end
data/lib/dalli/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '2.6.3'
2
+ VERSION = '2.6.4'
3
3
  end
data/test/helper.rb CHANGED
@@ -5,7 +5,6 @@ require 'rubygems'
5
5
  require 'minitest/pride'
6
6
  require 'minitest/autorun'
7
7
  require 'mocha/setup'
8
- require 'mini_shoulda'
9
8
  require 'memcached_mock'
10
9
 
11
10
  WANT_RAILS_VERSION = ENV['RAILS_VERSION'] || '>= 3.0.0'
@@ -8,14 +8,14 @@ class MockUser
8
8
  end
9
9
 
10
10
  describe 'ActiveSupport' do
11
- context 'active_support caching' do
11
+ describe 'active_support caching' do
12
12
 
13
- should 'have accessible options' do
13
+ it 'has accessible options' do
14
14
  @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122', :expires_in => 5.minutes, :frob => 'baz')
15
15
  assert_equal 'baz', @dalli.options[:frob]
16
16
  end
17
17
 
18
- should 'allow mute and silence' do
18
+ it 'allow mute and silence' do
19
19
  @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122')
20
20
  @dalli.mute do
21
21
  assert_equal true, @dalli.write('foo', 'bar', nil)
@@ -26,7 +26,7 @@ describe 'ActiveSupport' do
26
26
  assert_equal true, @dalli.silence?
27
27
  end
28
28
 
29
- should 'handle nil options' do
29
+ it 'handle nil options' do
30
30
  @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122')
31
31
  assert_equal true, @dalli.write('foo', 'bar', nil)
32
32
  assert_equal 'bar', @dalli.read('foo', nil)
@@ -38,7 +38,7 @@ describe 'ActiveSupport' do
38
38
  assert_equal true, @dalli.delete('lkjsa')
39
39
  end
40
40
 
41
- should 'support fetch' do
41
+ it 'support fetch' do
42
42
  with_activesupport do
43
43
  memcached do
44
44
  connect
@@ -65,7 +65,7 @@ describe 'ActiveSupport' do
65
65
  end
66
66
  end
67
67
 
68
- should 'support keys with spaces on Rails3' do
68
+ it 'support keys with spaces on Rails3' do
69
69
  with_activesupport do
70
70
  memcached do
71
71
  connect
@@ -75,7 +75,7 @@ describe 'ActiveSupport' do
75
75
  end
76
76
  end
77
77
 
78
- should 'support read_multi' do
78
+ it 'support read_multi' do
79
79
  with_activesupport do
80
80
  memcached do
81
81
  connect
@@ -89,7 +89,7 @@ describe 'ActiveSupport' do
89
89
  end
90
90
  end
91
91
 
92
- should 'support read_multi with an array' do
92
+ it 'support read_multi with an array' do
93
93
  with_activesupport do
94
94
  memcached do
95
95
  connect
@@ -105,7 +105,7 @@ describe 'ActiveSupport' do
105
105
  end
106
106
  end
107
107
 
108
- should 'support raw read_multi' do
108
+ it 'support raw read_multi' do
109
109
  with_activesupport do
110
110
  memcached do
111
111
  connect
@@ -116,7 +116,7 @@ describe 'ActiveSupport' do
116
116
  end
117
117
  end
118
118
 
119
- should 'support read_multi with LocalCache' do
119
+ it 'support read_multi with LocalCache' do
120
120
  with_activesupport do
121
121
  memcached do
122
122
  connect
@@ -147,7 +147,7 @@ describe 'ActiveSupport' do
147
147
  end
148
148
  end
149
149
 
150
- should 'support read, write and delete' do
150
+ it 'support read, write and delete' do
151
151
  with_activesupport do
152
152
  memcached do
153
153
  connect
@@ -180,7 +180,7 @@ describe 'ActiveSupport' do
180
180
  end
181
181
  end
182
182
 
183
- should 'support read, write and delete with LocalCache' do
183
+ it 'support read, write and delete with LocalCache' do
184
184
  with_activesupport do
185
185
  memcached do
186
186
  connect
@@ -208,7 +208,31 @@ describe 'ActiveSupport' do
208
208
  end
209
209
  end
210
210
 
211
- should 'support increment/decrement commands' do
211
+ it 'support unless_exist with LocalCache' do
212
+ with_activesupport do
213
+ memcached do
214
+ connect
215
+ y = rand_key.to_s
216
+ @dalli.with_local_cache do
217
+ Dalli::Client.any_instance.expects(:add).with(y, 123, nil, {:unless_exist => true}).once.returns(true)
218
+ dres = @dalli.write(y, 123, :unless_exist => true)
219
+ assert_equal true, dres
220
+
221
+ Dalli::Client.any_instance.expects(:add).with(y, 321, nil, {:unless_exist => true}).once.returns(false)
222
+
223
+ dres = @dalli.write(y, 321, :unless_exist => true)
224
+ assert_equal false, dres
225
+
226
+ Dalli::Client.any_instance.expects(:get).with(y, {}).once.returns(123)
227
+
228
+ dres = @dalli.read(y)
229
+ assert_equal 123, dres
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ it 'support increment/decrement commands' do
212
236
  with_activesupport do
213
237
  memcached do
214
238
  connect
@@ -246,7 +270,7 @@ describe 'ActiveSupport' do
246
270
  end
247
271
  end
248
272
 
249
- should 'support exist command' do
273
+ it 'support exist command' do
250
274
  with_activesupport do
251
275
  memcached do
252
276
  connect
@@ -265,7 +289,7 @@ describe 'ActiveSupport' do
265
289
  end
266
290
  end
267
291
 
268
- should 'support other esoteric commands' do
292
+ it 'support other esoteric commands' do
269
293
  with_activesupport do
270
294
  memcached do
271
295
  connect
@@ -278,7 +302,7 @@ describe 'ActiveSupport' do
278
302
  end
279
303
  end
280
304
 
281
- should 'respect "raise_errors" option' do
305
+ it 'respect "raise_errors" option' do
282
306
  with_activesupport do
283
307
  memcached(29125) do
284
308
  @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:29125')
@@ -308,7 +332,7 @@ describe 'ActiveSupport' do
308
332
  end
309
333
  end
310
334
 
311
- should 'handle crazy characters from far-away lands' do
335
+ it 'handle crazy characters from far-away lands' do
312
336
  with_activesupport do
313
337
  memcached do
314
338
  connect
@@ -320,7 +344,7 @@ describe 'ActiveSupport' do
320
344
  end
321
345
  end
322
346
 
323
- should 'normalize options as expected' do
347
+ it 'normalize options as expected' do
324
348
  with_activesupport do
325
349
  memcached do
326
350
  @dalli = ActiveSupport::Cache::DalliStore.new('localhost:19122', :expires_in => 1, :namespace => 'foo', :compress => true)
@@ -330,7 +354,7 @@ describe 'ActiveSupport' do
330
354
  end
331
355
  end
332
356
 
333
- should 'allow keys to be frozen' do
357
+ it 'allow keys to be frozen' do
334
358
  with_activesupport do
335
359
  memcached do
336
360
  connect
@@ -341,7 +365,7 @@ describe 'ActiveSupport' do
341
365
  end
342
366
  end
343
367
 
344
- should 'allow keys from a hash' do
368
+ it 'allow keys from a hash' do
345
369
  with_activesupport do
346
370
  memcached do
347
371
  connect
@@ -15,7 +15,7 @@ end
15
15
 
16
16
  describe 'Compressor' do
17
17
 
18
- should 'default to Dalli::Compressor' do
18
+ it 'default to Dalli::Compressor' do
19
19
  memcached_kill(29199) do |dc|
20
20
  memcache = Dalli::Client.new('127.0.0.1:29199')
21
21
  memcache.set 1,2
@@ -23,16 +23,16 @@ describe 'Compressor' do
23
23
  end
24
24
  end
25
25
 
26
- should 'support a custom compressor' do
26
+ it 'support a custom compressor' do
27
27
  memcached_kill(29199) do |dc|
28
28
  memcache = Dalli::Client.new('127.0.0.1:29199', :compressor => NoopCompressor)
29
29
  memcache.set 1,2
30
30
  begin
31
31
  assert_equal NoopCompressor, memcache.instance_variable_get('@ring').servers.first.compressor
32
32
 
33
- memcached(19127) do |dc|
34
- assert dc.set("string-test", "a test string")
35
- assert_equal("a test string", dc.get("string-test"))
33
+ memcached(19127) do |newdc|
34
+ assert newdc.set("string-test", "a test string")
35
+ assert_equal("a test string", newdc.get("string-test"))
36
36
  end
37
37
  end
38
38
  end
@@ -41,7 +41,7 @@ end
41
41
 
42
42
  describe 'GzipCompressor' do
43
43
 
44
- should 'compress and uncompress data using Zlib::GzipWriter/Reader' do
44
+ it 'compress and uncompress data using Zlib::GzipWriter/Reader' do
45
45
  memcached(19127,nil,{:compress=>true,:compressor=>Dalli::GzipCompressor}) do |dc|
46
46
  data = (0...1025).map{65.+(rand(26)).chr}.join
47
47
  assert dc.set("test", data)
data/test/test_dalli.rb CHANGED
@@ -3,19 +3,19 @@ require 'memcached_mock'
3
3
 
4
4
  describe 'Dalli' do
5
5
  describe 'options parsing' do
6
- should 'handle deprecated options' do
6
+ it 'handle deprecated options' do
7
7
  dc = Dalli::Client.new('foo', :compression => true)
8
8
  assert dc.instance_variable_get(:@options)[:compress]
9
9
  refute dc.instance_variable_get(:@options)[:compression]
10
10
  end
11
11
 
12
- should 'not warn about valid options' do
12
+ it 'not warn about valid options' do
13
13
  dc = Dalli::Client.new('foo', :compress => true)
14
14
  # Rails.logger.expects :warn
15
15
  assert dc.instance_variable_get(:@options)[:compress]
16
16
  end
17
17
 
18
- should 'raises error with invalid expires_in' do
18
+ it 'raises error with invalid expires_in' do
19
19
  bad_data = [{:bad => 'expires in data'}, Hash, [1,2,3]]
20
20
  bad_data.each do |bad|
21
21
  assert_raises ArgumentError do
@@ -26,7 +26,7 @@ describe 'Dalli' do
26
26
  end
27
27
 
28
28
  describe 'key validation' do
29
- should 'not allow blanks' do
29
+ it 'not allow blanks' do
30
30
  memcached do |dc|
31
31
  dc.set ' ', 1
32
32
  assert_equal 1, dc.get(' ')
@@ -44,7 +44,7 @@ describe 'Dalli' do
44
44
  end
45
45
  end
46
46
 
47
- should "default to localhost:11211" do
47
+ it "default to localhost:11211" do
48
48
  dc = Dalli::Client.new
49
49
  ring = dc.send(:ring)
50
50
  s1 = ring.servers.first.hostname
@@ -67,7 +67,7 @@ describe 'Dalli' do
67
67
  assert_equal s2, s3
68
68
  end
69
69
 
70
- should "accept comma separated string" do
70
+ it "accept comma separated string" do
71
71
  dc = Dalli::Client.new("server1.example.com:11211,server2.example.com:11211")
72
72
  ring = dc.send(:ring)
73
73
  assert_equal 2, ring.servers.size
@@ -76,7 +76,7 @@ describe 'Dalli' do
76
76
  assert_equal "server2.example.com", s2
77
77
  end
78
78
 
79
- should "accept array of servers" do
79
+ it "accept array of servers" do
80
80
  dc = Dalli::Client.new(["server1.example.com:11211","server2.example.com:11211"])
81
81
  ring = dc.send(:ring)
82
82
  assert_equal 2, ring.servers.size
@@ -85,9 +85,9 @@ describe 'Dalli' do
85
85
  assert_equal "server2.example.com", s2
86
86
  end
87
87
 
88
- context 'using a live server' do
88
+ describe 'using a live server' do
89
89
 
90
- should "support get/set" do
90
+ it "support get/set" do
91
91
  memcached do |dc|
92
92
  dc.flush
93
93
 
@@ -104,7 +104,7 @@ describe 'Dalli' do
104
104
  end
105
105
  end
106
106
 
107
- should "support stats" do
107
+ it "support stats" do
108
108
  memcached do |dc|
109
109
  # make sure that get_hits would not equal 0
110
110
  dc.get(:a)
@@ -144,7 +144,7 @@ describe 'Dalli' do
144
144
  end
145
145
  end
146
146
 
147
- should "support the fetch operation" do
147
+ it "support the fetch operation" do
148
148
  memcached do |dc|
149
149
  dc.flush
150
150
 
@@ -167,7 +167,7 @@ describe 'Dalli' do
167
167
  end
168
168
  end
169
169
 
170
- should "support the fetch operation with falsey values" do
170
+ it "support the fetch operation with falsey values" do
171
171
  memcached do |dc|
172
172
  dc.flush
173
173
 
@@ -181,14 +181,14 @@ describe 'Dalli' do
181
181
  end
182
182
  end
183
183
 
184
- should "support the cas operation" do
184
+ it "support the cas operation" do
185
185
  memcached do |dc|
186
186
  dc.flush
187
187
 
188
188
  expected = { 'blah' => 'blerg!' }
189
189
 
190
190
  resp = dc.cas('cas_key') do |value|
191
- fail('Value should not exist')
191
+ fail('Value it not exist')
192
192
  end
193
193
  assert_nil resp
194
194
 
@@ -205,7 +205,7 @@ describe 'Dalli' do
205
205
  end
206
206
  end
207
207
 
208
- should "support multi-get" do
208
+ it "support multi-get" do
209
209
  memcached do |dc|
210
210
  dc.close
211
211
  dc.flush
@@ -233,7 +233,7 @@ describe 'Dalli' do
233
233
  end
234
234
  end
235
235
 
236
- should 'support raw incr/decr' do
236
+ it 'support raw incr/decr' do
237
237
  memcached do |client|
238
238
  client.flush
239
239
 
@@ -263,7 +263,7 @@ describe 'Dalli' do
263
263
  end
264
264
  end
265
265
 
266
- should "support incr/decr operations" do
266
+ it "support incr/decr operations" do
267
267
  memcached do |dc|
268
268
  dc.flush
269
269
 
@@ -311,7 +311,7 @@ describe 'Dalli' do
311
311
  end
312
312
  end
313
313
 
314
- should 'support the append and prepend operations' do
314
+ it 'support the append and prepend operations' do
315
315
  memcached do |dc|
316
316
  dc.flush
317
317
  assert_equal true, dc.set('456', 'xyz', 0, :raw => true)
@@ -325,7 +325,7 @@ describe 'Dalli' do
325
325
  end
326
326
  end
327
327
 
328
- should 'support touch operation' do
328
+ it 'support touch operation' do
329
329
  memcached do |dc|
330
330
  begin
331
331
  dc.flush
@@ -341,7 +341,7 @@ describe 'Dalli' do
341
341
  end
342
342
  end
343
343
 
344
- should 'allow TCP connections to be configured for keepalive' do
344
+ it 'allow TCP connections to be configured for keepalive' do
345
345
  memcached(19122, '', :keepalive => true) do |dc|
346
346
  dc.set(:a, 1)
347
347
  ring = dc.send(:ring)
@@ -355,7 +355,7 @@ describe 'Dalli' do
355
355
  end
356
356
  end
357
357
 
358
- should "pass a simple smoke test" do
358
+ it "pass a simple smoke test" do
359
359
  memcached do |dc|
360
360
  resp = dc.flush
361
361
  refute_nil resp
@@ -413,7 +413,7 @@ describe 'Dalli' do
413
413
  end
414
414
  end
415
415
 
416
- should "support multithreaded access" do
416
+ it "support multithreaded access" do
417
417
  memcached do |cache|
418
418
  cache.flush
419
419
  workers = []
@@ -456,7 +456,7 @@ describe 'Dalli' do
456
456
  end
457
457
  end
458
458
 
459
- should "handle namespaced keys" do
459
+ it "handle namespaced keys" do
460
460
  memcached do |dc|
461
461
  dc = Dalli::Client.new('localhost:19122', :namespace => 'a')
462
462
  dc.set('namespaced', 1)
@@ -467,7 +467,7 @@ describe 'Dalli' do
467
467
  end
468
468
  end
469
469
 
470
- should 'truncate cache keys that are too long' do
470
+ it 'truncate cache keys that are too long' do
471
471
  memcached do
472
472
  @dalli = Dalli::Client.new('localhost:19122', :namespace => 'some:namspace')
473
473
  key = "this cache key is far too long so it must be hashed and truncated and stuff" * 10
@@ -477,7 +477,7 @@ describe 'Dalli' do
477
477
  end
478
478
  end
479
479
 
480
- should "handle namespaced keys in multi_get" do
480
+ it "handle namespaced keys in multi_get" do
481
481
  memcached do |dc|
482
482
  dc = Dalli::Client.new('localhost:19122', :namespace => 'a')
483
483
  dc.set('a', 1)
@@ -486,7 +486,7 @@ describe 'Dalli' do
486
486
  end
487
487
  end
488
488
 
489
- should "handle application marshalling issues" do
489
+ it "handle application marshalling issues" do
490
490
  memcached do |dc|
491
491
  old = Dalli.logger
492
492
  Dalli.logger = Logger.new(nil)
@@ -498,8 +498,8 @@ describe 'Dalli' do
498
498
  end
499
499
  end
500
500
 
501
- context 'with compression' do
502
- should 'allow large values' do
501
+ describe 'with compression' do
502
+ it 'allow large values' do
503
503
  memcached do |dc|
504
504
  dalli = Dalli::Client.new(dc.instance_variable_get(:@servers), :compress => true)
505
505
 
@@ -510,9 +510,9 @@ describe 'Dalli' do
510
510
  end
511
511
  end
512
512
 
513
- context 'in low memory conditions' do
513
+ describe 'in low memory conditions' do
514
514
 
515
- should 'handle error response correctly' do
515
+ it 'handle error response correctly' do
516
516
  memcached(19125, '-m 1 -M') do |dc|
517
517
  failed = false
518
518
  value = "1234567890"*100
@@ -529,7 +529,7 @@ describe 'Dalli' do
529
529
  end
530
530
  end
531
531
 
532
- should 'fit more values with compression' do
532
+ it 'fit more values with compression' do
533
533
  memcached(19126, '-m 1 -M') do |dc|
534
534
  dalli = Dalli::Client.new('localhost:19126', :compress => true)
535
535
  failed = false
@@ -4,8 +4,8 @@ require 'memcached_mock'
4
4
 
5
5
  describe 'Encoding' do
6
6
 
7
- context 'using a live server' do
8
- should 'support i18n content' do
7
+ describe 'using a live server' do
8
+ it 'support i18n content' do
9
9
  memcached do |dc|
10
10
  key = 'foo'
11
11
  utf_key = utf8 = 'ƒ©åÍÎ'
@@ -18,7 +18,7 @@ describe 'Encoding' do
18
18
  end
19
19
  end
20
20
 
21
- should 'support content expiry' do
21
+ it 'support content expiry' do
22
22
  memcached do |dc|
23
23
  key = 'foo'
24
24
  assert dc.set(key, 'bar', 1)
@@ -3,7 +3,7 @@ require 'helper'
3
3
  describe 'failover' do
4
4
 
5
5
  describe 'timeouts' do
6
- should 'not lead to corrupt sockets' do
6
+ it 'not lead to corrupt sockets' do
7
7
  memcached(29125) do
8
8
  dc = Dalli::Client.new ['localhost:29125']
9
9
  begin
@@ -22,9 +22,9 @@ describe 'failover' do
22
22
  end
23
23
 
24
24
 
25
- context 'assuming some bad servers' do
25
+ describe 'assuming some bad servers' do
26
26
 
27
- should 'silently reconnect if server hiccups' do
27
+ it 'silently reconnect if server hiccups' do
28
28
  memcached(29125) do
29
29
  dc = Dalli::Client.new ['localhost:29125']
30
30
  dc.set 'foo', 'bar'
@@ -42,7 +42,7 @@ describe 'failover' do
42
42
  end
43
43
  end
44
44
 
45
- should 'handle graceful failover' do
45
+ it 'handle graceful failover' do
46
46
  memcached(29125) do
47
47
  memcached(29126) do
48
48
  dc = Dalli::Client.new ['localhost:29125', 'localhost:29126']
@@ -65,7 +65,7 @@ describe 'failover' do
65
65
  end
66
66
  end
67
67
 
68
- should 'handle them gracefully in get_multi' do
68
+ it 'handle them gracefully in get_multi' do
69
69
  memcached(29125) do
70
70
  memcached(29126) do
71
71
  dc = Dalli::Client.new ['localhost:29125', 'localhost:29126']
@@ -81,7 +81,7 @@ describe 'failover' do
81
81
  end
82
82
  end
83
83
 
84
- should 'handle graceful failover in get_multi' do
84
+ it 'handle graceful failover in get_multi' do
85
85
  memcached(29125) do
86
86
  memcached(29126) do
87
87
  dc = Dalli::Client.new ['localhost:29125', 'localhost:29126']
@@ -105,7 +105,7 @@ describe 'failover' do
105
105
  end
106
106
  end
107
107
 
108
- should 'stats should still properly report' do
108
+ it 'stats it still properly report' do
109
109
  memcached(29125) do
110
110
  memcached(29126) do
111
111
  dc = Dalli::Client.new ['localhost:29125', 'localhost:29126']
data/test/test_network.rb CHANGED
@@ -2,17 +2,17 @@ require 'helper'
2
2
 
3
3
  describe 'Network' do
4
4
 
5
- context 'assuming a bad network' do
5
+ describe 'assuming a bad network' do
6
6
 
7
- should 'handle no server available' do
7
+ it 'handle no server available' do
8
8
  assert_raises Dalli::RingError, :message => "No server available" do
9
9
  dc = Dalli::Client.new 'localhost:19333'
10
10
  dc.get 'foo'
11
11
  end
12
12
  end
13
13
 
14
- context 'with a fake server' do
15
- should 'handle connection reset' do
14
+ describe 'with a fake server' do
15
+ it 'handle connection reset' do
16
16
  memcached_mock(lambda {|sock| sock.close }) do
17
17
  assert_raises Dalli::RingError, :message => "No server available" do
18
18
  dc = Dalli::Client.new('localhost:19123')
@@ -21,7 +21,7 @@ describe 'Network' do
21
21
  end
22
22
  end
23
23
 
24
- should 'handle malformed response' do
24
+ it 'handle malformed response' do
25
25
  memcached_mock(lambda {|sock| sock.write('123') }) do
26
26
  assert_raises Dalli::RingError, :message => "No server available" do
27
27
  dc = Dalli::Client.new('localhost:19123')
@@ -30,7 +30,7 @@ describe 'Network' do
30
30
  end
31
31
  end
32
32
 
33
- should 'handle connect timeouts' do
33
+ it 'handle connect timeouts' do
34
34
  memcached_mock(lambda {|sock| sleep(0.6); sock.close }, :delayed_start) do
35
35
  assert_raises Dalli::RingError, :message => "No server available" do
36
36
  dc = Dalli::Client.new('localhost:19123')
@@ -39,7 +39,7 @@ describe 'Network' do
39
39
  end
40
40
  end
41
41
 
42
- should 'handle read timeouts' do
42
+ it 'handle read timeouts' do
43
43
  memcached_mock(lambda {|sock| sleep(0.6); sock.write('giraffe') }) do
44
44
  assert_raises Dalli::RingError, :message => "No server available" do
45
45
  dc = Dalli::Client.new('localhost:19123')
data/test/test_ring.rb CHANGED
@@ -2,9 +2,9 @@ require 'helper'
2
2
 
3
3
  describe 'Ring' do
4
4
 
5
- context 'a ring of servers' do
5
+ describe 'a ring of servers' do
6
6
 
7
- should "have the continuum sorted by value" do
7
+ it "have the continuum sorted by value" do
8
8
  servers = [stub(:hostname => "localhost", :port => "11211", :weight => 1),
9
9
  stub(:hostname => "localhost", :port => "9500", :weight => 1)]
10
10
  ring = Dalli::Ring.new(servers, {})
@@ -15,15 +15,15 @@ describe 'Ring' do
15
15
  end
16
16
  end
17
17
 
18
- should 'raise when no servers are available/defined' do
18
+ it 'raise when no servers are available/defined' do
19
19
  ring = Dalli::Ring.new([], {})
20
20
  assert_raises Dalli::RingError, :message => "No server available" do
21
21
  ring.server_for_key('test')
22
22
  end
23
23
  end
24
24
 
25
- context 'containing only a single server' do
26
- should "raise correctly when it's not alive" do
25
+ describe 'containing only a single server' do
26
+ it "raise correctly when it's not alive" do
27
27
  servers = [
28
28
  Dalli::Server.new("localhost:12345"),
29
29
  ]
@@ -33,7 +33,7 @@ describe 'Ring' do
33
33
  end
34
34
  end
35
35
 
36
- should "return the server when it's alive" do
36
+ it "return the server when it's alive" do
37
37
  servers = [
38
38
  Dalli::Server.new("localhost:19191"),
39
39
  ]
@@ -45,8 +45,8 @@ describe 'Ring' do
45
45
  end
46
46
  end
47
47
 
48
- context 'containing multiple servers' do
49
- should "raise correctly when no server is alive" do
48
+ describe 'containing multiple servers' do
49
+ it "raise correctly when no server is alive" do
50
50
  servers = [
51
51
  Dalli::Server.new("localhost:12345"),
52
52
  Dalli::Server.new("localhost:12346"),
@@ -57,7 +57,7 @@ describe 'Ring' do
57
57
  end
58
58
  end
59
59
 
60
- should "return an alive server when at least one is alive" do
60
+ it "return an alive server when at least one is alive" do
61
61
  servers = [
62
62
  Dalli::Server.new("localhost:12346"),
63
63
  Dalli::Server.new("localhost:19191"),
@@ -70,7 +70,7 @@ describe 'Ring' do
70
70
  end
71
71
  end
72
72
 
73
- should 'detect when a dead server is up again' do
73
+ it 'detect when a dead server is up again' do
74
74
  memcached(19997) do
75
75
  down_retry_delay = 0.5
76
76
  dc = Dalli::Client.new(['localhost:19997', 'localhost:19998'], :down_retry_delay => down_retry_delay)
data/test/test_sasl.rb CHANGED
@@ -2,7 +2,11 @@ require 'helper'
2
2
 
3
3
  describe 'Sasl' do
4
4
 
5
- context 'a server requiring authentication' do
5
+ # https://github.com/seattlerb/minitest/issues/298
6
+ def self.xit(msg, &block)
7
+ end
8
+
9
+ describe 'a server requiring authentication' do
6
10
  before do
7
11
  @server = mock()
8
12
  @server.stubs(:request).returns(true)
@@ -11,7 +15,7 @@ describe 'Sasl' do
11
15
  @server.stubs(:port).returns("19124")
12
16
  end
13
17
 
14
- context 'without authentication credentials' do
18
+ describe 'without authentication credentials' do
15
19
  before do
16
20
  ENV['MEMCACHE_USERNAME'] = 'foo'
17
21
  ENV['MEMCACHE_PASSWORD'] = 'wrongpwd'
@@ -22,11 +26,11 @@ describe 'Sasl' do
22
26
  ENV['MEMCACHE_PASSWORD'] = nil
23
27
  end
24
28
 
25
- should 'provide one test that passes' do
29
+ it 'provide one test that passes' do
26
30
  assert true
27
31
  end
28
32
 
29
- should_eventually 'gracefully handle authentication failures' do
33
+ xit 'gracefully handle authentication failures' do
30
34
  memcached(19124, '-S') do |dc|
31
35
  assert_raise Dalli::DalliError, /32/ do
32
36
  dc.set('abc', 123)
@@ -35,7 +39,7 @@ describe 'Sasl' do
35
39
  end
36
40
  end
37
41
 
38
- should_eventually 'fail SASL authentication with wrong options' do
42
+ xit 'fail SASL authentication with wrong options' do
39
43
  memcached(19124, '-S') do |dc|
40
44
  dc = Dalli::Client.new('localhost:19124', :username => 'foo', :password => 'wrongpwd')
41
45
  assert_raise Dalli::DalliError, /32/ do
@@ -49,7 +53,7 @@ describe 'Sasl' do
49
53
  # saslpasswd2 -a memcached -c testuser
50
54
  #
51
55
  # with password 'testtest'
52
- context 'in an authenticated environment' do
56
+ describe 'in an authenticated environment' do
53
57
  before do
54
58
  ENV['MEMCACHE_USERNAME'] = 'testuser'
55
59
  ENV['MEMCACHE_PASSWORD'] = 'testtest'
@@ -60,7 +64,7 @@ describe 'Sasl' do
60
64
  ENV['MEMCACHE_PASSWORD'] = nil
61
65
  end
62
66
 
63
- should_eventually 'pass SASL authentication' do
67
+ xit 'pass SASL authentication' do
64
68
  memcached(19124, '-S') do |dc|
65
69
  # I get "Dalli::DalliError: Error authenticating: 32" in OSX
66
70
  # but SASL works on Heroku servers. YMMV.
@@ -73,7 +77,7 @@ describe 'Sasl' do
73
77
  end
74
78
  end
75
79
 
76
- should_eventually 'pass SASL authentication with options' do
80
+ xit 'pass SASL authentication with options' do
77
81
  memcached(19124, '-S') do |dc|
78
82
  dc = Dalli::Client.new('localhost:19124', :username => 'testuser', :password => 'testtest')
79
83
  # I get "Dalli::DalliError: Error authenticating: 32" in OSX
@@ -86,14 +90,14 @@ describe 'Sasl' do
86
90
  end
87
91
  end
88
92
 
89
- should 'pass SASL as URI' do
93
+ it 'pass SASL as URI' do
90
94
  Dalli::Server.expects(:new).with("localhost:19124",
91
95
  :username => "testuser", :password => "testtest").returns(@server)
92
96
  dc = Dalli::Client.new('memcached://testuser:testtest@localhost:19124')
93
97
  dc.flush_all
94
98
  end
95
99
 
96
- should 'pass SASL as ring of URIs' do
100
+ it 'pass SASL as ring of URIs' do
97
101
  Dalli::Server.expects(:new).with("localhost:19124",
98
102
  :username => "testuser", :password => "testtest").returns(@server)
99
103
  Dalli::Server.expects(:new).with("otherhost:19125",
@@ -5,7 +5,7 @@ require 'memcached_mock'
5
5
 
6
6
  describe 'Serializer' do
7
7
 
8
- should 'default to Marshal' do
8
+ it 'default to Marshal' do
9
9
  memcached_kill(29198) do |dc|
10
10
  memcache = Dalli::Client.new('127.0.0.1:29198')
11
11
  memcache.set 1,2
@@ -13,16 +13,16 @@ describe 'Serializer' do
13
13
  end
14
14
  end
15
15
 
16
- should 'support a custom serializer' do
16
+ it 'support a custom serializer' do
17
17
  memcached_kill(29198) do |dc|
18
18
  memcache = Dalli::Client.new('127.0.0.1:29198', :serializer => JSON)
19
19
  memcache.set 1,2
20
20
  begin
21
21
  assert_equal JSON, memcache.instance_variable_get('@ring').servers.first.serializer
22
22
 
23
- memcached(19128) do |dc|
24
- assert dc.set("json_test", {"foo" => "bar"})
25
- assert_equal({"foo" => "bar"}, dc.get("json_test"))
23
+ memcached(19128) do |newdc|
24
+ assert newdc.set("json_test", {"foo" => "bar"})
25
+ assert_equal({"foo" => "bar"}, newdc.get("json_test"))
26
26
  end
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,16 +9,16 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: mini_shoulda
15
+ name: minitest
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 5.0.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 5.0.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mocha
32
32
  requirement: !ruby/object:Gem::Requirement