|
16 | 16 | package com.rabbitmq.client.test;
|
17 | 17 |
|
18 | 18 | import com.rabbitmq.client.Address;
|
| 19 | +import com.rabbitmq.client.AddressResolver; |
19 | 20 | import com.rabbitmq.client.Connection;
|
20 | 21 | import com.rabbitmq.client.ConnectionFactory;
|
| 22 | +import com.rabbitmq.client.DnsRecordIpAddressResolver; |
| 23 | +import com.rabbitmq.client.ListAddressResolver; |
21 | 24 | import com.rabbitmq.client.MetricsCollector;
|
22 | 25 | import com.rabbitmq.client.impl.AMQConnection;
|
23 | 26 | import com.rabbitmq.client.impl.ConnectionParams;
|
|
27 | 30 | import org.junit.Test;
|
28 | 31 |
|
29 | 32 | import java.io.IOException;
|
| 33 | +import java.util.List; |
30 | 34 | import java.util.Queue;
|
31 | 35 | import java.util.concurrent.ArrayBlockingQueue;
|
32 | 36 | import java.util.concurrent.TimeoutException;
|
33 | 37 | import java.util.concurrent.atomic.AtomicBoolean;
|
| 38 | +import java.util.concurrent.atomic.AtomicReference; |
34 | 39 |
|
| 40 | +import static org.hamcrest.Matchers.allOf; |
| 41 | +import static org.hamcrest.Matchers.instanceOf; |
| 42 | +import static org.hamcrest.Matchers.notNullValue; |
35 | 43 | import static org.junit.Assert.*;
|
36 | 44 | import static org.mockito.Mockito.*;
|
37 | 45 |
|
@@ -90,4 +98,53 @@ protected AMQConnection createConnection(ConnectionParams params, FrameHandler f
|
90 | 98 | assertTrue(createCalled.get());
|
91 | 99 | }
|
92 | 100 |
|
| 101 | + @Test public void shouldNotUseDnsResolutionWhenOneAddressAndNoTls() throws Exception { |
| 102 | + AMQConnection connection = mock(AMQConnection.class); |
| 103 | + AtomicReference<AddressResolver> addressResolver = new AtomicReference<>(); |
| 104 | + |
| 105 | + ConnectionFactory connectionFactory = new ConnectionFactory() { |
| 106 | + @Override |
| 107 | + protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, |
| 108 | + MetricsCollector metricsCollector) { |
| 109 | + return connection; |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + protected AddressResolver createAddressResolver(List<Address> addresses) { |
| 114 | + addressResolver.set(super.createAddressResolver(addresses)); |
| 115 | + return addressResolver.get(); |
| 116 | + } |
| 117 | + }; |
| 118 | + |
| 119 | + doNothing().when(connection).start(); |
| 120 | + connectionFactory.newConnection(); |
| 121 | + |
| 122 | + assertThat(addressResolver.get(), allOf(notNullValue(), instanceOf(ListAddressResolver.class))); |
| 123 | + } |
| 124 | + |
| 125 | + @Test public void shouldNotUseDnsResolutionWhenOneAddressAndTls() throws Exception { |
| 126 | + AMQConnection connection = mock(AMQConnection.class); |
| 127 | + AtomicReference<AddressResolver> addressResolver = new AtomicReference<>(); |
| 128 | + |
| 129 | + ConnectionFactory connectionFactory = new ConnectionFactory() { |
| 130 | + @Override |
| 131 | + protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, |
| 132 | + MetricsCollector metricsCollector) { |
| 133 | + return connection; |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + protected AddressResolver createAddressResolver(List<Address> addresses) { |
| 138 | + addressResolver.set(super.createAddressResolver(addresses)); |
| 139 | + return addressResolver.get(); |
| 140 | + } |
| 141 | + }; |
| 142 | + |
| 143 | + doNothing().when(connection).start(); |
| 144 | + connectionFactory.useSslProtocol(); |
| 145 | + connectionFactory.newConnection(); |
| 146 | + |
| 147 | + assertThat(addressResolver.get(), allOf(notNullValue(), instanceOf(ListAddressResolver.class))); |
| 148 | + } |
| 149 | + |
93 | 150 | }
|
0 commit comments