test/distributed_test.rb in redis-3.0.0.rc1 vs test/distributed_test.rb in redis-3.0.0.rc2
- old
+ new
@@ -1,59 +1,58 @@
# encoding: UTF-8
-require File.expand_path("./helper", File.dirname(__FILE__))
-require "redis/distributed"
+require "helper"
-setup do
- log = StringIO.new
- init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
-end
+class TestDistributed < Test::Unit::TestCase
-test "handle multiple servers" do
- @r = Redis::Distributed.new ["redis://localhost:6379/15", *NODES]
+ include Helper::Distributed
- 100.times do |idx|
- @r.set(idx.to_s, "foo#{idx}")
- end
+ def test_handle_multiple_servers
+ @r = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
- 100.times do |idx|
- assert "foo#{idx}" == @r.get(idx.to_s)
- end
+ 100.times do |idx|
+ @r.set(idx.to_s, "foo#{idx}")
+ end
- assert "0" == @r.keys("*").sort.first
- assert "string" == @r.type("1")
-end
+ 100.times do |idx|
+ assert_equal "foo#{idx}", @r.get(idx.to_s)
+ end
-test "add nodes" do
- logger = Logger.new("/dev/null")
+ assert_equal "0", @r.keys("*").sort.first
+ assert_equal "string", @r.type("1")
+ end
- @r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
+ def test_add_nodes
+ logger = Logger.new("/dev/null")
- assert "127.0.0.1" == @r.nodes[0].client.host
- assert 6379 == @r.nodes[0].client.port
- assert 15 == @r.nodes[0].client.db
- assert 10 == @r.nodes[0].client.timeout
- assert logger == @r.nodes[0].client.logger
+ @r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
- @r.add_node("redis://localhost:6380/14")
+ assert_equal "127.0.0.1", @r.nodes[0].client.host
+ assert_equal PORT, @r.nodes[0].client.port
+ assert_equal 15, @r.nodes[0].client.db
+ assert_equal 10, @r.nodes[0].client.timeout
+ assert_equal logger, @r.nodes[0].client.logger
- assert "localhost" == @r.nodes[1].client.host
- assert 6380 == @r.nodes[1].client.port
- assert 14 == @r.nodes[1].client.db
- assert 10 == @r.nodes[1].client.timeout
- assert logger == @r.nodes[1].client.logger
-end
+ @r.add_node("redis://localhost:6380/14")
-test "Pipelining commands cannot be distributed" do |r|
- assert_raise Redis::Distributed::CannotDistribute do
- r.pipelined do
- r.lpush "foo", "s1"
- r.lpush "foo", "s2"
+ assert_equal "localhost", @r.nodes[1].client.host
+ assert_equal 6380, @r.nodes[1].client.port
+ assert_equal 14, @r.nodes[1].client.db
+ assert_equal 10, @r.nodes[1].client.timeout
+ assert_equal logger, @r.nodes[1].client.logger
+ end
+
+ def test_pipelining_commands_cannot_be_distributed
+ assert_raise Redis::Distributed::CannotDistribute do
+ r.pipelined do
+ r.lpush "foo", "s1"
+ r.lpush "foo", "s2"
+ end
end
end
-end
-test "Unknown commands does not work by default" do |r|
- assert_raise NoMethodError do
- r.not_yet_implemented_command
+ def test_unknown_commands_does_not_work_by_default
+ assert_raise NoMethodError do
+ r.not_yet_implemented_command
+ end
end
end