changeset 641:5d0230a77b38

HttpFlowParameters
author Devel 2
date Tue, 07 Nov 2017 13:54:16 +0100
parents 513143f046c8
children af2640f52b66
files stress-tester/src/main/java/com/passus/st/client/http/HttpFlowContext.java stress-tester/src/main/java/com/passus/st/client/http/HttpFlowParameters.java stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java stress-tester/src/test/java/com/passus/st/client/TestHttpClientListener.java stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java
diffstat 5 files changed, 54 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowContext.java	Tue Nov 07 11:37:34 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowContext.java	Tue Nov 07 13:54:16 2017 +0100
@@ -46,6 +46,8 @@
 
     long sendStartTimestamp = -1;
 
+    private HttpFlowParameters parameters;
+
     public HttpFlowContext(SessionInfo session, HttpScopes scopes) {
         this.scopes = scopes;
         this.session = session;
@@ -97,6 +99,14 @@
         return null;
     }
 
+    public HttpFlowParameters getParameters() {
+        return parameters;
+    }
+
+    void setParameters(HttpFlowParameters parameters) {
+        this.parameters = parameters;
+    }
+
     public SessionInfo sessionInfo() {
         return session;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowParameters.java	Tue Nov 07 13:54:16 2017 +0100
@@ -0,0 +1,19 @@
+package com.passus.st.client.http;
+
+/**
+ *
+ * @author Mirosław Hawrot
+ */
+public class HttpFlowParameters {
+
+    private final int loop;
+
+    public HttpFlowParameters(int loop) {
+        this.loop = loop;
+    }
+
+    public int getLoop() {
+        return loop;
+    }
+
+}
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java	Tue Nov 07 11:37:34 2017 +0100
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpSynchClientWorker.java	Tue Nov 07 13:54:16 2017 +0100
@@ -32,6 +32,8 @@
 
     private boolean loopEnd = false;
 
+    private HttpFlowParameters currentFlowParameters = new HttpFlowParameters(0);
+
     public HttpSynchClientWorker(Emitter emitter, String name, int index) {
         super(emitter, name, index);
     }
@@ -151,6 +153,9 @@
                     if (statusEvent.getStatus() == SessionStatusEvent.STATUS_ESTABLISHED) {
                         try {
                             currFlowContext = connect(statusEvent);
+                            if (currFlowContext != null) {
+                                currFlowContext.setParameters(currentFlowParameters);
+                            }
                         } catch (Exception e) {
                             logger.error(e.getMessage(), e);
                         }
@@ -184,6 +189,9 @@
                             case HttpFlowContext.STATE_DISCONNECTED:
                                 if (connectPartialSession) {
                                     currFlowContext = connect(sessEvent);
+                                    if (currFlowContext != null) {
+                                        currFlowContext.setParameters(currentFlowParameters);
+                                    }
                                     return false;
                                 } else {
                                     return true;
@@ -194,6 +202,7 @@
                     } else if (connectPartialSession) {
                         currFlowContext = connect(sessEvent);
                         if (currFlowContext != null) {
+                            currFlowContext.setParameters(currentFlowParameters);
                             eventsQueue.addFirst(sessEvent);
                             return false;
                         } else {
@@ -213,6 +222,7 @@
                 loopEnd = true;
                 closeAllConnections();
                 filterChain.reset();
+                currentFlowParameters = new HttpFlowParameters(currentFlowParameters.getLoop() + 1);
                 loopEnd = false;
                 return true;
             } else if (event.getType() == DataEnd.TYPE) {
--- a/stress-tester/src/test/java/com/passus/st/client/TestHttpClientListener.java	Tue Nov 07 11:37:34 2017 +0100
+++ b/stress-tester/src/test/java/com/passus/st/client/TestHttpClientListener.java	Tue Nov 07 13:54:16 2017 +0100
@@ -4,6 +4,7 @@
 import com.passus.net.http.HttpRequest;
 import com.passus.net.http.HttpResponse;
 import com.passus.st.client.http.HttpFlowContext;
+import com.passus.st.client.http.HttpFlowParameters;
 import java.util.LinkedList;
 import java.util.Queue;
 
@@ -82,7 +83,7 @@
 
     @Override
     public void responseReceived(HttpRequest request, HttpResponse response, HttpFlowContext context) {
-        add(new ResponseReceivedEvent(request, response, context.origReponse()));
+        add(new ResponseReceivedEvent(request, response, context.origReponse(), context.getParameters()));
     }
 
     public abstract static class HttpClientEvent {
@@ -104,12 +105,14 @@
         private final HttpRequest request;
         private final HttpResponse response;
         private final HttpResponse orgResponse;
+        private final HttpFlowParameters flowParameters;
 
-        public ResponseReceivedEvent(HttpRequest request, HttpResponse response, HttpResponse orgResponse) {
+        public ResponseReceivedEvent(HttpRequest request, HttpResponse response, HttpResponse orgResponse, HttpFlowParameters flowParameters) {
             super(HttpClientEventType.RESPONSE_RECEIVED);
             this.request = request;
             this.response = response;
             this.orgResponse = orgResponse;
+            this.flowParameters = flowParameters;
         }
 
         public HttpRequest getRequest() {
@@ -124,6 +127,10 @@
             return orgResponse;
         }
 
+        public HttpFlowParameters getFlowParameters() {
+            return flowParameters;
+        }
+
     }
 
 }
--- a/stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java	Tue Nov 07 11:37:34 2017 +0100
+++ b/stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java	Tue Nov 07 13:54:16 2017 +0100
@@ -127,11 +127,11 @@
 
         NioEmitter emitter = prepareEmitter("10.87.110.40:4214 ->  " + HOST + ":" + PORT);
         emitter.start();
-        TestHttpClientListener listner = new TestHttpClientListener();
+        TestHttpClientListener listener = new TestHttpClientListener();
 
         HttpClient client = new HttpClient(emitter);
         try {
-            client.addListener(listner);
+            client.addListener(listener);
             client.start();
 
             for (int i = 0; i < 3; i++) {
@@ -142,14 +142,15 @@
             client.handle(dataEnd);
             client.join();
 
-            assertEquals(3, listner.size());
+            assertEquals(3, listener.size());
 
             for (int i = 0; i < 3; i++) {
-                assertTrue(listner.get(i) instanceof ResponseReceivedEvent);
-                ResponseReceivedEvent event = (ResponseReceivedEvent) listner.get(i);
+                assertTrue(listener.get(i) instanceof ResponseReceivedEvent);
+                ResponseReceivedEvent event = (ResponseReceivedEvent) listener.get(i);
                 String responseStr = event.getResponse().toString();
                 assertTrue(responseStr.startsWith("HTTP/1.1 200 OK"));
                 assertTrue(responseStr.endsWith("test"));
+                assertEquals(i, event.getFlowParameters().getLoop());
             }
         } finally {
             ServiceUtils.stopQuietly(client);