Mercurial > stress-tester
changeset 962:e85498215df0
Refactorization in progress
author | Devel 2 |
---|---|
date | Fri, 31 May 2019 09:27:03 +0200 |
parents | 21c0c419d112 |
children | 3a4c9ca6593a |
files | stress-tester/src/test/java/com/passus/st/client/FlowFilterChainTest.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterChainTest.java stress-tester/src/test/resources/com/passus/st/config/test_job_config.yml |
diffstat | 3 files changed, 90 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/client/FlowFilterChainTest.java Fri May 31 09:27:03 2019 +0200 @@ -0,0 +1,89 @@ +package com.passus.st.client; + +import org.testng.annotations.Test; + +import static com.passus.st.client.http.filter.HttpFilter.*; +import static org.testng.Assert.assertEquals; + +/** + * @author mikolaj.podbielski + */ +public class FlowFilterChainTest { + + private static final class TestFlowFilter implements FlowFilter { + + private final int action; + + public TestFlowFilter(int action) { + this.action = action; + } + + @Override + public int filterOutbound(Object request, Object resp, FlowContext context) { + return action; + } + + @Override + public int filterInbound(Object request, Object resp, FlowContext context) { + return action; + } + + @Override + public FlowFilter instanceForWorker(int index) { + return new TestFlowFilter(action); + } + + } + + private static FlowFilter fAccept() { + return new TestFlowFilter(ACCEPT); + } + + private static FlowFilter fDeny() { + return new TestFlowFilter(DENY); + } + + private static FlowFilter fDunno() { + return new TestFlowFilter(DUNNO); + } + + private static FlowFilterChain filterChain(FlowFilter... filters) { + FlowFilterChain fc = new FlowFilterChain(); + for (FlowFilter filter : filters) { + fc.addFilter(filter); + } + return fc; + } + + private static void assertChainResult(int result, FlowFilterChain chain) { + assertEquals(chain.filterOutbound(null, null, null), result, "outbound"); + assertEquals(chain.filterInbound(null, null, null), result, "inbound"); + } + + private static void assertChainResult(int resultOut, int resultIn, FlowFilterChain chain) { + assertEquals(chain.filterOutbound(null, null, null), resultOut, "outbound"); + assertEquals(chain.filterInbound(null, null, null), resultIn, "inbound"); + } + + @Test + public void testFilterOutbound() { + assertChainResult(ACCEPT, filterChain()); + + assertChainResult(ACCEPT, filterChain(fAccept())); + assertChainResult(ACCEPT, filterChain(fDunno())); + assertChainResult(DENY, filterChain(fDeny())); + + assertChainResult(ACCEPT, filterChain(fAccept(), fAccept())); + assertChainResult(ACCEPT, filterChain(fAccept(), fDunno())); + assertChainResult(ACCEPT, ACCEPT, filterChain(fAccept(), fDeny())); + + assertChainResult(ACCEPT, filterChain(fDunno(), fAccept())); + assertChainResult(ACCEPT, filterChain(fDunno(), fDunno())); + assertChainResult(DENY, filterChain(fDunno(), fDeny())); + + assertChainResult(DENY, DENY, filterChain(fDeny(), fAccept())); + assertChainResult(DENY, filterChain(fDeny(), fDunno())); + assertChainResult(DENY, filterChain(fDeny(), fDeny())); + } + +}
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFilterChainTest.java Fri May 31 09:12:08 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -package com.passus.st.client.http.filter; - -import com.passus.net.http.HttpRequest; -import com.passus.net.http.HttpResponse; -import com.passus.st.client.FlowContext; -import com.passus.st.client.FlowFilterChain; -import org.testng.annotations.Test; - -import static com.passus.st.client.http.filter.HttpFilter.*; -import static org.testng.Assert.assertEquals; - -/** - * @author mikolaj.podbielski - */ -public class HttpFilterChainTest { - - private static final class TestHttpFilter extends HttpFilter { - - private final int action; - - public TestHttpFilter(int action) { - this.action = action; - } - - @Override - public int filterOutbound(HttpRequest request, HttpResponse resp, FlowContext context) { - return action; - } - - @Override - public int filterInbound(HttpRequest request, HttpResponse resp, FlowContext context) { - return action; - } - - @Override - public HttpFilter instanceForWorker(int index) { - return new TestHttpFilter(action); - } - - } - - private static HttpFilter fAccept() { - return new TestHttpFilter(ACCEPT); - } - - private static HttpFilter fDeny() { - return new TestHttpFilter(DENY); - } - - private static HttpFilter fDunno() { - return new TestHttpFilter(DUNNO); - } - - private static FlowFilterChain filterChain(HttpFilter... filters) { - FlowFilterChain fc = new FlowFilterChain(); - for (HttpFilter filter : filters) { - fc.addFilter(filter); - } - return fc; - } - - private static void assertChainResult(int result, FlowFilterChain chain) { - assertEquals(chain.filterOutbound(null, null, null), result, "outbound"); - assertEquals(chain.filterInbound(null, null, null), result, "inbound"); - } - - private static void assertChainResult(int resultOut, int resultIn, FlowFilterChain chain) { - assertEquals(chain.filterOutbound(null, null, null), resultOut, "outbound"); - assertEquals(chain.filterInbound(null, null, null), resultIn, "inbound"); - } - - @Test - public void testFilterOutbound() { - assertChainResult(ACCEPT, filterChain()); - - assertChainResult(ACCEPT, filterChain(fAccept())); - assertChainResult(ACCEPT, filterChain(fDunno())); - assertChainResult(DENY, filterChain(fDeny())); - - assertChainResult(ACCEPT, filterChain(fAccept(), fAccept())); - assertChainResult(ACCEPT, filterChain(fAccept(), fDunno())); - assertChainResult(ACCEPT, ACCEPT, filterChain(fAccept(), fDeny())); - - assertChainResult(ACCEPT, filterChain(fDunno(), fAccept())); - assertChainResult(ACCEPT, filterChain(fDunno(), fDunno())); - assertChainResult(DENY, filterChain(fDunno(), fDeny())); - - assertChainResult(DENY, DENY, filterChain(fDeny(), fAccept())); - assertChainResult(DENY, filterChain(fDeny(), fDunno())); - assertChainResult(DENY, filterChain(fDeny(), fDeny())); - } - -}
--- a/stress-tester/src/test/resources/com/passus/st/config/test_job_config.yml Fri May 31 09:12:08 2019 +0200 +++ b/stress-tester/src/test/resources/com/passus/st/config/test_job_config.yml Fri May 31 09:27:03 2019 +0200 @@ -37,7 +37,7 @@ collectMetrics: true workers: 4 -httpFilters: +filters: - type: requestCacheHeadersCleaner lookups: