Search in sources :

Example 11 with Address

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");
}
Also used : Address(com.rabbitmq.client.Address) DnsSrvRecordAddressResolver(com.rabbitmq.client.DnsSrvRecordAddressResolver) Test(org.junit.Test)

Example 12 with Address

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);
}
Also used : RecoveryAwareAMQConnectionFactory(com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory) FrameHandlerFactory(com.rabbitmq.client.impl.FrameHandlerFactory) MetricsCollector(com.rabbitmq.client.MetricsCollector) AddressResolver(com.rabbitmq.client.AddressResolver) FrameHandler(com.rabbitmq.client.impl.FrameHandler) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Address(com.rabbitmq.client.Address) RecoveryAwareAMQConnection(com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection) RecoveryAwareAMQConnection(com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection) Connection(com.rabbitmq.client.Connection) ConnectionParams(com.rabbitmq.client.impl.ConnectionParams) Test(org.junit.Test)

Aggregations

Address (com.rabbitmq.client.Address)12 Test (org.junit.Test)6 Connection (com.rabbitmq.client.Connection)4 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)4 MetricsCollector (com.rabbitmq.client.MetricsCollector)2 ConnectionParams (com.rabbitmq.client.impl.ConnectionParams)2 FrameHandler (com.rabbitmq.client.impl.FrameHandler)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 RabbitMqConfiguration (com.godaddy.pubsub.configurations.RabbitMqConfiguration)1 Provides (com.google.inject.Provides)1 LazySingleton (com.netflix.governator.guice.lazy.LazySingleton)1 AddressResolver (com.rabbitmq.client.AddressResolver)1 DnsSrvRecordAddressResolver (com.rabbitmq.client.DnsSrvRecordAddressResolver)1 AMQConnection (com.rabbitmq.client.impl.AMQConnection)1 FrameHandlerFactory (com.rabbitmq.client.impl.FrameHandlerFactory)1 RecoveryAwareAMQConnection (com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnection)1 RecoveryAwareAMQConnectionFactory (com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory)1 Host (io.paradoxical.rabbitmq.connectionManagment.Host)1 SimpleChannelProvider (io.paradoxical.rabbitmq.connectionManagment.SimpleChannelProvider)1 FileInputStream (java.io.FileInputStream)1