Commit 33a5782c authored by Rajko Albrecht's avatar Rajko Albrecht
Browse files

Implemented cas_multi tests

parent 86c42866
......@@ -48,6 +48,73 @@ describe "ActiveSupport::Cache::RedisStoreWithCas" do
@store.read("rabbit").must_equal(@black_rabbit)
end
describe "Test Multi cas" do
it "should fail with empty names" do
refute @store.cas_multi { |_hash| flunk }
end
it "should set new values" do
@store.write('rabbit', @white_rabbit)
@store.write('hare', @black_rabbit)
assert_equal true, (@store.cas_multi('rabbit', 'hare') do |hash|
assert_equal({ "rabbit" => @white_rabbit, 'hare' => @black_rabbit }, hash)
{ "rabbit" => @black_rabbit, 'hare' => @white_rabbit }
end)
assert_equal({ "rabbit" => @black_rabbit, 'hare' => @white_rabbit }, @store.read_multi('rabbit', 'hare'))
end
it "should set a ttl " do
@store.write('rabbit', @white_rabbit)
@store.write('hare', @black_rabbit)
@store.cas_multi('rabbit','hare',{:expires_in => 600,:race_condition_ttl => 1}) do |hash|
{ "rabbit" => @black_rabbit, "hare" => @white_rabbit}
end
values = @store.read_multi('rabbit', 'hare')
assert_equal({ "rabbit" => @black_rabbit, 'hare' => @white_rabbit },values)
re = @store.instance_variable_get('@data')
assert re.ttl('rabbit') > 0
assert re.ttl('hare') > 0
end
it "should not send values for not existing keys" do
assert(@store.cas_multi('not_exist') do |hash|
assert hash.empty?
{}
end)
end
it "should not write keys not in parameter" do
@store.write('foo', 'baz')
assert @store.cas_multi('foo') { |_hash| { 'fu' => 'baz' } }
assert_nil @store.read('fu')
assert_equal 'baz', @store.read('foo')
end
def test_cas_multi_with_partial_update
@store.write('foo', 'bar')
@store.write('fud', 'biz')
assert(@store.cas_multi('foo', 'fud') do |hash|
assert_equal({ "foo" => "bar", "fud" => "biz" }, hash)
{ "foo" => "baz" }
end)
assert_equal({ "foo" => "baz", "fud" => "biz" }, @store.read_multi('foo', 'fud'))
end
def test_cas_multi_with_partial_conflict
@store.write('foo', 'bar')
@store.write('fud', 'biz')
result = @store.cas_multi('foo', 'fud') do |hash|
assert_equal({ "foo" => "bar", "fud" => "biz" }, hash)
@store.write('foo', 'bad')
{ "foo" => "baz", "fud" => "buz" }
end
assert result
assert_equal({ "foo" => "bad", "fud" => "buz" }, @store.read_multi('foo', 'fud'))
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment