changeset 607:765556dd7c80

bugfixes
author Devel 2
date Mon, 09 Oct 2017 09:58:55 +0200
parents 2e185909d22c
children c4e1b90cb412 53d0d102a8b5
files stress-tester/src/main/java/com/passus/st/Main.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java
diffstat 2 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/Main.java	Mon Oct 09 09:08:32 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/Main.java	Mon Oct 09 09:58:55 2017 +0200
@@ -77,6 +77,10 @@
     }
 
     static void printMetrics(List<Metric> metrics, long startTime) {
+        if (startTime == 0) {
+            return;
+        }
+
         long endTime = System.currentTimeMillis();
         synchronized (System.out) {
             System.out.println("");
@@ -238,7 +242,11 @@
             client.setCollectMetrics(true);
             client.setConnectPartialSession(cl.hasOption("ps"));
             client.setWokerType(cl.getOptionValue("wt", "synch"));
-
+            client.addListener((request, response, context) -> {
+                if (startTime == 0) {
+                    startTime = System.currentTimeMillis();
+                }
+            });
             if (cl.hasOption("pr")) {
                 if (clArgs.length != 1) {
                     throw new IllegalArgumentException("Parameter \"parallelReplays\" works only for one pcap file.");
@@ -246,7 +254,7 @@
 
                 int parallelReplays = Integer.parseInt(cl.getOptionValue("pr"));
                 if (parallelReplays > 0 && parallelReplays <= 100) {
-//                    emitter.setMaxThreads(parallelReplays);
+                    emitter.setMaxThreads(parallelReplays);
                     client.setWorkersNum(parallelReplays);
                 } else {
                     throw new IllegalArgumentException("Parameter \"parallelReplays\" should be in range 1-100.");
@@ -395,7 +403,6 @@
             collector.register(client);
             collector.start();
 
-            startTime = System.currentTimeMillis();
             if (cl.hasOption("ca")) {
                 Set<String> sourcesName = new HashSet<>();
                 for (int i = 0; i < clArgs.length; i++) {
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Mon Oct 09 09:08:32 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java	Mon Oct 09 09:58:55 2017 +0200
@@ -518,25 +518,28 @@
             this.eventHandler = eventHandler;
         }
 
+        private void fireRequest(HttpRequest req, HttpResponse resp, SessionContext context, long timestamp) {
+            SessionInfo info = new SessionInfo(
+                    context.getSrcIpAddr(), context.getSrcPort(),
+                    context.getDstIpAddr(), context.getDstPort(),
+                    context.getProtocol(), context.getId());
+            info.setSourceName(name);
+
+            Event event = new HttpSessionPayloadEvent(info, req, resp, name);
+            event.setTimestamp(timestamp);
+            eventHandler.handle(event);
+            if (collectMetric) {
+                metric.incPayloads();
+            }
+        }
+
         @Override
         public void onMessageReceived(HttpMessage message, SessionContext context, long timestamp) {
             if (message.isRequest()) {
                 lastRequests.put(context.getKey(), (HttpRequest) message);
             } else {
                 HttpRequest req = lastRequests.remove(context.getKey());
-
-                SessionInfo info = new SessionInfo(
-                        context.getSrcIpAddr(), context.getSrcPort(),
-                        context.getDstIpAddr(), context.getDstPort(),
-                        context.getProtocol(), context.getId());
-                info.setSourceName(name);
-                
-                Event event = new HttpSessionPayloadEvent(info, req, (HttpResponse) message, name);
-                event.setTimestamp(timestamp);
-                eventHandler.handle(event);
-                if (collectMetric) {
-                    metric.incPayloads();
-                }
+                fireRequest(req, (HttpResponse) message, context, timestamp);
             }
         }
 
@@ -551,6 +554,10 @@
                 sessionInfoStatus = SessionStatusEvent.STATUS_CLOSING;
             } else {
                 sessionInfoStatus = SessionStatusEvent.STATUS_CLOSED;
+                HttpRequest req = lastRequests.get(context.getKey());
+                if (req != null) {
+                    fireRequest(req, null, context, timestamp);
+                }
             }
 
             SessionInfo info = new SessionInfo(
@@ -558,7 +565,7 @@
                     context.getDstIpAddr(), context.getDstPort(),
                     context.getProtocol(), context.getId());
             info.setSourceName(name);
-            
+
             Event event = new SessionStatusEvent(info, sessionInfoStatus, name);
             event.setTimestamp(timestamp);
             eventHandler.handle(event);