From 742042b41712a7fc8d240166732e6ca1716b1860 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 5 Aug 2015 23:01:27 +0900 Subject: [PATCH 01/63] Implement NTime --- lib/fluent/load.rb | 1 + lib/fluent/ntime.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lib/fluent/ntime.rb diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index 1a0d064443..614af06f81 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -16,6 +16,7 @@ end require 'cool.io' +require 'fluent/ntime' require 'fluent/env' require 'fluent/version' require 'fluent/log' diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb new file mode 100644 index 0000000000..be32053ba6 --- /dev/null +++ b/lib/fluent/ntime.rb @@ -0,0 +1,47 @@ +class Fluent::NTime + def initialize(sec, nsec = 0) + @sec = sec + @nsec = nsec + end + + def ==(other) + if other.is_a?(Fluent::NTime) + @sec == other.sec + else + @sec == other + end + end + + def sec + @sec + end + + def nsec + @nsec + end + + def to_int + @sec + end + + def to_msec + to_nsec / 1000000 + end + + def to_usec + to_nsec / 1000 + end + + def to_nsec + @sec * 1000000000 + @nsec + end + + def self.now + time = Time.now + Fluent::NTime.new(time.to_i, time.nsec) + end + + def method_missing(name, *args, &block) + @sec.send(name, *args, &block) + end +end From 1d7c9671fd7b6ff7387e635e0274ec958e579ed9 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 5 Aug 2015 23:02:58 +0900 Subject: [PATCH 02/63] Engine.now returns NTime --- lib/fluent/engine.rb | 2 +- test/test_event.rb | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index c347e7a4eb..cc6611cf02 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -132,7 +132,7 @@ def flush! def now # TODO thread update - Time.now.to_i + Fluent::NTime.now end def log_event_loop diff --git a/test/test_event.rb b/test/test_event.rb index 833ba6893f..fc1e0c0b8e 100644 --- a/test/test_event.rb +++ b/test/test_event.rb @@ -42,7 +42,8 @@ class ArrayEventStreamTest < ::Test::Unit::TestCase include Fluent def setup - @times = [Engine.now, Engine.now + 1] + time = Engine.now + @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = ArrayEventStream.new(@times.zip(@records)) end @@ -86,7 +87,8 @@ class MultiEventStreamTest < ::Test::Unit::TestCase include Fluent def setup - @times = [Engine.now, Engine.now + 1] + time = Engine.now + @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = MultiEventStream.new @times.zip(@records).each { |time, record| @@ -134,7 +136,8 @@ class MessagePackEventStreamTest < ::Test::Unit::TestCase def setup pk = MessagePack::Packer.new - @times = [Engine.now, Engine.now + 1] + time = Engine.now + @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @times.zip(@records).each { |time, record| pk.write([time, record]) From eed864b4a3888ace5f032f8b5f0ffe018f5a1f90 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 5 Aug 2015 23:34:07 +0900 Subject: [PATCH 03/63] TimeParser.parse returns NTime --- lib/fluent/ntime.rb | 7 +++++-- lib/fluent/parser.rb | 6 +++--- test/test_parser.rb | 21 ++++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index be32053ba6..30d98fb413 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -36,11 +36,14 @@ def to_nsec @sec * 1000000000 + @nsec end - def self.now - time = Time.now + def self.from_time(time) Fluent::NTime.new(time.to_i, time.nsec) end + def self.now + from_time(Time.now) + end + def method_missing(name, *args, &block) @sec.send(name, *args, &block) end diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 7f06bca353..51e417df49 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -60,9 +60,9 @@ def initialize(time_format) @cache2_time = nil @parser = if time_format - Proc.new { |value| Time.strptime(value, time_format) } + Proc.new { |value| NTime.from_time(Time.strptime(value, time_format)) } else - Time.method(:parse) + Proc.new { |value| NTime.from_time(Time.parse(value)) } end end @@ -77,7 +77,7 @@ def parse(value) return @cache2_time else begin - time = @parser.call(value).to_i + time = @parser.call(value) rescue => e raise ParserError, "invalid time format: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end diff --git a/test/test_parser.rb b/test/test_parser.rb index ead7d095fc..629a21aa03 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -7,9 +7,9 @@ module ParserTest def str2time(str_time, format = nil) if format - Time.strptime(str_time, format).to_i + NTime.from_time(Time.strptime(str_time, format)) else - Time.parse(str_time).to_i + NTime.from_time(Time.parse(str_time)) end end @@ -45,6 +45,8 @@ class TimeParserTest < ::Test::Unit::TestCase def test_call_with_parse parser = TextParser::TimeParser.new(nil) + assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::NTime)) + time = str2time('2013-09-18 12:00:00 +0900') assert_equal(time, parser.parse('2013-09-18 12:00:00 +0900')) end @@ -52,10 +54,23 @@ def test_call_with_parse def test_parse_with_strptime parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S %z') + assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::NTime)) + time = str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z') assert_equal(time, parser.parse('28/Feb/2013:12:00:00 +0900')) end + def test_parse_nsec_with_strptime + parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S:%N %z') + + assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::NTime)) + + time = str2time('28/Feb/2013:12:00:00:123456789 +0900', '%d/%b/%Y:%H:%M:%S:%N %z') + assert_equal(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) + + assert_equal(123456789, parser.parse('28/Feb/2013:12:00:00:123456789 +0900').nsec) + end + def test_parse_with_invalid_argument parser = TextParser::TimeParser.new(nil) @@ -113,7 +128,7 @@ def test_parse_with_time_key ) text = '2013-02-28 12:00:00 +0900' parser.parse(text) do |time, record| - assert_equal Time.parse(text).to_i, time + assert_equal NTime.from_time(Time.parse(text)), time end end From 028d64b4ce0cbcabb21ffece98473e0ae59b3e21 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 5 Aug 2015 23:58:58 +0900 Subject: [PATCH 04/63] Use Engine.now instead of Time.now.to_i in OutputTestDriver --- lib/fluent/test/output_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/fluent/test/output_test.rb b/lib/fluent/test/output_test.rb index bca6c3e911..4ff78fd484 100644 --- a/lib/fluent/test/output_test.rb +++ b/lib/fluent/test/output_test.rb @@ -37,8 +37,8 @@ def initialize(klass, tag='test', &block) attr_accessor :tag - def emit(record, time=Time.now) - es = OneEventStream.new(time.to_i, record) + def emit(record, time=Engine.now) + es = OneEventStream.new(time, record) chain = TestOutputChain.new @instance.emit(@tag, es, chain) assert_equal 1, chain.called @@ -60,8 +60,8 @@ def @instance.buffer attr_accessor :tag - def emit(record, time=Time.now) - @entries << [time.to_i, record] + def emit(record, time=Engine.now) + @entries << [time, record] self end @@ -109,11 +109,11 @@ def initialize(klass, tag='test', &block) attr_accessor :tag - def emit(record, time=Time.now) + def emit(record, time=Engine.now) slicer = @instance.instance_eval{@time_slicer} - key = slicer.call(time.to_i) + key = slicer.call(time) @entries[key] = [] unless @entries.has_key?(key) - @entries[key] << [time.to_i, record] + @entries[key] << [time, record] self end From 81f3a5d5389a15c7f21e1360abd7644f2dfa50e0 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 00:14:25 +0900 Subject: [PATCH 05/63] Use NTime instead of Time.now in test_{filter,out}_stdout --- test/plugin/test_filter_stdout.rb | 12 ++++++------ test/plugin/test_out_stdout.rb | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 761d1083a3..4d553c576e 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -32,7 +32,7 @@ def emit(d, msg, time) def test_through_record d = create_driver time = Time.now - filtered = emit(d, {'test' => 'test'}, time) + filtered = emit(d, {'test' => 'test'}, NTime.from_time(time)) assert_equal({'test' => 'test'}, filtered) end @@ -59,7 +59,7 @@ def test_configure_output_type def test_output_type_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, time) } + out = capture_log(d) { emit(d, {'test' => 'test'}, NTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -71,12 +71,12 @@ def test_output_type_json def test_output_type_hash d = create_driver(CONFIG + "\noutput_type hash") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, time) } + out = capture_log(d) { emit(d, {'test' => 'test'}, NTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. d = create_driver(CONFIG + "\noutput_type hash") - out = capture_log(d) { emit(d, {'test' => Float::NAN}, time) } + out = capture_log(d) { emit(d, {'test' => Float::NAN}, NTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out end @@ -84,7 +84,7 @@ def test_output_type_hash def test_include_time_key d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc") time = Time.now - message_time = Time.parse("2011-01-02 13:14:15 UTC").to_i + message_time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) out = capture_log(d) { emit(d, {'test' => 'test'}, message_time) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out end @@ -93,7 +93,7 @@ def test_include_time_key def test_format_json d = create_driver(CONFIG + "\nformat json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, time) } + out = capture_log(d) { emit(d, {'test' => 'test'}, NTime.from_time(time)) } assert_equal "{\"test\":\"test\"}\n", out end diff --git a/test/plugin/test_out_stdout.rb b/test/plugin/test_out_stdout.rb index 9b94793f69..3c299a7d19 100644 --- a/test/plugin/test_out_stdout.rb +++ b/test/plugin/test_out_stdout.rb @@ -2,6 +2,8 @@ require 'fluent/test' class StdoutOutputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup end @@ -33,7 +35,7 @@ def test_configure_output_type def test_emit_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log { d.emit({'test' => 'test'}, time) } + out = capture_log { d.emit({'test' => 'test'}, NTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -47,7 +49,7 @@ def test_emit_hash assert_equal "#{time.localtime} test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. - out = capture_log { d.emit({'test' => Float::NAN}, time) } + out = capture_log { d.emit({'test' => Float::NAN}, NTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\"=>NaN}\n", out end From 6ae478d7d83a4ff7cec6525204b7ab342c8ac8d0 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 03:30:27 +0900 Subject: [PATCH 06/63] Implement NTime#coerce --- lib/fluent/ntime.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index 30d98fb413..85a7c85062 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -24,6 +24,11 @@ def to_int @sec end + # for > and others + def coerce(other) + [other, @sec] + end + def to_msec to_nsec / 1000000 end From 556053d3fc8e59a942f6aef12e69d005163b2cec Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 03:40:35 +0900 Subject: [PATCH 07/63] Implement NTime#to_r --- lib/fluent/ntime.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index 85a7c85062..8f53f367c1 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -24,6 +24,11 @@ def to_int @sec end + # for Time.at + def to_r + Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000) + end + # for > and others def coerce(other) [other, @sec] From adc377ef7aa21a9cd6fcc06616dee88ed661ea01 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 11:26:08 +0900 Subject: [PATCH 08/63] Remove NTime#to_{m,u,n}sec --- lib/fluent/ntime.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index 8f53f367c1..154e20f423 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -34,18 +34,6 @@ def coerce(other) [other, @sec] end - def to_msec - to_nsec / 1000000 - end - - def to_usec - to_nsec / 1000 - end - - def to_nsec - @sec * 1000000000 + @nsec - end - def self.from_time(time) Fluent::NTime.new(time.to_i, time.nsec) end From 140a2c470f74ecd58af68d89125f5683538030da Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 11:26:15 +0900 Subject: [PATCH 09/63] Add comment --- lib/fluent/ntime.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index 154e20f423..c43d8ffd92 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -42,6 +42,7 @@ def self.now from_time(Time.now) end + ## TODO: For performance, implement +, -, and so on def method_missing(name, *args, &block) @sec.send(name, *args, &block) end From 931fb8a968d9addb64df3dc1dc6d02cb454f902b Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 11:30:15 +0900 Subject: [PATCH 10/63] Add tests for NTime --- test/test_ntime.rb | 130 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 test/test_ntime.rb diff --git a/test/test_ntime.rb b/test/test_ntime.rb new file mode 100644 index 0000000000..db51d44e9a --- /dev/null +++ b/test/test_ntime.rb @@ -0,0 +1,130 @@ +require_relative 'helper' + +class NTimeTest < Test::Unit::TestCase + include Fluent + + test '#sec' do + assert_equal(1, NTime.new(1, 2).sec) + end + + test '#nsec' do + assert_equal(2, NTime.new(1, 2).nsec) + assert_equal(0, NTime.new(1).nsec) + end + + test '#to_int' do + assert_equal(1, NTime.new(1, 2).to_int) + end + + test '#to_r' do + assert_equal(Rational(1_000_000_002, 1_000_000_000), NTime.new(1, 2).to_r) + end + + test '.from_time' do + sec = 1000 + usec = 2 + time = NTime.from_time(Time.at(sec, usec)) + assert_equal(time.sec, sec) + assert_equal(time.nsec, usec * 1000) + end + + test '.now' do + sec = 1000 + usec = 2 + time = Time.at(sec, usec) + Timecop.freeze(time) + assert_equal(sec, NTime.now.sec) + assert_equal(usec * 1000, NTime.now.nsec) + Timecop.return + end + + test '==' do + assert(NTime.new(1, 2) == NTime.new(1, 2)) + assert(NTime.new(1, 2) == NTime.new(1, 3)) + refute(NTime.new(1, 2) == NTime.new(3, 2)) + refute(NTime.new(1, 2) == NTime.new(3, 4)) + + assert(NTime.new(1, 2) == 1) + refute(NTime.new(1, 2) == 2) + + assert(1 == NTime.new(1, 2)) + refute(2 == NTime.new(1, 2)) + end + + test '+' do + assert_equal(4, NTime.new(1, 2) + NTime.new(3, 4)) + assert_equal(6, NTime.new(1, 2) + 5) + assert_equal(6, 5 + NTime.new(1, 2)) + end + + test '-' do + assert_equal(-2, NTime.new(1, 2) - NTime.new(3, 4)) + assert_equal(-4, NTime.new(1, 2) - 5) + assert_equal(4, 5 - NTime.new(1, 2)) + end + + test '>' do + assert(NTime.new(2) > NTime.new(1)) + refute(NTime.new(1) > NTime.new(1)) + refute(NTime.new(1) > NTime.new(2)) + + assert(NTime.new(2) > 1) + refute(NTime.new(1) > 1) + refute(NTime.new(1) > 2) + + assert(2 > NTime.new(1)) + refute(1 > NTime.new(1)) + refute(1 > NTime.new(2)) + end + + test '>=' do + assert(NTime.new(2) >= NTime.new(1)) + assert(NTime.new(1) >= NTime.new(1)) + refute(NTime.new(1) >= NTime.new(2)) + + assert(NTime.new(2) >= 1) + assert(NTime.new(1) >= 1) + refute(NTime.new(1) >= 2) + + assert(2 >= NTime.new(1)) + assert(1 >= NTime.new(1)) + refute(1 >= NTime.new(2)) + end + + test '<' do + assert(NTime.new(1) < NTime.new(2)) + refute(NTime.new(1) < NTime.new(1)) + refute(NTime.new(2) < NTime.new(1)) + + assert(NTime.new(1) < 2) + refute(NTime.new(1) < 1) + refute(NTime.new(2) < 1) + + assert(1 < NTime.new(2)) + refute(1 < NTime.new(1)) + refute(2 < NTime.new(1)) + end + + test '=<' do + assert(NTime.new(1) <= NTime.new(2)) + assert(NTime.new(1) <= NTime.new(1)) + refute(NTime.new(2) <= NTime.new(1)) + + assert(NTime.new(1) <= 2) + assert(NTime.new(1) <= 1) + refute(NTime.new(2) <= 1) + + assert(1 <= NTime.new(2)) + assert(1 <= NTime.new(1)) + refute(2 <= NTime.new(1)) + end + + test 'Time.at' do + sec = 1000 + nsec = 2000 + ntime = NTime.new(sec, nsec) + time = Time.at(ntime) + assert_equal(sec, time.to_i) + assert_equal(nsec, time.nsec) + end +end From 5684c087303645aaa40ea38fb159986e968e9109 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 11:55:12 +0900 Subject: [PATCH 11/63] Implement NTime#to_s --- lib/fluent/ntime.rb | 4 ++++ test/test_ntime.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index c43d8ffd92..85a64431a3 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -34,6 +34,10 @@ def coerce(other) [other, @sec] end + def to_s + @sec.to_s + end + def self.from_time(time) Fluent::NTime.new(time.to_i, time.nsec) end diff --git a/test/test_ntime.rb b/test/test_ntime.rb index db51d44e9a..cb2fe6cec9 100644 --- a/test/test_ntime.rb +++ b/test/test_ntime.rb @@ -20,6 +20,12 @@ class NTimeTest < Test::Unit::TestCase assert_equal(Rational(1_000_000_002, 1_000_000_000), NTime.new(1, 2).to_r) end + test '#to_s' do + time = NTime.new(100) + assert_equal('100', time.to_s) + assert_equal('100', "#{time}") + end + test '.from_time' do sec = 1000 usec = 2 From 2f6205911ac5d07289f8a6d4b9422fbc22948a52 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 12:08:20 +0900 Subject: [PATCH 12/63] in_exec emits NTime --- lib/fluent/plugin/in_exec.rb | 4 ++-- test/plugin/test_in_exec.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index fe31908dec..6fc48cd606 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -66,9 +66,9 @@ def configure(conf) if @time_key if @time_format f = @time_format - @time_parse_proc = Proc.new {|str| Time.strptime(str, f).to_i } + @time_parse_proc = Proc.new {|str| NTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| str.to_i } + @time_parse_proc = Proc.new {|str| NTime.new(str.to_i) } end end diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index 5d5911d474..b1e45e110c 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -3,9 +3,11 @@ require 'net/http' class ExecInputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup - @test_time = Time.parse("2011-01-02 13:14:15").to_i + @test_time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb')) end @@ -77,6 +79,8 @@ def test_emit emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] + assert_equal @test_time.sec, emits[0][1].sec + assert_equal @test_time.nsec, emits[0][1].nsec end def test_emit_json @@ -89,6 +93,8 @@ def test_emit_json emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] + assert_equal @test_time.sec, emits[0][1].sec + assert_equal @test_time.nsec, emits[0][1].nsec end def test_emit_msgpack @@ -101,5 +107,7 @@ def test_emit_msgpack emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] + assert_equal @test_time.sec, emits[0][1].sec + assert_equal @test_time.nsec, emits[0][1].nsec end end From 006c7a7643653f22c7f35cf498c3a40a9e876afa Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 12:13:51 +0900 Subject: [PATCH 13/63] out_exec_filter emits NTime --- lib/fluent/plugin/out_exec_filter.rb | 4 ++-- test/plugin/test_out_exec_filter.rb | 34 +++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index 4646e4a702..b811881f03 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -120,9 +120,9 @@ def configure(conf) if @out_time_key if f = @out_time_format - @time_parse_proc = Proc.new {|str| Time.strptime(str, f).to_i } + @time_parse_proc = Proc.new {|str| NTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| str.to_i } + @time_parse_proc = Proc.new {|str| NTime.new(str.to_i) } end elsif @out_time_format log.warn "out_time_format effects nothing when out_time_key is not specified: #{conf}" diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index 81b14cc5ee..31ab8c9423 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -3,6 +3,8 @@ require 'fileutils' class ExecFilterOutputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup end @@ -69,7 +71,7 @@ def test_configure def test_emit_1 d = create_driver - time = Time.parse("2011-01-02 13:14:15").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"k1"=>1}, time) @@ -79,7 +81,11 @@ def test_emit_1 emits = d.emits assert_equal 2, emits.length assert_equal ["test", time, {"k2"=>"1"}], emits[0] + assert_equal time.sec, emits[0][1].sec + assert_equal time.nsec, emits[0][1].nsec assert_equal ["test", time, {"k2"=>"2"}], emits[1] + assert_equal time.sec, emits[1][1].sec + assert_equal time.nsec, emits[1][1].nsec end def test_emit_2 @@ -92,7 +98,7 @@ def test_emit_2 num_children 3 ] - time = Time.parse("2011-01-02 13:14:15").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"k1"=>1}, time) @@ -102,7 +108,11 @@ def test_emit_2 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"k2"=>"1"}], emits[0] + assert_equal time.sec, emits[0][1].sec + assert_equal time.nsec, emits[0][1].nsec assert_equal ["xxx", time, {"k2"=>"2"}], emits[1] + assert_equal time.sec, emits[1][1].sec + assert_equal time.nsec, emits[1][1].nsec end def test_emit_3 @@ -115,7 +125,7 @@ def test_emit_3 num_children 3 ] - time = Time.parse("2011-01-02 13:14:15").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -125,6 +135,8 @@ def test_emit_3 emits = d.emits assert_equal 1, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value foo"}], emits[0] + assert_equal time.sec, emits[0][1].sec + assert_equal time.nsec, emits[0][1].nsec d = create_driver %[ command sed #{sed_unbuffered_option} -l -e s/foo/bar/ @@ -135,7 +147,7 @@ def test_emit_3 num_children 3 ] - time = Time.parse("2011-01-02 13:14:15").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -145,7 +157,11 @@ def test_emit_3 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value bar"}], emits[0] + assert_equal time.sec, emits[0][1].sec + assert_equal time.nsec, emits[0][1].nsec assert_equal ["xxx", time, {"val2"=>"sed-ed value poo"}], emits[1] + assert_equal time.sec, emits[1][1].sec + assert_equal time.nsec, emits[1][1].nsec end def test_emit_4 @@ -160,7 +176,7 @@ def test_emit_4 num_children 3 ], 'input.test') - time = Time.parse("2011-01-02 13:14:15").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -170,7 +186,11 @@ def test_emit_4 emits = d.emits assert_equal 2, emits.length assert_equal ["output.test", time, {"val2"=>"sed-ed value bar"}], emits[0] + assert_equal time.sec, emits[0][1].sec + assert_equal time.nsec, emits[0][1].nsec assert_equal ["output.test", time, {"val2"=>"sed-ed value poo"}], emits[1] + assert_equal time.sec, emits[1][1].sec + assert_equal time.nsec, emits[1][1].nsec end def test_json_1 @@ -182,7 +202,7 @@ def test_json_1 tag_key tag ], 'input.test') - time = Time.parse("2011-01-02 13:14:15").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"message"=>%[{"time":#{time},"tag":"t1","k1":"v1"}]}, time+10) @@ -191,6 +211,8 @@ def test_json_1 emits = d.emits assert_equal 1, emits.length assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] + assert_equal time.sec, emits[0][1].sec + assert_equal time.nsec, emits[0][1].nsec end end From 16321f7d34c42c1e84f2f3f6d6de91c86c92b0c4 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 13:08:13 +0900 Subject: [PATCH 14/63] Assert NTime in InputTestDriver --- lib/fluent/test/input_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index 062c4a46b0..094137d88a 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -140,7 +140,13 @@ def run(&block) tag, events = @emit_streams[j] events.each do |time, record| - assert_equal(@expects[i], [tag, time, record]) if @expects + if @expects + assert_equal(@expects[i], [tag, time, record]) + if @expects[i][1].is_a?(NTime) + assert_equal(@expects[i][1].sec, time.sec) + assert_equal(@expects[i][1].nsec, time.nsec) + end + end i += 1 end j += 1 From 9141b49a8422e9af41d9b0a0cd393f1b0eea396e Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 13:30:11 +0900 Subject: [PATCH 15/63] in_http always emits NTime --- lib/fluent/plugin/in_http.rb | 2 +- lib/fluent/test/base.rb | 2 +- test/plugin/test_in_http.rb | 22 ++++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 2285100501..7046657ff8 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -145,7 +145,7 @@ def on_request(path_info, params) end time = if param_time = params['time'] param_time = param_time.to_i - param_time.zero? ? Engine.now : param_time + param_time.zero? ? Engine.now : NTime.new(param_time) else record_time.nil? ? Engine.now : record_time end diff --git a/lib/fluent/test/base.rb b/lib/fluent/test/base.rb index 43be9002a5..b2408740f2 100644 --- a/lib/fluent/test/base.rb +++ b/lib/fluent/test/base.rb @@ -21,7 +21,7 @@ def self.setup engine = Fluent.const_set(:Engine, EngineClass.new).init engine.define_singleton_method(:now=) {|n| - @now = n.to_i + @now = n } engine.define_singleton_method(:now) { @now || super() diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index 1861f0cb63..41a4e8d536 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -3,6 +3,8 @@ require 'net/http' class HttpInputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup end @@ -32,7 +34,7 @@ def test_configure def test_time d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -49,7 +51,7 @@ def test_time def test_json d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -69,7 +71,7 @@ def test_json def test_multi_json d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -138,7 +140,7 @@ def test_multi_json_with_add_http_headers def test_json_with_add_http_headers d = create_driver(CONFIG + "add_http_headers true") - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]] @@ -158,7 +160,7 @@ def test_json_with_add_http_headers def test_application_json d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -174,7 +176,7 @@ def test_application_json def test_msgpack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -190,7 +192,7 @@ def test_msgpack def test_multi_msgpack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -212,7 +214,7 @@ def test_with_regexp types field_1:integer ]) - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'} d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'} @@ -236,7 +238,7 @@ def test_with_csv keys foo,bar ]) - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'} d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'} @@ -254,7 +256,7 @@ def test_resonse_with_empty_img d = create_driver(CONFIG + "respond_with_empty_img true") assert_equal true, d.instance.respond_with_empty_img - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} From a41dfd81bfd132ac113d2115831ed09b40c566e4 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 13:52:48 +0900 Subject: [PATCH 16/63] Parser always return NTime as time --- lib/fluent/parser.rb | 2 +- test/test_parser.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 51e417df49..2a7525bc22 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -256,7 +256,7 @@ def parse(text) time = @mutex.synchronize { @time_parser.parse(value) } else begin - time = value.to_i + time = NTime.new(value.to_i) rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end diff --git a/test/test_parser.rb b/test/test_parser.rb index 629a21aa03..908a886759 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -407,12 +407,26 @@ def test_parse_with_invalid_time def test_parse_with_keep_time_key parser = TextParser::JSONParser.new + format = "%d/%b/%Y:%H:%M:%S %z" parser.configure( - 'time_format'=>"%d/%b/%Y:%H:%M:%S %z", + 'time_format'=>format, 'keep_time_key'=>'true', ) text = "28/Feb/2013:12:00:00 +0900" parser.parse("{\"time\":\"#{text}\"}") do |time, record| + assert_equal Time.strptime(text, format).to_i, time.sec + assert_equal text, record['time'] + end + end + + def test_parse_with_keep_time_key_without_time_format + parser = TextParser::JSONParser.new + parser.configure( + 'keep_time_key'=>'true', + ) + text = "100" + parser.parse("{\"time\":\"#{text}\"}") do |time, record| + assert_equal text.to_i, time.sec assert_equal text, record['time'] end end From fc834ab87a09a1dc452999afc6d169fd854acad8 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 14:02:40 +0900 Subject: [PATCH 17/63] Separate Fluent::NTime declaration --- lib/fluent/ntime.rb | 82 +++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index 85a64431a3..b2a4878bcb 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -1,53 +1,55 @@ -class Fluent::NTime - def initialize(sec, nsec = 0) - @sec = sec - @nsec = nsec - end +module Fluent + class NTime + def initialize(sec, nsec = 0) + @sec = sec + @nsec = nsec + end - def ==(other) - if other.is_a?(Fluent::NTime) - @sec == other.sec - else - @sec == other + def ==(other) + if other.is_a?(Fluent::NTime) + @sec == other.sec + else + @sec == other + end end - end - def sec - @sec - end + def sec + @sec + end - def nsec - @nsec - end + def nsec + @nsec + end - def to_int - @sec - end + def to_int + @sec + end - # for Time.at - def to_r - Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000) - end + # for Time.at + def to_r + Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000) + end - # for > and others - def coerce(other) - [other, @sec] - end + # for > and others + def coerce(other) + [other, @sec] + end - def to_s - @sec.to_s - end + def to_s + @sec.to_s + end - def self.from_time(time) - Fluent::NTime.new(time.to_i, time.nsec) - end + def self.from_time(time) + Fluent::NTime.new(time.to_i, time.nsec) + end - def self.now - from_time(Time.now) - end + def self.now + from_time(Time.now) + end - ## TODO: For performance, implement +, -, and so on - def method_missing(name, *args, &block) - @sec.send(name, *args, &block) + ## TODO: For performance, implement +, -, and so on + def method_missing(name, *args, &block) + @sec.send(name, *args, &block) + end end end From 17187b6ffb2abecc0f03af0c729e6a173a6d9454 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 14:49:31 +0900 Subject: [PATCH 18/63] Add NTime tests for input plugins --- test/plugin/test_in_dummy.rb | 1 + test/plugin/test_in_gc_stat.rb | 1 + test/plugin/test_in_object_space.rb | 3 +-- test/plugin/test_in_status.rb | 1 + test/plugin/test_in_syslog.rb | 6 ++++-- test/plugin/test_in_tail.rb | 2 ++ test/plugin/test_in_tcp.rb | 1 + test/plugin/test_in_udp.rb | 10 +++++++--- 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/test/plugin/test_in_dummy.rb b/test/plugin/test_in_dummy.rb index 828a5a5601..ea6a48bbfd 100644 --- a/test/plugin/test_in_dummy.rb +++ b/test/plugin/test_in_dummy.rb @@ -77,6 +77,7 @@ def create_driver(conf) emits.each do |tag, time, record| assert_equal("dummy", tag) assert_equal({"foo"=>"bar"}, record) + assert(time.is_a?(Fluent::NTime)) end end diff --git a/test/plugin/test_in_gc_stat.rb b/test/plugin/test_in_gc_stat.rb index 3fc96d7f8e..05bf4a6475 100644 --- a/test/plugin/test_in_gc_stat.rb +++ b/test/plugin/test_in_gc_stat.rb @@ -33,5 +33,6 @@ def test_emit emits = d.emits assert(emits.length > 0) assert_equal(stat, emits[0][2]) + assert(emits[0][1].is_a?(Fluent::NTime)) end end diff --git a/test/plugin/test_in_object_space.rb b/test/plugin/test_in_object_space.rb index 57a4a0cbed..cbbdf71fd1 100644 --- a/test/plugin/test_in_object_space.rb +++ b/test/plugin/test_in_object_space.rb @@ -32,8 +32,6 @@ def test_configure def test_emit d = create_driver - time = Time.parse("2011-01-02 13:14:15").to_i - d.expected_emits_length = 2 d.run @@ -43,6 +41,7 @@ def test_emit emits.each { |tag, time, record| assert_equal d.instance.tag, tag assert_equal d.instance.top, record.keys.size + assert(time.is_a?(Fluent::NTime)) } end end diff --git a/test/plugin/test_in_status.rb b/test/plugin/test_in_status.rb index a3b96a2320..0d838ac94a 100644 --- a/test/plugin/test_in_status.rb +++ b/test/plugin/test_in_status.rb @@ -34,5 +34,6 @@ def test_emit emits = d.emits assert(emits.length > 0) assert_equal({"answer" => "42"}, emits[0][2]) + assert(emits[0][1].is_a?(Fluent::NTime)) end end diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index 3e1a20e106..f1d67ba8b5 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -2,6 +2,8 @@ require 'fluent/test' class SyslogInputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup require 'fluent/plugin/socket_util' @@ -43,8 +45,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S').to_i}, - {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S').to_i}, + {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 34008b4aa2..9396b61503 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -77,6 +77,8 @@ def test_emit assert_equal(true, emits.length > 0) assert_equal({"message" => "test3"}, emits[0][2]) assert_equal({"message" => "test4"}, emits[1][2]) + assert(emits[0][1].is_a?(Fluent::NTime)) + assert(emits[1][1].is_a?(Fluent::NTime)) assert_equal(1, d.emit_streams.size) end diff --git a/test/plugin/test_in_tcp.rb b/test/plugin/test_in_tcp.rb index 60280ddaae..eb9fef8274 100755 --- a/test/plugin/test_in_tcp.rb +++ b/test/plugin/test_in_tcp.rb @@ -83,6 +83,7 @@ def compare_test_result(emits, tests) assert_equal(2, emits.size) emits.each_index {|i| assert_equal(tests[i]['expected'], emits[i][2]['message']) + assert(emits[i][1].is_a?(Fluent::NTime)) } end end diff --git a/test/plugin/test_in_udp.rb b/test/plugin/test_in_udp.rb index e2b2166deb..f3dc14207f 100755 --- a/test/plugin/test_in_udp.rb +++ b/test/plugin/test_in_udp.rb @@ -2,6 +2,8 @@ require 'fluent/test' class UdpInputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup end @@ -44,8 +46,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S').to_i}, - {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S').to_i}, + {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do @@ -59,7 +61,8 @@ def test_time_format emits = d.emits emits.each_index {|i| - assert_equal(tests[i]['expected'], emits[i][1]) + assert_equal(tests[i]['expected'].sec, emits[i][1].sec) + assert_equal(tests[i]['expected'].nsec, emits[i][1].nsec) } } end @@ -99,6 +102,7 @@ def compare_test_result(emits, tests) assert_equal(2, emits.size) emits.each_index {|i| assert_equal(tests[i]['expected'], emits[i][2]['message']) + assert(emits[i][1].is_a?(Fluent::NTime)) } end end From c63c8a2b1d0d749d10a8036da98c001acb33f941 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 16:15:07 +0900 Subject: [PATCH 19/63] Add assert_equal_ntime --- lib/fluent/test/base.rb | 7 +++++++ lib/fluent/test/input_test.rb | 5 +---- test/plugin/test_in_exec.rb | 9 +++------ test/plugin/test_in_udp.rb | 3 +-- test/plugin/test_out_exec_filter.rb | 30 ++++++++++------------------- test/test_parser.rb | 4 +--- 6 files changed, 23 insertions(+), 35 deletions(-) diff --git a/lib/fluent/test/base.rb b/lib/fluent/test/base.rb index b2408740f2..c20b48180a 100644 --- a/lib/fluent/test/base.rb +++ b/lib/fluent/test/base.rb @@ -27,6 +27,13 @@ def self.setup @now || super() } + ::Test::Unit::Assertions.module_eval { + def assert_equal_ntime(a, b) + assert_equal(a.sec, b.sec) + assert_equal(a.nsec, b.nsec) + end + } + nil end diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index 094137d88a..bab534df82 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -142,10 +142,7 @@ def run(&block) events.each do |time, record| if @expects assert_equal(@expects[i], [tag, time, record]) - if @expects[i][1].is_a?(NTime) - assert_equal(@expects[i][1].sec, time.sec) - assert_equal(@expects[i][1].nsec, time.nsec) - end + assert_equal_ntime(@expects[i][1], time) if @expects[i][1].is_a?(NTime) end i += 1 end diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index b1e45e110c..b90d4ab7e0 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -79,8 +79,7 @@ def test_emit emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal @test_time.sec, emits[0][1].sec - assert_equal @test_time.nsec, emits[0][1].nsec + assert_equal_ntime(@test_time, emits[0][1]) end def test_emit_json @@ -93,8 +92,7 @@ def test_emit_json emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal @test_time.sec, emits[0][1].sec - assert_equal @test_time.nsec, emits[0][1].nsec + assert_equal_ntime(@test_time, emits[0][1]) end def test_emit_msgpack @@ -107,7 +105,6 @@ def test_emit_msgpack emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal @test_time.sec, emits[0][1].sec - assert_equal @test_time.nsec, emits[0][1].nsec + assert_equal_ntime(@test_time, emits[0][1]) end end diff --git a/test/plugin/test_in_udp.rb b/test/plugin/test_in_udp.rb index f3dc14207f..fd3d1d7189 100755 --- a/test/plugin/test_in_udp.rb +++ b/test/plugin/test_in_udp.rb @@ -61,8 +61,7 @@ def test_time_format emits = d.emits emits.each_index {|i| - assert_equal(tests[i]['expected'].sec, emits[i][1].sec) - assert_equal(tests[i]['expected'].nsec, emits[i][1].nsec) + assert_equal_ntime(tests[i]['expected'], emits[i][1]) } } end diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index 31ab8c9423..6c03936613 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -81,11 +81,9 @@ def test_emit_1 emits = d.emits assert_equal 2, emits.length assert_equal ["test", time, {"k2"=>"1"}], emits[0] - assert_equal time.sec, emits[0][1].sec - assert_equal time.nsec, emits[0][1].nsec + assert_equal_ntime time, emits[0][1] assert_equal ["test", time, {"k2"=>"2"}], emits[1] - assert_equal time.sec, emits[1][1].sec - assert_equal time.nsec, emits[1][1].nsec + assert_equal_ntime time, emits[1][1] end def test_emit_2 @@ -108,11 +106,9 @@ def test_emit_2 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"k2"=>"1"}], emits[0] - assert_equal time.sec, emits[0][1].sec - assert_equal time.nsec, emits[0][1].nsec + assert_equal_ntime time, emits[0][1] assert_equal ["xxx", time, {"k2"=>"2"}], emits[1] - assert_equal time.sec, emits[1][1].sec - assert_equal time.nsec, emits[1][1].nsec + assert_equal_ntime time, emits[1][1] end def test_emit_3 @@ -135,8 +131,7 @@ def test_emit_3 emits = d.emits assert_equal 1, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value foo"}], emits[0] - assert_equal time.sec, emits[0][1].sec - assert_equal time.nsec, emits[0][1].nsec + assert_equal_ntime time, emits[0][1] d = create_driver %[ command sed #{sed_unbuffered_option} -l -e s/foo/bar/ @@ -157,11 +152,9 @@ def test_emit_3 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value bar"}], emits[0] - assert_equal time.sec, emits[0][1].sec - assert_equal time.nsec, emits[0][1].nsec + assert_equal_ntime time, emits[0][1] assert_equal ["xxx", time, {"val2"=>"sed-ed value poo"}], emits[1] - assert_equal time.sec, emits[1][1].sec - assert_equal time.nsec, emits[1][1].nsec + assert_equal_ntime time, emits[1][1] end def test_emit_4 @@ -186,11 +179,9 @@ def test_emit_4 emits = d.emits assert_equal 2, emits.length assert_equal ["output.test", time, {"val2"=>"sed-ed value bar"}], emits[0] - assert_equal time.sec, emits[0][1].sec - assert_equal time.nsec, emits[0][1].nsec + assert_equal_ntime time, emits[0][1] assert_equal ["output.test", time, {"val2"=>"sed-ed value poo"}], emits[1] - assert_equal time.sec, emits[1][1].sec - assert_equal time.nsec, emits[1][1].nsec + assert_equal_ntime time, emits[1][1] end def test_json_1 @@ -211,8 +202,7 @@ def test_json_1 emits = d.emits assert_equal 1, emits.length assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] - assert_equal time.sec, emits[0][1].sec - assert_equal time.nsec, emits[0][1].nsec + assert_equal_ntime time, emits[0][1] end end diff --git a/test/test_parser.rb b/test/test_parser.rb index 908a886759..fb91a2cfc5 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -66,9 +66,7 @@ def test_parse_nsec_with_strptime assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::NTime)) time = str2time('28/Feb/2013:12:00:00:123456789 +0900', '%d/%b/%Y:%H:%M:%S:%N %z') - assert_equal(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) - - assert_equal(123456789, parser.parse('28/Feb/2013:12:00:00:123456789 +0900').nsec) + assert_equal_ntime(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) end def test_parse_with_invalid_argument From 67e25502d222326d5247c511d706c9834059e7af Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 6 Aug 2015 18:34:57 +0900 Subject: [PATCH 20/63] Serialize NTime as extention type --- Gemfile | 2 ++ fluentd.gemspec | 2 +- lib/fluent/buffer.rb | 2 +- lib/fluent/command/cat.rb | 2 +- lib/fluent/engine.rb | 4 ++++ lib/fluent/event.rb | 4 ++-- lib/fluent/ntime.rb | 14 ++++++++++++++ lib/fluent/plugin/buf_memory.rb | 2 +- lib/fluent/plugin/exec_util.rb | 2 +- lib/fluent/plugin/in_forward.rb | 8 ++++---- lib/fluent/plugin/in_stream.rb | 8 ++++---- lib/fluent/plugin/out_stream.rb | 2 +- lib/fluent/process.rb | 2 +- test/plugin/test_in_forward.rb | 34 +++++++++++++++++---------------- test/plugin/test_in_stream.rb | 10 ++++++---- test/plugin/test_out_copy.rb | 2 +- test/test_event.rb | 10 +++++----- 17 files changed, 67 insertions(+), 43 deletions(-) diff --git a/Gemfile b/Gemfile index 88ae4bc4e3..837367cea7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,8 @@ source 'https://rubygems.org/' gemspec +gem 'msgpack', github: 'msgpack/msgpack-ruby' + local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") if File.exist?(local_gemfile) puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v` diff --git a/fluentd.gemspec b/fluentd.gemspec index 10f1775d90..e9aec372c5 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 1.9.3' - gem.add_runtime_dependency("msgpack", [">= 0.5.11", "< 0.6.0"]) + #gem.add_runtime_dependency("msgpack", [">= 0.5.11", "< 0.6.0"]) gem.add_runtime_dependency("json", [">= 1.4.3"]) gem.add_runtime_dependency("yajl-ruby", ["~> 1.0"]) gem.add_runtime_dependency("cool.io", [">= 1.4.1", "< 2.0.0"]) diff --git a/lib/fluent/buffer.rb b/lib/fluent/buffer.rb index 71d0443b2a..4b06de4bf3 100644 --- a/lib/fluent/buffer.rb +++ b/lib/fluent/buffer.rb @@ -112,7 +112,7 @@ def write_to(io) def msgpack_each(&block) open {|io| - u = MessagePack::Unpacker.new(io) + u = Fluent::Engine.msgpack_factory.unpacker(io) begin u.each(&block) rescue EOFError diff --git a/lib/fluent/command/cat.rb b/lib/fluent/command/cat.rb index db7c0ed80f..49f4aaa469 100644 --- a/lib/fluent/command/cat.rb +++ b/lib/fluent/command/cat.rb @@ -289,7 +289,7 @@ def abort_message(time, record) when 'msgpack' begin - u = MessagePack::Unpacker.new($stdin) + u = Fluent::Engine.msgpack_factory.unpacker($stdin) u.each {|record| w.write(record) } diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index cc6611cf02..a61e78c657 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -30,6 +30,9 @@ def initialize @log_event_queue = [] @suppress_config_dump = false + + @msgpack_factory = MessagePack::Factory.new + @msgpack_factory.register_type(NTime::TYPE, NTime) end MATCH_CACHE_SIZE = 1024 @@ -37,6 +40,7 @@ def initialize attr_reader :root_agent attr_reader :matches, :sources + attr_reader :msgpack_factory def init(opts = {}) BasicSocket.do_not_reverse_lookup = true diff --git a/lib/fluent/event.rb b/lib/fluent/event.rb index 252fe92f72..f07bfd1a1e 100644 --- a/lib/fluent/event.rb +++ b/lib/fluent/event.rb @@ -27,7 +27,7 @@ def each(&block) end def to_msgpack_stream - out = MessagePack::Packer.new # MessagePack::Packer is fastest way to serialize events + out = Fluent::Engine.msgpack_factory.packer each {|time,record| out.write([time,record]) } @@ -143,7 +143,7 @@ def repeatable? def each(&block) # TODO format check - unpacker = MessagePack::Unpacker.new + unpacker = Fluent::Engine.msgpack_factory.unpacker unpacker.feed_each(@data, &block) nil end diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index b2a4878bcb..dabd657fe6 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -1,5 +1,7 @@ module Fluent class NTime + TYPE = 0 + def initialize(sec, nsec = 0) @sec = sec @nsec = nsec @@ -39,6 +41,18 @@ def to_s @sec.to_s end + def to_msgpack(io = nil) + MessagePack::ExtensionValue.new(TYPE, [@sec, @nsec].pack('LL')).to_msgpack(io) + end + + def to_msgpack_ext + [@sec, @nsec].pack('LL') + end + + def self.from_msgpack_ext(data) + new(*data.unpack('LL')) + end + def self.from_time(time) Fluent::NTime.new(time.to_i, time.nsec) end diff --git a/lib/fluent/plugin/buf_memory.rb b/lib/fluent/plugin/buf_memory.rb index 4773d1707e..f725d503d5 100644 --- a/lib/fluent/plugin/buf_memory.rb +++ b/lib/fluent/plugin/buf_memory.rb @@ -57,7 +57,7 @@ def write_to(io) # optimize def msgpack_each(&block) - u = MessagePack::Unpacker.new + u = Fluent::Engine.msgpack_factory.unpacker u.feed_each(@data, &block) end end diff --git a/lib/fluent/plugin/exec_util.rb b/lib/fluent/plugin/exec_util.rb index 35fd05853a..7fe262ecf6 100644 --- a/lib/fluent/plugin/exec_util.rb +++ b/lib/fluent/plugin/exec_util.rb @@ -58,7 +58,7 @@ def call(io) class MessagePackParser < Parser def call(io) - @u = MessagePack::Unpacker.new(io) + @u = Fluent::Engine.msgpack_factory.unpacker(io) begin @u.each(&@on_message) rescue EOFError diff --git a/lib/fluent/plugin/in_forward.rb b/lib/fluent/plugin/in_forward.rb index 2bfcee690d..0811fff259 100644 --- a/lib/fluent/plugin/in_forward.rb +++ b/lib/fluent/plugin/in_forward.rb @@ -153,8 +153,8 @@ def on_message(msg, chunk_size, source) entries.each {|e| record = e[1] next if record.nil? - time = e[0].to_i - time = (now ||= Engine.now) if time == 0 + time = e[0] + time = (now ||= Engine.now) if time.to_i == 0 es.add(time, record) } router.emit_stream(tag, es) @@ -165,7 +165,7 @@ def on_message(msg, chunk_size, source) record = msg[2] return if record.nil? time = msg[1] - time = Engine.now if time == 0 + time = Engine.now if time.to_i == 0 router.emit(tag, time, record) option = msg[3] end @@ -219,7 +219,7 @@ def on_read(data) else m = method(:on_read_msgpack) @serializer = :to_msgpack.to_proc - @u = MessagePack::Unpacker.new + @u = Fluent::Engine.msgpack_factory.unpacker end (class << self; self; end).module_eval do diff --git a/lib/fluent/plugin/in_stream.rb b/lib/fluent/plugin/in_stream.rb index ce2f72e636..f443914ac7 100644 --- a/lib/fluent/plugin/in_stream.rb +++ b/lib/fluent/plugin/in_stream.rb @@ -87,8 +87,8 @@ def on_message(msg) entries.each {|e| record = e[1] next if record.nil? - time = e[0].to_i - time = (now ||= Engine.now) if time == 0 + time = e[0] + time = (now ||= Engine.now) if time.to_i == 0 es.add(time, record) } router.emit_stream(tag, es) @@ -99,7 +99,7 @@ def on_message(msg) return if record.nil? time = msg[1] - time = Engine.now if time == 0 + time = Engine.now if time.to_i == 0 router.emit(tag, time, record) end end @@ -130,7 +130,7 @@ def on_read(data) @y.on_parse_complete = @on_message else m = method(:on_read_msgpack) - @u = MessagePack::Unpacker.new + @u = Fluent::Engine.msgpack_factory.unpacker end (class << self; self; end).module_eval do diff --git a/lib/fluent/plugin/out_stream.rb b/lib/fluent/plugin/out_stream.rb index f5d51bd79c..41db049c6d 100644 --- a/lib/fluent/plugin/out_stream.rb +++ b/lib/fluent/plugin/out_stream.rb @@ -65,7 +65,7 @@ def write(chunk) chain = NullOutputChain.instance chunk.open {|io| # TODO use MessagePackIoEventStream - u = MessagePack::Unpacker.new(io) + u = Fluent::Engine.msgpack_factory.unpacker(io) begin u.each {|(tag,entries)| es = MultiEventStream.new diff --git a/lib/fluent/process.rb b/lib/fluent/process.rb index 19a31c7e8c..f2b04e9058 100644 --- a/lib/fluent/process.rb +++ b/lib/fluent/process.rb @@ -176,7 +176,7 @@ def input_forward_main(ipr, pid) end def read_event_stream(r, &block) - u = MessagePack::Unpacker.new(r) + u = Fluent::Engine.msgpack_factory.unpacker(r) begin #buf = '' #map = {} diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index 329725f19e..f3699d94af 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -3,6 +3,8 @@ require 'base64' class ForwardInputTest < Test::Unit::TestCase + include Fluent + def setup Fluent::Test.setup @responses = [] # for testing responses after sending data @@ -36,7 +38,7 @@ def connect def test_time d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -52,7 +54,7 @@ def test_time def test_message d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -67,7 +69,7 @@ def test_message def test_forward d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -84,7 +86,7 @@ def test_forward def test_packed_forward d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -119,7 +121,7 @@ def test_send_large_chunk_warning chunk_size_limit 32M ]) - time = Time.parse("2014-04-25 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 16M chunk str = "X" * 1024 * 1024 @@ -128,7 +130,7 @@ def test_send_large_chunk_warning assert chunk.size < (32 * 1024 * 1024) d.run do - MessagePack::Unpacker.new.feed_each(chunk) do |obj| + Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") end end @@ -150,14 +152,14 @@ def test_send_large_chunk_only_warning d = create_driver(CONFIG + %[ chunk_size_warn_limit 16M ]) - time = Time.parse("2014-04-25 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 16M chunk str = "X" * 1024 * 1024 chunk = [ "test.tag", (0...16).map{|i| [time + i, {"data" => str}] } ].to_msgpack d.run do - MessagePack::Unpacker.new.feed_each(chunk) do |obj| + Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") end end @@ -175,7 +177,7 @@ def test_send_large_chunk_limit chunk_size_limit 32M ]) - time = Time.parse("2014-04-25 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 32M chunk str = "X" * 1024 * 1024 @@ -184,7 +186,7 @@ def test_send_large_chunk_limit # d.run => send_data d.run do - MessagePack::Unpacker.new.feed_each(chunk) do |obj| + Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") end end @@ -223,7 +225,7 @@ def test_send_broken_chunk(data) def test_respond_to_message_requiring_ack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -249,7 +251,7 @@ def test_respond_to_message_requiring_ack def test_respond_to_forward_requiring_ack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -276,7 +278,7 @@ def test_respond_to_forward_requiring_ack def test_respond_to_packed_forward_requiring_ack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -329,7 +331,7 @@ def test_respond_to_message_json_requiring_ack def test_not_respond_to_message_not_requiring_ack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -350,7 +352,7 @@ def test_not_respond_to_message_not_requiring_ack def test_not_respond_to_forward_not_requiring_ack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -373,7 +375,7 @@ def test_not_respond_to_forward_not_requiring_ack def test_not_respond_to_packed_forward_not_requiring_ack d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 0ac5a4ae4c..3b8d7046e4 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -2,6 +2,8 @@ require 'fluent/test' module StreamInputTest + include Fluent + def setup Fluent::Test.setup end @@ -9,7 +11,7 @@ def setup def test_time d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -25,7 +27,7 @@ def test_time def test_message d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -40,7 +42,7 @@ def test_message def test_forward d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -57,7 +59,7 @@ def test_forward def test_packed_forward d = create_driver - time = Time.parse("2011-01-02 13:14:15 UTC").to_i + time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} diff --git a/test/plugin/test_out_copy.rb b/test/plugin/test_out_copy.rb index 4ff5523019..04725d198c 100644 --- a/test/plugin/test_out_copy.rb +++ b/test/plugin/test_out_copy.rb @@ -86,7 +86,7 @@ def test_msgpack_es_emit_bug es = if defined?(MessagePack::Packer) time = Time.parse("2013-05-26 06:37:22 UTC").to_i - packer = MessagePack::Packer.new + packer = Fluent::Engine.msgpack_factory.packer packer.pack([time, {"a" => 1}]) packer.pack([time, {"a" => 2}]) Fluent::MessagePackEventStream.new(packer.to_s) diff --git a/test/test_event.rb b/test/test_event.rb index fc1e0c0b8e..ddb1eef0d6 100644 --- a/test/test_event.rb +++ b/test/test_event.rb @@ -31,7 +31,7 @@ def setup test 'to_msgpack_stream' do stream = @es.to_msgpack_stream - MessagePack::Unpacker.new.feed_each(stream) { |time, record| + Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record| assert_equal @time, time assert_equal @record, record } @@ -75,7 +75,7 @@ def setup test 'to_msgpack_stream' do i = 0 stream = @es.to_msgpack_stream - MessagePack::Unpacker.new.feed_each(stream) { |time, record| + Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record| assert_equal @times[i], time assert_equal @records[i], record i += 1 @@ -123,7 +123,7 @@ def setup test 'to_msgpack_stream' do i = 0 stream = @es.to_msgpack_stream - MessagePack::Unpacker.new.feed_each(stream) { |time, record| + Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record| assert_equal @times[i], time assert_equal @records[i], record i += 1 @@ -135,7 +135,7 @@ class MessagePackEventStreamTest < ::Test::Unit::TestCase include Fluent def setup - pk = MessagePack::Packer.new + pk = Fluent::Engine.msgpack_factory.packer time = Engine.now @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @@ -161,7 +161,7 @@ def setup test 'to_msgpack_stream' do i = 0 stream = @es.to_msgpack_stream - MessagePack::Unpacker.new.feed_each(stream) { |time, record| + Fluent::Engine.msgpack_factory.unpacker.feed_each(stream) { |time, record| assert_equal @times[i], time assert_equal @records[i], record i += 1 From 43069dc57f06b701277a2aa645021bdbb1db65e0 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 7 Aug 2015 11:07:48 +0900 Subject: [PATCH 21/63] Use LL instead of NN when serializing NTime --- lib/fluent/ntime.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fluent/ntime.rb b/lib/fluent/ntime.rb index dabd657fe6..96c4f041f9 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/ntime.rb @@ -42,15 +42,15 @@ def to_s end def to_msgpack(io = nil) - MessagePack::ExtensionValue.new(TYPE, [@sec, @nsec].pack('LL')).to_msgpack(io) + MessagePack::ExtensionValue.new(TYPE, [@sec, @nsec].pack('NN')).to_msgpack(io) end def to_msgpack_ext - [@sec, @nsec].pack('LL') + [@sec, @nsec].pack('NN') end def self.from_msgpack_ext(data) - new(*data.unpack('LL')) + new(*data.unpack('NN')) end def self.from_time(time) From cb330e5de49dbadb341dde067f4dd14cc1add097 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 7 Aug 2015 11:55:47 +0900 Subject: [PATCH 22/63] Implement time_as_integer option for out_forward --- lib/fluent/plugin/out_forward.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/fluent/plugin/out_forward.rb b/lib/fluent/plugin/out_forward.rb index 4f13275bef..2a0c0de752 100644 --- a/lib/fluent/plugin/out_forward.rb +++ b/lib/fluent/plugin/out_forward.rb @@ -63,6 +63,7 @@ def initialize # Linux default tcp_syn_retries is 5 (in many environment) # 3 + 6 + 12 + 24 + 48 + 96 -> 189 (sec) config_param :dns_round_robin, :bool, :default => false # heartbeat_type 'udp' is not available for this + config_param :time_as_integer, :bool, :default => true attr_reader :nodes @@ -173,6 +174,24 @@ def run log.error_backtrace end + def emit(tag, es, chain) + @emit_count += 1 + data = es.to_msgpack_stream + if @time_as_integer + # TODO: Implement in EventStream for optimization + unpacker = Fluent::Engine.msgpack_factory.unpacker + packer = Fluent::Engine.msgpack_factory.packer + unpacker.feed_each(data) {|time,record| + packer.write([time.to_i,record]) + } + data = packer.to_s + end + key = tag + if @buffer.emit(key, data, chain) + submit_flush + end + end + def write_objects(tag, chunk) return if chunk.empty? From 3588d0449c228a7ce417aabe3412cea1a1949cee Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 7 Aug 2015 13:37:17 +0900 Subject: [PATCH 23/63] Rename NTime to NanoTime --- lib/fluent/engine.rb | 4 +- lib/fluent/load.rb | 2 +- lib/fluent/parser.rb | 6 +- lib/fluent/plugin/in_exec.rb | 4 +- lib/fluent/plugin/in_http.rb | 2 +- lib/fluent/plugin/out_exec_filter.rb | 4 +- lib/fluent/test/base.rb | 2 +- lib/fluent/test/input_test.rb | 2 +- lib/fluent/{ntime.rb => time.rb} | 6 +- test/plugin/test_filter_stdout.rb | 12 +-- test/plugin/test_in_dummy.rb | 2 +- test/plugin/test_in_exec.rb | 8 +- test/plugin/test_in_forward.rb | 26 +++--- test/plugin/test_in_gc_stat.rb | 2 +- test/plugin/test_in_http.rb | 20 ++--- test/plugin/test_in_object_space.rb | 2 +- test/plugin/test_in_status.rb | 2 +- test/plugin/test_in_stream.rb | 8 +- test/plugin/test_in_syslog.rb | 4 +- test/plugin/test_in_tail.rb | 4 +- test/plugin/test_in_tcp.rb | 2 +- test/plugin/test_in_udp.rb | 8 +- test/plugin/test_out_exec_filter.rb | 32 +++---- test/plugin/test_out_stdout.rb | 4 +- test/test_event.rb | 6 +- test/test_ntime.rb | 122 +++++++++++++-------------- test/test_parser.rb | 14 +-- 27 files changed, 155 insertions(+), 155 deletions(-) rename lib/fluent/{ntime.rb => time.rb} (90%) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index a61e78c657..13f637217b 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -32,7 +32,7 @@ def initialize @suppress_config_dump = false @msgpack_factory = MessagePack::Factory.new - @msgpack_factory.register_type(NTime::TYPE, NTime) + @msgpack_factory.register_type(NanoTime::TYPE, NanoTime) end MATCH_CACHE_SIZE = 1024 @@ -136,7 +136,7 @@ def flush! def now # TODO thread update - Fluent::NTime.now + Fluent::NanoTime.now end def log_event_loop diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index 614af06f81..6ca9273778 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -16,7 +16,7 @@ end require 'cool.io' -require 'fluent/ntime' +require 'fluent/time' require 'fluent/env' require 'fluent/version' require 'fluent/log' diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 2a7525bc22..a03e5caa92 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -60,9 +60,9 @@ def initialize(time_format) @cache2_time = nil @parser = if time_format - Proc.new { |value| NTime.from_time(Time.strptime(value, time_format)) } + Proc.new { |value| NanoTime.from_time(Time.strptime(value, time_format)) } else - Proc.new { |value| NTime.from_time(Time.parse(value)) } + Proc.new { |value| NanoTime.from_time(Time.parse(value)) } end end @@ -256,7 +256,7 @@ def parse(text) time = @mutex.synchronize { @time_parser.parse(value) } else begin - time = NTime.new(value.to_i) + time = NanoTime.new(value.to_i) rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 6fc48cd606..16eeced135 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -66,9 +66,9 @@ def configure(conf) if @time_key if @time_format f = @time_format - @time_parse_proc = Proc.new {|str| NTime.from_time(Time.strptime(str, f)) } + @time_parse_proc = Proc.new {|str| NanoTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| NTime.new(str.to_i) } + @time_parse_proc = Proc.new {|str| NanoTime.new(str.to_i) } end end diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 7046657ff8..4d14ac1926 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -145,7 +145,7 @@ def on_request(path_info, params) end time = if param_time = params['time'] param_time = param_time.to_i - param_time.zero? ? Engine.now : NTime.new(param_time) + param_time.zero? ? Engine.now : NanoTime.new(param_time) else record_time.nil? ? Engine.now : record_time end diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index b811881f03..f5426efb62 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -120,9 +120,9 @@ def configure(conf) if @out_time_key if f = @out_time_format - @time_parse_proc = Proc.new {|str| NTime.from_time(Time.strptime(str, f)) } + @time_parse_proc = Proc.new {|str| NanoTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| NTime.new(str.to_i) } + @time_parse_proc = Proc.new {|str| NanoTime.new(str.to_i) } end elsif @out_time_format log.warn "out_time_format effects nothing when out_time_key is not specified: #{conf}" diff --git a/lib/fluent/test/base.rb b/lib/fluent/test/base.rb index c20b48180a..76865aab99 100644 --- a/lib/fluent/test/base.rb +++ b/lib/fluent/test/base.rb @@ -28,7 +28,7 @@ def self.setup } ::Test::Unit::Assertions.module_eval { - def assert_equal_ntime(a, b) + def assert_equal_nano_time(a, b) assert_equal(a.sec, b.sec) assert_equal(a.nsec, b.nsec) end diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index bab534df82..cba47ca1a3 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -142,7 +142,7 @@ def run(&block) events.each do |time, record| if @expects assert_equal(@expects[i], [tag, time, record]) - assert_equal_ntime(@expects[i][1], time) if @expects[i][1].is_a?(NTime) + assert_equal_nano_time(@expects[i][1], time) if @expects[i][1].is_a?(NanoTime) end i += 1 end diff --git a/lib/fluent/ntime.rb b/lib/fluent/time.rb similarity index 90% rename from lib/fluent/ntime.rb rename to lib/fluent/time.rb index 96c4f041f9..0cdddfed5c 100644 --- a/lib/fluent/ntime.rb +++ b/lib/fluent/time.rb @@ -1,5 +1,5 @@ module Fluent - class NTime + class NanoTime TYPE = 0 def initialize(sec, nsec = 0) @@ -8,7 +8,7 @@ def initialize(sec, nsec = 0) end def ==(other) - if other.is_a?(Fluent::NTime) + if other.is_a?(Fluent::NanoTime) @sec == other.sec else @sec == other @@ -54,7 +54,7 @@ def self.from_msgpack_ext(data) end def self.from_time(time) - Fluent::NTime.new(time.to_i, time.nsec) + Fluent::NanoTime.new(time.to_i, time.nsec) end def self.now diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 4d553c576e..24839f8d1f 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -32,7 +32,7 @@ def emit(d, msg, time) def test_through_record d = create_driver time = Time.now - filtered = emit(d, {'test' => 'test'}, NTime.from_time(time)) + filtered = emit(d, {'test' => 'test'}, NanoTime.from_time(time)) assert_equal({'test' => 'test'}, filtered) end @@ -59,7 +59,7 @@ def test_configure_output_type def test_output_type_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, NTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, NanoTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -71,12 +71,12 @@ def test_output_type_json def test_output_type_hash d = create_driver(CONFIG + "\noutput_type hash") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, NTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, NanoTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. d = create_driver(CONFIG + "\noutput_type hash") - out = capture_log(d) { emit(d, {'test' => Float::NAN}, NTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => Float::NAN}, NanoTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out end @@ -84,7 +84,7 @@ def test_output_type_hash def test_include_time_key d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc") time = Time.now - message_time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + message_time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) out = capture_log(d) { emit(d, {'test' => 'test'}, message_time) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out end @@ -93,7 +93,7 @@ def test_include_time_key def test_format_json d = create_driver(CONFIG + "\nformat json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, NTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, NanoTime.from_time(time)) } assert_equal "{\"test\":\"test\"}\n", out end diff --git a/test/plugin/test_in_dummy.rb b/test/plugin/test_in_dummy.rb index ea6a48bbfd..a53737f2ef 100644 --- a/test/plugin/test_in_dummy.rb +++ b/test/plugin/test_in_dummy.rb @@ -77,7 +77,7 @@ def create_driver(conf) emits.each do |tag, time, record| assert_equal("dummy", tag) assert_equal({"foo"=>"bar"}, record) - assert(time.is_a?(Fluent::NTime)) + assert(time.is_a?(Fluent::NanoTime)) end end diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index b90d4ab7e0..1fb2319131 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -7,7 +7,7 @@ class ExecInputTest < Test::Unit::TestCase def setup Fluent::Test.setup - @test_time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + @test_time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb')) end @@ -79,7 +79,7 @@ def test_emit emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal_ntime(@test_time, emits[0][1]) + assert_equal_nano_time(@test_time, emits[0][1]) end def test_emit_json @@ -92,7 +92,7 @@ def test_emit_json emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal_ntime(@test_time, emits[0][1]) + assert_equal_nano_time(@test_time, emits[0][1]) end def test_emit_msgpack @@ -105,6 +105,6 @@ def test_emit_msgpack emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal_ntime(@test_time, emits[0][1]) + assert_equal_nano_time(@test_time, emits[0][1]) end end diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index f3699d94af..8981d28086 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -38,7 +38,7 @@ def connect def test_time d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -54,7 +54,7 @@ def test_time def test_message d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -69,7 +69,7 @@ def test_message def test_forward d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -86,7 +86,7 @@ def test_forward def test_packed_forward d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -121,7 +121,7 @@ def test_send_large_chunk_warning chunk_size_limit 32M ]) - time = NTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 16M chunk str = "X" * 1024 * 1024 @@ -152,7 +152,7 @@ def test_send_large_chunk_only_warning d = create_driver(CONFIG + %[ chunk_size_warn_limit 16M ]) - time = NTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 16M chunk str = "X" * 1024 * 1024 @@ -177,7 +177,7 @@ def test_send_large_chunk_limit chunk_size_limit 32M ]) - time = NTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 32M chunk str = "X" * 1024 * 1024 @@ -225,7 +225,7 @@ def test_send_broken_chunk(data) def test_respond_to_message_requiring_ack d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -251,7 +251,7 @@ def test_respond_to_message_requiring_ack def test_respond_to_forward_requiring_ack d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -278,7 +278,7 @@ def test_respond_to_forward_requiring_ack def test_respond_to_packed_forward_requiring_ack d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -331,7 +331,7 @@ def test_respond_to_message_json_requiring_ack def test_not_respond_to_message_not_requiring_ack d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -352,7 +352,7 @@ def test_not_respond_to_message_not_requiring_ack def test_not_respond_to_forward_not_requiring_ack d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -375,7 +375,7 @@ def test_not_respond_to_forward_not_requiring_ack def test_not_respond_to_packed_forward_not_requiring_ack d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], diff --git a/test/plugin/test_in_gc_stat.rb b/test/plugin/test_in_gc_stat.rb index 05bf4a6475..14ea86b8e4 100644 --- a/test/plugin/test_in_gc_stat.rb +++ b/test/plugin/test_in_gc_stat.rb @@ -33,6 +33,6 @@ def test_emit emits = d.emits assert(emits.length > 0) assert_equal(stat, emits[0][2]) - assert(emits[0][1].is_a?(Fluent::NTime)) + assert(emits[0][1].is_a?(Fluent::NanoTime)) end end diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index 41a4e8d536..548b265c99 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -34,7 +34,7 @@ def test_configure def test_time d = create_driver - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -51,7 +51,7 @@ def test_time def test_json d = create_driver - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -71,7 +71,7 @@ def test_json def test_multi_json d = create_driver - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -140,7 +140,7 @@ def test_multi_json_with_add_http_headers def test_json_with_add_http_headers d = create_driver(CONFIG + "add_http_headers true") - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]] @@ -160,7 +160,7 @@ def test_json_with_add_http_headers def test_application_json d = create_driver - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -176,7 +176,7 @@ def test_application_json def test_msgpack d = create_driver - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -192,7 +192,7 @@ def test_msgpack def test_multi_msgpack d = create_driver - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -214,7 +214,7 @@ def test_with_regexp types field_1:integer ]) - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'} d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'} @@ -238,7 +238,7 @@ def test_with_csv keys foo,bar ]) - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'} d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'} @@ -256,7 +256,7 @@ def test_resonse_with_empty_img d = create_driver(CONFIG + "respond_with_empty_img true") assert_equal true, d.instance.respond_with_empty_img - time = NTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} diff --git a/test/plugin/test_in_object_space.rb b/test/plugin/test_in_object_space.rb index cbbdf71fd1..6715b40f6c 100644 --- a/test/plugin/test_in_object_space.rb +++ b/test/plugin/test_in_object_space.rb @@ -41,7 +41,7 @@ def test_emit emits.each { |tag, time, record| assert_equal d.instance.tag, tag assert_equal d.instance.top, record.keys.size - assert(time.is_a?(Fluent::NTime)) + assert(time.is_a?(Fluent::NanoTime)) } end end diff --git a/test/plugin/test_in_status.rb b/test/plugin/test_in_status.rb index 0d838ac94a..611a999a22 100644 --- a/test/plugin/test_in_status.rb +++ b/test/plugin/test_in_status.rb @@ -34,6 +34,6 @@ def test_emit emits = d.emits assert(emits.length > 0) assert_equal({"answer" => "42"}, emits[0][2]) - assert(emits[0][1].is_a?(Fluent::NTime)) + assert(emits[0][1].is_a?(Fluent::NanoTime)) end end diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 3b8d7046e4..91aaea2b5b 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -11,7 +11,7 @@ def setup def test_time d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -27,7 +27,7 @@ def test_time def test_message d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -42,7 +42,7 @@ def test_message def test_forward d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -59,7 +59,7 @@ def test_forward def test_packed_forward d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index f1d67ba8b5..5ed7a9efd7 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -45,8 +45,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, - {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 9396b61503..73b65050e5 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -77,8 +77,8 @@ def test_emit assert_equal(true, emits.length > 0) assert_equal({"message" => "test3"}, emits[0][2]) assert_equal({"message" => "test4"}, emits[1][2]) - assert(emits[0][1].is_a?(Fluent::NTime)) - assert(emits[1][1].is_a?(Fluent::NTime)) + assert(emits[0][1].is_a?(Fluent::NanoTime)) + assert(emits[1][1].is_a?(Fluent::NanoTime)) assert_equal(1, d.emit_streams.size) end diff --git a/test/plugin/test_in_tcp.rb b/test/plugin/test_in_tcp.rb index eb9fef8274..03a1b67c32 100755 --- a/test/plugin/test_in_tcp.rb +++ b/test/plugin/test_in_tcp.rb @@ -83,7 +83,7 @@ def compare_test_result(emits, tests) assert_equal(2, emits.size) emits.each_index {|i| assert_equal(tests[i]['expected'], emits[i][2]['message']) - assert(emits[i][1].is_a?(Fluent::NTime)) + assert(emits[i][1].is_a?(Fluent::NanoTime)) } end end diff --git a/test/plugin/test_in_udp.rb b/test/plugin/test_in_udp.rb index fd3d1d7189..7e2b9996ee 100755 --- a/test/plugin/test_in_udp.rb +++ b/test/plugin/test_in_udp.rb @@ -46,8 +46,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, - {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => NTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do @@ -61,7 +61,7 @@ def test_time_format emits = d.emits emits.each_index {|i| - assert_equal_ntime(tests[i]['expected'], emits[i][1]) + assert_equal_nano_time(tests[i]['expected'], emits[i][1]) } } end @@ -101,7 +101,7 @@ def compare_test_result(emits, tests) assert_equal(2, emits.size) emits.each_index {|i| assert_equal(tests[i]['expected'], emits[i][2]['message']) - assert(emits[i][1].is_a?(Fluent::NTime)) + assert(emits[i][1].is_a?(Fluent::NanoTime)) } end end diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index 6c03936613..a5cc7daec6 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -71,7 +71,7 @@ def test_configure def test_emit_1 d = create_driver - time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"k1"=>1}, time) @@ -81,9 +81,9 @@ def test_emit_1 emits = d.emits assert_equal 2, emits.length assert_equal ["test", time, {"k2"=>"1"}], emits[0] - assert_equal_ntime time, emits[0][1] + assert_equal_nano_time time, emits[0][1] assert_equal ["test", time, {"k2"=>"2"}], emits[1] - assert_equal_ntime time, emits[1][1] + assert_equal_nano_time time, emits[1][1] end def test_emit_2 @@ -96,7 +96,7 @@ def test_emit_2 num_children 3 ] - time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"k1"=>1}, time) @@ -106,9 +106,9 @@ def test_emit_2 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"k2"=>"1"}], emits[0] - assert_equal_ntime time, emits[0][1] + assert_equal_nano_time time, emits[0][1] assert_equal ["xxx", time, {"k2"=>"2"}], emits[1] - assert_equal_ntime time, emits[1][1] + assert_equal_nano_time time, emits[1][1] end def test_emit_3 @@ -121,7 +121,7 @@ def test_emit_3 num_children 3 ] - time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -131,7 +131,7 @@ def test_emit_3 emits = d.emits assert_equal 1, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value foo"}], emits[0] - assert_equal_ntime time, emits[0][1] + assert_equal_nano_time time, emits[0][1] d = create_driver %[ command sed #{sed_unbuffered_option} -l -e s/foo/bar/ @@ -142,7 +142,7 @@ def test_emit_3 num_children 3 ] - time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -152,9 +152,9 @@ def test_emit_3 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value bar"}], emits[0] - assert_equal_ntime time, emits[0][1] + assert_equal_nano_time time, emits[0][1] assert_equal ["xxx", time, {"val2"=>"sed-ed value poo"}], emits[1] - assert_equal_ntime time, emits[1][1] + assert_equal_nano_time time, emits[1][1] end def test_emit_4 @@ -169,7 +169,7 @@ def test_emit_4 num_children 3 ], 'input.test') - time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -179,9 +179,9 @@ def test_emit_4 emits = d.emits assert_equal 2, emits.length assert_equal ["output.test", time, {"val2"=>"sed-ed value bar"}], emits[0] - assert_equal_ntime time, emits[0][1] + assert_equal_nano_time time, emits[0][1] assert_equal ["output.test", time, {"val2"=>"sed-ed value poo"}], emits[1] - assert_equal_ntime time, emits[1][1] + assert_equal_nano_time time, emits[1][1] end def test_json_1 @@ -193,7 +193,7 @@ def test_json_1 tag_key tag ], 'input.test') - time = NTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"message"=>%[{"time":#{time},"tag":"t1","k1":"v1"}]}, time+10) @@ -202,7 +202,7 @@ def test_json_1 emits = d.emits assert_equal 1, emits.length assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] - assert_equal_ntime time, emits[0][1] + assert_equal_nano_time time, emits[0][1] end end diff --git a/test/plugin/test_out_stdout.rb b/test/plugin/test_out_stdout.rb index 3c299a7d19..65d7d89e7b 100644 --- a/test/plugin/test_out_stdout.rb +++ b/test/plugin/test_out_stdout.rb @@ -35,7 +35,7 @@ def test_configure_output_type def test_emit_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log { d.emit({'test' => 'test'}, NTime.from_time(time)) } + out = capture_log { d.emit({'test' => 'test'}, NanoTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -49,7 +49,7 @@ def test_emit_hash assert_equal "#{time.localtime} test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. - out = capture_log { d.emit({'test' => Float::NAN}, NTime.from_time(time)) } + out = capture_log { d.emit({'test' => Float::NAN}, NanoTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\"=>NaN}\n", out end diff --git a/test/test_event.rb b/test/test_event.rb index ddb1eef0d6..9fd27c6918 100644 --- a/test/test_event.rb +++ b/test/test_event.rb @@ -43,7 +43,7 @@ class ArrayEventStreamTest < ::Test::Unit::TestCase def setup time = Engine.now - @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] + @times = [Fluent::NanoTime.new(time.sec), Fluent::NanoTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = ArrayEventStream.new(@times.zip(@records)) end @@ -88,7 +88,7 @@ class MultiEventStreamTest < ::Test::Unit::TestCase def setup time = Engine.now - @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] + @times = [Fluent::NanoTime.new(time.sec), Fluent::NanoTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = MultiEventStream.new @times.zip(@records).each { |time, record| @@ -137,7 +137,7 @@ class MessagePackEventStreamTest < ::Test::Unit::TestCase def setup pk = Fluent::Engine.msgpack_factory.packer time = Engine.now - @times = [Fluent::NTime.new(time.sec), Fluent::NTime.new(time.sec + 1)] + @times = [Fluent::NanoTime.new(time.sec), Fluent::NanoTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @times.zip(@records).each { |time, record| pk.write([time, record]) diff --git a/test/test_ntime.rb b/test/test_ntime.rb index cb2fe6cec9..e98fcf4eb8 100644 --- a/test/test_ntime.rb +++ b/test/test_ntime.rb @@ -1,27 +1,27 @@ require_relative 'helper' -class NTimeTest < Test::Unit::TestCase +class NanoTimeTest < Test::Unit::TestCase include Fluent test '#sec' do - assert_equal(1, NTime.new(1, 2).sec) + assert_equal(1, NanoTime.new(1, 2).sec) end test '#nsec' do - assert_equal(2, NTime.new(1, 2).nsec) - assert_equal(0, NTime.new(1).nsec) + assert_equal(2, NanoTime.new(1, 2).nsec) + assert_equal(0, NanoTime.new(1).nsec) end test '#to_int' do - assert_equal(1, NTime.new(1, 2).to_int) + assert_equal(1, NanoTime.new(1, 2).to_int) end test '#to_r' do - assert_equal(Rational(1_000_000_002, 1_000_000_000), NTime.new(1, 2).to_r) + assert_equal(Rational(1_000_000_002, 1_000_000_000), NanoTime.new(1, 2).to_r) end test '#to_s' do - time = NTime.new(100) + time = NanoTime.new(100) assert_equal('100', time.to_s) assert_equal('100', "#{time}") end @@ -29,7 +29,7 @@ class NTimeTest < Test::Unit::TestCase test '.from_time' do sec = 1000 usec = 2 - time = NTime.from_time(Time.at(sec, usec)) + time = NanoTime.from_time(Time.at(sec, usec)) assert_equal(time.sec, sec) assert_equal(time.nsec, usec * 1000) end @@ -39,96 +39,96 @@ class NTimeTest < Test::Unit::TestCase usec = 2 time = Time.at(sec, usec) Timecop.freeze(time) - assert_equal(sec, NTime.now.sec) - assert_equal(usec * 1000, NTime.now.nsec) + assert_equal(sec, NanoTime.now.sec) + assert_equal(usec * 1000, NanoTime.now.nsec) Timecop.return end test '==' do - assert(NTime.new(1, 2) == NTime.new(1, 2)) - assert(NTime.new(1, 2) == NTime.new(1, 3)) - refute(NTime.new(1, 2) == NTime.new(3, 2)) - refute(NTime.new(1, 2) == NTime.new(3, 4)) + assert(NanoTime.new(1, 2) == NanoTime.new(1, 2)) + assert(NanoTime.new(1, 2) == NanoTime.new(1, 3)) + refute(NanoTime.new(1, 2) == NanoTime.new(3, 2)) + refute(NanoTime.new(1, 2) == NanoTime.new(3, 4)) - assert(NTime.new(1, 2) == 1) - refute(NTime.new(1, 2) == 2) + assert(NanoTime.new(1, 2) == 1) + refute(NanoTime.new(1, 2) == 2) - assert(1 == NTime.new(1, 2)) - refute(2 == NTime.new(1, 2)) + assert(1 == NanoTime.new(1, 2)) + refute(2 == NanoTime.new(1, 2)) end test '+' do - assert_equal(4, NTime.new(1, 2) + NTime.new(3, 4)) - assert_equal(6, NTime.new(1, 2) + 5) - assert_equal(6, 5 + NTime.new(1, 2)) + assert_equal(4, NanoTime.new(1, 2) + NanoTime.new(3, 4)) + assert_equal(6, NanoTime.new(1, 2) + 5) + assert_equal(6, 5 + NanoTime.new(1, 2)) end test '-' do - assert_equal(-2, NTime.new(1, 2) - NTime.new(3, 4)) - assert_equal(-4, NTime.new(1, 2) - 5) - assert_equal(4, 5 - NTime.new(1, 2)) + assert_equal(-2, NanoTime.new(1, 2) - NanoTime.new(3, 4)) + assert_equal(-4, NanoTime.new(1, 2) - 5) + assert_equal(4, 5 - NanoTime.new(1, 2)) end test '>' do - assert(NTime.new(2) > NTime.new(1)) - refute(NTime.new(1) > NTime.new(1)) - refute(NTime.new(1) > NTime.new(2)) + assert(NanoTime.new(2) > NanoTime.new(1)) + refute(NanoTime.new(1) > NanoTime.new(1)) + refute(NanoTime.new(1) > NanoTime.new(2)) - assert(NTime.new(2) > 1) - refute(NTime.new(1) > 1) - refute(NTime.new(1) > 2) + assert(NanoTime.new(2) > 1) + refute(NanoTime.new(1) > 1) + refute(NanoTime.new(1) > 2) - assert(2 > NTime.new(1)) - refute(1 > NTime.new(1)) - refute(1 > NTime.new(2)) + assert(2 > NanoTime.new(1)) + refute(1 > NanoTime.new(1)) + refute(1 > NanoTime.new(2)) end test '>=' do - assert(NTime.new(2) >= NTime.new(1)) - assert(NTime.new(1) >= NTime.new(1)) - refute(NTime.new(1) >= NTime.new(2)) + assert(NanoTime.new(2) >= NanoTime.new(1)) + assert(NanoTime.new(1) >= NanoTime.new(1)) + refute(NanoTime.new(1) >= NanoTime.new(2)) - assert(NTime.new(2) >= 1) - assert(NTime.new(1) >= 1) - refute(NTime.new(1) >= 2) + assert(NanoTime.new(2) >= 1) + assert(NanoTime.new(1) >= 1) + refute(NanoTime.new(1) >= 2) - assert(2 >= NTime.new(1)) - assert(1 >= NTime.new(1)) - refute(1 >= NTime.new(2)) + assert(2 >= NanoTime.new(1)) + assert(1 >= NanoTime.new(1)) + refute(1 >= NanoTime.new(2)) end test '<' do - assert(NTime.new(1) < NTime.new(2)) - refute(NTime.new(1) < NTime.new(1)) - refute(NTime.new(2) < NTime.new(1)) + assert(NanoTime.new(1) < NanoTime.new(2)) + refute(NanoTime.new(1) < NanoTime.new(1)) + refute(NanoTime.new(2) < NanoTime.new(1)) - assert(NTime.new(1) < 2) - refute(NTime.new(1) < 1) - refute(NTime.new(2) < 1) + assert(NanoTime.new(1) < 2) + refute(NanoTime.new(1) < 1) + refute(NanoTime.new(2) < 1) - assert(1 < NTime.new(2)) - refute(1 < NTime.new(1)) - refute(2 < NTime.new(1)) + assert(1 < NanoTime.new(2)) + refute(1 < NanoTime.new(1)) + refute(2 < NanoTime.new(1)) end test '=<' do - assert(NTime.new(1) <= NTime.new(2)) - assert(NTime.new(1) <= NTime.new(1)) - refute(NTime.new(2) <= NTime.new(1)) + assert(NanoTime.new(1) <= NanoTime.new(2)) + assert(NanoTime.new(1) <= NanoTime.new(1)) + refute(NanoTime.new(2) <= NanoTime.new(1)) - assert(NTime.new(1) <= 2) - assert(NTime.new(1) <= 1) - refute(NTime.new(2) <= 1) + assert(NanoTime.new(1) <= 2) + assert(NanoTime.new(1) <= 1) + refute(NanoTime.new(2) <= 1) - assert(1 <= NTime.new(2)) - assert(1 <= NTime.new(1)) - refute(2 <= NTime.new(1)) + assert(1 <= NanoTime.new(2)) + assert(1 <= NanoTime.new(1)) + refute(2 <= NanoTime.new(1)) end test 'Time.at' do sec = 1000 nsec = 2000 - ntime = NTime.new(sec, nsec) + ntime = NanoTime.new(sec, nsec) time = Time.at(ntime) assert_equal(sec, time.to_i) assert_equal(nsec, time.nsec) diff --git a/test/test_parser.rb b/test/test_parser.rb index fb91a2cfc5..341b1776fc 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -7,9 +7,9 @@ module ParserTest def str2time(str_time, format = nil) if format - NTime.from_time(Time.strptime(str_time, format)) + NanoTime.from_time(Time.strptime(str_time, format)) else - NTime.from_time(Time.parse(str_time)) + NanoTime.from_time(Time.parse(str_time)) end end @@ -45,7 +45,7 @@ class TimeParserTest < ::Test::Unit::TestCase def test_call_with_parse parser = TextParser::TimeParser.new(nil) - assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::NTime)) + assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::NanoTime)) time = str2time('2013-09-18 12:00:00 +0900') assert_equal(time, parser.parse('2013-09-18 12:00:00 +0900')) @@ -54,7 +54,7 @@ def test_call_with_parse def test_parse_with_strptime parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S %z') - assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::NTime)) + assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::NanoTime)) time = str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z') assert_equal(time, parser.parse('28/Feb/2013:12:00:00 +0900')) @@ -63,10 +63,10 @@ def test_parse_with_strptime def test_parse_nsec_with_strptime parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S:%N %z') - assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::NTime)) + assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::NanoTime)) time = str2time('28/Feb/2013:12:00:00:123456789 +0900', '%d/%b/%Y:%H:%M:%S:%N %z') - assert_equal_ntime(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) + assert_equal_nano_time(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) end def test_parse_with_invalid_argument @@ -126,7 +126,7 @@ def test_parse_with_time_key ) text = '2013-02-28 12:00:00 +0900' parser.parse(text) do |time, record| - assert_equal NTime.from_time(Time.parse(text)), time + assert_equal NanoTime.from_time(Time.parse(text)), time end end From 80788474e0256fa5aa230e327cb911766c5de542 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 7 Aug 2015 16:49:25 +0900 Subject: [PATCH 24/63] TimeFormatter cache time as NanoTime if possible --- lib/fluent/mixin.rb | 5 +++-- lib/fluent/time.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index ff4b1680d1..ed3c97d92b 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -17,6 +17,7 @@ module Fluent class TimeFormatter require 'fluent/timezone' + require 'fluent/time' def initialize(format, localtime, timezone = nil) @tc1 = 0 @@ -55,9 +56,9 @@ def initialize(format, localtime, timezone = nil) end def format(time) - if @tc1 == time + if Fluent::NanoTime.eq?(@tc1, time) return @tc1_str - elsif @tc2 == time + elsif Fluent::NanoTime.eq?(@tc2, time) return @tc2_str else str = format_nocache(time) diff --git a/lib/fluent/time.rb b/lib/fluent/time.rb index 0cdddfed5c..3fd0900b5a 100644 --- a/lib/fluent/time.rb +++ b/lib/fluent/time.rb @@ -61,6 +61,14 @@ def self.now from_time(Time.now) end + def self.eq?(a, b) + if a.is_a?(Fluent::NanoTime) && b.is_a?(Fluent::NanoTime) + a.sec == b.sec && a.nsec == b.nsec + else + a == b + end + end + ## TODO: For performance, implement +, -, and so on def method_missing(name, *args, &block) @sec.send(name, *args, &block) From 2455be9f74ce819a404fa87b8cfa9322f4930c6c Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 12:55:23 +0900 Subject: [PATCH 25/63] Enable in_http accept msgpack including NanoTime --- lib/fluent/plugin/in_http.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 4d14ac1926..c91c16b47a 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -145,7 +145,7 @@ def on_request(path_info, params) end time = if param_time = params['time'] param_time = param_time.to_i - param_time.zero? ? Engine.now : NanoTime.new(param_time) + param_time.zero? ? Engine.now : param_time else record_time.nil? ? Engine.now : record_time end @@ -191,7 +191,7 @@ def on_request(path_info, params) def parse_params_default(params) record = if msgpack = params['msgpack'] - MessagePack.unpack(msgpack) + Engine.msgpack_factory.unpacker.feed(msgpack).read elsif js = params['json'] JSON.parse(js) else From bca8ebab66dc44f1004ca5453f61694db6df399e Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 13:07:17 +0900 Subject: [PATCH 26/63] Use Time.now instead of unnecessary use of Engine.now --- lib/fluent/output.rb | 2 +- lib/fluent/root_agent.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index 652d711b49..a6b4117df8 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -529,7 +529,7 @@ def configure(conf) else @flush_interval = [60, @time_slice_cache_interval].min @enqueue_buffer_proc = Proc.new do - nowslice = @time_slicer.call(Engine.now - @time_slice_wait) + nowslice = @time_slicer.call(Time.now - @time_slice_wait) @buffer.keys.each {|key| if key < nowslice @buffer.push(key) diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index 2368e1274c..235d7fb534 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -184,7 +184,7 @@ def handle_emits_error(tag, es, error) log.warn "send an error event stream to @ERROR:", error_info @error_collector.emit_stream(tag, es) else - now = Engine.now + now = Time.now if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time log.warn "emit transaction failed:", error_info log.warn_backtrace From 66a7d5c456002add11fe46b3ce82222e61ca0c8e Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 14:24:23 +0900 Subject: [PATCH 27/63] in_http always returns NanoTime --- lib/fluent/plugin/in_http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index c91c16b47a..4aae43609c 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -145,7 +145,7 @@ def on_request(path_info, params) end time = if param_time = params['time'] param_time = param_time.to_i - param_time.zero? ? Engine.now : param_time + param_time.zero? ? Engine.now : NanoTime.new(param_time) else record_time.nil? ? Engine.now : record_time end From 17e29d710f46912dbe16490c68c473bd79972e38 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 15:05:36 +0900 Subject: [PATCH 28/63] NanoTime#to_msgpack returns the value of @sec.to_msgpack --- lib/fluent/time.rb | 2 +- test/plugin/test_in_forward.rb | 10 +++++----- test/plugin/test_in_stream.rb | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/fluent/time.rb b/lib/fluent/time.rb index 3fd0900b5a..0478ab86bf 100644 --- a/lib/fluent/time.rb +++ b/lib/fluent/time.rb @@ -42,7 +42,7 @@ def to_s end def to_msgpack(io = nil) - MessagePack::ExtensionValue.new(TYPE, [@sec, @nsec].pack('NN')).to_msgpack(io) + @sec.to_msgpack(io) end def to_msgpack_ext diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index 8981d28086..8813b47908 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -46,7 +46,7 @@ def test_time d.run do d.expected_emits.each {|tag,time,record| - send_data [tag, 0, record].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write([tag, 0, record]).to_s } end end @@ -61,7 +61,7 @@ def test_message d.run do d.expected_emits.each {|tag,time,record| - send_data [tag, time, record].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write([tag, time, record]).to_s } end end @@ -79,7 +79,7 @@ def test_forward d.expected_emits.each {|tag,time,record| entries << [time, record] } - send_data ["tag1", entries].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s end end @@ -94,9 +94,9 @@ def test_packed_forward d.run do entries = '' d.expected_emits.each {|tag,time,record| - [time, record].to_msgpack(entries) + Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush } - send_data ["tag1", entries].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s end end diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 91aaea2b5b..4c56d9f11f 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -19,7 +19,7 @@ def test_time d.run do d.expected_emits.each {|tag,time,record| - send_data [tag, 0, record].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write([tag, 0, record]).to_s } end end @@ -34,7 +34,7 @@ def test_message d.run do d.expected_emits.each {|tag,time,record| - send_data [tag, time, record].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write([tag, time, record]).to_s } end end @@ -52,7 +52,7 @@ def test_forward d.expected_emits.each {|tag,time,record| entries << [time, record] } - send_data ["tag1", entries].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s end end @@ -67,9 +67,9 @@ def test_packed_forward d.run do entries = '' d.expected_emits.each {|tag,time,record| - [time, record].to_msgpack(entries) + Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush } - send_data ["tag1", entries].to_msgpack + send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s end end From 2fda4a875118d4f5c5790e5f38c70636186d713f Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 16:38:39 +0900 Subject: [PATCH 29/63] Add comment --- lib/fluent/mixin.rb | 1 + lib/fluent/parser.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index ed3c97d92b..1f1b09fbec 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -55,6 +55,7 @@ def initialize(format, localtime, timezone = nil) end end + # TODO: new cache mechanism using format string def format(time) if Fluent::NanoTime.eq?(@tc1, time) return @tc1_str diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index a03e5caa92..9f36e10bf4 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -66,6 +66,7 @@ def initialize(time_format) end end + # TODO: new cache mechanism using format string def parse(value) unless value.is_a?(String) raise ParserError, "value must be string: #{value}" From 7a199a37f3d6baeca7738e970bf0e68218628b72 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 18:31:30 +0900 Subject: [PATCH 30/63] Rename test_ntime to test_nano_time --- test/{test_ntime.rb => test_nano_time.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/{test_ntime.rb => test_nano_time.rb} (99%) diff --git a/test/test_ntime.rb b/test/test_nano_time.rb similarity index 99% rename from test/test_ntime.rb rename to test/test_nano_time.rb index e98fcf4eb8..4607f15161 100644 --- a/test/test_ntime.rb +++ b/test/test_nano_time.rb @@ -49,7 +49,7 @@ class NanoTimeTest < Test::Unit::TestCase assert(NanoTime.new(1, 2) == NanoTime.new(1, 3)) refute(NanoTime.new(1, 2) == NanoTime.new(3, 2)) refute(NanoTime.new(1, 2) == NanoTime.new(3, 4)) - + assert(NanoTime.new(1, 2) == 1) refute(NanoTime.new(1, 2) == 2) From b12bf13ae83df1e2f85d4a3b817f34149ce7ebc1 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 11 Aug 2015 18:32:35 +0900 Subject: [PATCH 31/63] Remove Fluent::NanoTime.now --- lib/fluent/engine.rb | 2 +- lib/fluent/time.rb | 4 ---- test/test_nano_time.rb | 10 ---------- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index 13f637217b..ebe661cf37 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -136,7 +136,7 @@ def flush! def now # TODO thread update - Fluent::NanoTime.now + Fluent::NanoTime.from_time(Time.now) end def log_event_loop diff --git a/lib/fluent/time.rb b/lib/fluent/time.rb index 0478ab86bf..c8c2504d37 100644 --- a/lib/fluent/time.rb +++ b/lib/fluent/time.rb @@ -57,10 +57,6 @@ def self.from_time(time) Fluent::NanoTime.new(time.to_i, time.nsec) end - def self.now - from_time(Time.now) - end - def self.eq?(a, b) if a.is_a?(Fluent::NanoTime) && b.is_a?(Fluent::NanoTime) a.sec == b.sec && a.nsec == b.nsec diff --git a/test/test_nano_time.rb b/test/test_nano_time.rb index 4607f15161..e80dac664e 100644 --- a/test/test_nano_time.rb +++ b/test/test_nano_time.rb @@ -34,16 +34,6 @@ class NanoTimeTest < Test::Unit::TestCase assert_equal(time.nsec, usec * 1000) end - test '.now' do - sec = 1000 - usec = 2 - time = Time.at(sec, usec) - Timecop.freeze(time) - assert_equal(sec, NanoTime.now.sec) - assert_equal(usec * 1000, NanoTime.now.nsec) - Timecop.return - end - test '==' do assert(NanoTime.new(1, 2) == NanoTime.new(1, 2)) assert(NanoTime.new(1, 2) == NanoTime.new(1, 3)) From a0f93be45fbb02b4a47110e55db070ac1a1a2844 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 12 Aug 2015 11:35:14 +0900 Subject: [PATCH 32/63] Move time_as_integer option to ObjectBufferdOutput --- lib/fluent/output.rb | 11 +++++++++++ lib/fluent/plugin/out_forward.rb | 19 ------------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index a6b4117df8..b1d97aa77e 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -431,6 +431,8 @@ def flush_secondary(secondary) class ObjectBufferedOutput < BufferedOutput + config_param :time_as_integer, :bool, :default => true + def initialize super end @@ -438,6 +440,15 @@ def initialize def emit(tag, es, chain) @emit_count += 1 data = es.to_msgpack_stream + if @time_as_integer + # TODO: Implement in EventStream for optimization + unpacker = Fluent::Engine.msgpack_factory.unpacker + packer = Fluent::Engine.msgpack_factory.packer + unpacker.feed_each(data) {|time,record| + packer.write([time.to_i,record]) + } + data = packer.to_s + end key = tag if @buffer.emit(key, data, chain) submit_flush diff --git a/lib/fluent/plugin/out_forward.rb b/lib/fluent/plugin/out_forward.rb index 2a0c0de752..4f13275bef 100644 --- a/lib/fluent/plugin/out_forward.rb +++ b/lib/fluent/plugin/out_forward.rb @@ -63,7 +63,6 @@ def initialize # Linux default tcp_syn_retries is 5 (in many environment) # 3 + 6 + 12 + 24 + 48 + 96 -> 189 (sec) config_param :dns_round_robin, :bool, :default => false # heartbeat_type 'udp' is not available for this - config_param :time_as_integer, :bool, :default => true attr_reader :nodes @@ -174,24 +173,6 @@ def run log.error_backtrace end - def emit(tag, es, chain) - @emit_count += 1 - data = es.to_msgpack_stream - if @time_as_integer - # TODO: Implement in EventStream for optimization - unpacker = Fluent::Engine.msgpack_factory.unpacker - packer = Fluent::Engine.msgpack_factory.packer - unpacker.feed_each(data) {|time,record| - packer.write([time.to_i,record]) - } - data = packer.to_s - end - key = tag - if @buffer.emit(key, data, chain) - submit_flush - end - end - def write_objects(tag, chunk) return if chunk.empty? From 462378ec8606ee14c8b0952742bc4aaaef82b56e Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 12 Aug 2015 13:24:07 +0900 Subject: [PATCH 33/63] Optimize time_as_integer --- lib/fluent/event.rb | 16 ++++++++++++++++ lib/fluent/output.rb | 11 +++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/fluent/event.rb b/lib/fluent/event.rb index f07bfd1a1e..c7e70d0e4e 100644 --- a/lib/fluent/event.rb +++ b/lib/fluent/event.rb @@ -33,6 +33,14 @@ def to_msgpack_stream } out.to_s end + + def to_msgpack_stream_forced_integer + out = Fluent::Engine.msgpack_factory.packer + each {|time,record| + out.write([time.to_i,record]) + } + out.to_s + end end @@ -151,6 +159,14 @@ def each(&block) def to_msgpack_stream @data end + + def to_msgpack_stream_forced_integer + out = Fluent::Engine.msgpack_factory.packer + each {|time,record| + out.write([time.to_i,record]) + } + out.to_s + end end end diff --git a/lib/fluent/output.rb b/lib/fluent/output.rb index b1d97aa77e..491d8dd34e 100644 --- a/lib/fluent/output.rb +++ b/lib/fluent/output.rb @@ -439,15 +439,10 @@ def initialize def emit(tag, es, chain) @emit_count += 1 - data = es.to_msgpack_stream if @time_as_integer - # TODO: Implement in EventStream for optimization - unpacker = Fluent::Engine.msgpack_factory.unpacker - packer = Fluent::Engine.msgpack_factory.packer - unpacker.feed_each(data) {|time,record| - packer.write([time.to_i,record]) - } - data = packer.to_s + data = es.to_msgpack_stream_forced_integer + else + data = es.to_msgpack_stream end key = tag if @buffer.emit(key, data, chain) From 4bd415198106ed61c3af81e03179b598b2e381a7 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Wed, 12 Aug 2015 18:12:03 +0900 Subject: [PATCH 34/63] Add tests for NanoTime.eq? --- test/test_nano_time.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_nano_time.rb b/test/test_nano_time.rb index e80dac664e..5b034dbef0 100644 --- a/test/test_nano_time.rb +++ b/test/test_nano_time.rb @@ -34,6 +34,19 @@ class NanoTimeTest < Test::Unit::TestCase assert_equal(time.nsec, usec * 1000) end + test 'eq?' do + assert(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(1, 2))) + refute(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(1, 3))) + refute(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(3, 2))) + refute(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(3, 4))) + + assert(NanoTime.eq?(NanoTime.new(1, 2), 1)) + refute(NanoTime.eq?(NanoTime.new(1, 2), 2)) + + assert(NanoTime.eq?(1, NanoTime.new(1, 2))) + refute(NanoTime.eq?(2, NanoTime.new(1, 2))) + end + test '==' do assert(NanoTime.new(1, 2) == NanoTime.new(1, 2)) assert(NanoTime.new(1, 2) == NanoTime.new(1, 3)) From c9b27d09aa3303ea4d738acd5a5305bf2e197f25 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 13 Aug 2015 08:27:38 +0900 Subject: [PATCH 35/63] Optimize TimeFormatter.format in the case subsec is no needed --- lib/fluent/mixin.rb | 35 +++++++++++++++++++++++++++++++++-- test/test_formatter.rb | 6 ++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index 1f1b09fbec..7864f4fd89 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -25,6 +25,16 @@ def initialize(format, localtime, timezone = nil) @tc2 = 0 @tc2_str = nil + if !format || format !~ /%L|%\d*N/ + define_singleton_method(:format) {|time| + format_without_subsec(time) + } + else + define_singleton_method(:format) {|time| + format_with_subsec(time) + } + end + if formatter = Fluent::Timezone.formatter(timezone, format) define_singleton_method(:format_nocache) {|time| formatter.call(time) @@ -55,8 +65,25 @@ def initialize(format, localtime, timezone = nil) end end - # TODO: new cache mechanism using format string - def format(time) + def format_without_subsec(time) + if @tc1 == time + return @tc1_str + elsif @tc2 == time + return @tc2_str + else + str = format_nocache(time) + if @tc1 < @tc2 + @tc1 = time + @tc1_str = str + else + @tc2 = time + @tc2_str = str + end + return str + end + end + + def format_with_subsec(time) if Fluent::NanoTime.eq?(@tc1, time) return @tc1_str elsif Fluent::NanoTime.eq?(@tc2, time) @@ -74,6 +101,10 @@ def format(time) end end + def format(time) + # will be overridden in initialize + end + def format_nocache(time) # will be overridden in initialize end diff --git a/test/test_formatter.rb b/test/test_formatter.rb index 38f26c6a92..da80d43dc0 100644 --- a/test/test_formatter.rb +++ b/test/test_formatter.rb @@ -563,6 +563,12 @@ def test_specific_localtime_timezone assert_equal("20140926 1400-1000", format(@fmt, true, "-10")) end end + + def test_format_with_subsec + time = Fluent::NanoTime.new(@time) + formatter = Fluent::TimeFormatter.new("%Y%m%d %H%M.%N", false, nil) + assert_equal("20140927 0000.000000000", formatter.format(time)) + end end class TimeConfigTest < ::Test::Unit::TestCase From 4a4d74d3952cb483e199cbcb9f6bfc4b082e9ba2 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 13 Aug 2015 15:28:49 +0900 Subject: [PATCH 36/63] JSONParser parses time as float when time_format is not set --- lib/fluent/parser.rb | 2 +- test/test_parser.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 9f36e10bf4..ed87130f5a 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -257,7 +257,7 @@ def parse(text) time = @mutex.synchronize { @time_parser.parse(value) } else begin - time = NanoTime.new(value.to_i) + time = NanoTime.from_time(Time.at(value.to_f)) rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end diff --git a/test/test_parser.rb b/test/test_parser.rb index 341b1776fc..bb6b46a241 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -5,6 +5,10 @@ module ParserTest include Fluent + def setup + Fluent::Test.setup + end + def str2time(str_time, format = nil) if format NanoTime.from_time(Time.strptime(str_time, format)) @@ -403,6 +407,16 @@ def test_parse_with_invalid_time end end + def test_parse_float_time + parser = TextParser::JSONParser.new + format = "%d/%b/%Y:%H:%M:%S %z" + text = "100.1" + parser.parse("{\"time\":\"#{text}\"}") do |time, record| + assert_equal Time.at(text.to_f).to_i, time.sec + assert_equal Time.at(text.to_f).nsec, time.nsec + end + end + def test_parse_with_keep_time_key parser = TextParser::JSONParser.new format = "%d/%b/%Y:%H:%M:%S %z" From 6a71f7ec7a57c49800a089c8f671862ddef24481 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 13 Aug 2015 19:16:26 +0900 Subject: [PATCH 37/63] Don't use `include Fluent` --- test/plugin/test_in_exec.rb | 4 +- test/plugin/test_in_forward.rb | 28 +++--- test/plugin/test_in_http.rb | 22 +++-- test/plugin/test_in_stream.rb | 10 +-- test/plugin/test_in_syslog.rb | 6 +- test/plugin/test_in_udp.rb | 6 +- test/plugin/test_out_exec_filter.rb | 14 ++- test/plugin/test_out_stdout.rb | 6 +- test/test_nano_time.rb | 134 ++++++++++++++-------------- 9 files changed, 106 insertions(+), 124 deletions(-) diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index 1fb2319131..3b7825e9e9 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -3,11 +3,9 @@ require 'net/http' class ExecInputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup - @test_time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + @test_time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb')) end diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index 8813b47908..132fb87483 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -3,8 +3,6 @@ require 'base64' class ForwardInputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup @responses = [] # for testing responses after sending data @@ -38,7 +36,7 @@ def connect def test_time d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -54,7 +52,7 @@ def test_time def test_message d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -69,7 +67,7 @@ def test_message def test_forward d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -86,7 +84,7 @@ def test_forward def test_packed_forward d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -121,7 +119,7 @@ def test_send_large_chunk_warning chunk_size_limit 32M ]) - time = NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 16M chunk str = "X" * 1024 * 1024 @@ -152,7 +150,7 @@ def test_send_large_chunk_only_warning d = create_driver(CONFIG + %[ chunk_size_warn_limit 16M ]) - time = NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 16M chunk str = "X" * 1024 * 1024 @@ -177,7 +175,7 @@ def test_send_large_chunk_limit chunk_size_limit 32M ]) - time = NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) # generate over 32M chunk str = "X" * 1024 * 1024 @@ -225,7 +223,7 @@ def test_send_broken_chunk(data) def test_respond_to_message_requiring_ack d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -251,7 +249,7 @@ def test_respond_to_message_requiring_ack def test_respond_to_forward_requiring_ack d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -278,7 +276,7 @@ def test_respond_to_forward_requiring_ack def test_respond_to_packed_forward_requiring_ack d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -331,7 +329,7 @@ def test_respond_to_message_json_requiring_ack def test_not_respond_to_message_not_requiring_ack d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -352,7 +350,7 @@ def test_not_respond_to_message_not_requiring_ack def test_not_respond_to_forward_not_requiring_ack d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], @@ -375,7 +373,7 @@ def test_not_respond_to_forward_not_requiring_ack def test_not_respond_to_packed_forward_not_requiring_ack d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) events = [ ["tag1", time, {"a"=>1}], diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index 548b265c99..82112f8e34 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -3,8 +3,6 @@ require 'net/http' class HttpInputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup end @@ -34,7 +32,7 @@ def test_configure def test_time d = create_driver - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -51,7 +49,7 @@ def test_time def test_json d = create_driver - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -71,7 +69,7 @@ def test_json def test_multi_json d = create_driver - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -140,7 +138,7 @@ def test_multi_json_with_add_http_headers def test_json_with_add_http_headers d = create_driver(CONFIG + "add_http_headers true") - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]] @@ -160,7 +158,7 @@ def test_json_with_add_http_headers def test_application_json d = create_driver - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -176,7 +174,7 @@ def test_application_json def test_msgpack d = create_driver - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -192,7 +190,7 @@ def test_msgpack def test_multi_msgpack d = create_driver - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -214,7 +212,7 @@ def test_with_regexp types field_1:integer ]) - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'} d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'} @@ -238,7 +236,7 @@ def test_with_csv keys foo,bar ]) - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'} d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'} @@ -256,7 +254,7 @@ def test_resonse_with_empty_img d = create_driver(CONFIG + "respond_with_empty_img true") assert_equal true, d.instance.respond_with_empty_img - time = NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 4c56d9f11f..0fc224aae3 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -2,8 +2,6 @@ require 'fluent/test' module StreamInputTest - include Fluent - def setup Fluent::Test.setup end @@ -11,7 +9,7 @@ def setup def test_time d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -27,7 +25,7 @@ def test_time def test_message d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -42,7 +40,7 @@ def test_message def test_forward d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -59,7 +57,7 @@ def test_forward def test_packed_forward d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index 5ed7a9efd7..f4f4a55285 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -2,8 +2,6 @@ require 'fluent/test' class SyslogInputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup require 'fluent/plugin/socket_util' @@ -45,8 +43,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, - {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do diff --git a/test/plugin/test_in_udp.rb b/test/plugin/test_in_udp.rb index 7e2b9996ee..e317ba9973 100755 --- a/test/plugin/test_in_udp.rb +++ b/test/plugin/test_in_udp.rb @@ -2,8 +2,6 @@ require 'fluent/test' class UdpInputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup end @@ -46,8 +44,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, - {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index a5cc7daec6..beed4e4e1d 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -3,8 +3,6 @@ require 'fileutils' class ExecFilterOutputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup end @@ -71,7 +69,7 @@ def test_configure def test_emit_1 d = create_driver - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"k1"=>1}, time) @@ -96,7 +94,7 @@ def test_emit_2 num_children 3 ] - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"k1"=>1}, time) @@ -121,7 +119,7 @@ def test_emit_3 num_children 3 ] - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -142,7 +140,7 @@ def test_emit_3 num_children 3 ] - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -169,7 +167,7 @@ def test_emit_4 num_children 3 ], 'input.test') - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -193,7 +191,7 @@ def test_json_1 tag_key tag ], 'input.test') - time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) d.run do d.emit({"message"=>%[{"time":#{time},"tag":"t1","k1":"v1"}]}, time+10) diff --git a/test/plugin/test_out_stdout.rb b/test/plugin/test_out_stdout.rb index 65d7d89e7b..dfbfb2259b 100644 --- a/test/plugin/test_out_stdout.rb +++ b/test/plugin/test_out_stdout.rb @@ -2,8 +2,6 @@ require 'fluent/test' class StdoutOutputTest < Test::Unit::TestCase - include Fluent - def setup Fluent::Test.setup end @@ -35,7 +33,7 @@ def test_configure_output_type def test_emit_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log { d.emit({'test' => 'test'}, NanoTime.from_time(time)) } + out = capture_log { d.emit({'test' => 'test'}, Fluent::NanoTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -49,7 +47,7 @@ def test_emit_hash assert_equal "#{time.localtime} test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. - out = capture_log { d.emit({'test' => Float::NAN}, NanoTime.from_time(time)) } + out = capture_log { d.emit({'test' => Float::NAN}, Fluent::NanoTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\"=>NaN}\n", out end diff --git a/test/test_nano_time.rb b/test/test_nano_time.rb index 5b034dbef0..0dfbbbe54a 100644 --- a/test/test_nano_time.rb +++ b/test/test_nano_time.rb @@ -1,27 +1,25 @@ require_relative 'helper' class NanoTimeTest < Test::Unit::TestCase - include Fluent - test '#sec' do - assert_equal(1, NanoTime.new(1, 2).sec) + assert_equal(1, Fluent::NanoTime.new(1, 2).sec) end test '#nsec' do - assert_equal(2, NanoTime.new(1, 2).nsec) - assert_equal(0, NanoTime.new(1).nsec) + assert_equal(2, Fluent::NanoTime.new(1, 2).nsec) + assert_equal(0, Fluent::NanoTime.new(1).nsec) end test '#to_int' do - assert_equal(1, NanoTime.new(1, 2).to_int) + assert_equal(1, Fluent::NanoTime.new(1, 2).to_int) end test '#to_r' do - assert_equal(Rational(1_000_000_002, 1_000_000_000), NanoTime.new(1, 2).to_r) + assert_equal(Rational(1_000_000_002, 1_000_000_000), Fluent::NanoTime.new(1, 2).to_r) end test '#to_s' do - time = NanoTime.new(100) + time = Fluent::NanoTime.new(100) assert_equal('100', time.to_s) assert_equal('100', "#{time}") end @@ -29,109 +27,109 @@ class NanoTimeTest < Test::Unit::TestCase test '.from_time' do sec = 1000 usec = 2 - time = NanoTime.from_time(Time.at(sec, usec)) + time = Fluent::NanoTime.from_time(Time.at(sec, usec)) assert_equal(time.sec, sec) assert_equal(time.nsec, usec * 1000) end test 'eq?' do - assert(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(1, 2))) - refute(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(1, 3))) - refute(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(3, 2))) - refute(NanoTime.eq?(NanoTime.new(1, 2), NanoTime.new(3, 4))) + assert(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 2))) + refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 3))) + refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(3, 2))) + refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(3, 4))) - assert(NanoTime.eq?(NanoTime.new(1, 2), 1)) - refute(NanoTime.eq?(NanoTime.new(1, 2), 2)) + assert(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), 1)) + refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), 2)) - assert(NanoTime.eq?(1, NanoTime.new(1, 2))) - refute(NanoTime.eq?(2, NanoTime.new(1, 2))) + assert(Fluent::NanoTime.eq?(1, Fluent::NanoTime.new(1, 2))) + refute(Fluent::NanoTime.eq?(2, Fluent::NanoTime.new(1, 2))) end test '==' do - assert(NanoTime.new(1, 2) == NanoTime.new(1, 2)) - assert(NanoTime.new(1, 2) == NanoTime.new(1, 3)) - refute(NanoTime.new(1, 2) == NanoTime.new(3, 2)) - refute(NanoTime.new(1, 2) == NanoTime.new(3, 4)) + assert(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(1, 2)) + assert(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(1, 3)) + refute(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(3, 2)) + refute(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(3, 4)) - assert(NanoTime.new(1, 2) == 1) - refute(NanoTime.new(1, 2) == 2) + assert(Fluent::NanoTime.new(1, 2) == 1) + refute(Fluent::NanoTime.new(1, 2) == 2) - assert(1 == NanoTime.new(1, 2)) - refute(2 == NanoTime.new(1, 2)) + assert(1 == Fluent::NanoTime.new(1, 2)) + refute(2 == Fluent::NanoTime.new(1, 2)) end test '+' do - assert_equal(4, NanoTime.new(1, 2) + NanoTime.new(3, 4)) - assert_equal(6, NanoTime.new(1, 2) + 5) - assert_equal(6, 5 + NanoTime.new(1, 2)) + assert_equal(4, Fluent::NanoTime.new(1, 2) + Fluent::NanoTime.new(3, 4)) + assert_equal(6, Fluent::NanoTime.new(1, 2) + 5) + assert_equal(6, 5 + Fluent::NanoTime.new(1, 2)) end test '-' do - assert_equal(-2, NanoTime.new(1, 2) - NanoTime.new(3, 4)) - assert_equal(-4, NanoTime.new(1, 2) - 5) - assert_equal(4, 5 - NanoTime.new(1, 2)) + assert_equal(-2, Fluent::NanoTime.new(1, 2) - Fluent::NanoTime.new(3, 4)) + assert_equal(-4, Fluent::NanoTime.new(1, 2) - 5) + assert_equal(4, 5 - Fluent::NanoTime.new(1, 2)) end test '>' do - assert(NanoTime.new(2) > NanoTime.new(1)) - refute(NanoTime.new(1) > NanoTime.new(1)) - refute(NanoTime.new(1) > NanoTime.new(2)) + assert(Fluent::NanoTime.new(2) > Fluent::NanoTime.new(1)) + refute(Fluent::NanoTime.new(1) > Fluent::NanoTime.new(1)) + refute(Fluent::NanoTime.new(1) > Fluent::NanoTime.new(2)) - assert(NanoTime.new(2) > 1) - refute(NanoTime.new(1) > 1) - refute(NanoTime.new(1) > 2) + assert(Fluent::NanoTime.new(2) > 1) + refute(Fluent::NanoTime.new(1) > 1) + refute(Fluent::NanoTime.new(1) > 2) - assert(2 > NanoTime.new(1)) - refute(1 > NanoTime.new(1)) - refute(1 > NanoTime.new(2)) + assert(2 > Fluent::NanoTime.new(1)) + refute(1 > Fluent::NanoTime.new(1)) + refute(1 > Fluent::NanoTime.new(2)) end test '>=' do - assert(NanoTime.new(2) >= NanoTime.new(1)) - assert(NanoTime.new(1) >= NanoTime.new(1)) - refute(NanoTime.new(1) >= NanoTime.new(2)) + assert(Fluent::NanoTime.new(2) >= Fluent::NanoTime.new(1)) + assert(Fluent::NanoTime.new(1) >= Fluent::NanoTime.new(1)) + refute(Fluent::NanoTime.new(1) >= Fluent::NanoTime.new(2)) - assert(NanoTime.new(2) >= 1) - assert(NanoTime.new(1) >= 1) - refute(NanoTime.new(1) >= 2) + assert(Fluent::NanoTime.new(2) >= 1) + assert(Fluent::NanoTime.new(1) >= 1) + refute(Fluent::NanoTime.new(1) >= 2) - assert(2 >= NanoTime.new(1)) - assert(1 >= NanoTime.new(1)) - refute(1 >= NanoTime.new(2)) + assert(2 >= Fluent::NanoTime.new(1)) + assert(1 >= Fluent::NanoTime.new(1)) + refute(1 >= Fluent::NanoTime.new(2)) end test '<' do - assert(NanoTime.new(1) < NanoTime.new(2)) - refute(NanoTime.new(1) < NanoTime.new(1)) - refute(NanoTime.new(2) < NanoTime.new(1)) + assert(Fluent::NanoTime.new(1) < Fluent::NanoTime.new(2)) + refute(Fluent::NanoTime.new(1) < Fluent::NanoTime.new(1)) + refute(Fluent::NanoTime.new(2) < Fluent::NanoTime.new(1)) - assert(NanoTime.new(1) < 2) - refute(NanoTime.new(1) < 1) - refute(NanoTime.new(2) < 1) + assert(Fluent::NanoTime.new(1) < 2) + refute(Fluent::NanoTime.new(1) < 1) + refute(Fluent::NanoTime.new(2) < 1) - assert(1 < NanoTime.new(2)) - refute(1 < NanoTime.new(1)) - refute(2 < NanoTime.new(1)) + assert(1 < Fluent::NanoTime.new(2)) + refute(1 < Fluent::NanoTime.new(1)) + refute(2 < Fluent::NanoTime.new(1)) end test '=<' do - assert(NanoTime.new(1) <= NanoTime.new(2)) - assert(NanoTime.new(1) <= NanoTime.new(1)) - refute(NanoTime.new(2) <= NanoTime.new(1)) + assert(Fluent::NanoTime.new(1) <= Fluent::NanoTime.new(2)) + assert(Fluent::NanoTime.new(1) <= Fluent::NanoTime.new(1)) + refute(Fluent::NanoTime.new(2) <= Fluent::NanoTime.new(1)) - assert(NanoTime.new(1) <= 2) - assert(NanoTime.new(1) <= 1) - refute(NanoTime.new(2) <= 1) + assert(Fluent::NanoTime.new(1) <= 2) + assert(Fluent::NanoTime.new(1) <= 1) + refute(Fluent::NanoTime.new(2) <= 1) - assert(1 <= NanoTime.new(2)) - assert(1 <= NanoTime.new(1)) - refute(2 <= NanoTime.new(1)) + assert(1 <= Fluent::NanoTime.new(2)) + assert(1 <= Fluent::NanoTime.new(1)) + refute(2 <= Fluent::NanoTime.new(1)) end test 'Time.at' do sec = 1000 nsec = 2000 - ntime = NanoTime.new(sec, nsec) + ntime = Fluent::NanoTime.new(sec, nsec) time = Time.at(ntime) assert_equal(sec, time.to_i) assert_equal(nsec, time.nsec) From 969bd6fa70e02a2c855c25eb23907245a53bfecf Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 13 Aug 2015 19:25:26 +0900 Subject: [PATCH 38/63] Use Fluent::NanoTime instead of NanoTime --- lib/fluent/engine.rb | 2 +- lib/fluent/parser.rb | 6 +++--- lib/fluent/plugin/in_exec.rb | 4 ++-- lib/fluent/plugin/in_http.rb | 2 +- lib/fluent/plugin/out_exec_filter.rb | 4 ++-- lib/fluent/test/input_test.rb | 2 +- test/plugin/test_filter_stdout.rb | 12 ++++++------ test/test_parser.rb | 6 +++--- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index ebe661cf37..7b5851e4e3 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -32,7 +32,7 @@ def initialize @suppress_config_dump = false @msgpack_factory = MessagePack::Factory.new - @msgpack_factory.register_type(NanoTime::TYPE, NanoTime) + @msgpack_factory.register_type(Fluent::NanoTime::TYPE, Fluent::NanoTime) end MATCH_CACHE_SIZE = 1024 diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index ed87130f5a..13ac154442 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -60,9 +60,9 @@ def initialize(time_format) @cache2_time = nil @parser = if time_format - Proc.new { |value| NanoTime.from_time(Time.strptime(value, time_format)) } + Proc.new { |value| Fluent::NanoTime.from_time(Time.strptime(value, time_format)) } else - Proc.new { |value| NanoTime.from_time(Time.parse(value)) } + Proc.new { |value| Fluent::NanoTime.from_time(Time.parse(value)) } end end @@ -257,7 +257,7 @@ def parse(text) time = @mutex.synchronize { @time_parser.parse(value) } else begin - time = NanoTime.from_time(Time.at(value.to_f)) + time = Fluent::NanoTime.from_time(Time.at(value.to_f)) rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 16eeced135..8e2cd84a66 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -66,9 +66,9 @@ def configure(conf) if @time_key if @time_format f = @time_format - @time_parse_proc = Proc.new {|str| NanoTime.from_time(Time.strptime(str, f)) } + @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| NanoTime.new(str.to_i) } + @time_parse_proc = Proc.new {|str| Fluent::NanoTime.new(str.to_i) } end end diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 4aae43609c..c98ebd9179 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -145,7 +145,7 @@ def on_request(path_info, params) end time = if param_time = params['time'] param_time = param_time.to_i - param_time.zero? ? Engine.now : NanoTime.new(param_time) + param_time.zero? ? Engine.now : Fluent::NanoTime.new(param_time) else record_time.nil? ? Engine.now : record_time end diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index f5426efb62..39f517a13b 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -120,9 +120,9 @@ def configure(conf) if @out_time_key if f = @out_time_format - @time_parse_proc = Proc.new {|str| NanoTime.from_time(Time.strptime(str, f)) } + @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| NanoTime.new(str.to_i) } + @time_parse_proc = Proc.new {|str| Fluent::NanoTime.new(str.to_i) } end elsif @out_time_format log.warn "out_time_format effects nothing when out_time_key is not specified: #{conf}" diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index cba47ca1a3..434ed1cd95 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -142,7 +142,7 @@ def run(&block) events.each do |time, record| if @expects assert_equal(@expects[i], [tag, time, record]) - assert_equal_nano_time(@expects[i][1], time) if @expects[i][1].is_a?(NanoTime) + assert_equal_nano_time(@expects[i][1], time) if @expects[i][1].is_a?(Fluent::NanoTime) end i += 1 end diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 24839f8d1f..8cb51ce0ce 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -32,7 +32,7 @@ def emit(d, msg, time) def test_through_record d = create_driver time = Time.now - filtered = emit(d, {'test' => 'test'}, NanoTime.from_time(time)) + filtered = emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) assert_equal({'test' => 'test'}, filtered) end @@ -59,7 +59,7 @@ def test_configure_output_type def test_output_type_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -71,12 +71,12 @@ def test_output_type_json def test_output_type_hash d = create_driver(CONFIG + "\noutput_type hash") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. d = create_driver(CONFIG + "\noutput_type hash") - out = capture_log(d) { emit(d, {'test' => Float::NAN}, NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => Float::NAN}, Fluent::NanoTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out end @@ -84,7 +84,7 @@ def test_output_type_hash def test_include_time_key d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc") time = Time.now - message_time = NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + message_time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) out = capture_log(d) { emit(d, {'test' => 'test'}, message_time) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out end @@ -93,7 +93,7 @@ def test_include_time_key def test_format_json d = create_driver(CONFIG + "\nformat json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) } assert_equal "{\"test\":\"test\"}\n", out end diff --git a/test/test_parser.rb b/test/test_parser.rb index bb6b46a241..529fe0b6a5 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -11,9 +11,9 @@ def setup def str2time(str_time, format = nil) if format - NanoTime.from_time(Time.strptime(str_time, format)) + Fluent::NanoTime.from_time(Time.strptime(str_time, format)) else - NanoTime.from_time(Time.parse(str_time)) + Fluent::NanoTime.from_time(Time.parse(str_time)) end end @@ -130,7 +130,7 @@ def test_parse_with_time_key ) text = '2013-02-28 12:00:00 +0900' parser.parse(text) do |time, record| - assert_equal NanoTime.from_time(Time.parse(text)), time + assert_equal Fluent::NanoTime.from_time(Time.parse(text)), time end end From 2c3d4b526285a0ba42176f1ca538c9b09220a350 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 11:57:36 +0900 Subject: [PATCH 39/63] Add test for in_syslog --- test/plugin/test_in_syslog.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index f4f4a55285..29aa0019b6 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -58,7 +58,7 @@ def test_time_format emits = d.emits emits.each_index {|i| - assert_equal(tests[i]['expected'], emits[i][1]) + assert_equal_nano_time(tests[i]['expected'], emits[i][1]) } } end From 809ff35a289317a30b0e2788d95eacd75587476b Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 12:25:12 +0900 Subject: [PATCH 40/63] in_http accepts float as NanoTime --- lib/fluent/plugin/in_http.rb | 4 ++-- test/plugin/test_in_http.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index c98ebd9179..9bcbdc4fe9 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -144,8 +144,8 @@ def on_request(path_info, params) end end time = if param_time = params['time'] - param_time = param_time.to_i - param_time.zero? ? Engine.now : Fluent::NanoTime.new(param_time) + param_time = param_time.to_f + param_time.zero? ? Engine.now : Fluent::NanoTime.from_time(Time.at(param_time)) else record_time.nil? ? Engine.now : record_time end diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index 82112f8e34..dcc4e19313 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -46,6 +46,22 @@ def test_time end end + def test_time_as_float + d = create_driver + + float_time = Time.parse("2011-01-02 13:14:15.123 UTC").to_f + time = Fluent::NanoTime.from_time(Time.at(float_time)) + + d.expect_emit "tag1", time, {"a"=>1} + + d.run do + d.expected_emits.each {|tag,time,record| + res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s}) + assert_equal "200", res.code + } + end + end + def test_json d = create_driver From 308f8dda4aa17062576ecef832de2a72a24e9e74 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 12:44:53 +0900 Subject: [PATCH 41/63] Add tests for in_forward --- test/plugin/test_in_forward.rb | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index 132fb87483..a81a9f7a7b 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -64,6 +64,21 @@ def test_message end end + def test_message_with_time_as_integer + d = create_driver + + time = Time.parse("2011-01-02 13:14:15 UTC").to_i + + d.expect_emit "tag1", time, {"a"=>1} + d.expect_emit "tag2", time, {"a"=>2} + + d.run do + d.expected_emits.each {|tag,time,record| + send_data Fluent::Engine.msgpack_factory.packer.write([tag, time, record]).to_s + } + end + end + def test_forward d = create_driver @@ -81,6 +96,23 @@ def test_forward end end + def test_forward_with_time_as_integer + d = create_driver + + time = Time.parse("2011-01-02 13:14:15 UTC").to_i + + d.expect_emit "tag1", time, {"a"=>1} + d.expect_emit "tag1", time, {"a"=>2} + + d.run do + entries = [] + d.expected_emits.each {|tag,time,record| + entries << [time, record] + } + send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s + end + end + def test_packed_forward d = create_driver @@ -98,6 +130,23 @@ def test_packed_forward end end + def test_packed_forward_with_time_as_integer + d = create_driver + + time = Time.parse("2011-01-02 13:14:15 UTC").to_i + + d.expect_emit "tag1", time, {"a"=>1} + d.expect_emit "tag1", time, {"a"=>2} + + d.run do + entries = '' + d.expected_emits.each {|tag,time,record| + Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush + } + send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s + end + end + def test_message_json d = create_driver From 564c29f6f18cacad2d3e6e2bc96fc686b8bae2c6 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 13:01:07 +0900 Subject: [PATCH 42/63] Add test for out_exec --- test/plugin/test_out_exec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/plugin/test_out_exec.rb b/test/plugin/test_out_exec.rb index 361eba63f8..95a8a20545 100644 --- a/test/plugin/test_out_exec.rb +++ b/test/plugin/test_out_exec.rb @@ -88,6 +88,28 @@ def test_format_msgpack d.run end + def test_format_time + config = %[ + keys "time,tag,k1" + tag_key "tag" + time_key "time" + time_format %Y-%m-%d %H:%M:%S.%3N + ] + d = create_driver(config) + + time = Fluent::NanoTime::from_time(Time.parse("2011-01-02 13:14:15.123")) + tests = [{"k1"=>"v1","kx"=>"vx"}, {"k1"=>"v2","kx"=>"vx"}] + + tests.each { |test| + d.emit(test, time) + } + + d.expect_format %[2011-01-02 13:14:15.123\ttest\tv1\n] + d.expect_format %[2011-01-02 13:14:15.123\ttest\tv2\n] + + d.run + end + def test_write d = create_driver time, tests = create_test_case From 7b143252e872c7ad98d7a818ae563157ff6eb596 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 18:51:10 +0900 Subject: [PATCH 43/63] test_out_exec_filter accepts float as NanoTime --- lib/fluent/plugin/out_exec_filter.rb | 2 +- test/plugin/test_out_exec_filter.rb | 45 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index 39f517a13b..e7e3d356f4 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -122,7 +122,7 @@ def configure(conf) if f = @out_time_format @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| Fluent::NanoTime.new(str.to_i) } + @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.at(str.to_f)) } end elsif @out_time_format log.warn "out_time_format effects nothing when out_time_key is not specified: #{conf}" diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index beed4e4e1d..9f944582fc 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -202,5 +202,50 @@ def test_json_1 assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] assert_equal_nano_time time, emits[0][1] end + + def test_json_with_float_time + d = create_driver(%[ + command cat + in_keys message + out_format json + time_key time + tag_key tag + ], 'input.test') + + float_time = Time.parse("2011-01-02 13:14:15").to_f + time = Fluent::NanoTime.from_time(Time.at(float_time)) + + d.run do + d.emit({"message"=>%[{"time":#{float_time},"tag":"t1","k1":"v1"}]}, time+10) + end + + emits = d.emits + assert_equal 1, emits.length + assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] + assert_equal_nano_time time, emits[0][1] + end + + def test_json_with_time_format + d = create_driver(%[ + command cat + in_keys message + out_format json + time_key time + time_format %d/%b/%Y %H:%M:%S.%N %z + tag_key tag + ], 'input.test') + + time_str = "28/Feb/2013 12:00:00.123456789 +0900" + time = Fluent::NanoTime.from_time(Time.strptime(time_str, "%d/%b/%Y %H:%M:%S.%N %z")) + + d.run do + d.emit({"message"=>%[{"time":"#{time_str}","tag":"t1","k1":"v1"}]}, time+10) + end + + emits = d.emits + assert_equal 1, emits.length + assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] + assert_equal_nano_time time, emits[0][1] + end end From 618eba36689e629fc3cf10a81ceab35269c69293 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 18:53:11 +0900 Subject: [PATCH 44/63] in_exec accepts float as NanoTime --- lib/fluent/plugin/in_exec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 8e2cd84a66..896e1b59a0 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -68,7 +68,7 @@ def configure(conf) f = @time_format @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } else - @time_parse_proc = Proc.new {|str| Fluent::NanoTime.new(str.to_i) } + @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.at(str.to_f)) } end end From 42e4e69d42bdad6269af5f25db42a6b35ad0da8c Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 19:18:12 +0900 Subject: [PATCH 45/63] Add tests for out_forward --- lib/fluent/event.rb | 8 ---- test/plugin/test_out_forward.rb | 69 +++++++++++++++++++++++++++++++++ test/test_output.rb | 20 ++++++++++ 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/lib/fluent/event.rb b/lib/fluent/event.rb index c7e70d0e4e..b1920de45a 100644 --- a/lib/fluent/event.rb +++ b/lib/fluent/event.rb @@ -159,14 +159,6 @@ def each(&block) def to_msgpack_stream @data end - - def to_msgpack_stream_forced_integer - out = Fluent::Engine.msgpack_factory.packer - each {|time,record| - out.write([time.to_i,record]) - } - out.to_s - end end end diff --git a/test/plugin/test_out_forward.rb b/test/plugin/test_out_forward.rb index edafd190e5..0b6d4c5c23 100644 --- a/test/plugin/test_out_forward.rb +++ b/test/plugin/test_out_forward.rb @@ -106,6 +106,75 @@ def test_wait_response_timeout_config assert_equal 2, d.instance.ack_response_timeout end + def test_send_with_time_as_integer + target_input_driver = create_target_input_driver + + d = create_driver(CONFIG + %[flush_interval 1s]) + + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + + records = [ + {"a" => 1}, + {"a" => 2} + ] + d.register_run_post_condition do + d.instance.responses.length == 1 + end + + target_input_driver.run do + d.run do + records.each do |record| + d.emit record, time + end + end + end + + emits = target_input_driver.emits + assert_equal ['test', time, records[0]], emits[0] + assert_equal ['test', time, records[1]], emits[1] + assert(emits[0][1].is_a?(Integer)) + assert(emits[1][1].is_a?(Integer)) + + assert_equal [nil], d.instance.responses # not attempt to receive responses, so nil is returned + assert_empty d.instance.exceptions + end + + def test_send_without_time_as_integer + target_input_driver = create_target_input_driver + + d = create_driver(CONFIG + %[ + flush_interval 1s + time_as_integer false + ]) + + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + + records = [ + {"a" => 1}, + {"a" => 2} + ] + d.register_run_post_condition do + d.instance.responses.length == 1 + end + + target_input_driver.run do + d.run do + records.each do |record| + d.emit record, time + end + end + end + + emits = target_input_driver.emits + assert_equal ['test', time, records[0]], emits[0] + assert_equal ['test', time, records[1]], emits[1] + assert_equal_nano_time(time, emits[0][1]) + assert_equal_nano_time(time, emits[1][1]) + + assert_equal [nil], d.instance.responses # not attempt to receive responses, so nil is returned + assert_empty d.instance.exceptions + end + def test_send_to_a_node_supporting_responses target_input_driver = create_target_input_driver(true) diff --git a/test/test_output.rb b/test/test_output.rb index 351e6ed284..6066b5bc81 100644 --- a/test/test_output.rb +++ b/test/test_output.rb @@ -203,6 +203,26 @@ def test_secondary end end + class ObjectBufferedOutputTest < ::Test::Unit::TestCase + include FluentOutputTest + + def setup + Fluent::Test.setup + end + + CONFIG = %[] + + def create_driver(conf=CONFIG) + Fluent::Test::OutputTestDriver.new(Fluent::ObjectBufferedOutput).configure(conf, true) + end + + def test_configure + # default + d = create_driver + assert_equal true, d.instance.time_as_integer + end + end + class TimeSlicedOutputTest < ::Test::Unit::TestCase include FluentOutputTest include FlexMock::TestCase From e7b1c453ed8c2284d4da3fc6671d14dc007b8374 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 19:36:03 +0900 Subject: [PATCH 46/63] Add test for out_stream --- test/plugin/test_out_stream.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/plugin/test_out_stream.rb b/test/plugin/test_out_stream.rb index 499599ceef..2877136ba6 100644 --- a/test/plugin/test_out_stream.rb +++ b/test/plugin/test_out_stream.rb @@ -22,6 +22,23 @@ def test_write assert_equal(expect, result) end + def test_write_nano_time + d = create_driver + + time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + d.emit({"a"=>1}, time) + d.emit({"a"=>2}, time) + + expect = ["test", + Fluent::Engine.msgpack_factory.packer.write([time,{"a"=>1}]).to_s + + Fluent::Engine.msgpack_factory.packer.write([time,{"a"=>2}]).to_s + ] + expect = Fluent::Engine.msgpack_factory.packer.write(expect).to_s + + result = d.run + assert_equal(expect, result) + end + def create_driver(klass, conf) Fluent::Test::BufferedOutputTestDriver.new(klass) do def write(chunk) From b077c432293c044be6277c65a43a706109792622 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 19:52:17 +0900 Subject: [PATCH 47/63] filter_record_transformer accept float as NanoTime --- lib/fluent/plugin/filter_record_transformer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/plugin/filter_record_transformer.rb b/lib/fluent/plugin/filter_record_transformer.rb index f61d4f3598..f7d6395817 100644 --- a/lib/fluent/plugin/filter_record_transformer.rb +++ b/lib/fluent/plugin/filter_record_transformer.rb @@ -88,7 +88,7 @@ def filter_stream(tag, es) last_record = record # for debug log new_record = reform(time, record, placeholders) if @renew_time_key && new_record.has_key?(@renew_time_key) - time = new_record[@renew_time_key].to_i + time = NanoTime.from_time(Time.at(new_record[@renew_time_key].to_f)) end new_es.add(time, new_record) end From 56bc9b975573b89480f559e282633c2aa587633c Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Mon, 17 Aug 2015 20:27:38 +0900 Subject: [PATCH 48/63] Add test for test_filter_record_transformer --- test/plugin/test_filter_record_transformer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/plugin/test_filter_record_transformer.rb b/test/plugin/test_filter_record_transformer.rb index f1af131f0c..492f1b8d76 100644 --- a/test/plugin/test_filter_record_transformer.rb +++ b/test/plugin/test_filter_record_transformer.rb @@ -95,10 +95,11 @@ def emit(config, msgs = ['']) test 'renew_time_key' do config = %[renew_time_key message] times = [ Time.local(2,2,3,4,5,2010,nil,nil,nil,nil), Time.local(3,2,3,4,5,2010,nil,nil,nil,nil) ] - msgs = times.map{|t| t.to_i.to_s } + msgs = times.map{|t| t.to_f.to_s } es = emit(config, msgs) es.each_with_index do |(time, record), i| assert_equal(times[i].to_i, time) + assert(time.is_a?(Fluent::NanoTime)) end end From 5e2f5aa0ec37992808ed706da248b3ea282697f9 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 21 Aug 2015 10:49:26 +0900 Subject: [PATCH 49/63] Add NanoTime.now --- lib/fluent/engine.rb | 2 +- lib/fluent/time.rb | 4 ++++ test/test_nano_time.rb | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index 7b5851e4e3..1ab5e280ee 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -136,7 +136,7 @@ def flush! def now # TODO thread update - Fluent::NanoTime.from_time(Time.now) + Fluent::NanoTime.now end def log_event_loop diff --git a/lib/fluent/time.rb b/lib/fluent/time.rb index c8c2504d37..8ddfdf98b7 100644 --- a/lib/fluent/time.rb +++ b/lib/fluent/time.rb @@ -65,6 +65,10 @@ def self.eq?(a, b) end end + def self.now + from_time(Time.now) + end + ## TODO: For performance, implement +, -, and so on def method_missing(name, *args, &block) @sec.send(name, *args, &block) diff --git a/test/test_nano_time.rb b/test/test_nano_time.rb index 0dfbbbe54a..06755e93bc 100644 --- a/test/test_nano_time.rb +++ b/test/test_nano_time.rb @@ -1,6 +1,16 @@ require_relative 'helper' +require 'timecop' class NanoTimeTest < Test::Unit::TestCase + setup do + @now = Time.now + Timecop.freeze(@now) + end + + teardown do + Timecop.return + end + test '#sec' do assert_equal(1, Fluent::NanoTime.new(1, 2).sec) end @@ -32,6 +42,11 @@ class NanoTimeTest < Test::Unit::TestCase assert_equal(time.nsec, usec * 1000) end + test 'now' do + assert_equal(@now.to_i, Fluent::NanoTime.now.sec) + assert_equal(@now.nsec, Fluent::NanoTime.now.nsec) + end + test 'eq?' do assert(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 2))) refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 3))) From 905ad91044f82bff83fb28d8c6783159e2c0fbaf Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 21 Aug 2015 11:03:10 +0900 Subject: [PATCH 50/63] Add NanoTime.parse --- lib/fluent/parser.rb | 2 +- lib/fluent/time.rb | 4 ++++ test/plugin/test_filter_stdout.rb | 2 +- test/plugin/test_in_exec.rb | 2 +- test/plugin/test_in_forward.rb | 26 +++++++++++++------------- test/plugin/test_in_stream.rb | 8 ++++---- test/plugin/test_out_exec_filter.rb | 12 ++++++------ test/plugin/test_out_forward.rb | 4 ++-- test/plugin/test_out_stream.rb | 2 +- test/test_nano_time.rb | 5 +++++ test/test_parser.rb | 4 ++-- 11 files changed, 40 insertions(+), 31 deletions(-) diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 13ac154442..11912cbed1 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -62,7 +62,7 @@ def initialize(time_format) if time_format Proc.new { |value| Fluent::NanoTime.from_time(Time.strptime(value, time_format)) } else - Proc.new { |value| Fluent::NanoTime.from_time(Time.parse(value)) } + Proc.new { |value| Fluent::NanoTime.parse(value) } end end diff --git a/lib/fluent/time.rb b/lib/fluent/time.rb index 8ddfdf98b7..ed4a4243a1 100644 --- a/lib/fluent/time.rb +++ b/lib/fluent/time.rb @@ -69,6 +69,10 @@ def self.now from_time(Time.now) end + def self.parse(*args) + from_time(Time.parse(*args)) + end + ## TODO: For performance, implement +, -, and so on def method_missing(name, *args, &block) @sec.send(name, *args, &block) diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 8cb51ce0ce..41e2c3307d 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -84,7 +84,7 @@ def test_output_type_hash def test_include_time_key d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc") time = Time.now - message_time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + message_time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") out = capture_log(d) { emit(d, {'test' => 'test'}, message_time) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out end diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index 3b7825e9e9..3637f7868a 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -5,7 +5,7 @@ class ExecInputTest < Test::Unit::TestCase def setup Fluent::Test.setup - @test_time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + @test_time = Fluent::NanoTime.parse("2011-01-02 13:14:15") @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb')) end diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index a81a9f7a7b..d2c95e91d2 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -36,7 +36,7 @@ def connect def test_time d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -52,7 +52,7 @@ def test_time def test_message d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -82,7 +82,7 @@ def test_message_with_time_as_integer def test_forward d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -116,7 +116,7 @@ def test_forward_with_time_as_integer def test_packed_forward d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -168,7 +168,7 @@ def test_send_large_chunk_warning chunk_size_limit 32M ]) - time = Fluent::NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2014-04-25 13:14:15 UTC") # generate over 16M chunk str = "X" * 1024 * 1024 @@ -199,7 +199,7 @@ def test_send_large_chunk_only_warning d = create_driver(CONFIG + %[ chunk_size_warn_limit 16M ]) - time = Fluent::NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2014-04-25 13:14:15 UTC") # generate over 16M chunk str = "X" * 1024 * 1024 @@ -224,7 +224,7 @@ def test_send_large_chunk_limit chunk_size_limit 32M ]) - time = Fluent::NanoTime.from_time(Time.parse("2014-04-25 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2014-04-25 13:14:15 UTC") # generate over 32M chunk str = "X" * 1024 * 1024 @@ -272,7 +272,7 @@ def test_send_broken_chunk(data) def test_respond_to_message_requiring_ack d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -298,7 +298,7 @@ def test_respond_to_message_requiring_ack def test_respond_to_forward_requiring_ack d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -325,7 +325,7 @@ def test_respond_to_forward_requiring_ack def test_respond_to_packed_forward_requiring_ack d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -378,7 +378,7 @@ def test_respond_to_message_json_requiring_ack def test_not_respond_to_message_not_requiring_ack d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -399,7 +399,7 @@ def test_not_respond_to_message_not_requiring_ack def test_not_respond_to_forward_not_requiring_ack d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -422,7 +422,7 @@ def test_not_respond_to_forward_not_requiring_ack def test_not_respond_to_packed_forward_not_requiring_ack d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index 0fc224aae3..e9c873d8aa 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -9,7 +9,7 @@ def setup def test_time d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -25,7 +25,7 @@ def test_time def test_message d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -40,7 +40,7 @@ def test_message def test_forward d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -57,7 +57,7 @@ def test_forward def test_packed_forward d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index 9f944582fc..3891004ba8 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -69,7 +69,7 @@ def test_configure def test_emit_1 d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15") d.run do d.emit({"k1"=>1}, time) @@ -94,7 +94,7 @@ def test_emit_2 num_children 3 ] - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15") d.run do d.emit({"k1"=>1}, time) @@ -119,7 +119,7 @@ def test_emit_3 num_children 3 ] - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15") d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -140,7 +140,7 @@ def test_emit_3 num_children 3 ] - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15") d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -167,7 +167,7 @@ def test_emit_4 num_children 3 ], 'input.test') - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15") d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -191,7 +191,7 @@ def test_json_1 tag_key tag ], 'input.test') - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15") d.run do d.emit({"message"=>%[{"time":#{time},"tag":"t1","k1":"v1"}]}, time+10) diff --git a/test/plugin/test_out_forward.rb b/test/plugin/test_out_forward.rb index 0b6d4c5c23..4af3d767ba 100644 --- a/test/plugin/test_out_forward.rb +++ b/test/plugin/test_out_forward.rb @@ -111,7 +111,7 @@ def test_send_with_time_as_integer d = create_driver(CONFIG + %[flush_interval 1s]) - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") records = [ {"a" => 1}, @@ -147,7 +147,7 @@ def test_send_without_time_as_integer time_as_integer false ]) - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") records = [ {"a" => 1}, diff --git a/test/plugin/test_out_stream.rb b/test/plugin/test_out_stream.rb index 2877136ba6..144f40bea7 100644 --- a/test/plugin/test_out_stream.rb +++ b/test/plugin/test_out_stream.rb @@ -25,7 +25,7 @@ def test_write def test_write_nano_time d = create_driver - time = Fluent::NanoTime.from_time(Time.parse("2011-01-02 13:14:15 UTC")) + time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") d.emit({"a"=>1}, time) d.emit({"a"=>2}, time) diff --git a/test/test_nano_time.rb b/test/test_nano_time.rb index 06755e93bc..94b5139ef1 100644 --- a/test/test_nano_time.rb +++ b/test/test_nano_time.rb @@ -47,6 +47,11 @@ class NanoTimeTest < Test::Unit::TestCase assert_equal(@now.nsec, Fluent::NanoTime.now.nsec) end + test 'parse' do + assert_equal(Time.parse("2011-01-02 13:14:15").to_i, Fluent::NanoTime.parse("2011-01-02 13:14:15").sec) + assert_equal(Time.parse("2011-01-02 13:14:15").nsec, Fluent::NanoTime.parse("2011-01-02 13:14:15").nsec) + end + test 'eq?' do assert(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 2))) refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 3))) diff --git a/test/test_parser.rb b/test/test_parser.rb index 529fe0b6a5..593c579b47 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -13,7 +13,7 @@ def str2time(str_time, format = nil) if format Fluent::NanoTime.from_time(Time.strptime(str_time, format)) else - Fluent::NanoTime.from_time(Time.parse(str_time)) + Fluent::NanoTime.parse(str_time) end end @@ -130,7 +130,7 @@ def test_parse_with_time_key ) text = '2013-02-28 12:00:00 +0900' parser.parse(text) do |time, record| - assert_equal Fluent::NanoTime.from_time(Time.parse(text)), time + assert_equal Fluent::NanoTime.parse(text), time end end From 51130d3e714715d4735001ce0e3dee5d349a6335 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 21 Aug 2015 18:43:58 +0900 Subject: [PATCH 51/63] Use strptime gem for optimization of TimeParser --- Gemfile | 1 + lib/fluent/load.rb | 1 + lib/fluent/parser.rb | 7 ++++++- lib/fluent/plugin/in_exec.rb | 8 +++++++- lib/fluent/plugin/out_exec_filter.rb | 8 +++++++- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 837367cea7..c0406724d0 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source 'https://rubygems.org/' gemspec gem 'msgpack', github: 'msgpack/msgpack-ruby' +gem 'strptime', github: 'nurse/strptime' local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") if File.exist?(local_gemfile) diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index 6ca9273778..874f3b3b73 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -9,6 +9,7 @@ require 'yajl' require 'uri' require 'msgpack' +require 'strptime' begin require 'sigdump/setup' rescue diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index 11912cbed1..b91f9f0d50 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -60,7 +60,12 @@ def initialize(time_format) @cache2_time = nil @parser = if time_format - Proc.new { |value| Fluent::NanoTime.from_time(Time.strptime(value, time_format)) } + begin + strptime = Strptime.new(time_format) + Proc.new { |value| Fluent::NanoTime.from_time(strptime.exec(value)) } + rescue + Proc.new { |value| Fluent::NanoTime.from_time(Time.strptime(value, time_format)) } + end else Proc.new { |value| Fluent::NanoTime.parse(value) } end diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 896e1b59a0..00af1db6ff 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -66,7 +66,13 @@ def configure(conf) if @time_key if @time_format f = @time_format - @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } + @time_parse_proc = + begin + strptime = Strptime.new(f) + Proc.new { |str| Fluent::NanoTime.from_time(strptime.exec(str)) } + rescue + Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } + end else @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.at(str.to_f)) } end diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index e7e3d356f4..bc873e3d6c 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -120,7 +120,13 @@ def configure(conf) if @out_time_key if f = @out_time_format - @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } + @time_parse_proc = + begin + strptime = Strptime.new(f) + Proc.new { |str| Fluent::NanoTime.from_time(strptime.exec(str)) } + rescue + Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } + end else @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.at(str.to_f)) } end From 304c681f6c473c2935dc4a5a61aa6662ae53faf5 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 21 Aug 2015 18:45:49 +0900 Subject: [PATCH 52/63] Add a comment for gems --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index c0406724d0..1df2a4e281 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source 'https://rubygems.org/' gemspec +# These gems will move to gemspec when they is released. gem 'msgpack', github: 'msgpack/msgpack-ruby' gem 'strptime', github: 'nurse/strptime' From 385564f625ec3c906eee2f813b19ca6b17e3146d Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 27 Aug 2015 01:56:24 +0900 Subject: [PATCH 53/63] Fix regexp to check whether format string include subsec or not --- lib/fluent/mixin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index 7864f4fd89..6d76bacf21 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -25,7 +25,7 @@ def initialize(format, localtime, timezone = nil) @tc2 = 0 @tc2_str = nil - if !format || format !~ /%L|%\d*N/ + if !format || format !~ /(^|[^%])(%%)*%L|(^|[^%])(%%)*%\d*N/ define_singleton_method(:format) {|time| format_without_subsec(time) } From 4ea193da3b135aa26b6e40102e5bef8d09374716 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 27 Aug 2015 02:18:16 +0900 Subject: [PATCH 54/63] Cosmetic change --- lib/fluent/mixin.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index 6d76bacf21..904fc39127 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -25,13 +25,13 @@ def initialize(format, localtime, timezone = nil) @tc2 = 0 @tc2_str = nil - if !format || format !~ /(^|[^%])(%%)*%L|(^|[^%])(%%)*%\d*N/ + if format && format =~ /(^|[^%])(%%)*%L|(^|[^%])(%%)*%\d*N/ define_singleton_method(:format) {|time| - format_without_subsec(time) + format_with_subsec(time) } else define_singleton_method(:format) {|time| - format_with_subsec(time) + format_without_subsec(time) } end From 9a1a4b1a1eb10978fd6e31d9f8d458a2b6dc6fb3 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 27 Aug 2015 02:25:59 +0900 Subject: [PATCH 55/63] Rename NanoTime to EventTime --- lib/fluent/engine.rb | 4 +- lib/fluent/mixin.rb | 4 +- lib/fluent/parser.rb | 8 +- .../plugin/filter_record_transformer.rb | 2 +- lib/fluent/plugin/in_exec.rb | 6 +- lib/fluent/plugin/in_http.rb | 2 +- lib/fluent/plugin/out_exec_filter.rb | 6 +- lib/fluent/test/base.rb | 2 +- lib/fluent/test/input_test.rb | 2 +- lib/fluent/time.rb | 8 +- test/plugin/test_filter_record_transformer.rb | 2 +- test/plugin/test_filter_stdout.rb | 12 +- test/plugin/test_in_dummy.rb | 2 +- test/plugin/test_in_exec.rb | 8 +- test/plugin/test_in_forward.rb | 26 +-- test/plugin/test_in_gc_stat.rb | 2 +- test/plugin/test_in_http.rb | 22 +-- test/plugin/test_in_object_space.rb | 2 +- test/plugin/test_in_status.rb | 2 +- test/plugin/test_in_stream.rb | 8 +- test/plugin/test_in_syslog.rb | 6 +- test/plugin/test_in_tail.rb | 4 +- test/plugin/test_in_tcp.rb | 2 +- test/plugin/test_in_udp.rb | 8 +- test/plugin/test_out_exec.rb | 2 +- test/plugin/test_out_exec_filter.rb | 40 ++--- test/plugin/test_out_forward.rb | 8 +- test/plugin/test_out_stdout.rb | 4 +- test/plugin/test_out_stream.rb | 4 +- test/test_event.rb | 6 +- test/test_event_time.rb | 157 ++++++++++++++++++ test/test_formatter.rb | 2 +- test/test_nano_time.rb | 157 ------------------ test/test_parser.rb | 14 +- 34 files changed, 272 insertions(+), 272 deletions(-) create mode 100644 test/test_event_time.rb delete mode 100644 test/test_nano_time.rb diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index 1ab5e280ee..6952495478 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -32,7 +32,7 @@ def initialize @suppress_config_dump = false @msgpack_factory = MessagePack::Factory.new - @msgpack_factory.register_type(Fluent::NanoTime::TYPE, Fluent::NanoTime) + @msgpack_factory.register_type(Fluent::EventTime::TYPE, Fluent::EventTime) end MATCH_CACHE_SIZE = 1024 @@ -136,7 +136,7 @@ def flush! def now # TODO thread update - Fluent::NanoTime.now + Fluent::EventTime.now end def log_event_loop diff --git a/lib/fluent/mixin.rb b/lib/fluent/mixin.rb index 904fc39127..a43e69c8be 100644 --- a/lib/fluent/mixin.rb +++ b/lib/fluent/mixin.rb @@ -84,9 +84,9 @@ def format_without_subsec(time) end def format_with_subsec(time) - if Fluent::NanoTime.eq?(@tc1, time) + if Fluent::EventTime.eq?(@tc1, time) return @tc1_str - elsif Fluent::NanoTime.eq?(@tc2, time) + elsif Fluent::EventTime.eq?(@tc2, time) return @tc2_str else str = format_nocache(time) diff --git a/lib/fluent/parser.rb b/lib/fluent/parser.rb index b91f9f0d50..bcef71a952 100644 --- a/lib/fluent/parser.rb +++ b/lib/fluent/parser.rb @@ -62,12 +62,12 @@ def initialize(time_format) if time_format begin strptime = Strptime.new(time_format) - Proc.new { |value| Fluent::NanoTime.from_time(strptime.exec(value)) } + Proc.new { |value| Fluent::EventTime.from_time(strptime.exec(value)) } rescue - Proc.new { |value| Fluent::NanoTime.from_time(Time.strptime(value, time_format)) } + Proc.new { |value| Fluent::EventTime.from_time(Time.strptime(value, time_format)) } end else - Proc.new { |value| Fluent::NanoTime.parse(value) } + Proc.new { |value| Fluent::EventTime.parse(value) } end end @@ -262,7 +262,7 @@ def parse(text) time = @mutex.synchronize { @time_parser.parse(value) } else begin - time = Fluent::NanoTime.from_time(Time.at(value.to_f)) + time = Fluent::EventTime.from_time(Time.at(value.to_f)) rescue => e raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}" end diff --git a/lib/fluent/plugin/filter_record_transformer.rb b/lib/fluent/plugin/filter_record_transformer.rb index f7d6395817..64375e804c 100644 --- a/lib/fluent/plugin/filter_record_transformer.rb +++ b/lib/fluent/plugin/filter_record_transformer.rb @@ -88,7 +88,7 @@ def filter_stream(tag, es) last_record = record # for debug log new_record = reform(time, record, placeholders) if @renew_time_key && new_record.has_key?(@renew_time_key) - time = NanoTime.from_time(Time.at(new_record[@renew_time_key].to_f)) + time = EventTime.from_time(Time.at(new_record[@renew_time_key].to_f)) end new_es.add(time, new_record) end diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index 00af1db6ff..98d0949c02 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -69,12 +69,12 @@ def configure(conf) @time_parse_proc = begin strptime = Strptime.new(f) - Proc.new { |str| Fluent::NanoTime.from_time(strptime.exec(str)) } + Proc.new { |str| Fluent::EventTime.from_time(strptime.exec(str)) } rescue - Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } + Proc.new {|str| Fluent::EventTime.from_time(Time.strptime(str, f)) } end else - @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.at(str.to_f)) } + @time_parse_proc = Proc.new {|str| Fluent::EventTime.from_time(Time.at(str.to_f)) } end end diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 9bcbdc4fe9..17212b4f89 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -145,7 +145,7 @@ def on_request(path_info, params) end time = if param_time = params['time'] param_time = param_time.to_f - param_time.zero? ? Engine.now : Fluent::NanoTime.from_time(Time.at(param_time)) + param_time.zero? ? Engine.now : Fluent::EventTime.from_time(Time.at(param_time)) else record_time.nil? ? Engine.now : record_time end diff --git a/lib/fluent/plugin/out_exec_filter.rb b/lib/fluent/plugin/out_exec_filter.rb index bc873e3d6c..4488234c5d 100644 --- a/lib/fluent/plugin/out_exec_filter.rb +++ b/lib/fluent/plugin/out_exec_filter.rb @@ -123,12 +123,12 @@ def configure(conf) @time_parse_proc = begin strptime = Strptime.new(f) - Proc.new { |str| Fluent::NanoTime.from_time(strptime.exec(str)) } + Proc.new { |str| Fluent::EventTime.from_time(strptime.exec(str)) } rescue - Proc.new {|str| Fluent::NanoTime.from_time(Time.strptime(str, f)) } + Proc.new {|str| Fluent::EventTime.from_time(Time.strptime(str, f)) } end else - @time_parse_proc = Proc.new {|str| Fluent::NanoTime.from_time(Time.at(str.to_f)) } + @time_parse_proc = Proc.new {|str| Fluent::EventTime.from_time(Time.at(str.to_f)) } end elsif @out_time_format log.warn "out_time_format effects nothing when out_time_key is not specified: #{conf}" diff --git a/lib/fluent/test/base.rb b/lib/fluent/test/base.rb index 76865aab99..a3f9b77de0 100644 --- a/lib/fluent/test/base.rb +++ b/lib/fluent/test/base.rb @@ -28,7 +28,7 @@ def self.setup } ::Test::Unit::Assertions.module_eval { - def assert_equal_nano_time(a, b) + def assert_equal_event_time(a, b) assert_equal(a.sec, b.sec) assert_equal(a.nsec, b.nsec) end diff --git a/lib/fluent/test/input_test.rb b/lib/fluent/test/input_test.rb index 434ed1cd95..4a4bad790a 100644 --- a/lib/fluent/test/input_test.rb +++ b/lib/fluent/test/input_test.rb @@ -142,7 +142,7 @@ def run(&block) events.each do |time, record| if @expects assert_equal(@expects[i], [tag, time, record]) - assert_equal_nano_time(@expects[i][1], time) if @expects[i][1].is_a?(Fluent::NanoTime) + assert_equal_event_time(@expects[i][1], time) if @expects[i][1].is_a?(Fluent::EventTime) end i += 1 end diff --git a/lib/fluent/time.rb b/lib/fluent/time.rb index ed4a4243a1..abf2ede2cd 100644 --- a/lib/fluent/time.rb +++ b/lib/fluent/time.rb @@ -1,5 +1,5 @@ module Fluent - class NanoTime + class EventTime TYPE = 0 def initialize(sec, nsec = 0) @@ -8,7 +8,7 @@ def initialize(sec, nsec = 0) end def ==(other) - if other.is_a?(Fluent::NanoTime) + if other.is_a?(Fluent::EventTime) @sec == other.sec else @sec == other @@ -54,11 +54,11 @@ def self.from_msgpack_ext(data) end def self.from_time(time) - Fluent::NanoTime.new(time.to_i, time.nsec) + Fluent::EventTime.new(time.to_i, time.nsec) end def self.eq?(a, b) - if a.is_a?(Fluent::NanoTime) && b.is_a?(Fluent::NanoTime) + if a.is_a?(Fluent::EventTime) && b.is_a?(Fluent::EventTime) a.sec == b.sec && a.nsec == b.nsec else a == b diff --git a/test/plugin/test_filter_record_transformer.rb b/test/plugin/test_filter_record_transformer.rb index 492f1b8d76..66aa23dd1b 100644 --- a/test/plugin/test_filter_record_transformer.rb +++ b/test/plugin/test_filter_record_transformer.rb @@ -99,7 +99,7 @@ def emit(config, msgs = ['']) es = emit(config, msgs) es.each_with_index do |(time, record), i| assert_equal(times[i].to_i, time) - assert(time.is_a?(Fluent::NanoTime)) + assert(time.is_a?(Fluent::EventTime)) end end diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 41e2c3307d..32cc8b005f 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -32,7 +32,7 @@ def emit(d, msg, time) def test_through_record d = create_driver time = Time.now - filtered = emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) + filtered = emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) assert_equal({'test' => 'test'}, filtered) end @@ -59,7 +59,7 @@ def test_configure_output_type def test_output_type_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -71,12 +71,12 @@ def test_output_type_json def test_output_type_hash d = create_driver(CONFIG + "\noutput_type hash") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. d = create_driver(CONFIG + "\noutput_type hash") - out = capture_log(d) { emit(d, {'test' => Float::NAN}, Fluent::NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => Float::NAN}, Fluent::EventTime.from_time(time)) } assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out end @@ -84,7 +84,7 @@ def test_output_type_hash def test_include_time_key d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc") time = Time.now - message_time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + message_time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") out = capture_log(d) { emit(d, {'test' => 'test'}, message_time) } assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out end @@ -93,7 +93,7 @@ def test_include_time_key def test_format_json d = create_driver(CONFIG + "\nformat json") time = Time.now - out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::NanoTime.from_time(time)) } + out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) } assert_equal "{\"test\":\"test\"}\n", out end diff --git a/test/plugin/test_in_dummy.rb b/test/plugin/test_in_dummy.rb index a53737f2ef..d2bf159bc0 100644 --- a/test/plugin/test_in_dummy.rb +++ b/test/plugin/test_in_dummy.rb @@ -77,7 +77,7 @@ def create_driver(conf) emits.each do |tag, time, record| assert_equal("dummy", tag) assert_equal({"foo"=>"bar"}, record) - assert(time.is_a?(Fluent::NanoTime)) + assert(time.is_a?(Fluent::EventTime)) end end diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index 3637f7868a..91677bfdd9 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -5,7 +5,7 @@ class ExecInputTest < Test::Unit::TestCase def setup Fluent::Test.setup - @test_time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + @test_time = Fluent::EventTime.parse("2011-01-02 13:14:15") @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb')) end @@ -77,7 +77,7 @@ def test_emit emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal_nano_time(@test_time, emits[0][1]) + assert_equal_event_time(@test_time, emits[0][1]) end def test_emit_json @@ -90,7 +90,7 @@ def test_emit_json emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal_nano_time(@test_time, emits[0][1]) + assert_equal_event_time(@test_time, emits[0][1]) end def test_emit_msgpack @@ -103,6 +103,6 @@ def test_emit_msgpack emits = d.emits assert_equal true, emits.length > 0 assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0] - assert_equal_nano_time(@test_time, emits[0][1]) + assert_equal_event_time(@test_time, emits[0][1]) end end diff --git a/test/plugin/test_in_forward.rb b/test/plugin/test_in_forward.rb index d2c95e91d2..10a2fed9d2 100644 --- a/test/plugin/test_in_forward.rb +++ b/test/plugin/test_in_forward.rb @@ -36,7 +36,7 @@ def connect def test_time d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -52,7 +52,7 @@ def test_time def test_message d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -82,7 +82,7 @@ def test_message_with_time_as_integer def test_forward d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -116,7 +116,7 @@ def test_forward_with_time_as_integer def test_packed_forward d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -168,7 +168,7 @@ def test_send_large_chunk_warning chunk_size_limit 32M ]) - time = Fluent::NanoTime.parse("2014-04-25 13:14:15 UTC") + time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC") # generate over 16M chunk str = "X" * 1024 * 1024 @@ -199,7 +199,7 @@ def test_send_large_chunk_only_warning d = create_driver(CONFIG + %[ chunk_size_warn_limit 16M ]) - time = Fluent::NanoTime.parse("2014-04-25 13:14:15 UTC") + time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC") # generate over 16M chunk str = "X" * 1024 * 1024 @@ -224,7 +224,7 @@ def test_send_large_chunk_limit chunk_size_limit 32M ]) - time = Fluent::NanoTime.parse("2014-04-25 13:14:15 UTC") + time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC") # generate over 32M chunk str = "X" * 1024 * 1024 @@ -272,7 +272,7 @@ def test_send_broken_chunk(data) def test_respond_to_message_requiring_ack d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -298,7 +298,7 @@ def test_respond_to_message_requiring_ack def test_respond_to_forward_requiring_ack d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -325,7 +325,7 @@ def test_respond_to_forward_requiring_ack def test_respond_to_packed_forward_requiring_ack d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -378,7 +378,7 @@ def test_respond_to_message_json_requiring_ack def test_not_respond_to_message_not_requiring_ack d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -399,7 +399,7 @@ def test_not_respond_to_message_not_requiring_ack def test_not_respond_to_forward_not_requiring_ack d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], @@ -422,7 +422,7 @@ def test_not_respond_to_forward_not_requiring_ack def test_not_respond_to_packed_forward_not_requiring_ack d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") events = [ ["tag1", time, {"a"=>1}], diff --git a/test/plugin/test_in_gc_stat.rb b/test/plugin/test_in_gc_stat.rb index 14ea86b8e4..ff0638251f 100644 --- a/test/plugin/test_in_gc_stat.rb +++ b/test/plugin/test_in_gc_stat.rb @@ -33,6 +33,6 @@ def test_emit emits = d.emits assert(emits.length > 0) assert_equal(stat, emits[0][2]) - assert(emits[0][1].is_a?(Fluent::NanoTime)) + assert(emits[0][1].is_a?(Fluent::EventTime)) end end diff --git a/test/plugin/test_in_http.rb b/test/plugin/test_in_http.rb index dcc4e19313..0ecc0706d4 100644 --- a/test/plugin/test_in_http.rb +++ b/test/plugin/test_in_http.rb @@ -32,7 +32,7 @@ def test_configure def test_time d = create_driver - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -50,7 +50,7 @@ def test_time_as_float d = create_driver float_time = Time.parse("2011-01-02 13:14:15.123 UTC").to_f - time = Fluent::NanoTime.from_time(Time.at(float_time)) + time = Fluent::EventTime.from_time(Time.at(float_time)) d.expect_emit "tag1", time, {"a"=>1} @@ -65,7 +65,7 @@ def test_time_as_float def test_json d = create_driver - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -85,7 +85,7 @@ def test_json def test_multi_json d = create_driver - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -154,7 +154,7 @@ def test_multi_json_with_add_http_headers def test_json_with_add_http_headers d = create_driver(CONFIG + "add_http_headers true") - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) records = [["tag1", time, {"a"=>1}], ["tag2", time, {"a"=>2}]] @@ -174,7 +174,7 @@ def test_json_with_add_http_headers def test_application_json d = create_driver - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -190,7 +190,7 @@ def test_application_json def test_msgpack d = create_driver - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -206,7 +206,7 @@ def test_msgpack def test_multi_msgpack d = create_driver - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) events = [{"a"=>1},{"a"=>2}] tag = "tag1" @@ -228,7 +228,7 @@ def test_with_regexp types field_1:integer ]) - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"field_1" => 1, "field_2" => 'str'} d.expect_emit "tag2", time, {"field_1" => 2, "field_2" => 'str'} @@ -252,7 +252,7 @@ def test_with_csv keys foo,bar ]) - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"foo" => "1", "bar" => 'st"r'} d.expect_emit "tag2", time, {"foo" => "2", "bar" => 'str'} @@ -270,7 +270,7 @@ def test_resonse_with_empty_img d = create_driver(CONFIG + "respond_with_empty_img true") assert_equal true, d.instance.respond_with_empty_img - time = Fluent::NanoTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) + time = Fluent::EventTime.new(Time.parse("2011-01-02 13:14:15 UTC").to_i) d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} diff --git a/test/plugin/test_in_object_space.rb b/test/plugin/test_in_object_space.rb index 6715b40f6c..fc370e9529 100644 --- a/test/plugin/test_in_object_space.rb +++ b/test/plugin/test_in_object_space.rb @@ -41,7 +41,7 @@ def test_emit emits.each { |tag, time, record| assert_equal d.instance.tag, tag assert_equal d.instance.top, record.keys.size - assert(time.is_a?(Fluent::NanoTime)) + assert(time.is_a?(Fluent::EventTime)) } end end diff --git a/test/plugin/test_in_status.rb b/test/plugin/test_in_status.rb index 611a999a22..5ca754ff3f 100644 --- a/test/plugin/test_in_status.rb +++ b/test/plugin/test_in_status.rb @@ -34,6 +34,6 @@ def test_emit emits = d.emits assert(emits.length > 0) assert_equal({"answer" => "42"}, emits[0][2]) - assert(emits[0][1].is_a?(Fluent::NanoTime)) + assert(emits[0][1].is_a?(Fluent::EventTime)) end end diff --git a/test/plugin/test_in_stream.rb b/test/plugin/test_in_stream.rb index e9c873d8aa..2501832f17 100644 --- a/test/plugin/test_in_stream.rb +++ b/test/plugin/test_in_stream.rb @@ -9,7 +9,7 @@ def setup def test_time d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") Fluent::Engine.now = time d.expect_emit "tag1", time, {"a"=>1} @@ -25,7 +25,7 @@ def test_time def test_message d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag2", time, {"a"=>2} @@ -40,7 +40,7 @@ def test_message def test_forward d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} @@ -57,7 +57,7 @@ def test_forward def test_packed_forward d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.expect_emit "tag1", time, {"a"=>1} d.expect_emit "tag1", time, {"a"=>2} diff --git a/test/plugin/test_in_syslog.rb b/test/plugin/test_in_syslog.rb index 29aa0019b6..d65c4afd32 100755 --- a/test/plugin/test_in_syslog.rb +++ b/test/plugin/test_in_syslog.rb @@ -43,8 +43,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, - {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 11 00:00:00 localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '<6>Sep 1 00:00:00 localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do @@ -58,7 +58,7 @@ def test_time_format emits = d.emits emits.each_index {|i| - assert_equal_nano_time(tests[i]['expected'], emits[i][1]) + assert_equal_event_time(tests[i]['expected'], emits[i][1]) } } end diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 73b65050e5..fe2736f533 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -77,8 +77,8 @@ def test_emit assert_equal(true, emits.length > 0) assert_equal({"message" => "test3"}, emits[0][2]) assert_equal({"message" => "test4"}, emits[1][2]) - assert(emits[0][1].is_a?(Fluent::NanoTime)) - assert(emits[1][1].is_a?(Fluent::NanoTime)) + assert(emits[0][1].is_a?(Fluent::EventTime)) + assert(emits[1][1].is_a?(Fluent::EventTime)) assert_equal(1, d.emit_streams.size) end diff --git a/test/plugin/test_in_tcp.rb b/test/plugin/test_in_tcp.rb index 03a1b67c32..0b89da8c9e 100755 --- a/test/plugin/test_in_tcp.rb +++ b/test/plugin/test_in_tcp.rb @@ -83,7 +83,7 @@ def compare_test_result(emits, tests) assert_equal(2, emits.size) emits.each_index {|i| assert_equal(tests[i]['expected'], emits[i][2]['message']) - assert(emits[i][1].is_a?(Fluent::NanoTime)) + assert(emits[i][1].is_a?(Fluent::EventTime)) } end end diff --git a/test/plugin/test_in_udp.rb b/test/plugin/test_in_udp.rb index e317ba9973..1d4d46284f 100755 --- a/test/plugin/test_in_udp.rb +++ b/test/plugin/test_in_udp.rb @@ -44,8 +44,8 @@ def test_time_format d = create_driver(v) tests = [ - {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, - {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => Fluent::NanoTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 11 00:00:00] localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Sep 11 00:00:00', '%b %d %H:%M:%S'))}, + {'msg' => '[Sep 1 00:00:00] localhost logger: foo', 'expected' => Fluent::EventTime.from_time(Time.strptime('Sep 1 00:00:00', '%b %d %H:%M:%S'))}, ] d.run do @@ -59,7 +59,7 @@ def test_time_format emits = d.emits emits.each_index {|i| - assert_equal_nano_time(tests[i]['expected'], emits[i][1]) + assert_equal_event_time(tests[i]['expected'], emits[i][1]) } } end @@ -99,7 +99,7 @@ def compare_test_result(emits, tests) assert_equal(2, emits.size) emits.each_index {|i| assert_equal(tests[i]['expected'], emits[i][2]['message']) - assert(emits[i][1].is_a?(Fluent::NanoTime)) + assert(emits[i][1].is_a?(Fluent::EventTime)) } end end diff --git a/test/plugin/test_out_exec.rb b/test/plugin/test_out_exec.rb index 95a8a20545..3b8a8a25af 100644 --- a/test/plugin/test_out_exec.rb +++ b/test/plugin/test_out_exec.rb @@ -97,7 +97,7 @@ def test_format_time ] d = create_driver(config) - time = Fluent::NanoTime::from_time(Time.parse("2011-01-02 13:14:15.123")) + time = Fluent::EventTime::from_time(Time.parse("2011-01-02 13:14:15.123")) tests = [{"k1"=>"v1","kx"=>"vx"}, {"k1"=>"v2","kx"=>"vx"}] tests.each { |test| diff --git a/test/plugin/test_out_exec_filter.rb b/test/plugin/test_out_exec_filter.rb index 3891004ba8..00d888dd5c 100644 --- a/test/plugin/test_out_exec_filter.rb +++ b/test/plugin/test_out_exec_filter.rb @@ -69,7 +69,7 @@ def test_configure def test_emit_1 d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + time = Fluent::EventTime.parse("2011-01-02 13:14:15") d.run do d.emit({"k1"=>1}, time) @@ -79,9 +79,9 @@ def test_emit_1 emits = d.emits assert_equal 2, emits.length assert_equal ["test", time, {"k2"=>"1"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] assert_equal ["test", time, {"k2"=>"2"}], emits[1] - assert_equal_nano_time time, emits[1][1] + assert_equal_event_time time, emits[1][1] end def test_emit_2 @@ -94,7 +94,7 @@ def test_emit_2 num_children 3 ] - time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + time = Fluent::EventTime.parse("2011-01-02 13:14:15") d.run do d.emit({"k1"=>1}, time) @@ -104,9 +104,9 @@ def test_emit_2 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"k2"=>"1"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] assert_equal ["xxx", time, {"k2"=>"2"}], emits[1] - assert_equal_nano_time time, emits[1][1] + assert_equal_event_time time, emits[1][1] end def test_emit_3 @@ -119,7 +119,7 @@ def test_emit_3 num_children 3 ] - time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + time = Fluent::EventTime.parse("2011-01-02 13:14:15") d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -129,7 +129,7 @@ def test_emit_3 emits = d.emits assert_equal 1, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value foo"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] d = create_driver %[ command sed #{sed_unbuffered_option} -l -e s/foo/bar/ @@ -140,7 +140,7 @@ def test_emit_3 num_children 3 ] - time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + time = Fluent::EventTime.parse("2011-01-02 13:14:15") d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -150,9 +150,9 @@ def test_emit_3 emits = d.emits assert_equal 2, emits.length assert_equal ["xxx", time, {"val2"=>"sed-ed value bar"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] assert_equal ["xxx", time, {"val2"=>"sed-ed value poo"}], emits[1] - assert_equal_nano_time time, emits[1][1] + assert_equal_event_time time, emits[1][1] end def test_emit_4 @@ -167,7 +167,7 @@ def test_emit_4 num_children 3 ], 'input.test') - time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + time = Fluent::EventTime.parse("2011-01-02 13:14:15") d.run do d.emit({"val1"=>"sed-ed value foo"}, time) @@ -177,9 +177,9 @@ def test_emit_4 emits = d.emits assert_equal 2, emits.length assert_equal ["output.test", time, {"val2"=>"sed-ed value bar"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] assert_equal ["output.test", time, {"val2"=>"sed-ed value poo"}], emits[1] - assert_equal_nano_time time, emits[1][1] + assert_equal_event_time time, emits[1][1] end def test_json_1 @@ -191,7 +191,7 @@ def test_json_1 tag_key tag ], 'input.test') - time = Fluent::NanoTime.parse("2011-01-02 13:14:15") + time = Fluent::EventTime.parse("2011-01-02 13:14:15") d.run do d.emit({"message"=>%[{"time":#{time},"tag":"t1","k1":"v1"}]}, time+10) @@ -200,7 +200,7 @@ def test_json_1 emits = d.emits assert_equal 1, emits.length assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] end def test_json_with_float_time @@ -213,7 +213,7 @@ def test_json_with_float_time ], 'input.test') float_time = Time.parse("2011-01-02 13:14:15").to_f - time = Fluent::NanoTime.from_time(Time.at(float_time)) + time = Fluent::EventTime.from_time(Time.at(float_time)) d.run do d.emit({"message"=>%[{"time":#{float_time},"tag":"t1","k1":"v1"}]}, time+10) @@ -222,7 +222,7 @@ def test_json_with_float_time emits = d.emits assert_equal 1, emits.length assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] end def test_json_with_time_format @@ -236,7 +236,7 @@ def test_json_with_time_format ], 'input.test') time_str = "28/Feb/2013 12:00:00.123456789 +0900" - time = Fluent::NanoTime.from_time(Time.strptime(time_str, "%d/%b/%Y %H:%M:%S.%N %z")) + time = Fluent::EventTime.from_time(Time.strptime(time_str, "%d/%b/%Y %H:%M:%S.%N %z")) d.run do d.emit({"message"=>%[{"time":"#{time_str}","tag":"t1","k1":"v1"}]}, time+10) @@ -245,7 +245,7 @@ def test_json_with_time_format emits = d.emits assert_equal 1, emits.length assert_equal ["t1", time, {"k1"=>"v1"}], emits[0] - assert_equal_nano_time time, emits[0][1] + assert_equal_event_time time, emits[0][1] end end diff --git a/test/plugin/test_out_forward.rb b/test/plugin/test_out_forward.rb index 4af3d767ba..6f957797c5 100644 --- a/test/plugin/test_out_forward.rb +++ b/test/plugin/test_out_forward.rb @@ -111,7 +111,7 @@ def test_send_with_time_as_integer d = create_driver(CONFIG + %[flush_interval 1s]) - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") records = [ {"a" => 1}, @@ -147,7 +147,7 @@ def test_send_without_time_as_integer time_as_integer false ]) - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") records = [ {"a" => 1}, @@ -168,8 +168,8 @@ def test_send_without_time_as_integer emits = target_input_driver.emits assert_equal ['test', time, records[0]], emits[0] assert_equal ['test', time, records[1]], emits[1] - assert_equal_nano_time(time, emits[0][1]) - assert_equal_nano_time(time, emits[1][1]) + assert_equal_event_time(time, emits[0][1]) + assert_equal_event_time(time, emits[1][1]) assert_equal [nil], d.instance.responses # not attempt to receive responses, so nil is returned assert_empty d.instance.exceptions diff --git a/test/plugin/test_out_stdout.rb b/test/plugin/test_out_stdout.rb index dfbfb2259b..ca5ef0a3c0 100644 --- a/test/plugin/test_out_stdout.rb +++ b/test/plugin/test_out_stdout.rb @@ -33,7 +33,7 @@ def test_configure_output_type def test_emit_json d = create_driver(CONFIG + "\noutput_type json") time = Time.now - out = capture_log { d.emit({'test' => 'test'}, Fluent::NanoTime.from_time(time)) } + out = capture_log { d.emit({'test' => 'test'}, Fluent::EventTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\":\"test\"}\n", out # NOTE: Float::NAN is not jsonable @@ -47,7 +47,7 @@ def test_emit_hash assert_equal "#{time.localtime} test: {\"test\"=>\"test\"}\n", out # NOTE: Float::NAN is not jsonable, but hash string can output it. - out = capture_log { d.emit({'test' => Float::NAN}, Fluent::NanoTime.from_time(time)) } + out = capture_log { d.emit({'test' => Float::NAN}, Fluent::EventTime.from_time(time)) } assert_equal "#{time.localtime} test: {\"test\"=>NaN}\n", out end diff --git a/test/plugin/test_out_stream.rb b/test/plugin/test_out_stream.rb index 144f40bea7..b105411a5c 100644 --- a/test/plugin/test_out_stream.rb +++ b/test/plugin/test_out_stream.rb @@ -22,10 +22,10 @@ def test_write assert_equal(expect, result) end - def test_write_nano_time + def test_write_event_time d = create_driver - time = Fluent::NanoTime.parse("2011-01-02 13:14:15 UTC") + time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") d.emit({"a"=>1}, time) d.emit({"a"=>2}, time) diff --git a/test/test_event.rb b/test/test_event.rb index 9fd27c6918..e7489c2d4d 100644 --- a/test/test_event.rb +++ b/test/test_event.rb @@ -43,7 +43,7 @@ class ArrayEventStreamTest < ::Test::Unit::TestCase def setup time = Engine.now - @times = [Fluent::NanoTime.new(time.sec), Fluent::NanoTime.new(time.sec + 1)] + @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = ArrayEventStream.new(@times.zip(@records)) end @@ -88,7 +88,7 @@ class MultiEventStreamTest < ::Test::Unit::TestCase def setup time = Engine.now - @times = [Fluent::NanoTime.new(time.sec), Fluent::NanoTime.new(time.sec + 1)] + @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @es = MultiEventStream.new @times.zip(@records).each { |time, record| @@ -137,7 +137,7 @@ class MessagePackEventStreamTest < ::Test::Unit::TestCase def setup pk = Fluent::Engine.msgpack_factory.packer time = Engine.now - @times = [Fluent::NanoTime.new(time.sec), Fluent::NanoTime.new(time.sec + 1)] + @times = [Fluent::EventTime.new(time.sec), Fluent::EventTime.new(time.sec + 1)] @records = [{'k' => 'v1', 'n' => 1}, {'k' => 'v2', 'n' => 2}] @times.zip(@records).each { |time, record| pk.write([time, record]) diff --git a/test/test_event_time.rb b/test/test_event_time.rb new file mode 100644 index 0000000000..9dee908a6d --- /dev/null +++ b/test/test_event_time.rb @@ -0,0 +1,157 @@ +require_relative 'helper' +require 'timecop' + +class EventTimeTest < Test::Unit::TestCase + setup do + @now = Time.now + Timecop.freeze(@now) + end + + teardown do + Timecop.return + end + + test '#sec' do + assert_equal(1, Fluent::EventTime.new(1, 2).sec) + end + + test '#nsec' do + assert_equal(2, Fluent::EventTime.new(1, 2).nsec) + assert_equal(0, Fluent::EventTime.new(1).nsec) + end + + test '#to_int' do + assert_equal(1, Fluent::EventTime.new(1, 2).to_int) + end + + test '#to_r' do + assert_equal(Rational(1_000_000_002, 1_000_000_000), Fluent::EventTime.new(1, 2).to_r) + end + + test '#to_s' do + time = Fluent::EventTime.new(100) + assert_equal('100', time.to_s) + assert_equal('100', "#{time}") + end + + test '.from_time' do + sec = 1000 + usec = 2 + time = Fluent::EventTime.from_time(Time.at(sec, usec)) + assert_equal(time.sec, sec) + assert_equal(time.nsec, usec * 1000) + end + + test 'now' do + assert_equal(@now.to_i, Fluent::EventTime.now.sec) + assert_equal(@now.nsec, Fluent::EventTime.now.nsec) + end + + test 'parse' do + assert_equal(Time.parse("2011-01-02 13:14:15").to_i, Fluent::EventTime.parse("2011-01-02 13:14:15").sec) + assert_equal(Time.parse("2011-01-02 13:14:15").nsec, Fluent::EventTime.parse("2011-01-02 13:14:15").nsec) + end + + test 'eq?' do + assert(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(1, 2))) + refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(1, 3))) + refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(3, 2))) + refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), Fluent::EventTime.new(3, 4))) + + assert(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), 1)) + refute(Fluent::EventTime.eq?(Fluent::EventTime.new(1, 2), 2)) + + assert(Fluent::EventTime.eq?(1, Fluent::EventTime.new(1, 2))) + refute(Fluent::EventTime.eq?(2, Fluent::EventTime.new(1, 2))) + end + + test '==' do + assert(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(1, 2)) + assert(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(1, 3)) + refute(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(3, 2)) + refute(Fluent::EventTime.new(1, 2) == Fluent::EventTime.new(3, 4)) + + assert(Fluent::EventTime.new(1, 2) == 1) + refute(Fluent::EventTime.new(1, 2) == 2) + + assert(1 == Fluent::EventTime.new(1, 2)) + refute(2 == Fluent::EventTime.new(1, 2)) + end + + test '+' do + assert_equal(4, Fluent::EventTime.new(1, 2) + Fluent::EventTime.new(3, 4)) + assert_equal(6, Fluent::EventTime.new(1, 2) + 5) + assert_equal(6, 5 + Fluent::EventTime.new(1, 2)) + end + + test '-' do + assert_equal(-2, Fluent::EventTime.new(1, 2) - Fluent::EventTime.new(3, 4)) + assert_equal(-4, Fluent::EventTime.new(1, 2) - 5) + assert_equal(4, 5 - Fluent::EventTime.new(1, 2)) + end + + test '>' do + assert(Fluent::EventTime.new(2) > Fluent::EventTime.new(1)) + refute(Fluent::EventTime.new(1) > Fluent::EventTime.new(1)) + refute(Fluent::EventTime.new(1) > Fluent::EventTime.new(2)) + + assert(Fluent::EventTime.new(2) > 1) + refute(Fluent::EventTime.new(1) > 1) + refute(Fluent::EventTime.new(1) > 2) + + assert(2 > Fluent::EventTime.new(1)) + refute(1 > Fluent::EventTime.new(1)) + refute(1 > Fluent::EventTime.new(2)) + end + + test '>=' do + assert(Fluent::EventTime.new(2) >= Fluent::EventTime.new(1)) + assert(Fluent::EventTime.new(1) >= Fluent::EventTime.new(1)) + refute(Fluent::EventTime.new(1) >= Fluent::EventTime.new(2)) + + assert(Fluent::EventTime.new(2) >= 1) + assert(Fluent::EventTime.new(1) >= 1) + refute(Fluent::EventTime.new(1) >= 2) + + assert(2 >= Fluent::EventTime.new(1)) + assert(1 >= Fluent::EventTime.new(1)) + refute(1 >= Fluent::EventTime.new(2)) + end + + test '<' do + assert(Fluent::EventTime.new(1) < Fluent::EventTime.new(2)) + refute(Fluent::EventTime.new(1) < Fluent::EventTime.new(1)) + refute(Fluent::EventTime.new(2) < Fluent::EventTime.new(1)) + + assert(Fluent::EventTime.new(1) < 2) + refute(Fluent::EventTime.new(1) < 1) + refute(Fluent::EventTime.new(2) < 1) + + assert(1 < Fluent::EventTime.new(2)) + refute(1 < Fluent::EventTime.new(1)) + refute(2 < Fluent::EventTime.new(1)) + end + + test '=<' do + assert(Fluent::EventTime.new(1) <= Fluent::EventTime.new(2)) + assert(Fluent::EventTime.new(1) <= Fluent::EventTime.new(1)) + refute(Fluent::EventTime.new(2) <= Fluent::EventTime.new(1)) + + assert(Fluent::EventTime.new(1) <= 2) + assert(Fluent::EventTime.new(1) <= 1) + refute(Fluent::EventTime.new(2) <= 1) + + assert(1 <= Fluent::EventTime.new(2)) + assert(1 <= Fluent::EventTime.new(1)) + refute(2 <= Fluent::EventTime.new(1)) + end + + test 'Time.at' do + sec = 1000 + nsec = 2000 + ntime = Fluent::EventTime.new(sec, nsec) + time = Time.at(ntime) + assert_equal(sec, time.to_i) + assert_equal(nsec, time.nsec) + end +end diff --git a/test/test_formatter.rb b/test/test_formatter.rb index da80d43dc0..e77a5636cc 100644 --- a/test/test_formatter.rb +++ b/test/test_formatter.rb @@ -565,7 +565,7 @@ def test_specific_localtime_timezone end def test_format_with_subsec - time = Fluent::NanoTime.new(@time) + time = Fluent::EventTime.new(@time) formatter = Fluent::TimeFormatter.new("%Y%m%d %H%M.%N", false, nil) assert_equal("20140927 0000.000000000", formatter.format(time)) end diff --git a/test/test_nano_time.rb b/test/test_nano_time.rb deleted file mode 100644 index 94b5139ef1..0000000000 --- a/test/test_nano_time.rb +++ /dev/null @@ -1,157 +0,0 @@ -require_relative 'helper' -require 'timecop' - -class NanoTimeTest < Test::Unit::TestCase - setup do - @now = Time.now - Timecop.freeze(@now) - end - - teardown do - Timecop.return - end - - test '#sec' do - assert_equal(1, Fluent::NanoTime.new(1, 2).sec) - end - - test '#nsec' do - assert_equal(2, Fluent::NanoTime.new(1, 2).nsec) - assert_equal(0, Fluent::NanoTime.new(1).nsec) - end - - test '#to_int' do - assert_equal(1, Fluent::NanoTime.new(1, 2).to_int) - end - - test '#to_r' do - assert_equal(Rational(1_000_000_002, 1_000_000_000), Fluent::NanoTime.new(1, 2).to_r) - end - - test '#to_s' do - time = Fluent::NanoTime.new(100) - assert_equal('100', time.to_s) - assert_equal('100', "#{time}") - end - - test '.from_time' do - sec = 1000 - usec = 2 - time = Fluent::NanoTime.from_time(Time.at(sec, usec)) - assert_equal(time.sec, sec) - assert_equal(time.nsec, usec * 1000) - end - - test 'now' do - assert_equal(@now.to_i, Fluent::NanoTime.now.sec) - assert_equal(@now.nsec, Fluent::NanoTime.now.nsec) - end - - test 'parse' do - assert_equal(Time.parse("2011-01-02 13:14:15").to_i, Fluent::NanoTime.parse("2011-01-02 13:14:15").sec) - assert_equal(Time.parse("2011-01-02 13:14:15").nsec, Fluent::NanoTime.parse("2011-01-02 13:14:15").nsec) - end - - test 'eq?' do - assert(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 2))) - refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(1, 3))) - refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(3, 2))) - refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), Fluent::NanoTime.new(3, 4))) - - assert(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), 1)) - refute(Fluent::NanoTime.eq?(Fluent::NanoTime.new(1, 2), 2)) - - assert(Fluent::NanoTime.eq?(1, Fluent::NanoTime.new(1, 2))) - refute(Fluent::NanoTime.eq?(2, Fluent::NanoTime.new(1, 2))) - end - - test '==' do - assert(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(1, 2)) - assert(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(1, 3)) - refute(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(3, 2)) - refute(Fluent::NanoTime.new(1, 2) == Fluent::NanoTime.new(3, 4)) - - assert(Fluent::NanoTime.new(1, 2) == 1) - refute(Fluent::NanoTime.new(1, 2) == 2) - - assert(1 == Fluent::NanoTime.new(1, 2)) - refute(2 == Fluent::NanoTime.new(1, 2)) - end - - test '+' do - assert_equal(4, Fluent::NanoTime.new(1, 2) + Fluent::NanoTime.new(3, 4)) - assert_equal(6, Fluent::NanoTime.new(1, 2) + 5) - assert_equal(6, 5 + Fluent::NanoTime.new(1, 2)) - end - - test '-' do - assert_equal(-2, Fluent::NanoTime.new(1, 2) - Fluent::NanoTime.new(3, 4)) - assert_equal(-4, Fluent::NanoTime.new(1, 2) - 5) - assert_equal(4, 5 - Fluent::NanoTime.new(1, 2)) - end - - test '>' do - assert(Fluent::NanoTime.new(2) > Fluent::NanoTime.new(1)) - refute(Fluent::NanoTime.new(1) > Fluent::NanoTime.new(1)) - refute(Fluent::NanoTime.new(1) > Fluent::NanoTime.new(2)) - - assert(Fluent::NanoTime.new(2) > 1) - refute(Fluent::NanoTime.new(1) > 1) - refute(Fluent::NanoTime.new(1) > 2) - - assert(2 > Fluent::NanoTime.new(1)) - refute(1 > Fluent::NanoTime.new(1)) - refute(1 > Fluent::NanoTime.new(2)) - end - - test '>=' do - assert(Fluent::NanoTime.new(2) >= Fluent::NanoTime.new(1)) - assert(Fluent::NanoTime.new(1) >= Fluent::NanoTime.new(1)) - refute(Fluent::NanoTime.new(1) >= Fluent::NanoTime.new(2)) - - assert(Fluent::NanoTime.new(2) >= 1) - assert(Fluent::NanoTime.new(1) >= 1) - refute(Fluent::NanoTime.new(1) >= 2) - - assert(2 >= Fluent::NanoTime.new(1)) - assert(1 >= Fluent::NanoTime.new(1)) - refute(1 >= Fluent::NanoTime.new(2)) - end - - test '<' do - assert(Fluent::NanoTime.new(1) < Fluent::NanoTime.new(2)) - refute(Fluent::NanoTime.new(1) < Fluent::NanoTime.new(1)) - refute(Fluent::NanoTime.new(2) < Fluent::NanoTime.new(1)) - - assert(Fluent::NanoTime.new(1) < 2) - refute(Fluent::NanoTime.new(1) < 1) - refute(Fluent::NanoTime.new(2) < 1) - - assert(1 < Fluent::NanoTime.new(2)) - refute(1 < Fluent::NanoTime.new(1)) - refute(2 < Fluent::NanoTime.new(1)) - end - - test '=<' do - assert(Fluent::NanoTime.new(1) <= Fluent::NanoTime.new(2)) - assert(Fluent::NanoTime.new(1) <= Fluent::NanoTime.new(1)) - refute(Fluent::NanoTime.new(2) <= Fluent::NanoTime.new(1)) - - assert(Fluent::NanoTime.new(1) <= 2) - assert(Fluent::NanoTime.new(1) <= 1) - refute(Fluent::NanoTime.new(2) <= 1) - - assert(1 <= Fluent::NanoTime.new(2)) - assert(1 <= Fluent::NanoTime.new(1)) - refute(2 <= Fluent::NanoTime.new(1)) - end - - test 'Time.at' do - sec = 1000 - nsec = 2000 - ntime = Fluent::NanoTime.new(sec, nsec) - time = Time.at(ntime) - assert_equal(sec, time.to_i) - assert_equal(nsec, time.nsec) - end -end diff --git a/test/test_parser.rb b/test/test_parser.rb index 593c579b47..9e252f0a5b 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -11,9 +11,9 @@ def setup def str2time(str_time, format = nil) if format - Fluent::NanoTime.from_time(Time.strptime(str_time, format)) + Fluent::EventTime.from_time(Time.strptime(str_time, format)) else - Fluent::NanoTime.parse(str_time) + Fluent::EventTime.parse(str_time) end end @@ -49,7 +49,7 @@ class TimeParserTest < ::Test::Unit::TestCase def test_call_with_parse parser = TextParser::TimeParser.new(nil) - assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::NanoTime)) + assert(parser.parse('2013-09-18 12:00:00 +0900').is_a?(Fluent::EventTime)) time = str2time('2013-09-18 12:00:00 +0900') assert_equal(time, parser.parse('2013-09-18 12:00:00 +0900')) @@ -58,7 +58,7 @@ def test_call_with_parse def test_parse_with_strptime parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S %z') - assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::NanoTime)) + assert(parser.parse('28/Feb/2013:12:00:00 +0900').is_a?(Fluent::EventTime)) time = str2time('28/Feb/2013:12:00:00 +0900', '%d/%b/%Y:%H:%M:%S %z') assert_equal(time, parser.parse('28/Feb/2013:12:00:00 +0900')) @@ -67,10 +67,10 @@ def test_parse_with_strptime def test_parse_nsec_with_strptime parser = TextParser::TimeParser.new('%d/%b/%Y:%H:%M:%S:%N %z') - assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::NanoTime)) + assert(parser.parse('28/Feb/2013:12:00:00:123456789 +0900').is_a?(Fluent::EventTime)) time = str2time('28/Feb/2013:12:00:00:123456789 +0900', '%d/%b/%Y:%H:%M:%S:%N %z') - assert_equal_nano_time(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) + assert_equal_event_time(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900')) end def test_parse_with_invalid_argument @@ -130,7 +130,7 @@ def test_parse_with_time_key ) text = '2013-02-28 12:00:00 +0900' parser.parse(text) do |time, record| - assert_equal Fluent::NanoTime.parse(text), time + assert_equal Fluent::EventTime.parse(text), time end end From 9f78bcc29f7d0c1c5779ef63963c040e0e2aacc4 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 3 Sep 2015 13:05:14 +0900 Subject: [PATCH 56/63] Fix comment --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1df2a4e281..ecf25791b9 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org/' gemspec -# These gems will move to gemspec when they is released. +# These gems will move to gemspec when they are released. gem 'msgpack', github: 'msgpack/msgpack-ruby' gem 'strptime', github: 'nurse/strptime' From a18a3cb4ad7a49c5f8e70474e67a85e87d40bf1d Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 4 Sep 2015 11:23:52 +0900 Subject: [PATCH 57/63] Remove 1.9.3 from .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dcfa243458..85e250f485 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: ruby rvm: - - 1.9.3 - 2.0.0 - 2.1 - 2.2 From 4647c99bfa9d1211115c58ceb90a1c75ed373d26 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 18 Sep 2015 12:46:12 +0900 Subject: [PATCH 58/63] Use released gems --- Gemfile | 4 ---- fluentd.gemspec | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index ecf25791b9..88ae4bc4e3 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,6 @@ source 'https://rubygems.org/' gemspec -# These gems will move to gemspec when they are released. -gem 'msgpack', github: 'msgpack/msgpack-ruby' -gem 'strptime', github: 'nurse/strptime' - local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") if File.exist?(local_gemfile) puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v` diff --git a/fluentd.gemspec b/fluentd.gemspec index e9aec372c5..6a21bf9dd3 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 1.9.3' - #gem.add_runtime_dependency("msgpack", [">= 0.5.11", "< 0.6.0"]) + gem.add_runtime_dependency("msgpack", [">= 0.7.0dev1"]) gem.add_runtime_dependency("json", [">= 1.4.3"]) gem.add_runtime_dependency("yajl-ruby", ["~> 1.0"]) gem.add_runtime_dependency("cool.io", [">= 1.4.1", "< 2.0.0"]) @@ -34,6 +34,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency("win32-event", ["~> 0.6.1"]) gem.add_runtime_dependency("windows-pr", ["~> 1.2.3"]) end + gem.add_runtime_dependency("strptime", [">= 0.1.0"]) gem.add_development_dependency("rake", [">= 0.9.2"]) gem.add_development_dependency("flexmock", ["~> 1.3.3"]) From f185cb1d969057682a977fdea1d0721ebec51206 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 18 Sep 2015 12:47:00 +0900 Subject: [PATCH 59/63] Use flexmock 2.0.0 or later --- fluentd.gemspec | 2 +- test/plugin/test_filter_stdout.rb | 2 +- test/plugin/test_in_tail.rb | 2 +- test/test_output.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fluentd.gemspec b/fluentd.gemspec index 6a21bf9dd3..0ea0d2fa5e 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency("strptime", [">= 0.1.0"]) gem.add_development_dependency("rake", [">= 0.9.2"]) - gem.add_development_dependency("flexmock", ["~> 1.3.3"]) + gem.add_development_dependency("flexmock", [">= 2.0.0"]) gem.add_development_dependency("parallel_tests", [">= 0.15.3"]) gem.add_development_dependency("simplecov", ["~> 0.6.4"]) gem.add_development_dependency("rr", [">= 1.0.0"]) diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 32cc8b005f..95880b193f 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -1,7 +1,7 @@ require_relative '../helper' require 'fluent/plugin/filter_stdout' require 'timecop' -require 'flexmock' +require 'flexmock/test_unit' class StdoutFilterTest < Test::Unit::TestCase include Fluent diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index fe2736f533..0685f30186 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -1,7 +1,7 @@ require_relative '../helper' require 'fluent/test' require 'net/http' -require 'flexmock' +require 'flexmock/test_unit' class TailInputTest < Test::Unit::TestCase include FlexMock::TestCase diff --git a/test/test_output.rb b/test/test_output.rb index 6066b5bc81..e60be0132d 100644 --- a/test/test_output.rb +++ b/test/test_output.rb @@ -2,7 +2,7 @@ require 'fluent/test' require 'fluent/output' require 'timecop' -require 'flexmock' +require 'flexmock/test_unit' module FluentOutputTest include Fluent From a1025d310a1a985e68e167a60c992f922356fa18 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 8 Oct 2015 15:38:05 +0900 Subject: [PATCH 60/63] Revert "Use flexmock 2.0.0 or later" This reverts commit f185cb1d969057682a977fdea1d0721ebec51206. --- fluentd.gemspec | 2 +- test/plugin/test_filter_stdout.rb | 2 +- test/plugin/test_in_tail.rb | 2 +- test/test_output.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fluentd.gemspec b/fluentd.gemspec index 0ea0d2fa5e..6a21bf9dd3 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency("strptime", [">= 0.1.0"]) gem.add_development_dependency("rake", [">= 0.9.2"]) - gem.add_development_dependency("flexmock", [">= 2.0.0"]) + gem.add_development_dependency("flexmock", ["~> 1.3.3"]) gem.add_development_dependency("parallel_tests", [">= 0.15.3"]) gem.add_development_dependency("simplecov", ["~> 0.6.4"]) gem.add_development_dependency("rr", [">= 1.0.0"]) diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 95880b193f..32cc8b005f 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -1,7 +1,7 @@ require_relative '../helper' require 'fluent/plugin/filter_stdout' require 'timecop' -require 'flexmock/test_unit' +require 'flexmock' class StdoutFilterTest < Test::Unit::TestCase include Fluent diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index 0685f30186..fe2736f533 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -1,7 +1,7 @@ require_relative '../helper' require 'fluent/test' require 'net/http' -require 'flexmock/test_unit' +require 'flexmock' class TailInputTest < Test::Unit::TestCase include FlexMock::TestCase diff --git a/test/test_output.rb b/test/test_output.rb index e60be0132d..6066b5bc81 100644 --- a/test/test_output.rb +++ b/test/test_output.rb @@ -2,7 +2,7 @@ require 'fluent/test' require 'fluent/output' require 'timecop' -require 'flexmock/test_unit' +require 'flexmock' module FluentOutputTest include Fluent From e991f7639a2c0f5796db2acc00cabc5fffa2beef Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Thu, 8 Oct 2015 23:57:52 +0900 Subject: [PATCH 61/63] Update strptime version to 0.1.2 --- fluentd.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluentd.gemspec b/fluentd.gemspec index 6a21bf9dd3..379cc76090 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency("win32-event", ["~> 0.6.1"]) gem.add_runtime_dependency("windows-pr", ["~> 1.2.3"]) end - gem.add_runtime_dependency("strptime", [">= 0.1.0"]) + gem.add_runtime_dependency("strptime", [">= 0.1.2"]) gem.add_development_dependency("rake", [">= 0.9.2"]) gem.add_development_dependency("flexmock", ["~> 1.3.3"]) From 3fc0430c5241dbf05ed2fc46b5b25554290c65d8 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Fri, 9 Oct 2015 15:09:29 +0900 Subject: [PATCH 62/63] Update strptime version to 0.1.3 --- fluentd.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluentd.gemspec b/fluentd.gemspec index 379cc76090..a5fc11c66b 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency("win32-event", ["~> 0.6.1"]) gem.add_runtime_dependency("windows-pr", ["~> 1.2.3"]) end - gem.add_runtime_dependency("strptime", [">= 0.1.2"]) + gem.add_runtime_dependency("strptime", [">= 0.1.3"]) gem.add_development_dependency("rake", [">= 0.9.2"]) gem.add_development_dependency("flexmock", ["~> 1.3.3"]) From 1817567355c3c5b53c8eedb7179cc6b80aed598f Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Sat, 24 Oct 2015 21:09:55 +0900 Subject: [PATCH 63/63] Update msgpack to 0.7.0 --- fluentd.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluentd.gemspec b/fluentd.gemspec index a5fc11c66b..b0bc9928fb 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 1.9.3' - gem.add_runtime_dependency("msgpack", [">= 0.7.0dev1"]) + gem.add_runtime_dependency("msgpack", [">= 0.7.0"]) gem.add_runtime_dependency("json", [">= 1.4.3"]) gem.add_runtime_dependency("yajl-ruby", ["~> 1.0"]) gem.add_runtime_dependency("cool.io", [">= 1.4.1", "< 2.0.0"])