test/pipelining_commands_test.rb in redis-3.0.0.rc1 vs test/pipelining_commands_test.rb in redis-3.0.0.rc2
- old
+ new
@@ -1,186 +1,195 @@
# encoding: UTF-8
-require File.expand_path("./helper", File.dirname(__FILE__))
+require "helper"
-setup do
- init Redis.new(OPTIONS)
-end
+class TestPipeliningCommands < Test::Unit::TestCase
-test "BULK commands" do |r|
- r.pipelined do
- r.lpush "foo", "s1"
- r.lpush "foo", "s2"
- end
+ include Helper::Client
- assert 2 == r.llen("foo")
- assert "s2" == r.lpop("foo")
- assert "s1" == r.lpop("foo")
-end
+ def test_bulk_commands
+ r.pipelined do
+ r.lpush "foo", "s1"
+ r.lpush "foo", "s2"
+ end
-test "MULTI_BULK commands" do |r|
- r.pipelined do
- r.mset("foo", "s1", "bar", "s2")
- r.mset("baz", "s3", "qux", "s4")
+ assert_equal 2, r.llen("foo")
+ assert_equal "s2", r.lpop("foo")
+ assert_equal "s1", r.lpop("foo")
end
- assert "s1" == r.get("foo")
- assert "s2" == r.get("bar")
- assert "s3" == r.get("baz")
- assert "s4" == r.get("qux")
-end
+ def test_multi_bulk_commands
+ r.pipelined do
+ r.mset("foo", "s1", "bar", "s2")
+ r.mset("baz", "s3", "qux", "s4")
+ end
-test "BULK and MULTI_BULK commands mixed" do |r|
- r.pipelined do
- r.lpush "foo", "s1"
- r.lpush "foo", "s2"
- r.mset("baz", "s3", "qux", "s4")
+ assert_equal "s1", r.get("foo")
+ assert_equal "s2", r.get("bar")
+ assert_equal "s3", r.get("baz")
+ assert_equal "s4", r.get("qux")
end
- assert 2 == r.llen("foo")
- assert "s2" == r.lpop("foo")
- assert "s1" == r.lpop("foo")
- assert "s3" == r.get("baz")
- assert "s4" == r.get("qux")
-end
+ def test_bulk_and_multi_bulk_commands_mixed
+ r.pipelined do
+ r.lpush "foo", "s1"
+ r.lpush "foo", "s2"
+ r.mset("baz", "s3", "qux", "s4")
+ end
-test "MULTI_BULK and BULK commands mixed" do |r|
- r.pipelined do
- r.mset("baz", "s3", "qux", "s4")
- r.lpush "foo", "s1"
- r.lpush "foo", "s2"
+ assert_equal 2, r.llen("foo")
+ assert_equal "s2", r.lpop("foo")
+ assert_equal "s1", r.lpop("foo")
+ assert_equal "s3", r.get("baz")
+ assert_equal "s4", r.get("qux")
end
- assert 2 == r.llen("foo")
- assert "s2" == r.lpop("foo")
- assert "s1" == r.lpop("foo")
- assert "s3" == r.get("baz")
- assert "s4" == r.get("qux")
-end
-
-test "Pipelined with an empty block" do |r|
- assert_nothing_raised do
+ def test_multi_bulk_and_bulk_commands_mixed
r.pipelined do
+ r.mset("baz", "s3", "qux", "s4")
+ r.lpush "foo", "s1"
+ r.lpush "foo", "s2"
end
+
+ assert_equal 2, r.llen("foo")
+ assert_equal "s2", r.lpop("foo")
+ assert_equal "s1", r.lpop("foo")
+ assert_equal "s3", r.get("baz")
+ assert_equal "s4", r.get("qux")
end
- assert 0 == r.dbsize
-end
+ def test_pipelined_with_an_empty_block
+ assert_nothing_raised do
+ r.pipelined do
+ end
+ end
-test "Returning the result of a pipeline" do |r|
- result = r.pipelined do
- r.set "foo", "bar"
- r.get "foo"
- r.get "bar"
+ assert_equal 0, r.dbsize
end
- assert ["OK", "bar", nil] == result
-end
+ def test_returning_the_result_of_a_pipeline
+ result = r.pipelined do
+ r.set "foo", "bar"
+ r.get "foo"
+ r.get "bar"
+ end
-test "Assignment of results inside the block" do |r|
- r.pipelined do
- @first = r.sadd("foo", 1)
- @second = r.sadd("foo", 1)
+ assert_equal ["OK", "bar", nil], result
end
- assert_equal true, @first.value
- assert_equal false, @second.value
-end
-
-# Although we could support accessing the values in these futures,
-# it doesn't make a lot of sense.
-test "Assignment of results inside the block with errors" do |r|
- assert_raise do
+ def test_assignment_of_results_inside_the_block
r.pipelined do
- r.doesnt_exist
@first = r.sadd("foo", 1)
- r.doesnt_exist
@second = r.sadd("foo", 1)
- r.doesnt_exist
end
+
+ assert_equal true, @first.value
+ assert_equal false, @second.value
end
- assert_raise(Redis::FutureNotReady) { @first.value }
- assert_raise(Redis::FutureNotReady) { @second.value }
-end
+ # Although we could support accessing the values in these futures,
+ # it doesn't make a lot of sense.
+ def test_assignment_of_results_inside_the_block_with_errors
+ assert_raise(Redis::CommandError) do
+ r.pipelined do
+ r.doesnt_exist
+ @first = r.sadd("foo", 1)
+ r.doesnt_exist
+ @second = r.sadd("foo", 1)
+ r.doesnt_exist
+ end
+ end
-test "Assignment of results inside a nested block" do |r|
- r.pipelined do
- @first = r.sadd("foo", 1)
+ assert_raise(Redis::FutureNotReady) { @first.value }
+ assert_raise(Redis::FutureNotReady) { @second.value }
+ end
+ def test_assignment_of_results_inside_a_nested_block
r.pipelined do
- @second = r.sadd("foo", 1)
+ @first = r.sadd("foo", 1)
+
+ r.pipelined do
+ @second = r.sadd("foo", 1)
+ end
end
+
+ assert_equal true, @first.value
+ assert_equal false, @second.value
end
- assert_equal true, @first.value
- assert_equal false, @second.value
-end
+ def test_futures_raise_when_confused_with_something_else
+ r.pipelined do
+ @result = r.sadd("foo", 1)
+ end
-test "Futures raise when confused with something else" do |r|
- r.pipelined do
- @result = r.sadd("foo", 1)
+ assert_raise(NoMethodError) { @result.to_s }
end
- assert_raise(NoMethodError) { @result.to_s }
-end
-
-test "Futures raise when trying to access their values too early" do |r|
- r.pipelined do
- assert_raise(Redis::FutureNotReady) do
- r.sadd("foo", 1).value
+ def test_futures_raise_when_trying_to_access_their_values_too_early
+ r.pipelined do
+ assert_raise(Redis::FutureNotReady) do
+ r.sadd("foo", 1).value
+ end
end
end
-end
-test "Returning the result of an empty pipeline" do |r|
- result = r.pipelined do
+ def test_returning_the_result_of_an_empty_pipeline
+ result = r.pipelined do
+ end
+
+ assert_equal [], result
end
- assert [] == result
-end
-
-test "Nesting pipeline blocks" do |r|
- r.pipelined do
- r.set("foo", "s1")
+ def test_nesting_pipeline_blocks
r.pipelined do
- r.set("bar", "s2")
+ r.set("foo", "s1")
+ r.pipelined do
+ r.set("bar", "s2")
+ end
end
+
+ assert_equal "s1", r.get("foo")
+ assert_equal "s2", r.get("bar")
end
- assert "s1" == r.get("foo")
- assert "s2" == r.get("bar")
-end
+ def test_info_in_a_pipeline_returns_hash
+ result = r.pipelined do
+ r.info
+ end
-test "INFO in a pipeline returns hash" do |r|
- result = r.pipelined do
- r.info
+ assert result.first.kind_of?(Hash)
end
- assert result.first.kind_of?(Hash)
-end
+ def test_config_get_in_a_pipeline_returns_hash
+ result = r.pipelined do
+ r.config(:get, "*")
+ end
-test "CONFIG GET in a pipeline returns hash" do |r|
- result = r.pipelined do
- r.config(:get, "*")
+ assert result.first.kind_of?(Hash)
end
- assert result.first.kind_of?(Hash)
-end
+ def test_hgetall_in_a_pipeline_returns_hash
+ r.hmset("hash", "field", "value")
+ result = r.pipelined do
+ r.hgetall("hash")
+ end
-test "HGETALL in a pipeline returns hash" do |r|
- r.hmset("hash", "field", "value")
- result = r.pipelined do
- r.hgetall("hash")
+ assert_equal result.first, { "field" => "value" }
end
- assert result.first == { "field" => "value" }
-end
+ def test_keys_in_a_pipeline
+ r.set("key", "value")
+ result = r.pipelined do
+ r.keys("*")
+ end
-test "KEYS in a pipeline" do |r|
- r.set("key", "value")
- result = r.pipelined do
- r.keys("*")
+ assert_equal ["key"], result.first
end
- assert ["key"] == result.first
+ def test_pipeline_yields_a_connection
+ r.pipelined do |p|
+ p.set("foo", "bar")
+ end
+
+ assert_equal "bar", r.get("foo")
+ end
end