use of com.rabbitmq.client.Address in project rabbitmq-java-client by rabbitmq.
the class DnsSrvRecordAddressResolverTest method recordsParsedAndSorted.
@Test
public void recordsParsedAndSorted() throws IOException {
DnsSrvRecordAddressResolver resolver = new DnsSrvRecordAddressResolver("rabbitmq") {
@Override
protected List<SrvRecord> lookupSrvRecords(String service, String dnsUrls) throws IOException {
return Arrays.asList(DnsSrvRecordAddressResolver.SrvRecord.fromSrvQueryResult("20 0 5269 alt2.xmpp-server.l.google.com."), DnsSrvRecordAddressResolver.SrvRecord.fromSrvQueryResult("30 0 5269 alt3.xmpp-server.l.google.com."), DnsSrvRecordAddressResolver.SrvRecord.fromSrvQueryResult("10 0 5269 alt1.xmpp-server.l.google.com."), DnsSrvRecordAddressResolver.SrvRecord.fromSrvQueryResult("50 0 5269 alt5.xmpp-server.l.google.com."), DnsSrvRecordAddressResolver.SrvRecord.fromSrvQueryResult("40 0 5269 alt4.xmpp-server.l.google.com."));
}
};
List<Address> addresses = resolver.getAddresses();
assertThat(addresses.size()).isEqualTo(5);
assertThat(addresses.get(0).getHost()).isEqualTo("alt1.xmpp-server.l.google.com");
assertThat(addresses.get(1).getHost()).isEqualTo("alt2.xmpp-server.l.google.com");
assertThat(addresses.get(2).getHost()).isEqualTo("alt3.xmpp-server.l.google.com");
assertThat(addresses.get(3).getHost()).isEqualTo("alt4.xmpp-server.l.google.com");
assertThat(addresses.get(4).getHost()).isEqualTo("alt5.xmpp-server.l.google.com");
}
use of com.rabbitmq.client.Address in project rabbitmq-java-client by rabbitmq.
the class RecoveryAwareAMQConnectionFactoryTest method tryNextAddressIfTimeoutException.
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/262
@Test
public void tryNextAddressIfTimeoutException() throws IOException, TimeoutException {
final RecoveryAwareAMQConnection connectionThatThrowsTimeout = mock(RecoveryAwareAMQConnection.class);
final RecoveryAwareAMQConnection connectionThatSucceeds = mock(RecoveryAwareAMQConnection.class);
final Queue<RecoveryAwareAMQConnection> connections = new ArrayBlockingQueue<RecoveryAwareAMQConnection>(10);
connections.add(connectionThatThrowsTimeout);
connections.add(connectionThatSucceeds);
AddressResolver addressResolver = () -> Arrays.asList(new Address("host1"), new Address("host2"));
RecoveryAwareAMQConnectionFactory connectionFactory = new RecoveryAwareAMQConnectionFactory(new ConnectionParams(), mock(FrameHandlerFactory.class), addressResolver) {
@Override
protected RecoveryAwareAMQConnection createConnection(ConnectionParams params, FrameHandler handler, MetricsCollector metricsCollector) {
return connections.poll();
}
};
doThrow(TimeoutException.class).when(connectionThatThrowsTimeout).start();
doNothing().when(connectionThatSucceeds).start();
Connection returnedConnection = connectionFactory.newConnection();
assertSame(connectionThatSucceeds, returnedConnection);
}
Aggregations