PageRenderTime 35ms CodeModel.GetById 23ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/delowong/logstash
Ruby | 52 lines | 37 code | 14 blank | 1 comment | 0 complexity | 4e45b83f373a8c65527a061a50c14755 MD5 | raw file
 1# encoding: UTF-8
 2
 3require File.expand_path("helper", File.dirname(__FILE__))
 4
 5class TestDistributedKeyTags < Test::Unit::TestCase
 6
 7  include Helper
 8  include Helper::Distributed
 9
10  def test_hashes_consistently
11    r1 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
12    r2 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
13    r3 = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
14
15    assert_equal r1.node_for("foo").id, r2.node_for("foo").id
16    assert_equal r1.node_for("foo").id, r3.node_for("foo").id
17  end
18
19  def test_allows_clustering_of_keys
20    r = Redis::Distributed.new(NODES)
21    r.add_node("redis://127.0.0.1:#{PORT}/14")
22    r.flushdb
23
24    100.times do |i|
25      r.set "{foo}users:#{i}", i
26    end
27
28    assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
29  end
30
31  def test_distributes_keys_if_no_clustering_is_used
32    r.add_node("redis://127.0.0.1:#{PORT}/14")
33    r.flushdb
34
35    r.set "users:1", 1
36    r.set "users:4", 4
37
38    assert_equal [1, 1], r.nodes.map { |node| node.keys.size }
39  end
40
41  def test_allows_passing_a_custom_tag_extractor
42    r = Redis::Distributed.new(NODES, :tag => /^(.+?):/)
43    r.add_node("redis://127.0.0.1:#{PORT}/14")
44    r.flushdb
45
46    100.times do |i|
47      r.set "foo:users:#{i}", i
48    end
49
50    assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
51  end
52end