spec/outputs/statsd_spec.rb in logstash-output-statsd-3.1.5 vs spec/outputs/statsd_spec.rb in logstash-output-statsd-3.2.0
- old
+ new
@@ -1,57 +1,60 @@
# encoding: utf-8
require_relative "../spec_helper"
require "logstash/outputs/statsd"
+require "socket"
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
+ describe "IO" do
+ let(:host) { "localhost" }
+ let(:port) { rand(2000..10000) }
+ let!(:server) { StatsdServer.new.run(port, protocol) }
- context "count metrics" do
+ after(:each) { server.close }
+ shared_examples "it receives sent data" do
let(:config) do
- { "host" => host, "sender" => "spec", "port" => port, "count" => [ "foo.bar", "0.1" ] }
+ { "host" => host, "sender" => "spec", "port" => port, "protocol" => protocol, "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
+ before(:each) { subject.register }
it "should receive data send to the server" do
subject.receive(event)
- # Since we are dealing with threads and networks,
+ # 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")
- }
+ try { expect(server.received).to include("logstash.spec.foo.bar:0.1|c") }
end
+ end
+ describe "UDP" do
+ let(:protocol) { "udp" }
+
+ context "#send" do
+ include_examples "it receives sent data"
+ end
end
- end
+ describe "TCP" do
+ let(:protocol) { "tcp" }
+
+ context "#send" do
+ include_examples "it receives sent data"
+ end
+ end
+ end
end