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:18:42 UTC

[tomcat] branch 7.0.x 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 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/7.0.x by this push:
     new 9aa43a8  Attempt to fix intermittent test failure in CI system
9aa43a8 is described below

commit 9aa43a8e12b39602d51064077cf49039e5a48d0e
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 68a1698..7811fb3 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<String, Integer>();
-        private static final AtomicInteger updateCount = new AtomicInteger(0);
+        private static final Map<String, Integer> records = new HashMap<String,Integer>();
+        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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org