PageRenderTime 61ms CodeModel.GetById 19ms app.highlight 38ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/delowong/logstash
Ruby | 117 lines | 85 code | 31 blank | 1 comment | 5 complexity | 8ac6e0d28d477cb3e23365f93814e802 MD5 | raw file
  1# encoding: UTF-8
  2
  3require File.expand_path("helper", File.dirname(__FILE__))
  4
  5class TestRemoteServerControlCommands < Test::Unit::TestCase
  6
  7  include Helper::Client
  8
  9  def test_info
 10    keys = [
 11     "redis_version",
 12     "uptime_in_seconds",
 13     "uptime_in_days",
 14     "connected_clients",
 15     "used_memory",
 16     "total_connections_received",
 17     "total_commands_processed",
 18    ]
 19
 20    info = r.info
 21
 22    keys.each do |k|
 23      msg = "expected #info to include #{k}"
 24      assert info.keys.include?(k), msg
 25    end
 26  end
 27
 28  def test_info_commandstats
 29    target_version "2.5.7" do
 30      r.config(:resetstat)
 31      r.ping
 32
 33      result = r.info(:commandstats)
 34      assert_equal "1", result["ping"]["calls"]
 35    end
 36  end
 37
 38  def test_monitor_redis_lt_2_5_0
 39    return unless version < "2.5.0"
 40
 41    log = []
 42
 43    wire = Wire.new do
 44      Redis.new(OPTIONS).monitor do |line|
 45        log << line
 46        break if log.size == 3
 47      end
 48    end
 49
 50    Wire.pass while log.empty? # Faster than sleep
 51
 52    r.set "foo", "s1"
 53
 54    wire.join
 55
 56    assert log[-1][%q{(db 15) "set" "foo" "s1"}]
 57  end
 58
 59  def test_monitor_redis_gte_2_5_0
 60    return unless version >= "2.5.0"
 61
 62    log = []
 63
 64    wire = Wire.new do
 65      Redis.new(OPTIONS).monitor do |line|
 66        log << line
 67        break if line =~ /set/
 68      end
 69    end
 70
 71    Wire.pass while log.empty? # Faster than sleep
 72
 73    r.set "foo", "s1"
 74
 75    wire.join
 76
 77    assert log[-1] =~ /\b15\b.* "set" "foo" "s1"/
 78  end
 79
 80  def test_monitor_returns_value_for_break
 81    result = r.monitor do |line|
 82      break line
 83    end
 84
 85    assert_equal result, "OK"
 86  end
 87
 88  def test_echo
 89    assert_equal "foo bar baz\n", r.echo("foo bar baz\n")
 90  end
 91
 92  def test_debug
 93    r.set "foo", "s1"
 94
 95    assert r.debug(:object, "foo").kind_of?(String)
 96  end
 97
 98  def test_object
 99    r.lpush "list", "value"
100
101    assert_equal r.object(:refcount, "list"), 1
102    assert_equal r.object(:encoding, "list"), "ziplist"
103    assert r.object(:idletime, "list").kind_of?(Fixnum)
104  end
105
106  def test_sync
107    redis_mock(:sync => lambda { "+OK" }) do |redis|
108      assert_equal "OK", redis.sync
109    end
110  end
111
112  def test_slowlog
113    r.slowlog(:reset)
114    result = r.slowlog(:len)
115    assert_equal result, 0
116  end
117end