From 8c11d7a377c6fe5d7f8ca26839d958ded7561603 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 13 Feb 2015 10:52:52 +0200 Subject: [PATCH] INT-3580: Polishing to the last STOMP tests fix JIRA: https://jira.spring.io/browse/INT-3580 * Uncomment `org.springframework.integration.ip` category for the IP tests `log4j.properties` * Since all tests in the `StompIntegrationTests` uses the same application context and therefore the same `SubscriptionRegistry` the `waitForSubscribe()` should wait exactly for that `subscription` in which it is interested in. The previous fix wasn't enough --- .../src/test/resources/log4j.properties | 2 +- .../client/StompIntegrationTests.java | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/spring-integration-ip/src/test/resources/log4j.properties b/spring-integration-ip/src/test/resources/log4j.properties index 4b6a87af5e..c38d3b65db 100644 --- a/spring-integration-ip/src/test/resources/log4j.properties +++ b/spring-integration-ip/src/test/resources/log4j.properties @@ -5,4 +5,4 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %c{1} [%t] : %m%n log4j.category.org.springframework.integration=WARN -#log4j.category.org.springframework.integration.ip=WARN +log4j.category.org.springframework.integration.ip=WARN diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java index b8ca7c9c6d..16edbd1638 100644 --- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java +++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java @@ -135,7 +135,7 @@ public class StompIntegrationTests { this.webSocketOutputChannel.send(message); - waitForSubscribe(); + waitForSubscribe("increment"); this.webSocketOutputChannel.send(message2); @@ -161,7 +161,7 @@ public class StompIntegrationTests { this.webSocketOutputChannel.send(message); - waitForSubscribe(); + waitForSubscribe("foo"); this.webSocketOutputChannel.send(message2); @@ -215,7 +215,7 @@ public class StompIntegrationTests { this.webSocketOutputChannel.send(message); - waitForSubscribe(); + waitForSubscribe("error"); this.webSocketOutputChannel.send(message2); @@ -248,7 +248,7 @@ public class StompIntegrationTests { this.webSocketOutputChannel.send(message); - waitForSubscribe(); + waitForSubscribe("answer"); this.webSocketOutputChannel.send(message2); @@ -257,25 +257,33 @@ public class StompIntegrationTests { assertEquals("Hello Bob", receive.getPayload()); } - private void waitForSubscribe() throws InterruptedException { + private void waitForSubscribe(String destination) throws InterruptedException { SimpleBrokerMessageHandler serverBrokerMessageHandler = this.serverContext.getBean("simpleBrokerMessageHandler", SimpleBrokerMessageHandler.class); SubscriptionRegistry subscriptionRegistry = serverBrokerMessageHandler.getSubscriptionRegistry(); - @SuppressWarnings("rawtypes") - Map subscriptions = TestUtils.getPropertyValue(subscriptionRegistry, "subscriptionRegistry.sessions", Map.class); - int n = 0; - - while (subscriptions.isEmpty() && n++ < 100) { + while (!containsDestination(destination, subscriptionRegistry) && n++ < 100) { Thread.sleep(100); - subscriptions = TestUtils.getPropertyValue(subscriptionRegistry, "subscriptionRegistry.sessions", Map.class); } - assertTrue("The subscription for the 'user/queue/error' hasn't been registered", n < 100); + assertTrue("The subscription for the '" + destination + "' destination hasn't been registered", n < 100); } + @SuppressWarnings("rawtypes") + private boolean containsDestination(String destination, SubscriptionRegistry subscriptionRegistry) { + Map sessions = TestUtils.getPropertyValue(subscriptionRegistry, "subscriptionRegistry.sessions", Map.class); + for (Object info : sessions.values()) { + Map subscriptions = TestUtils.getPropertyValue(info, "subscriptions", Map.class); + for (Object dest : subscriptions.keySet()) { + if (((String) dest).contains(destination)) { + return true; + } + } + } + return false; + } @Configuration @EnableIntegration