Sha256: 4d77d01a983f5b1a4ad74f1d8b0739388ab73d5594c251977996db64610afdc1

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/ganglia"
require_relative "support/client"

module GangliaHelpers

  def setup_clients(number_of_clients, port)
    number_of_clients.times.inject([]) do |clients|
      clients << GangliaClient.new(localhost, port)
    end
  end

  def input(config, size, &block)
    pipeline = LogStash::Pipeline.new(config)
    queue = Queue.new

    pipeline.instance_eval do
      # create closure to capture queue
      @output_func = lambda { |event| queue << event }

      # output_func is now a method, call closure
      def output_func(event)
        @output_func.call(event)
      end
    end

    pipeline_thread = Thread.new { pipeline.run }
    sleep 0.1 while !pipeline.ready?

    block.call
    sleep 0.1 while queue.size != size

    result = size.times.inject([]) do |acc|
      acc << queue.pop
    end

    pipeline.shutdown
    pipeline_thread.join

    result
  end # def input

end

RSpec.configure do |c|
  c.include GangliaHelpers
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logstash-input-ganglia-2.0.2 spec/spec_helper.rb
logstash-input-ganglia-2.0.1 spec/spec_helper.rb