Sha256: ac23b874e56c7eafe4e754415ae871c204bc5592484ff293b4fe606793a2b1ba

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
require_relative "../spec_helper"
require "logstash/outputs/statsd"

describe LogStash::Outputs::Statsd do

  let(:host)   { "localhost" }
  let(:port)   { rand(2000..10000) }
  let!(:server) { StatsdServer.new.run(port) }

  after(:each) do
    server.close
  end

  describe "registration and close" do

    it "should register without errors" do
      output = LogStash::Plugin.lookup("output", "statsd").new
      expect {output.register}.to_not raise_error
    end

  end

  describe "#send" do

    context "count metrics" do

      let(:config) do
        { "host" => host, "sender" => "spec", "port" => port, "count" => [ "foo.bar", "0.1" ] }
      end

      let(:properties) do
        { "metric" => "foo.bar", "count" => 10 }
      end

      let(:event) { LogStash::Event.new(properties) }

      subject { LogStash::Outputs::Statsd.new(config) }

      before(:each) do
        subject.register
      end

      it "should receive data send to the server" do
        subject.receive(event)
        # Since we are dealing with threads and networks, 
        # we might experience delays or timing issues.
        # lets try a few times before giving up completely.
        try {
          expect(server.received).to include("logstash.spec.foo.bar:0.1|c")
        }
      end

    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
logstash-output-statsd-3.1.5 spec/outputs/statsd_spec.rb
logstash-output-statsd-3.1.4 spec/outputs/statsd_spec.rb
logstash-output-statsd-3.1.3 spec/outputs/statsd_spec.rb
logstash-output-statsd-3.1.2 spec/outputs/statsd_spec.rb