Sha256: a32c467259cd583e6de808a47f1ed3cbb2cac76f10b7df7e6d3e83505f46ca01

Contents?: true

Size: 1.82 KB

Versions: 8

Compression:

Stored size: 1.82 KB

Contents

#
# Fluent
#
# Copyright (C) 2011 FURUHASHI Sadayuki
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
module Fluent
module Test


class TestOutputChain
  def initialize
    @called = 0
  end

  def next
    @called += 1
  end

  attr_reader :called
end


class OutputTestDriver < InputTestDriver
  def initialize(klass, tag='test', &block)
    super(klass, &block)
    @tag = tag
  end

  attr_accessor :tag

  def emit(record, time=Time.now)
    es = OneEventStream.new(time.to_i, record)
    chain = TestOutputChain.new
    @instance.emit(@tag, es, chain)
    assert_equal 1, chain.called
  end
end


class BufferedOutputTestDriver < InputTestDriver
  def initialize(klass, tag='test', &block)
    super(klass, &block)
    @entries = []
    @expected_buffer = nil
    @tag = tag
  end

  attr_accessor :tag

  def emit(record, time=Time.now)
    @entries << [time.to_i, record]
    self
  end

  def expect_format(str)
    (@expected_buffer ||= '') << str
  end

  def run(&block)
    result = nil
    super {
      es = ArrayEventStream.new(@entries)
      buffer = @instance.format_stream(@tag, es)

      block.call if block

      if @expected_buffer
        assert_equal(@expected_buffer, buffer)
      end

      chunk = MemoryBufferChunk.new('', buffer)
      result = @instance.write(chunk)
    }
    result
  end
end


end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fluentd-0.10.7 lib/fluent/test/output_test.rb
fluentd-0.10.6 lib/fluent/test/output_test.rb
fluentd-0.10.5 lib/fluent/test/output_test.rb
fluentd-0.10.4 lib/fluent/test/output_test.rb
fluentd-0.10.3 lib/fluent/test/output_test.rb
fluentd-0.10.2 lib/fluent/test/output_test.rb
fluentd-0.10.1 lib/fluent/test/output_test.rb
fluentd-0.10.0 lib/fluent/test/output_test.rb