Skip to content
Browse files

write skeleton of plugin and its tests

  • Loading branch information...
1 parent d49ec95 commit 125ae54e983c382d5af1985692d8d6234c8381d0 @tagomoris committed Feb 21, 2012
Showing with 119 additions and 5 deletions.
  1. +10 −0 Rakefile
  2. +35 −5 lib/fluent/plugin/out_datacounter.rb
  3. +18 −0 test/helper.rb
  4. +56 −0 test/plugin/test_out_datacounter.rb
View
10 Rakefile
@@ -1 +1,11 @@
require "bundler/gem_tasks"
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+task :default => :test
+
View
40 lib/fluent/plugin/out_datacounter.rb
@@ -1,9 +1,39 @@
require "fluent/plugin/out_datacounter/version"
-module Fluent
- module Plugin
- module DataCounterOutput
- # Your code goes here...
- end
+class Fluent::DataCounterOutput < Fluent::BufferedOutput
+ Fluent::Plugin.register_output('datacounter', self)
+
+ # config_param :hoge, :string, :default => 'hoge'
+
+ def initialize
+ super
+ # require 'hogepos'
+ end
+
+ def configure(conf)
+ super
+ # @path = conf['path']
+ end
+
+ def start
+ super
+ # init
+ end
+
+ def shutdown
+ super
+ # destroy
+ end
+
+ def format(tag, time, record)
+ [tag, time, record].to_msgpack
+ end
+
+ def write(chunk)
+ records = []
+ chunk.msgpack_each { |record|
+ # records << record
+ }
+ # write records
end
end
View
18 test/helper.rb
@@ -0,0 +1,18 @@
+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 'fluent/test'
+require 'fluent/plugin/out_datacounter'
+
+class Test::Unit::TestCase
+end
View
56 test/plugin/test_out_datacounter.rb
@@ -0,0 +1,56 @@
+require 'helper'
+
+class DataCounterOutputTest < Test::Unit::TestCase
+ def setup
+ Fluent::Test.setup
+ end
+
+ CONFIG = %[
+ ]
+ # CONFIG = %[
+ # path #{TMP_DIR}/out_file_test
+ # compress gz
+ # utc
+ # ]
+
+ def create_driver(conf = CONFIG, tag='test')
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::DataCounterOutput, tag).configure(conf)
+ end
+
+ def test_configure
+ #### set configurations
+ # d = create_driver %[
+ # path test_path
+ # compress gz
+ # ]
+ #### check configurations
+ # assert_equal 'test_path', d.instance.path
+ # assert_equal :gz, d.instance.compress
+ end
+
+ def test_format
+ d = create_driver
+
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
+ # d.emit({"a"=>1}, time)
+ # d.emit({"a"=>2}, time)
+
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
+
+ # d.run
+ end
+
+ def test_write
+ d = create_driver
+
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
+ # d.emit({"a"=>1}, time)
+ # d.emit({"a"=>2}, time)
+
+ # ### FileOutput#write returns path
+ # path = d.run
+ # expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
+ # assert_equal expect_path, path
+ end
+end

0 comments on commit 125ae54

Please sign in to comment.
Something went wrong with that request. Please try again.