Skip to content

Commit

Permalink
Merge pull request #60 from paegun/master
Browse files Browse the repository at this point in the history
load_sim support for AUTH + minor --help for AUTH + test cleanup
  • Loading branch information
steelThread committed Nov 18, 2013
2 parents 1baa3bd + e573df5 commit dc33a9f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bin/redmon
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RedmonCLI
:short => '-r URL',
:long => '--redis URL',
:default => 'redis://127.0.0.1:6379',
:description => "The Redis url for monitor (default: redis://127.0.0.1:6379)"
:description => "The Redis url for monitor (default: redis://127.0.0.1:6379, note: password is support, ie redis://:password@127.0.0.1:6379)"

option :namespace,
:short => '-n NAMESPACE',
Expand Down
43 changes: 31 additions & 12 deletions load_sim.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
$: << ::File.expand_path("../lib/", __FILE__)
require "rubygems"
require "bundler/setup"
require 'mixlib/cli'
require 'redmon'
require 'redis'

redis = Redis.connect
class RedmonLoadSimCLI
include Mixlib::CLI

loop do
start = rand(100000)
multi = rand(5)
start.upto(multi * start) do |i|
redis.set("key-#{i}", "abcdedghijklmnopqrstuvwxyz")
end
option :redis_url,
:short => '-r URL',
:long => '--redis URL',
:default => 'redis://127.0.0.1:6379',
:description => "The Redis url to load simulated traffic against (default: redis://127.0.0.1:6379, note: password is supported, ie redis://:password@127.0.0.1:6379)"

start.upto(multi * start) do |i|
redis.get("key-#{i}")
redis.del("key-#{i}")
end
end
def run
parse_options

redis_options = Redis::Client::DEFAULTS || {}
redis_options[:url] = config[:redis_url] if config[:redis_url]
redis = Redis.new(redis_options)

loop do
start = rand(100000)
multi = rand(5)
start.upto(multi * start) do |i|
redis.set("key-#{i}", "abcdedghijklmnopqrstuvwxyz")
end

start.upto(multi * start) do |i|
redis.get("key-#{i}")
redis.del("key-#{i}")
end
end
end
end

RedmonLoadSimCLI.new.run
22 changes: 11 additions & 11 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ def em_redis

describe "#ns" do
it "should return the configured namespace" do
Redmon.config.namespace.should == Redmon::Redis.ns
Redmon::Redis.ns.should == Redmon.config.namespace
end
end

describe "#redis_url" do
it "should return the configured redis url" do
Redmon.config.redis_url.should == Redmon::Redis.redis_url
Redmon::Redis.redis_url.should == Redmon.config.redis_url
end
end

describe "#redis_host" do
it "should return the configured redis host" do
Redmon.config.redis_url.gsub('redis://', '').should == Redmon::Redis.redis_host
config_uri = URI.parse(Redmon.config.redis_url)
Redmon::Redis.redis_host.should == "#{config_uri.host}:#{config_uri.port}"
end
end

describe "#unquoted" do
it "should return the configured redis host" do
(%w{string OK} << '(empty list or set)').should == Redmon::Redis.unquoted
Redmon::Redis.unquoted.should == (%w{string OK} << '(empty list or set)')
end
end

Expand All @@ -56,33 +57,32 @@ def em_redis

describe "#empty_result" do
it "should return the empty list message" do
'(empty list or set)'.should == Redmon::Redis.empty_result
Redmon::Redis.empty_result.should == '(empty list or set)'
end
end

describe "#unknown" do
it "should return the unknown command message" do
"(error) ERR unknown command 'unknown'".should == Redmon::Redis.unknown('unknown')
Redmon::Redis.unknown("unknown").should == "(error) ERR unknown command 'unknown'"
end
end

describe "#wrong_number_of_arguments_for" do
it "" do
"(error) ERR wrong number of arguments for 'unknown' command".should ==
Redmon::Redis.wrong_number_of_arguments_for('unknown')
Redmon::Redis.wrong_number_of_arguments_for("unknown").should ==
"(error) ERR wrong number of arguments for 'unknown' command"
end
end

describe "#connection_refused" do
it "should return the connection refused message" do
"Could not connect to Redis at 127.0.0.1:6379: Connection refused".should ==
Redmon::Redis.connection_refused
Redmon::Redis.connection_refused.should == "Could not connect to Redis at 127.0.0.1:6379: Connection refused"
end
end

describe "#stats_key" do
it "should return the namespaced scoped stats key" do
"redmon:redis:127.0.0.1:6379:stats".should == Redmon::Redis.stats_key
Redmon::Redis.stats_key.should == "redmon:redis:127.0.0.1:6379:stats"
end
end

Expand Down
24 changes: 21 additions & 3 deletions spec/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@ def mock_timer
end

describe "#run!" do
it "should poll and record stats"
it "should poll and record stats" do
Redmon.config.poll_interval = 1 #reduce the interval to a second for testing
redis = mock_redis
redis.should_receive(:zadd).at_least(:twice)
redis.should_receive(:zremrangebyscore).at_least(:twice)

@worker.stub(:stats).and_return(['ts', 'stats'])

emThread = Thread.new do
EM.run do
@timer = @worker.run!
end
end

puts "sleeping for 3 cycles of Redmon.config.poll_interval: #{Redmon.config.poll_interval} seconds to ensure polling occurred"
sleep 3 * Redmon.config.poll_interval.seconds
@timer.cancel
emThread.kill
@worker.cleanup_old_stats
end
end

describe "#record_stats" do
Expand All @@ -34,13 +53,12 @@ def mock_timer

describe "#stats" do
it "should fetch info, dbsize and slowlog from redis" do
pending
redis = mock_redis
redis.should_receive(:info).with(no_args()).and_return({})
redis.should_receive(:dbsize).with(no_args()).and_return(0)
redis.should_receive(:slowlog).with(:get).and_return({})

@worker.stub(:entires).and_return([{}])
@worker.stub(:entries).and_return([{}])
@worker.stats
end
end
Expand Down

0 comments on commit dc33a9f

Please sign in to comment.