Skip to content
Browse files

Test consistent hashing.

  • Loading branch information...
1 parent a6b17c3 commit 32c3adf845fa779e80941c9337229ba02879393c @evan committed
Showing with 31 additions and 15 deletions.
  1. +4 −3 test/setup.rb
  2. +27 −12 test/unit/memcached_test.rb
View
7 test/setup.rb
@@ -3,7 +3,7 @@
HERE = File.dirname(__FILE__)
-`ps awx`.split("\n").grep(/4304[2-3]/).map do |process|
+`ps awx`.split("\n").grep(/4304[2-6]/).map do |process|
system("kill -9 #{process.to_i}")
end
@@ -12,5 +12,6 @@
verbosity = (ENV['DEBUG'] ? "-vv" : "")
-system "memcached #{verbosity} -p 43042 >> #{log} 2>&1 &"
-system "memcached #{verbosity} -p 43043 >> #{log} 2>&1 &"
+(43042..43046).each do |port|
+ system "memcached #{verbosity} -p #{port} >> #{log} 2>&1 &"
+end
View
39 test/unit/memcached_test.rb
@@ -621,7 +621,7 @@ def test_no_block_existing_add
def test_missing_server
cache = Memcached.new(
- [@servers.last, '127.0.0.1:43044'], # Use a server that isn't running
+ [@servers.last, '127.0.0.1:43041'], # Use a server that isn't running
:namespace => @namespace
)
@@ -640,6 +640,31 @@ def test_missing_server
cache.get(key)
end
end
+
+ def test_consistent_hashing
+ cache = Memcached.new(
+ @servers + ['127.0.0.1:43044', '127.0.0.1:43045', '127.0.0.1:43046'], # Five servers
+ :namespace => @namespace
+ )
+
+ keys = ['zero1', 'one_', 'two__', 'three=', 'four-']
+ keys.each_with_index do |key, index|
+ assert_equal index, cache.send(:hash, key)
+ end
+
+ cache = Memcached.new(
+ @servers + ['127.0.0.1:43044', '127.0.0.1:43046'], # Pull a server
+ :namespace => @namespace
+ )
+
+ targets, results = [], []
+ keys.each_with_index do |key, index|
+ targets << index
+ results << cache.send(:hash, key)
+ end
+
+ assert_equal targets, results
+ end
# Concurrency
@@ -679,16 +704,6 @@ def test_hash_generation
def key
caller.first[/`(.*)'/, 1]
end
-
- def start(port)
- system "memcached -p #{port} >> /tmp/memcached.log 2>&1 &"
- end
-
- def stop(port)
- `ps awx`.split("\n").grep(/#{port}/).map do |process|
- system("kill -9 #{process.to_i}")
- end
- end
-
+
end

0 comments on commit 32c3adf

Please sign in to comment.
Something went wrong with that request. Please try again.