Skip to content

Commit 925840d

Browse files
committed
Set address resolver in test
The default address resolver uses 2 inet addresses, which can trigger a retry if the first connection attempt fails. The test is meant to fail with a ProtocolVersionMismatch exception, retrying is not necessary and makes debugging harder. (cherry picked from commit bb26af7)
1 parent 3840502 commit 925840d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/test/java/com/rabbitmq/client/test/ProtocolVersionMismatch.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1919

20+
import com.rabbitmq.client.Address;
21+
import com.rabbitmq.client.AddressResolver;
2022
import com.rabbitmq.client.ConnectionFactory;
23+
import com.rabbitmq.client.ListAddressResolver;
2124
import com.rabbitmq.client.MalformedFrameException;
2225
import io.netty.bootstrap.ServerBootstrap;
2326
import io.netty.buffer.ByteBuf;
@@ -31,12 +34,17 @@
3134
import io.netty.channel.socket.SocketChannel;
3235
import io.netty.channel.socket.nio.NioServerSocketChannel;
3336
import io.netty.util.ReferenceCountUtil;
37+
import java.util.Collections;
3438
import java.util.concurrent.TimeUnit;
3539
import org.junit.jupiter.params.ParameterizedTest;
3640
import org.junit.jupiter.params.provider.MethodSource;
41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
3743

3844
public class ProtocolVersionMismatch {
3945

46+
private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolVersionMismatch.class);
47+
4048
@ParameterizedTest
4149
@MethodSource("com.rabbitmq.client.test.TestUtils#ioLayers")
4250
void connectionShouldFailWithProtocolVersionMismatch(String ioLayer) throws Exception {
@@ -45,7 +53,10 @@ void connectionShouldFailWithProtocolVersionMismatch(String ioLayer) throws Exce
4553
ConnectionFactory cf = TestUtils.connectionFactory();
4654
TestUtils.setIoLayer(cf, ioLayer);
4755
cf.setPort(port);
48-
assertThatThrownBy(cf::newConnection).hasRootCauseInstanceOf(MalformedFrameException.class);
56+
AddressResolver addressResolver =
57+
new ListAddressResolver(Collections.singletonList(new Address("localhost", port)));
58+
assertThatThrownBy(() -> cf.newConnection(addressResolver))
59+
.hasRootCauseInstanceOf(MalformedFrameException.class);
4960
}
5061
}
5162

@@ -69,6 +80,7 @@ protected void initChannel(SocketChannel ch) {
6980
new ChannelInboundHandlerAdapter() {
7081
@Override
7182
public void channelRead(ChannelHandlerContext ctx, Object msg) {
83+
LOGGER.debug("Client connection in test AMQP 1.0 server");
7284
// discard the data
7385
ReferenceCountUtil.release(msg);
7486
ByteBuf b = ctx.alloc().buffer(AMQP_HEADER.length);

src/test/java/com/rabbitmq/client/test/TestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.util.concurrent.TimeoutException;
4141
import java.util.function.Function;
4242
import java.util.function.Supplier;
43-
4443
import org.assertj.core.api.Assertions;
4544
import org.assertj.core.api.Condition;
4645
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
@@ -135,7 +134,8 @@ public static void waitAtMost(Duration timeout, CallableBooleanSupplier conditio
135134
waitAtMost(timeout, condition, null);
136135
}
137136

138-
public static void waitAtMost(Duration timeout, CallableBooleanSupplier condition, Supplier<String> message) {
137+
public static void waitAtMost(
138+
Duration timeout, CallableBooleanSupplier condition, Supplier<String> message) {
139139
try {
140140
if (condition.getAsBoolean()) {
141141
return;

src/test/resources/logback-test.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<logger name="com.rabbitmq.client.test.server.TopicPermissions" level="debug" />
1010
<logger name="com.rabbitmq.client.impl.AbstractMetricsCollector" level="debug" />
1111
<logger name="com.rabbitmq.client.impl.NettyFrameHandlerFactory" level="debug" />
12+
<logger name="com.rabbitmq.client.test.ProtocolVersionMismatch" level="debug" />
1213

1314
<root level="warn">
1415
<appender-ref ref="STDOUT" />

0 commit comments

Comments
 (0)