As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 3fe9cea0 authored by Jacob Vosmaer's avatar Jacob Vosmaer
Browse files

Vendor redis_rb from Rubygems, not GitHub

Also just include the entire gem. Space used is negligible and this
way we don't have to think about what to leave in/out.

Create a vendor-gem script in Ruby instead of Make.
parent a3712cc1
No related branches found
No related tags found
No related merge requests found
Showing
with 1098 additions and 0 deletions
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/blocking_commands"
class TestDistributedBlockingCommands < Test::Unit::TestCase
include Helper::Distributed
include Lint::BlockingCommands
def test_blpop_raises
assert_raises(Redis::Distributed::CannotDistribute) do
r.blpop(["foo", "bar"])
end
end
def test_blpop_raises_with_old_prototype
assert_raises(Redis::Distributed::CannotDistribute) do
r.blpop("foo", "bar", 0)
end
end
def test_brpop_raises
assert_raises(Redis::Distributed::CannotDistribute) do
r.brpop(["foo", "bar"])
end
end
def test_brpop_raises_with_old_prototype
assert_raises(Redis::Distributed::CannotDistribute) do
r.brpop("foo", "bar", 0)
end
end
def test_brpoplpush_raises
assert_raises(Redis::Distributed::CannotDistribute) do
r.brpoplpush("foo", "bar")
end
end
def test_brpoplpush_raises_with_old_prototype
assert_raises(Redis::Distributed::CannotDistribute) do
r.brpoplpush("foo", "bar", 0)
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/hashes"
class TestDistributedCommandsOnHashes < Test::Unit::TestCase
include Helper::Distributed
include Lint::Hashes
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/hyper_log_log"
class TestDistributedCommandsOnHyperLogLog < Test::Unit::TestCase
include Helper::Distributed
include Lint::HyperLogLog
def test_pfmerge
target_version "2.8.9" do
assert_raise Redis::Distributed::CannotDistribute do
r.pfadd "foo", "s1"
r.pfadd "bar", "s2"
assert r.pfmerge("res", "foo", "bar")
end
end
end
def test_pfcount_multiple_keys_diff_nodes
target_version "2.8.9" do
assert_raise Redis::Distributed::CannotDistribute do
r.pfadd "foo", "s1"
r.pfadd "bar", "s2"
assert r.pfcount("res", "foo", "bar")
end
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/lists"
class TestDistributedCommandsOnLists < Test::Unit::TestCase
include Helper::Distributed
include Lint::Lists
def test_rpoplpush
assert_raise Redis::Distributed::CannotDistribute do
r.rpoplpush("foo", "bar")
end
end
def test_brpoplpush
assert_raise Redis::Distributed::CannotDistribute do
r.brpoplpush("foo", "bar", :timeout => 1)
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/sets"
class TestDistributedCommandsOnSets < Test::Unit::TestCase
include Helper::Distributed
include Lint::Sets
def test_smove
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "bar", "s2"
r.smove("foo", "bar", "s1")
end
end
def test_sinter
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "foo", "s2"
r.sadd "bar", "s2"
r.sinter("foo", "bar")
end
end
def test_sinterstore
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "foo", "s2"
r.sadd "bar", "s2"
r.sinterstore("baz", "foo", "bar")
end
end
def test_sunion
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "foo", "s2"
r.sadd "bar", "s2"
r.sadd "bar", "s3"
r.sunion("foo", "bar")
end
end
def test_sunionstore
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "foo", "s2"
r.sadd "bar", "s2"
r.sadd "bar", "s3"
r.sunionstore("baz", "foo", "bar")
end
end
def test_sdiff
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "foo", "s2"
r.sadd "bar", "s2"
r.sadd "bar", "s3"
r.sdiff("foo", "bar")
end
end
def test_sdiffstore
assert_raise Redis::Distributed::CannotDistribute do
r.sadd "foo", "s1"
r.sadd "foo", "s2"
r.sadd "bar", "s2"
r.sadd "bar", "s3"
r.sdiffstore("baz", "foo", "bar")
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/sorted_sets"
class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
include Helper::Distributed
include Lint::SortedSets
def test_zcount
r.zadd "foo", 1, "s1"
r.zadd "foo", 2, "s2"
r.zadd "foo", 3, "s3"
assert_equal 2, r.zcount("foo", 2, 3)
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/strings"
class TestDistributedCommandsOnStrings < Test::Unit::TestCase
include Helper::Distributed
include Lint::Strings
def test_mget
assert_raise Redis::Distributed::CannotDistribute do
r.mget("foo", "bar")
end
end
def test_mget_mapped
assert_raise Redis::Distributed::CannotDistribute do
r.mapped_mget("foo", "bar")
end
end
def test_mset
assert_raise Redis::Distributed::CannotDistribute do
r.mset(:foo, "s1", :bar, "s2")
end
end
def test_mset_mapped
assert_raise Redis::Distributed::CannotDistribute do
r.mapped_mset(:foo => "s1", :bar => "s2")
end
end
def test_msetnx
assert_raise Redis::Distributed::CannotDistribute do
r.set("foo", "s1")
r.msetnx(:foo, "s2", :bar, "s3")
end
end
def test_msetnx_mapped
assert_raise Redis::Distributed::CannotDistribute do
r.set("foo", "s1")
r.mapped_msetnx(:foo => "s2", :bar => "s3")
end
end
def test_bitop
target_version "2.5.10" do
assert_raise Redis::Distributed::CannotDistribute do
r.set("foo", "a")
r.set("bar", "b")
r.bitop(:and, "foo&bar", "foo", "bar")
end
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
require "lint/value_types"
class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
include Helper::Distributed
include Lint::ValueTypes
def test_del
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equal 1, r.del("foo")
assert_equal ["bar", "baz"], r.keys("*").sort
assert_equal 2, r.del("bar", "baz")
assert_equal [], r.keys("*").sort
end
def test_del_with_array_argument
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equal 1, r.del(["foo"])
assert_equal ["bar", "baz"], r.keys("*").sort
assert_equal 2, r.del(["bar", "baz"])
assert_equal [], r.keys("*").sort
end
def test_randomkey
assert_raise Redis::Distributed::CannotDistribute do
r.randomkey
end
end
def test_rename
assert_raise Redis::Distributed::CannotDistribute do
r.set("foo", "s1")
r.rename "foo", "bar"
end
assert_equal "s1", r.get("foo")
assert_equal nil, r.get("bar")
end
def test_renamenx
assert_raise Redis::Distributed::CannotDistribute do
r.set("foo", "s1")
r.rename "foo", "bar"
end
assert_equal "s1", r.get("foo")
assert_equal nil , r.get("bar")
end
def test_dbsize
assert_equal [0], r.dbsize
r.set("foo", "s1")
assert_equal [1], r.dbsize
end
def test_flushdb
r.set("foo", "s1")
r.set("bar", "s2")
assert_equal [2], r.dbsize
r.flushdb
assert_equal [0], r.dbsize
end
def test_migrate
r.set("foo", "s1")
assert_raise Redis::Distributed::CannotDistribute do
r.migrate("foo", {})
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedCommandsRequiringClustering < Test::Unit::TestCase
include Helper::Distributed
def test_rename
r.set("{qux}foo", "s1")
r.rename "{qux}foo", "{qux}bar"
assert_equal "s1", r.get("{qux}bar")
assert_equal nil, r.get("{qux}foo")
end
def test_renamenx
r.set("{qux}foo", "s1")
r.set("{qux}bar", "s2")
assert_equal false, r.renamenx("{qux}foo", "{qux}bar")
assert_equal "s1", r.get("{qux}foo")
assert_equal "s2", r.get("{qux}bar")
end
def test_brpoplpush
r.rpush "{qux}foo", "s1"
r.rpush "{qux}foo", "s2"
assert_equal "s2", r.brpoplpush("{qux}foo", "{qux}bar", :timeout => 1)
assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
end
def test_rpoplpush
r.rpush "{qux}foo", "s1"
r.rpush "{qux}foo", "s2"
assert_equal "s2", r.rpoplpush("{qux}foo", "{qux}bar")
assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
assert_equal "s1", r.rpoplpush("{qux}foo", "{qux}bar")
assert_equal ["s1", "s2"], r.lrange("{qux}bar", 0, -1)
end
def test_smove
r.sadd "{qux}foo", "s1"
r.sadd "{qux}bar", "s2"
assert r.smove("{qux}foo", "{qux}bar", "s1")
assert r.sismember("{qux}bar", "s1")
end
def test_sinter
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
assert_equal ["s2"], r.sinter("{qux}foo", "{qux}bar")
end
def test_sinterstore
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sinterstore("{qux}baz", "{qux}foo", "{qux}bar")
assert_equal ["s2"], r.smembers("{qux}baz")
end
def test_sunion
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
assert_equal ["s1", "s2", "s3"], r.sunion("{qux}foo", "{qux}bar").sort
end
def test_sunionstore
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
r.sunionstore("{qux}baz", "{qux}foo", "{qux}bar")
assert_equal ["s1", "s2", "s3"], r.smembers("{qux}baz").sort
end
def test_sdiff
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
assert_equal ["s1"], r.sdiff("{qux}foo", "{qux}bar")
assert_equal ["s3"], r.sdiff("{qux}bar", "{qux}foo")
end
def test_sdiffstore
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
r.sdiffstore("{qux}baz", "{qux}foo", "{qux}bar")
assert_equal ["s1"], r.smembers("{qux}baz")
end
def test_sort
r.set("{qux}foo:1", "s1")
r.set("{qux}foo:2", "s2")
r.rpush("{qux}bar", "1")
r.rpush("{qux}bar", "2")
assert_equal ["s1"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1])
assert_equal ["s2"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1], :order => "desc alpha")
end
def test_sort_with_an_array_of_gets
r.set("{qux}foo:1:a", "s1a")
r.set("{qux}foo:1:b", "s1b")
r.set("{qux}foo:2:a", "s2a")
r.set("{qux}foo:2:b", "s2b")
r.rpush("{qux}bar", "1")
r.rpush("{qux}bar", "2")
assert_equal [["s1a", "s1b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1])
assert_equal [["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1], :order => "desc alpha")
assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"])
end
def test_sort_with_store
r.set("{qux}foo:1", "s1")
r.set("{qux}foo:2", "s2")
r.rpush("{qux}bar", "1")
r.rpush("{qux}bar", "2")
r.sort("{qux}bar", :get => "{qux}foo:*", :store => "{qux}baz")
assert_equal ["s1", "s2"], r.lrange("{qux}baz", 0, -1)
end
def test_bitop
target_version "2.5.10" do
r.set("{qux}foo", "a")
r.set("{qux}bar", "b")
r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
assert_equal "\x60", r.get("{qux}foo&bar")
r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
assert_equal "\x63", r.get("{qux}foo|bar")
r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
assert_equal "\x03", r.get("{qux}foo^bar")
r.bitop(:not, "{qux}~foo", "{qux}foo")
assert_equal "\x9E", r.get("{qux}~foo")
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedConnectionHandling < Test::Unit::TestCase
include Helper::Distributed
def test_ping
assert_equal ["PONG"], r.ping
end
def test_select
r.set "foo", "bar"
r.select 14
assert_equal nil, r.get("foo")
r.select 15
assert_equal "bar", r.get("foo")
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedInternals < Test::Unit::TestCase
include Helper::Distributed
def test_provides_a_meaningful_inspect
nodes = ["redis://localhost:#{PORT}/15", *NODES]
redis = Redis::Distributed.new nodes
assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
end
def test_default_as_urls
nodes = ["redis://localhost:#{PORT}/15", *NODES]
redis = Redis::Distributed.new nodes
assert_equal ["redis://localhost:#{PORT}/15", *NODES], redis.nodes.map { |node| node.client.id}
end
def test_default_as_config_hashes
nodes = [OPTIONS.merge(:host => '127.0.0.1'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
redis = Redis::Distributed.new nodes
assert_equal ["redis://127.0.0.1:#{PORT}/15","redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node.client.id }
end
def test_as_mix_and_match
nodes = ["redis://127.0.0.1:7389/15", OPTIONS.merge(:host => 'somehost'), OPTIONS.merge(:host => 'somehost', :port => PORT.next)]
redis = Redis::Distributed.new nodes
assert_equal ["redis://127.0.0.1:7389/15", "redis://somehost:#{PORT}/15", "redis://somehost:#{PORT.next}/15"], redis.nodes.map { |node| node.client.id }
end
def test_override_id
nodes = [OPTIONS.merge(:host => '127.0.0.1', :id => "test"), OPTIONS.merge( :host => 'somehost', :port => PORT.next, :id => "test1")]
redis = Redis::Distributed.new nodes
assert_equal redis.nodes.first.client.id, "test"
assert_equal redis.nodes.last.client.id, "test1"
assert_equal "#<Redis client v#{Redis::VERSION} for #{redis.nodes.map(&:id).join(', ')}>", redis.inspect
end
def test_can_be_duped_to_create_a_new_connection
redis = Redis::Distributed.new(NODES)
clients = redis.info[0]["connected_clients"].to_i
r2 = redis.dup
r2.ping
assert_equal clients + 1, redis.info[0]["connected_clients"].to_i
end
def test_keeps_options_after_dup
r1 = Redis::Distributed.new(NODES, :tag => /^(\w+):/)
assert_raise(Redis::Distributed::CannotDistribute) do
r1.sinter("foo", "bar")
end
assert_equal [], r1.sinter("baz:foo", "baz:bar")
r2 = r1.dup
assert_raise(Redis::Distributed::CannotDistribute) do
r2.sinter("foo", "bar")
end
assert_equal [], r2.sinter("baz:foo", "baz:bar")
end
def test_colliding_node_ids
nodes = ["redis://localhost:#{PORT}/15", "redis://localhost:#{PORT}/15", *NODES]
assert_raise(RuntimeError) do
Redis::Distributed.new nodes
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedKeyTags < Test::Unit::TestCase
include Helper
include Helper::Distributed
def test_hashes_consistently
r1 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
r2 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
r3 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
assert_equal r1.node_for("foo").id, r2.node_for("foo").id
assert_equal r1.node_for("foo").id, r3.node_for("foo").id
end
def test_allows_clustering_of_keys
r = Redis::Distributed.new(NODES)
r.add_node("redis://127.0.0.1:#{PORT}/14")
r.flushdb
100.times do |i|
r.set "{foo}users:#{i}", i
end
assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
end
def test_distributes_keys_if_no_clustering_is_used
r.add_node("redis://127.0.0.1:#{PORT}/14")
r.flushdb
r.set "users:1", 1
r.set "users:4", 4
assert_equal [1, 1], r.nodes.map { |node| node.keys.size }
end
def test_allows_passing_a_custom_tag_extractor
r = Redis::Distributed.new(NODES, :tag => /^(.+?):/)
r.add_node("redis://127.0.0.1:#{PORT}/14")
r.flushdb
100.times do |i|
r.set "foo:users:#{i}", i
end
assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedPersistenceControlCommands < Test::Unit::TestCase
include Helper::Distributed
def test_save
redis_mock(:save => lambda { "+SAVE" }) do |redis|
assert_equal ["SAVE"], redis.save
end
end
def test_bgsave
redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
assert_equal ["BGSAVE"], redis.bgsave
end
end
def test_lastsave
redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
assert_equal ["LASTSAVE"], redis.lastsave
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedPublishSubscribe < Test::Unit::TestCase
include Helper::Distributed
def test_subscribe_and_unsubscribe
assert_raise Redis::Distributed::CannotDistribute do
r.subscribe("foo", "bar") { }
end
assert_raise Redis::Distributed::CannotDistribute do
r.subscribe("{qux}foo", "bar") { }
end
end
def test_subscribe_and_unsubscribe_with_tags
@subscribed = false
@unsubscribed = false
wire = Wire.new do
r.subscribe("foo") do |on|
on.subscribe do |channel, total|
@subscribed = true
@t1 = total
end
on.message do |channel, message|
if message == "s1"
r.unsubscribe
@message = message
end
end
on.unsubscribe do |channel, total|
@unsubscribed = true
@t2 = total
end
end
end
# Wait until the subscription is active before publishing
Wire.pass while !@subscribed
Redis::Distributed.new(NODES).publish("foo", "s1")
wire.join
assert @subscribed
assert_equal 1, @t1
assert @unsubscribed
assert_equal 0, @t2
assert_equal "s1", @message
end
def test_subscribe_within_subscribe
@channels = []
wire = Wire.new do
r.subscribe("foo") do |on|
on.subscribe do |channel, total|
@channels << channel
r.subscribe("bar") if channel == "foo"
r.unsubscribe if channel == "bar"
end
end
end
wire.join
assert_equal ["foo", "bar"], @channels
end
def test_other_commands_within_a_subscribe
assert_raise Redis::CommandError do
r.subscribe("foo") do |on|
on.subscribe do |channel, total|
r.set("bar", "s2")
end
end
end
end
def test_subscribe_without_a_block
assert_raise LocalJumpError do
r.subscribe("foo")
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedRemoteServerControlCommands < Test::Unit::TestCase
include Helper::Distributed
def test_info
keys = [
"redis_version",
"uptime_in_seconds",
"uptime_in_days",
"connected_clients",
"used_memory",
"total_connections_received",
"total_commands_processed",
]
infos = r.info
infos.each do |info|
keys.each do |k|
msg = "expected #info to include #{k}"
assert info.keys.include?(k), msg
end
end
end
def test_info_commandstats
target_version "2.5.7" do
r.nodes.each { |n| n.config(:resetstat) }
r.ping # Executed on every node
r.info(:commandstats).each do |info|
assert_equal "1", info["ping"]["calls"]
end
end
end
def test_monitor
begin
r.monitor
rescue Exception => ex
ensure
assert ex.kind_of?(NotImplementedError)
end
end
def test_echo
assert_equal ["foo bar baz\n"], r.echo("foo bar baz\n")
end
def test_time
target_version "2.5.4" do
# Test that the difference between the time that Ruby reports and the time
# that Redis reports is minimal (prevents the test from being racy).
r.time.each do |rv|
redis_usec = rv[0] * 1_000_000 + rv[1]
ruby_usec = Integer(Time.now.to_f * 1_000_000)
assert 500_000 > (ruby_usec - redis_usec).abs
end
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedScripting < Test::Unit::TestCase
include Helper::Distributed
def to_sha(script)
r.script(:load, script).first
end
def test_script_exists
target_version "2.5.9" do # 2.6-rc1
a = to_sha("return 1")
b = a.succ
assert_equal [true], r.script(:exists, a)
assert_equal [false], r.script(:exists, b)
assert_equal [[true]], r.script(:exists, [a])
assert_equal [[false]], r.script(:exists, [b])
assert_equal [[true, false]], r.script(:exists, [a, b])
end
end
def test_script_flush
target_version "2.5.9" do # 2.6-rc1
sha = to_sha("return 1")
assert r.script(:exists, sha).first
assert_equal ["OK"], r.script(:flush)
assert !r.script(:exists, sha).first
end
end
def test_script_kill
target_version "2.5.9" do # 2.6-rc1
redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
assert_equal ["KILL"], redis.script(:kill)
end
end
end
def test_eval
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return #KEYS")
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return KEYS", ["k1", "k2"])
end
assert_equal ["k1"], r.eval("return KEYS", ["k1"])
assert_equal ["a1", "a2"], r.eval("return ARGV", ["k1"], ["a1", "a2"])
end
end
def test_eval_with_options_hash
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return #KEYS", {})
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return KEYS", { :keys => ["k1", "k2"] })
end
assert_equal ["k1"], r.eval("return KEYS", { :keys => ["k1"] })
assert_equal ["a1", "a2"], r.eval("return ARGV", { :keys => ["k1"], :argv => ["a1", "a2"] })
end
end
def test_evalsha
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return #KEYS"))
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
end
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), ["k1"])
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), ["k1"], ["a1", "a2"])
end
end
def test_evalsha_with_options_hash
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return #KEYS"), {})
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
end
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1"] })
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :keys => ["k1"], :argv => ["a1", "a2"] })
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedSorting < Test::Unit::TestCase
include Helper::Distributed
def test_sort
assert_raise(Redis::Distributed::CannotDistribute) do
r.set("foo:1", "s1")
r.set("foo:2", "s2")
r.rpush("bar", "1")
r.rpush("bar", "2")
r.sort("bar", :get => "foo:*", :limit => [0, 1])
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributed < Test::Unit::TestCase
include Helper::Distributed
def test_handle_multiple_servers
@r = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
100.times do |idx|
@r.set(idx.to_s, "foo#{idx}")
end
100.times do |idx|
assert_equal "foo#{idx}", @r.get(idx.to_s)
end
assert_equal "0", @r.keys("*").sort.first
assert_equal "string", @r.type("1")
end
def test_add_nodes
logger = Logger.new("/dev/null")
@r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
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
@r.add_node("redis://127.0.0.1:6380/14")
assert_equal "127.0.0.1", @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
def test_unknown_commands_does_not_work_by_default
assert_raise NoMethodError do
r.not_yet_implemented_command
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedTransactions < Test::Unit::TestCase
include Helper::Distributed
def test_multi_discard
@foo = nil
assert_raise Redis::Distributed::CannotDistribute do
r.multi { @foo = 1 }
end
assert_equal nil, @foo
assert_raise Redis::Distributed::CannotDistribute do
r.discard
end
end
def test_watch_unwatch
assert_raise Redis::Distributed::CannotDistribute do
r.watch("foo")
end
assert_raise Redis::Distributed::CannotDistribute do
r.unwatch
end
end
end
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestEncoding < Test::Unit::TestCase
include Helper::Client
def test_returns_properly_encoded_strings
if defined?(Encoding)
with_external_encoding("UTF-8") do
r.set "foo", "שלום"
assert_equal "Shalom שלום", "Shalom " + r.get("foo")
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment