changeset 516:8c11c2e8a23c

HttpSynchClientWorker data loop end bugfix
author Devel 2
date Mon, 21 Aug 2017 13:48:38 +0200
parents 7edad974d3f8
children 36d1920e57f0
files stress-tester/src/main/java/com/passus/st/client/http/HttpFlowBasedClientWorker.java stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java
diffstat 2 files changed, 44 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowBasedClientWorker.java	Fri Aug 18 16:08:26 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowBasedClientWorker.java	Mon Aug 21 13:48:38 2017 +0200
@@ -47,7 +47,7 @@
         DEFAULT_TIMEOUTS = Collections.unmodifiableMap(defaultTimeouts);
     }
 
-    private final Map<SessionInfo, HttpFlowContext> sessions = new ConcurrentHashMap<>();
+    protected final Map<SessionInfo, HttpFlowContext> sessions = new ConcurrentHashMap<>();
 
     private final Map<Integer, Long> timeouts = new HashMap<>();
 
@@ -289,8 +289,10 @@
     }
 
     protected void closeAllConnections() {
-        for (HttpFlowContext flowContext : sessions.values()) {
-            closeSession(flowContext, true);
+        synchronized (lock) {
+            for (HttpFlowContext flowContext : sessions.values()) {
+                closeSession(flowContext, true);
+            }
         }
     }
 
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java	Fri Aug 18 16:08:26 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java	Mon Aug 21 13:48:38 2017 +0200
@@ -27,6 +27,8 @@
 
     private HttpFlowContext currFlowContext;
 
+    private boolean loopEnd = false;
+
     public HttpSynchClientWorker(Emitter emitter, String name, int index) {
         super(emitter, name, index);
     }
@@ -68,6 +70,37 @@
         }
     }
 
+    @Override
+    protected void closeAllConnections() {
+        synchronized (lock) {
+            boolean wait;
+            do {
+                wait = false;
+                for (HttpFlowContext flowContext : sessions.values()) {
+                    if (flowContext.state == HttpFlowContext.STATE_REQ_SENT) {
+                        wait = true;
+                        break;
+                    }
+                }
+
+                if (wait) {
+                    try {
+                        lock.wait(100);
+                    } catch (Exception e) {
+                    }
+                }
+            } while (wait);
+
+            super.closeAllConnections();
+            do {
+                try {
+                    lock.wait(100);
+                } catch (Exception e) {
+                }
+            } while (!sessions.isEmpty());
+        }
+    }
+
     private boolean pollNext() {
         Event event = eventsQueue.peek();
         if (event != null) {
@@ -139,8 +172,10 @@
                         logger.debug("DataLoopEnd received.");
                     }
 
+                    loopEnd = true;
                     closeAllConnections();
                     filterChain.reset();
+                    loopEnd = false;
                     return true;
                 } else if (event.getType() == DataEnd.TYPE) {
                     if (logger.isDebugEnabled()) {
@@ -168,9 +203,12 @@
                     } catch (InterruptedException ignore) {
                     }
 
-                    //processTimeouts();
                     boolean pollNext = false;
                     do {
+                        if (loopEnd) {
+                            break;
+                        }
+
                         if (currFlowContext == null) {
                             pollNext = pollNext();
                         } else if (currFlowContext.state != HttpFlowContext.STATE_CONNECTING