spec/onstomp/failover/client_spec.rb in onstomp-1.0.8 vs spec/onstomp/failover/client_spec.rb in onstomp-1.0.9
- old
+ new
@@ -1,34 +1,63 @@
# -*- encoding: utf-8 -*-
require 'spec_helper'
module OnStomp::Failover
describe Client, :failover => true do
+ let(:client_options) { Hash.new }
let(:active_client) {
mock('active client').tap do |m|
m.extend OnStomp::Interfaces::ClientEvents
end
}
let(:client) {
Client.new('failover:(stomp:///,stomp+ssl:///)').tap do |c|
c.stub(:active_client => active_client)
end
}
+
+ class DummyBuffer
+ def initialize *args
+ end
+ end
+
describe "initialize" do
it "should be initialized by string" do
c = Client.new('failover:(stomp:///,stomp+ssl:///)')
c.uri.to_s.should == 'failover:(stomp:///,stomp+ssl:///)'
c.hosts.should == ['stomp:///', 'stomp+ssl:///']
end
+
it "should be initialized by array" do
real_client = OnStomp::Client.new('stomp+ssl:///')
c = Client.new(['stomp:///', real_client])
c.uri.to_s.should == 'failover:()'
c.hosts.should == ['stomp:///', real_client]
end
+
+ it 'passes other options on to the client pool' do
+ # We really only need to verify that the failover client is passing
+ # the appropriate hash to the pool, because we have a spec that ensures
+ # the pool is passing the options hash on to the underlying clients.
+ # However, even performing this simple test requires an impressive
+ # amount of legwork. This design is far too muddy.
+
+ m_client = mock('client', on_connection_closed: "ignore me!")
+ Pools::Base.should_receive(:new).with([ 'stomp:///', 'stomp+ssl:///' ], {
+ ssl: { ca_file: 'ca.crt' },
+ login: 'user_name'
+ }).and_return([ m_client ])
+
+ c = Client.new('failover:(stomp:///,stomp+ssl:///)', {
+ buffer: 'OnStomp::Failover::DummyBuffer',
+ retry_attempts: 2,
+ ssl: { ca_file: 'ca.crt' },
+ login: 'user_name'
+ })
+ end
end
-
+
describe ".connected?" do
it "should be connected if it has an active client that's connected" do
active_client.stub(:connected? => true)
client.connected?.should be_true
end
@@ -79,10 +108,10 @@
}
before(:each) do
# Get the hooks installed on our mocks
active_client.stub(:connection => connection)
client.stub(:client_pool => client_pool)
- client.__send__ :create_client_pool, []
+ client.__send__ :create_client_pool, [], {}
end
it "should do nothing special if there is no active client" do
client.stub(:active_client => nil)
client.disconnect
end