PageRenderTime 33ms CodeModel.GetById 18ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/redis-3.0.7/test/distributed_test.rb

https://github.com/delowong/logstash
Ruby | 58 lines | 43 code | 14 blank | 1 comment | 0 complexity | d4dc5ea8edf83a20eff68d71d009412a MD5 | raw file
 1# encoding: UTF-8
 2
 3require File.expand_path("helper", File.dirname(__FILE__))
 4
 5class TestDistributed < Test::Unit::TestCase
 6
 7  include Helper::Distributed
 8
 9  def test_handle_multiple_servers
10    @r = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
11
12    100.times do |idx|
13      @r.set(idx.to_s, "foo#{idx}")
14    end
15
16    100.times do |idx|
17      assert_equal "foo#{idx}", @r.get(idx.to_s)
18    end
19
20    assert_equal "0", @r.keys("*").sort.first
21    assert_equal "string", @r.type("1")
22  end
23
24  def test_add_nodes
25    logger = Logger.new("/dev/null")
26
27    @r = Redis::Distributed.new NODES, :logger => logger, :timeout => 10
28
29    assert_equal "127.0.0.1", @r.nodes[0].client.host
30    assert_equal PORT, @r.nodes[0].client.port
31    assert_equal 15, @r.nodes[0].client.db
32    assert_equal 10, @r.nodes[0].client.timeout
33    assert_equal logger, @r.nodes[0].client.logger
34
35    @r.add_node("redis://127.0.0.1:6380/14")
36
37    assert_equal "127.0.0.1", @r.nodes[1].client.host
38    assert_equal 6380, @r.nodes[1].client.port
39    assert_equal 14, @r.nodes[1].client.db
40    assert_equal 10, @r.nodes[1].client.timeout
41    assert_equal logger, @r.nodes[1].client.logger
42  end
43
44  def test_pipelining_commands_cannot_be_distributed
45    assert_raise Redis::Distributed::CannotDistribute do
46      r.pipelined do
47        r.lpush "foo", "s1"
48        r.lpush "foo", "s2"
49      end
50    end
51  end
52
53  def test_unknown_commands_does_not_work_by_default
54    assert_raise NoMethodError do
55      r.not_yet_implemented_command
56    end
57  end
58end