diff --git a/README.md b/README.md index fead462..d986894 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,17 @@ can specify the path to `rabbitmqctl` like the following: ./gradlew check -Drabbitmqctl.bin=/path/to/rabbitmqctl -You need a local running RabbitMQ instance. +You need a local running RabbitMQ instance. + +### Running tests with Docker + +Start a RabbitMQ container: + + docker run -it --rm --name rabbitmq -p 5672:5672 rabbitmq:3.8 + +Run the test suite: + + ./gradlew check -i -s -Drabbitmqctl.bin=DOCKER:rabbitmq ### Building IDE project ./gradlew eclipse diff --git a/src/test/java/reactor/rabbitmq/ConnectionRecoveryTests.java b/src/test/java/reactor/rabbitmq/ConnectionRecoveryTests.java index 6c6b1e7..70d9d14 100644 --- a/src/test/java/reactor/rabbitmq/ConnectionRecoveryTests.java +++ b/src/test/java/reactor/rabbitmq/ConnectionRecoveryTests.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; @@ -85,7 +86,7 @@ private static void wait(CountDownLatch latch) throws InterruptedException { } @BeforeEach - public void init() throws Exception { + public void init(TestInfo info) throws Exception { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.useNio(); connectionFactory.setNetworkRecoveryInterval(RECOVERY_INTERVAL); @@ -96,7 +97,9 @@ public void init() throws Exception { channel.close(); receiver = null; sender = null; - connectionMono = Mono.just(connectionFactory.newConnection()).cache(); + connectionMono = Mono.just(connectionFactory.newConnection( + info.getTestMethod().get().getName())) + .cache(); } @AfterEach @@ -142,7 +145,7 @@ public void consumeConsumerShouldRecoverAutomatically(BiFunction listConnections() throws IOException { - String output = capture(rabbitmqctl("list_connections -q pid peer_port").getInputStream()); + String output = capture(rabbitmqctl("list_connections -q pid peer_port client_properties") + .getInputStream()); // output (header line presence depends on broker version): // pid peer_port - // 58713 + // 58713 [{"product","RabbitMQ"},{"... String[] allLines = output.split("\n"); ArrayList result = new ArrayList(); @@ -112,7 +123,8 @@ public static List listConnections() throws IOException { String[] columns = line.split("\t"); // can be also header line, so ignoring NumberFormatException try { - result.add(new ConnectionInfo(columns[0], Integer.valueOf(columns[1]))); + Integer.valueOf(columns[1]); // just to ignore header line + result.add(new ConnectionInfo(columns[0], connectionName(columns[2]))); } catch (NumberFormatException e) { // OK } @@ -120,10 +132,22 @@ public static List listConnections() throws IOException { return result; } - private static Host.ConnectionInfo findConnectionInfoFor(List xs, NetworkConnection c) { + private static String connectionName(String clientProperties) { + String beginning = "\"connection_name\",\""; + int begin = clientProperties.indexOf(beginning); + if (begin > 0) { + int start = clientProperties.indexOf(beginning) + beginning.length(); + int end = clientProperties.indexOf("\"", start); + return clientProperties.substring(start, end); + } else { + return null; + } + } + + private static Host.ConnectionInfo findConnectionInfoFor(List xs, Connection c) { Host.ConnectionInfo result = null; for (Host.ConnectionInfo ci : xs) { - if (c.getLocalPort() == ci.getPeerPort()) { + if (c.getClientProvidedName().equals(ci.getName())) { result = ci; break; } @@ -134,19 +158,19 @@ private static Host.ConnectionInfo findConnectionInfoFor(List xs public static class ConnectionInfo { private final String pid; - private final int peerPort; + private final String name; - public ConnectionInfo(String pid, int peerPort) { + public ConnectionInfo(String pid, String name) { this.pid = pid; - this.peerPort = peerPort; + this.name = name; } public String getPid() { return pid; } - public int getPeerPort() { - return peerPort; + public String getName() { + return name; } } }