This commit is contained in:
Evan Weaver 2012-02-26 09:34:26 -08:00
Родитель 5f60e9ee81
Коммит 1b38c7057c
6 изменённых файлов: 60 добавлений и 65 удалений

Просмотреть файл

@ -1,6 +1,8 @@
v1.4.0. Update Memcached::Rails compatibility wrapper to play along with Rails 3.2, including support for the horrendous ActiveSupport::Duration (tomhughes).
v1.3.7. Rebuild gem to work around timestamp issue in Gemspec on Rubygems 1.7 (tarcieri).
v1.3.6. Stop autoconf from running (eric). Raise generic Memcached::Error (instead of nil) on unexpected return code (gcampbell). Retry on Memcached::ServerEnd (ChristopherThorpe)..8
v1.3.6. Stop autoconf from running (eric). Raise generic Memcached::Error (instead of nil) on unexpected return code (gcampbell). Retry on Memcached::ServerEnd (ChristopherThorpe).
v1.3.5. Fix build again (eric).

Просмотреть файл

@ -152,6 +152,7 @@ ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver
ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c
ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4
ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4
ext/libmemcached-0.32/m4/aclocal.m4
ext/libmemcached-0.32/m4/acx_pthread.m4
ext/libmemcached-0.32/m4/byteorder.m4
ext/libmemcached-0.32/m4/deprecated.m4
@ -224,7 +225,6 @@ lib/memcached/exceptions.rb
lib/memcached/experimental.rb
lib/memcached/memcached.rb
lib/memcached/rails.rb
memcached.gemspec
test/profile/benchmark.rb
test/profile/c_profiler.rb
test/profile/exercise.rb

4
TODO
Просмотреть файл

@ -1,4 +1,4 @@
* Promote touch support to toplevel and add ASCII protocol touching
* Remove SWIG and modify libmemcached to accept and return Ruby objects directly
* Verify that DNS lookups are getting cached
* Check for memory leaks in Valgrind after free callback change
* Re-run benchmarks

Просмотреть файл

