From ea7ae8949e1b0411beddd74347e5c33123d8a91d Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 15 Jul 2014 16:10:27 -0400 Subject: [PATCH] Use regex comparison in WebSocket stats test The output includes thread pool information which appears to not vary enough to cause failures locally but does so on the build server. --- ...essageBrokerBeanDefinitionParserTests.java | 18 ++++++++------- ...essageBrokerConfigurationSupportTests.java | 22 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java index 3cd52748bb7..f76e90c8e6d 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java @@ -257,14 +257,16 @@ public class MessageBrokerBeanDefinitionParserTests { String name = "webSocketMessageBrokerStats"; WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class); - assertEquals("WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), " + - "0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], " + - "stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " + - "stompBrokerRelay[0 sessions, relayhost:1234 (not available), processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " + - "inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " + - "outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " + - "sockJsScheduler[pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]", - stats.toString()); + String actual = stats.toString(); + String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " + + "0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " + + "stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + + "stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + + "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + + "outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + + "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]"; + + assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected)); } @Test diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java index 5bc9f732d24..85fdff711e1 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java @@ -22,6 +22,10 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ScheduledThreadPoolExecutor; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; +import org.hamcrest.TypeSafeMatcher; import org.junit.Before; import org.junit.Test; @@ -138,14 +142,16 @@ public class WebSocketMessageBrokerConfigurationSupportTests { public void webSocketMessageBrokerStats() { String name = "webSocketMessageBrokerStats"; WebSocketMessageBrokerStats stats = this.config.getBean(name, WebSocketMessageBrokerStats.class); - assertEquals("WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), " + - "0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], " + - "stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " + - "stompBrokerRelay[null], " + - "inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " + - "outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " + - "sockJsScheduler[pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]", - stats.toString()); + String actual = stats.toString(); + String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " + + "0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " + + "stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " + + "stompBrokerRelay\\[null\\], " + + "inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + + "outboundChannelpool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " + + "sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]"; + + assertTrue("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual, actual.matches(expected)); }