You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2020/04/17 13:10:42 UTC
[tomcat] branch master updated: Attempt to fix intermittent test
failure in CI system
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 9a4173f Attempt to fix intermittent test failure in CI system
9a4173f is described below
commit 9a4173f6c3edd4f95e861fed67fb07cd6337f09c
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 | 31 ++++++++++++----------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java b/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java
index 3ddd00f..0dad184 100644
--- a/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java
+++ b/test/org/apache/tomcat/websocket/TestWsWebSocketContainerGetOpenSessions.java
@@ -19,10 +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 jakarta.servlet.ServletContextEvent;
import jakarta.websocket.ClientEndpointConfig;
import jakarta.websocket.CloseReason;
@@ -355,15 +353,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 synchronized static 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 synchronized static boolean checkRecord(String key, int expectedCount) {
Integer actualCount = records.get(key);
if (actualCount == null) {
if (expectedCount == 0) {
@@ -376,16 +379,16 @@ public class TestWsWebSocketContainerGetOpenSessions extends WebSocketBaseTest {
}
}
- public static int getUpdateCount() {
- return updateCount.intValue();
+ public synchronized static int getUpdateCount() {
+ return updateCount;
}
- public static void reset() {
+ public synchronized static void reset() {
records.clear();
- updateCount.set(0);
+ updateCount = 0;
}
- public static String dump() {
+ public synchronized static String dump() {
return records.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org