1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
# frozen_string_literal: true
require_relative 'helper'
# ruby -w -Itest test/cluster_client_transactions_test.rb
class TestClusterClientTransactions < Minitest::Test
include Helper::Cluster
def test_transaction_with_hash_tag
rc1 = redis
rc2 = build_another_client
rc1.multi do |cli|
100.times { |i| cli.set("{key}#{i}", i) }
end
100.times { |i| assert_equal i.to_s, rc1.get("{key}#{i}") }
100.times { |i| assert_equal i.to_s, rc2.get("{key}#{i}") }
end
def test_transaction_without_hash_tag
rc1 = redis
rc2 = build_another_client
assert_raises(Redis::Cluster::CrossSlotPipeliningError) do
rc1.multi do |cli|
100.times { |i| cli.set("key#{i}", i) }
end
end
100.times { |i| assert_nil rc1.get("key#{i}") }
100.times { |i| assert_nil rc2.get("key#{i}") }
end
def test_transaction_with_replicas
rc1 = build_another_client(replica: true)
rc2 = build_another_client(replica: true)
rc1.multi do |cli|
100.times { |i| cli.set("{key}#{i}", i) }
end
rc1.wait(1, TIMEOUT.to_i * 1000)
100.times { |i| assert_equal i.to_s, rc1.get("{key}#{i}") }
100.times { |i| assert_equal i.to_s, rc2.get("{key}#{i}") }
end
def test_transaction_with_watch
rc1 = redis
rc2 = build_another_client
rc1.set('{key}1', 100)
rc1.watch('{key}1')
rc2.set('{key}1', 200)
val = rc1.get('{key}1').to_i
val += 1
rc1.multi do |cli|
cli.set('{key}1', val)
cli.set('{key}2', 300)
end
assert_equal '200', rc1.get('{key}1')
assert_equal '200', rc2.get('{key}1')
assert_nil rc1.get('{key}2')
assert_nil rc2.get('{key}2')
end
end
|