changeset 966:74eb9b0e8b37

Bugfixes
author Devel 2
date Fri, 31 May 2019 13:25:02 +0200
parents acb064dc26b9
children 57e0d4394116
files stress-tester/src/main/java/com/passus/st/ConverterHttpClient.java stress-tester/src/main/java/com/passus/st/client/http/HttpFlowHandler.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilter.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterTestUtils.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFormLoginFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java
diffstat 7 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/ConverterHttpClient.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/ConverterHttpClient.java	Fri May 31 13:25:02 2019 +0200
@@ -133,7 +133,7 @@
     private FlowContext getFlow(SessionInfo session) {
         FlowContext flowContext = sessions.get(session);
         if (flowContext == null) {
-            flowContext = HttpFlowUtils.createFlowContext(session);
+            flowContext = HttpFlowUtils.createFlowContext(session, scopes);
             sessions.put(session, flowContext);
         }
         return flowContext;
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowHandler.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowHandler.java	Fri May 31 13:25:02 2019 +0200
@@ -3,10 +3,10 @@
 import com.passus.commons.time.TimeAware;
 import com.passus.commons.time.TimeGenerator;
 import com.passus.net.http.HttpRequest;
+import com.passus.st.client.FlowContext;
 import com.passus.st.client.FlowHandler;
 import com.passus.st.client.FlowHandlerDataDecoder;
 import com.passus.st.client.FlowHandlerDataEncoder;
-import com.passus.st.client.FlowContext;
 import com.passus.st.metric.MetricsContainer;
 
 import static com.passus.st.Protocols.HTTP;
@@ -25,9 +25,12 @@
 
     HttpClientWorkerMetric metric;
 
+    HttpScopes scopes;
+
     public HttpFlowHandler() {
         decoder = new HttpFlowHandlerDataDecoder(this);
         encoder = new HttpFlowHandlerDataEncoder();
+        scopes = new HttpScopes();
     }
 
     @Override
@@ -48,7 +51,7 @@
     @Override
     public void init(FlowContext flowContext) {
         //TODO Poprawic, w HttpScopes sa parametry globalne
-        flowContext.setParam(HttpFlowConst.PARAM_HTTP_CONTEXT, new HttpFlowContext(flowContext, new HttpScopes()));
+        flowContext.setParam(HttpFlowConst.PARAM_HTTP_CONTEXT, new HttpFlowContext(flowContext, scopes));
     }
 
     @Override
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilter.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilter.java	Fri May 31 13:25:02 2019 +0200
@@ -27,7 +27,7 @@
     @Override
     public int filterOutbound(Object req, Object resp, FlowContext context) {
         if (req instanceof HttpRequest
-                && resp instanceof HttpResponse) {
+                || resp instanceof HttpResponse) {
             return filterOutbound((HttpRequest) req, (HttpResponse) resp, context);
         }
 
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterTestUtils.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterTestUtils.java	Fri May 31 13:25:02 2019 +0200
@@ -29,9 +29,12 @@
     private static final boolean DEFAULT_USE_ACCELERATED_EXTRACTORS = true;
 
     public static FlowContext createMockContext() {
+        return createMockContext(new HttpScopes());
+    }
+
+    public static FlowContext createMockContext(HttpScopes scopes) {
         FlowContext mockContext = mock(FlowContext.class);
         HttpFlowContext mockHttpContext = mock(HttpFlowContext.class);
-        final HttpScopes scopes = new HttpScopes();
         when(mockContext.getParamValue(HttpFlowConst.PARAM_HTTP_CONTEXT)).thenReturn(mockHttpContext);
         when(mockHttpContext.scopes()).thenReturn(scopes);
         return mockContext;
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFormLoginFilterTest.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFormLoginFilterTest.java	Fri May 31 13:25:02 2019 +0200
@@ -43,8 +43,6 @@
             + "Content-Length: 2\r\n\r\n"
             + "OK";
 
-    final FlowContext mockContext = createMockContext();
-
     public static HttpFormLoginFilter createFilter(CredentialsProvider provider) {
         return createFilter(provider, (http) -> true);
     }
@@ -68,6 +66,7 @@
 
         HttpFormLoginFilter filter = createFilter(provider(new Credentials("test", "test")));
 
+        FlowContext mockContext = createMockContext();
         filter.filterOutbound(request, null, mockContext);
         assertContent(request, "_username=test&_password=test");
         assertEquals(extractHttpContext(mockContext).scopes().getConversation(request).get(PARAM_USERNAME), "test");
@@ -84,6 +83,7 @@
 
         HttpFormLoginFilter filter = createFilter(provider(null));
 
+        FlowContext mockContext = createMockContext();
         filter.filterOutbound(request, null, mockContext);
         assertContent(request, "_username=admin&_password=qwerty");
         assertEquals(extractHttpContext(mockContext).scopes().getConversation(request).get(PARAM_USERNAME), "admin");
@@ -98,6 +98,7 @@
         HttpResponse response = TestHttpUtils.response(RESPS);
         request.setTag(TAG_SESSION_ID, "sid1");
 
+        FlowContext mockContext = createMockContext();
         HttpFormLoginFilter filter = createFilter(null);
         when(extractHttpContext(mockContext).scopes()).thenReturn(new HttpScopes());
 
@@ -117,6 +118,7 @@
 
         HttpFormLoginFilter filter = createFilter(provider(new Credentials("test", "test")), (http) -> false);
 
+        FlowContext mockContext = createMockContext();
         filter.filterOutbound(request, null, mockContext);
         assertContent(request, "_username=admin&_password=qwerty");
         assertEquals(extractHttpContext(mockContext).scopes().getConversation(request).get(PARAM_USERNAME), null);
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpLogoutFilterTest.java	Fri May 31 13:25:02 2019 +0200
@@ -48,7 +48,7 @@
         req.setTag(TAG_SESSION_ID, sessionId);
         resp.setTag(TAG_SESSION_ID, sessionId);
 
-        FlowContext mockContext = createMockContext();
+        FlowContext mockContext = createMockContext(scopes);
         HttpLogoutFilter filter = new HttpLogoutFilter(predicate, true);
         filter.filterOutbound(req, resp, mockContext);
 
@@ -69,7 +69,7 @@
         req.setTag(TAG_SESSION_ID, sessionId);
         resp.setTag(TAG_SESSION_ID, sessionId);
 
-        FlowContext mockContext = createMockContext();
+        FlowContext mockContext = createMockContext(scopes);
         HttpLogoutFilter filter = new HttpLogoutFilter(predicate, false);
         filter.filterOutbound(req, resp, mockContext);
 
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Fri May 31 11:40:55 2019 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java	Fri May 31 13:25:02 2019 +0200
@@ -244,7 +244,7 @@
         Errors errors = new Errors();
         ConfigurationContextImpl emptyContext = new ConfigurationContextImpl();
         List<FlowFilter> filters = FlowFiltersConfigurator.getFilters(filterConfig, errors, emptyContext);
-        HttpFilterTestUtils.printErrors(errors);
+
         assertEquals(0, errors.getErrorCount());
         assertEquals(2, filters.size());
         assertTrue(filters.get(0) instanceof HttpMessageModificationFilter);