Sha256: 43371116541795fbfabb402bd4d1b83ed13874d0b4084c3f095e37c737cb472f

Contents?: true

Size: 1.76 KB

Versions: 14

Compression:

Stored size: 1.76 KB

Contents

# encoding: utf-8
require "flores/random"

shared_examples "send events" do
  it "successfully send the events" do
    wait(20).for { queue.size }.to eq(number_of_events), "Expected: #{number_of_events} got: #{queue.size}, execution output:\n #{@execution_output}" 
    expect(queue.collect { |e| e.get("message") }).to eq(events)
  end
end

shared_examples "doesn't send events" do
  it "doesn't send any events" do
    expect(queue.size).to eq(0), "Expected: #{number_of_events} got: #{queue.size}, execution output:\n #{@execution_output}"
  end
end

shared_context "beats configuration" do
  # common
  let(:port) { Flores::Random.port }
  let(:host) { "localhost" }

  let(:queue) { [] }
  let_tmp_file(:log_file) { events.join("\n") + "\n" } # make sure we end of line
  let(:number_of_events) { 5 }
  let(:event) { "Hello world" }
  let(:events) do
    events = []
    number_of_events.times { |n| events << "#{event} #{n}" }
    events
  end

  let(:input_config) do
    {
      "host" => host,
      "port" => port
    }
  end

  let(:beats) do
    LogStash::Inputs::Beats.new(input_config)
  end

  before :each do
    beats.register

    @abort_on_exception = Thread.abort_on_exception
    Thread.abort_on_exception = true

    @server = Thread.new do
      begin
        # use to know what lumberjack is actually doing
        if ENV["DEBUG"]
          logger = Logger.new(STDOUT)
          beats.logger = Cabin::Channel.new
          beats.logger.subscribe(logger)
          beats.logger.level = :debug
        end

        beats.run(queue)
      rescue => e
        retry unless beats.stop?
      end
    end
    @server.abort_on_exception = true

    sleep(1) while @server.status != "run"
  end

  after(:each) do
    beats.stop
    Thread.abort_on_exception = @abort_on_exception
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
logstash-input-beats-3.1.5-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.4-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.3-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.2-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.1-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.0-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.0.beta4-java spec/support/integration_shared_context.rb
logstash-input-beats-3.1.0.beta3-java spec/support/integration_shared_context.rb
logstash-input-beats-3.0.4 spec/support/integration_shared_context.rb
logstash-input-beats-3.1.0.beta1-java spec/support/integration_shared_context.rb
logstash-input-beats-3.0.3 spec/support/integration_shared_context.rb
logstash-input-beats-3.0.2 spec/support/integration_shared_context.rb
logstash-input-beats-3.0.1 spec/support/integration_shared_context.rb
logstash-input-beats-3.0.0 spec/support/integration_shared_context.rb