Skip to content

Commit

Permalink
plugin initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
riywo committed Feb 5, 2012
1 parent 71059c4 commit 158f219
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .llenv.pl
@@ -0,0 +1,9 @@
+{
ruby => {
ll_path => '$LLENV_ROOT/lls/$LLENV_OSTYPE/ruby/versions/1.9.2-p290/bin/ruby',
bundle_lib => '$LLENV_ROOT/apps/fluent-plugin-aggregate-filter/vendor/bundle/ruby/1.9.1',
bundle_path => '$LLENV_ROOT/apps/fluent-plugin-aggregate-filter/vendor/bundle/ruby/1.9.1/bin',
app_lib => '$LLENV_ROOT/apps/fluent-plugin-aggregate-filter/lib',
app_path => '$LLENV_ROOT/apps/fluent-plugin-aggregate-filter/bin',
},
}
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -14,3 +14,4 @@ group :development do
end

#gem "fluentd", :path => 'vendor/fluentd' if RUBY_VERSION >= "1.9.2"
gem "fluentd"
3 changes: 3 additions & 0 deletions Rakefile
Expand Up @@ -27,6 +27,9 @@ Jeweler::RubygemsDotOrgTasks.new

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
unless ENV['DEBUG']
ENV['FLUENT_TEST_DEBUG'] = 'TRUE'
end
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
Expand Down
44 changes: 44 additions & 0 deletions lib/fluent/plugin/out_aggregate_filter.rb
@@ -0,0 +1,44 @@
class Fluent::AggregationFilter < Fluent::TimeSlicedOutput
Fluent::Plugin.register_output('aggregation_filter', self)

include Fluent::SetTagKeyMixin
config_set_default :include_tag_key, false

include Fluent::SetTimeKeyMixin
config_set_default :include_time_key, true

# 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

11 changes: 11 additions & 0 deletions test/helper.rb
Expand Up @@ -12,7 +12,18 @@

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'fluent/test'
require 'fluent/plugin/out_aggregate_filter'

if ENV['FLUENT_TEST_DEBUG'] == 'TRUE'
nulllogger = Object.new
nulllogger.instance_eval {|obj|
def method_missing(method, *args)
# pass
end
}
$log = nulllogger
end

class Test::Unit::TestCase
end
67 changes: 64 additions & 3 deletions test/plugin/test_out_aggregate_filter.rb
@@ -1,7 +1,68 @@
require 'helper'
# require 'time'

class TestFluentPluginAggregateFilter < Test::Unit::TestCase
should "probably rename this file and start testing for real" do
flunk "hey buddy, you should probably rename this file and start testing for real"
class AggregationFilterTest < Test::Unit::TestCase
TMP_DIR = File.dirname(__FILE__) + "/../tmp"

def setup
Fluent::Test.setup
FileUtils.rm_rf(TMP_DIR)
FileUtils.mkdir_p(TMP_DIR)
end

CONFIG = %[
buffer_path #{TMP_DIR}/buffer
]
# CONFIG = %[
# path #{TMP_DIR}/out_file_test
# compress gz
# utc
# ]

def create_driver(conf = CONFIG)
Fluent::Test::TimeSlicedOutputTestDriver.new(Fluent::AggregationFilter).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

# data = Zlib::GzipReader.open(expect_path) {|f| f.read }
# assert_equal %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] +
# %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n],
# data
end
end

0 comments on commit 158f219

Please sign in to comment.