@ -4,7 +4,7 @@ class Memcached
eval("alias :'#{method_name}_orig' :'#{method_name}'")
end
# A legacy compatibility wrapper for the Memcached class. It has basic compatibility with the <b>memcache-client</b> API.
# A legacy compatibility wrapper for the Memcached class. It has basic compatibility with the <b>memcache-client</b> API and Rails 3.2.
class Rails < ::Memcached
DEFAULTS = {
@ -67,9 +67,9 @@ class Memcached
def cas(key, ttl=@default_ttl, raw=false, &block)
super(key, ttl, !raw, &block)
true
rescue TypeError
ttl = ttl.to_i
retry
rescue TypeError => e
# Maybe we got an ActiveSupport::Duration
ttl = ttl.value and retry rescue raise e
rescue NotFound, ConnectionDataExists
false
end
@ -85,9 +85,9 @@ class Memcached
def set(key, value, ttl=@default_ttl, raw=false)
super(key, value, ttl, !raw)
true
rescue TypeError
ttl = ttl.to_i
retry
rescue TypeError => e
# Maybe we got an ActiveSupport::Duration
ttl = ttl.value and retry rescue raise e
rescue NotStored
false
end
@ -101,11 +101,10 @@ class Memcached
# Wraps Memcached#add so that it doesn't raise.
def add(key, value, ttl=@default_ttl, raw=false)
super(key, value, ttl, !raw)
# This causes me pain
@string_return_types ? "STORED\r\n" : true
rescue TypeError
ttl = ttl.to_i
retry
rescue TypeError => e
# Maybe we got an ActiveSupport::Duration
ttl = ttl.value and retry rescue raise e
rescue NotStored
@string_return_types? "NOT STORED\r\n" : false
end

Просмотреть файл

@ -60,7 +60,7 @@ class MemcachedExperimentalTest < Test::Unit::TestCase
end
def test_get_len
server_get_len_capable {
server_get_len_capable do
value = "foobar"
@experimental_cache.set key, value, 0, false
result = @experimental_cache.get_len 1, key
@ -82,52 +82,52 @@ class MemcachedExperimentalTest < Test::Unit::TestCase
result = @experimental_cache.get_len 32, key
assert_equal result.size, 6
assert_equal result, value
}
end
end
def test_get_len_0_failure
server_get_len_capable {
server_get_len_capable do
value = "Test that we cannot get 0 bytes with a get_len call."
@experimental_cache.set key, value, 0, false
assert_raises(Memcached::Failure) do
result = @experimental_cache.get_len 0, key
end
}
end
end
def test_get_len_large
server_get_len_capable {
server_get_len_capable do
value = "Test that we can get the first 20 bytes of a string"
@experimental_cache.set key, value, 0, false
result = @experimental_cache.get_len 20, key
assert_equal result.size, 20
assert_equal result, value[0..19]
}
end
end
def test_get_len_packed
server_get_len_capable {
server_get_len_capable do
value = [1, 2, 3, 4].pack("Q*")
@experimental_cache.set key, value, 0, false
result = @experimental_cache.get_len 8, key
assert_equal [1], result.unpack("Q*")
}
end
end
# get_len is not supported when using the binary protocol.
# Make sure the single get variant fails appropriately.
def test_get_len_binary
server_get_len_capable {
server_get_len_capable do
@experimental_binary_protocol_cache.set key, @value
assert_raises(Memcached::ActionNotSupported) do
result = @experimental_binary_protocol_cache.get_len 2, key
end
}
end
end
# Retrieve the first 64 bits of the values for multiple keys.
def test_get_len_multi_packed
server_get_len_capable {
server_get_len_capable do
key_1 = "get_len_1"
value_1 = [1, 2, 3].pack("Q*")
key_2 = "get_len_missing"
@ -140,13 +140,13 @@ class MemcachedExperimentalTest < Test::Unit::TestCase
{key_1=>value_1[0..7], key_3=>value_3[0..7]},
@experimental_cache.get_len(8, keys)
)
}
end
end
# Test that the entire value is passed back when the length specified
# is larger than any of the values (e.g., 32 in the case below).
def test_get_len_multi_packed_full
server_get_len_capable {
server_get_len_capable do
key_1 = "get_len_1"
value_1 = [1, 2, 3].pack("Q*")
key_2 = "get_len_missing"
@ -159,13 +159,13 @@ class MemcachedExperimentalTest < Test::Unit::TestCase
{key_1=>value_1, key_3=>value_3},
@experimental_cache.get_len(32, keys)
)
}
end
end
# get_len is not supported when using the binary protocol.
# Test that the multi get variant fails appropriately.
def test_get_len_multi_packed_binary
server_get_len_capable {
server_get_len_capable do
key_1 = "get_len_1"
value_1 = [1, 2, 3].pack("Q*")
key_2 = "get_len_2"
@ -176,63 +176,63 @@ class MemcachedExperimentalTest < Test::Unit::TestCase
assert_raises(Memcached::ActionNotSupported) do
result = @experimental_binary_protocol_cache.get_len 2, keys
end
}
end
end
def test_get_len_multi_completely_missing
server_get_len_capable {
server_get_len_capable do
@experimental_cache.delete "#{key}_1" rescue nil
@experimental_cache.delete "#{key}_2" rescue nil
assert_equal(
{},
@experimental_cache.get_len(1, ["#{key}_1", "#{key}_2"])
)
}
end
end
def test_get_len_failure
server_get_len_capable {
server_get_len_capable do
value = "Test that we cannot use get_len without setting the :experimental_features config."
assert_raises(NoMethodError) do
result = @cache.get_len 10, key
end
}
end
end
def test_cas
server_get_len_capable {
server_get_len_capable do
# Get the first three chars of the value back.
@experimental_cas_cache.set(key, "foo_bar", 0, false)
assert_equal "foo", @experimental_cas_cache.get_len(3, key)
assert_equal "foo_bar", @experimental_cas_cache.get_len(7, key)
}
end
end
# Touch command
def test_touch_capability
server_touch_capable {
@cache.set(key, "value", 3)
server_touch_capable do
@experimental_binary_protocol_cache.set(key, "value", 10)
assert_nothing_raised do
@experimental_binary_protocol_cache.touch(key, 10)
@experimental_binary_protocol_cache.touch(key, 20)
end
assert_raises(Memcached::ActionNotSupported) do
@experimental_cache.touch(key, 10)
end
}
end
end
def test_touch_missing_key
server_touch_capable {
server_touch_capable do
@experimental_binary_protocol_cache.delete key rescue nil
assert_raises(Memcached::NotFound) do
@experimental_binary_protocol_cache.touch(key, 10)
end
}
end
end
def test_touch
server_touch_capable {
server_touch_capable do
@experimental_binary_protocol_cache.set key, @value, 2
assert_equal @value, @experimental_binary_protocol_cache.get(key)
sleep(1)
@ -244,7 +244,7 @@ class MemcachedExperimentalTest < Test::Unit::TestCase
assert_raises(Memcached::NotFound) do
@experimental_binary_protocol_cache.get(key)
end
}
end
end
# Memory cleanup

