This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 98e4b4b Attempt to fix intermittent test failure in CI system 98e4b4b is described below commit 98e4b4bbb30e6ec2ca7ffdebaad0c2acdcf959ee Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Apr 17 14:10:01 2020 +0100 Attempt to fix intermittent test failure in CI system --- .../TestWsWebSocketContainerGetOpenSessions.java | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java b/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java index 8190d6c..033ee63 100644 --- a/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java +++ b/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java @@ -19,9 +19,8 @@ package org.apache.tomcat.websocket; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletContextEvent; import javax.websocket.ClientEndpointConfig; @@ -355,15 +354,20 @@ public class TestWsWebSocketContainerGetOpenSessions extends WebSocketBaseTest { public static class Tracker { - private static final Map<String, Integer> records = new ConcurrentHashMap<>(); - private static final AtomicInteger updateCount = new AtomicInteger(0); + private static final Map<String, Integer> records = new HashMap<>(); + private static int updateCount = 0; - public static void addRecord(String key, int count) { - records.put(key, Integer.valueOf(count)); - updateCount.incrementAndGet(); + public static synchronized void addRecord(String key, int count) { + // Need to avoid out of order updates to the Map. If out of order + // updates occur, keep the one with the highest count. + Integer oldCount = records.get(key); + if (oldCount == null || oldCount.intValue() < count) { + records.put(key, Integer.valueOf(count)); + } + updateCount++; } - public static boolean checkRecord(String key, int expectedCount) { + public static synchronized boolean checkRecord(String key, int expectedCount) { Integer actualCount = records.get(key); if (actualCount == null) { if (expectedCount == 0) { @@ -376,16 +380,16 @@ public class TestWsWebSocketContainerGetOpenSessions extends WebSocketBaseTest { } } - public static int getUpdateCount() { - return updateCount.intValue(); + public static synchronized int getUpdateCount() { + return updateCount; } - public static void reset() { + public static synchronized void reset() { records.clear(); - updateCount.set(0); + updateCount = 0; } - public static String dump() { + public static synchronized String dump() { return records.toString(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org