1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# frozen_string_literal: true
require 'riemann'
require 'riemann/client'
require 'spec_helper'
require 'shared_examples'
RSpec.describe 'Riemann::Client' do
let(:client) do
Riemann::Client.new(host: 'localhost', port: 5555)
end
let(:expected_rate) { 100 }
context('with TLS transport') do
let(:client) do
Riemann::Client.new(host: 'localhost', port: 5554, ssl: true,
key_file: '/etc/riemann/riemann_server.pkcs8',
cert_file: '/etc/riemann/riemann_server.crt',
ca_file: '/etc/riemann/riemann_server.crt',
ssl_verify: true)
end
let(:client_with_transport) { client.tcp }
it_behaves_like 'a riemann client'
it_behaves_like 'a riemann client that acknowledge messages'
end
context 'with TCP transport' do
let(:client_with_transport) { client.tcp }
it_behaves_like 'a riemann client'
it_behaves_like 'a riemann client that acknowledge messages'
end
context('with UDP transport') do
let(:client_with_transport) { client.udp }
let(:expected_rate) { 1000 }
it_behaves_like 'a riemann client'
it_behaves_like 'a riemann client that does not acknowledge messages'
context 'when sending a message too large for UDP transport' do
let(:large_message) do
{
data: 'X' * (Riemann::Client::UDP::MAX_SIZE + 10)
}
end
before do
allow(client.udp).to receive(:send_maybe_recv).and_call_original
allow(client.tcp).to receive(:send_maybe_recv).and_call_original
client << large_message
end
it 'has tried to send the message using UDP' do
expect(client.udp).to have_received(:send_maybe_recv)
end
it 'has retried to send the message using TCP' do
expect(client.tcp).to have_received(:send_maybe_recv)
end
end
end
end
|