Просмотреть файл

@ -6,6 +6,7 @@ class RailsTest < Test::Unit::TestCase
def setup
@servers = ['127.0.0.1:43042', '127.0.0.1:43043', "#{UNIX_SOCKET_NAME}0"]
@duration = ActiveSupport::Duration.new(2592000, [[:months, 1]])
@namespace = 'rails_test'
@cache = Memcached::Rails.new(:servers => @servers, :namespace => @namespace)
@value = OpenStruct.new(:a => 1, :b => 2, :c => GenericClass)
@ -19,6 +20,7 @@ class RailsTest < Test::Unit::TestCase
end
def test_exist
@cache.delete(key)
assert !@cache.exist?(key)
@cache.set key, nil
assert @cache.exist?(key)
@ -137,7 +139,7 @@ class RailsTest < Test::Unit::TestCase
cache = Memcached::Rails.new(:servers => @servers, :namespace => @namespace, :support_cas => true)
value2 = OpenStruct.new(:d => 3, :e => 4, :f => GenericClass)
cache.set key, @value
cache.cas(key, ActiveSupport::Duration.new(2592000, [[:months, 1]])) do |current|
cache.cas(key, @duration) do |current|
assert_equal @value, current
value2
end
@ -145,19 +147,25 @@ class RailsTest < Test::Unit::TestCase
end
def test_set_with_duration
@cache.set key, @value, ActiveSupport::Duration.new(2592000, [[:months, 1]])
@cache.set key, @value, @duration
result = @cache.get key
assert_equal @value, result
end
def test_set_with_invalid_type
assert_raises(TypeError) do
@cache.set key, Object.new, 0, true
end
end
def test_write_with_duration
@cache.write key, @value, :ttl => ActiveSupport::Duration.new(2592000, [[:months, 1]])
@cache.write key, @value, :ttl => @duration
result = @cache.get key
assert_equal @value, result
end
def test_add_with_duration
@cache.add key, @value, ActiveSupport::Duration.new(2592000, [[:months, 1]])
@cache.add key, @value, @duration
result = @cache.get key
assert_equal @value, result
end
@ -169,20 +177,6 @@ class RailsTest < Test::Unit::TestCase
end
def compare_servers(cache, servers)
cache_servers = cache.servers
assert_equal servers.count, cache_servers.count
cache_servers.count.times do |n|
server = servers[n]
if cache_servers[n].type == Memcached::Lib::MEMCACHED_CONNECTION_UNIX_SOCKET
assert_equal server, cache_servers[n].hostname
else
host, port = server.split(":")
assert_equal host, cache_servers[n].hostname
assert_equal port, cache_servers[n].port.to_s
cache.servers.map{|s| "#{s.hostname}:#{s.port}".chomp(':0')} == servers
end
assert_equal 8, cache_servers[n].weight
assert cache_servers[n].alive?
end
end
end