# -*- coding: utf-8 -*- require 'test/unit' require 'fluent/test' require 'fluent/plugin/out_onlineuser' require 'redis' class OnlineuserOutputTest < Test::Unit::TestCase CONFIG = %[ host localhost port 6379 db_number 0 ] @redis def setup Fluent::Test.setup @redis = Redis.new(:host => 'localhost', :port => 6379, :thread_safe => true, :db => 0) end def teardown @redis.quit end def create_driver(conf, tag='test') Fluent::Test::BufferedOutputTestDriver.new(Fluent::OnlineuserOutput, tag).configure(conf) end def test_event_counter d = create_driver CONFIG t = Time.now time = t.to_i d.emit({"name" => "test", "uid" => 1}, time) d.emit({"name" => "test", "uid" => 2}, time) d.emit({"name" => "test", "uid" => 3}, time) d.run assert_equal 3, @redis.zcard('counter:online_user:all') end end