-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,43 @@ | ||
require 'test/unit' | ||
require 'fluent/test' | ||
require 'lib/fluent/plugin/out_fnordmetric' | ||
require 'test_helper' | ||
|
||
class FnordMetricOutputTest < Test::Unit::TestCase | ||
|
||
CONFIG = %[ | ||
redis_url redis://localhost:6379 | ||
redis_prefix fnordmetric | ||
event_queue_ttl 120 | ||
event_data_ttl 2592000 | ||
] | ||
|
||
def setup | ||
require 'lib/fluent/plugin/out_fnordmetric' | ||
require 'fnordmetric' | ||
FnordMetric::API.send(:include, RedisWrapper) | ||
end | ||
|
||
|
||
def create_driver(conf=CONFIG) | ||
Fluent::Test::OutputTestDriver.new(Fluent::FnordMetricOutput).configure(conf) | ||
end | ||
|
||
def test_configure | ||
d = create_driver | ||
assert_equal 'redis://localhost:6379', d.instance.redis_url | ||
assert_equal 'fnordmetric', d.instance.redis_prefix | ||
assert_equal 120, d.instance.event_queue_ttl | ||
assert_equal 2592000, d.instance.event_data_ttl | ||
end | ||
|
||
def test_event | ||
d = create_driver | ||
time = Time.parse("2011-01-02 13:14:15 UTC").to_i | ||
d.tag = "fnordmetric" | ||
d.emit({"a"=>1}, time) | ||
event_id = d.instance.api.redis.lpop("#{d.instance.redis_prefix}-queue") | ||
event = d.instance.api.redis.get "#{d.instance.redis_prefix}-event-#{event_id}" | ||
event_json = JSON.parse(event) | ||
assert_equal event_json["_type"], d.tag | ||
assert_equal event_json["info"], {"a"=>1} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
require 'rubygems' | ||
require 'bundler' | ||
begin | ||
Bundler.setup(:default, :development) | ||
rescue Bundler::BundlerError => e | ||
$stderr.puts e.message | ||
$stderr.puts "Run `bundle install` to install missing gems" | ||
exit e.status_code | ||
end | ||
require 'test/unit' | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
|
||
require 'test/unit' | ||
require 'fluent/test' | ||
unless ENV.has_key?('VERBOSE') | ||
nulllogger = Object.new | ||
nulllogger.instance_eval {|obj| | ||
def method_missing(method, *args) | ||
# pass | ||
end | ||
} | ||
$log = nulllogger | ||
end | ||
require 'mock_redis' | ||
|
||
class Test::Unit::TestCase | ||
end | ||
|
||
module RedisWrapper | ||
|
||
def self.included base | ||
|
||
base.class_eval do | ||
|
||
attr_reader :redis | ||
@@opts = nil | ||
|
||
def connect | ||
@redis = MockRedis.new(:url => @@opts[:redis_url]) | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |