Mercurial > stress-tester
changeset 611:d3c6e21084cd
switching to HttpMessageHelper.get()
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/java/ThreadLocalBenchmark.java Mon Oct 09 13:44:39 2017 +0200 @@ -0,0 +1,46 @@ +package com.passus.java; + +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +/** + * + * @author mikolaj.podbielski + */ +@State(Scope.Thread) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@Fork(value = 1) +@Measurement(iterations = 5) +@Warmup(iterations = 4) +public class ThreadLocalBenchmark { + + private final Object object = new Object(); + private final ThreadLocal<Object> threadLocal = new ThreadLocal<Object>() { + @Override + protected Object initialValue() { + return object; + } + }; + + @Benchmark + public Object testThreadLocal() { + return threadLocal.get(); + } + + public static void main(String[] args) throws Exception { + Options opt = new OptionsBuilder().include(ThreadLocalBenchmark.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + } +}
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpSessionPayloadEvent.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpSessionPayloadEvent.java Mon Oct 09 13:44:39 2017 +0200 @@ -68,13 +68,14 @@ public String toString() { String req = null; String resp = null; + HttpMessageHelper helper = HttpMessageHelper.get(); if (getRequest() != null) { - req = HttpMessageHelper.NOT_STRICT.firstLineToString(getRequest()); + req = helper.firstLineToString(getRequest()); } if (getResponse() != null) { - resp = HttpMessageHelper.NOT_STRICT.firstLineToString(getResponse()); + resp = helper.firstLineToString(getResponse()); } return "HttpSessionPayloadEvent{"
--- a/stress-tester/src/main/java/com/passus/st/client/http/extractor/ContentExtractor.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/extractor/ContentExtractor.java Mon Oct 09 13:44:39 2017 +0200 @@ -11,7 +11,7 @@ public interface ContentExtractor { public default String extract(HttpMessage response) throws IOException { - String content = HttpMessageHelper.STRICT.contentToString(response, true); + String content = HttpMessageHelper.get().contentToString(response, true); return extract(content); }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilter.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpCsrfFilter.java Mon Oct 09 13:44:39 2017 +0200 @@ -60,7 +60,7 @@ @Override public ByteString extract(HttpMessage msg) { - HttpCookie cookie = HELPER.getCookie(msg, cookieName); + HttpCookie cookie = HttpMessageHelper.get().getCookie(msg, cookieName); if (cookie != null) { LOGGER.debug("extracting token {} (cookie)", cookie.getValue()); return cookie.getValue(); @@ -132,7 +132,7 @@ @Override public void inject(HttpMessage msg, ByteString csrfToken) { LOGGER.debug("injecting token {} (cookie)", csrfToken); - HELPER.updateCookieValue(msg, cookieName, csrfToken); + HttpMessageHelper.get().updateCookieValue(msg, cookieName, csrfToken); } } @@ -190,8 +190,6 @@ } } - private static final HttpMessageHelper HELPER = HttpMessageHelper.NOT_STRICT; - public static final String TYPE = "csrf"; public static final String SESSION_KEY = "_csrfTokens";
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessageWrapper.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterMessageWrapper.java Mon Oct 09 13:44:39 2017 +0200 @@ -14,8 +14,6 @@ */ public abstract class HttpFilterMessageWrapper<T extends HttpMessage> { - protected static final HttpMessageHelper HELPER = HttpMessageHelper.NOT_STRICT; - protected final T message; private final boolean request; @@ -44,7 +42,7 @@ } public ByteString getCookie(CharSequence name) { - HttpCookie cookie = HELPER.getCookie(message, name); + HttpCookie cookie = HttpMessageHelper.get().getCookie(message, name); return cookie == null ? null : cookie.getValue(); } }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterRequestWrapper.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFilterRequestWrapper.java Mon Oct 09 13:44:39 2017 +0200 @@ -1,6 +1,7 @@ package com.passus.st.client.http.filter; import com.passus.data.ByteString; +import com.passus.net.http.HttpMessageHelper; import com.passus.net.http.HttpRequest; import com.passus.net.http.URL; import static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID; @@ -23,7 +24,7 @@ public URL getUrl() { if (url == null) { - url = HELPER.getUrl(message); + url = HttpMessageHelper.get().getUrl(message); } return url;
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpMessageModificationFilter.java Mon Oct 09 13:44:39 2017 +0200 @@ -465,7 +465,7 @@ private final List<Operation> operations = new ArrayList<>(); - private static final HttpMessageHelper HELPER = HttpMessageHelper.STRICT; + private static final HttpMessageHelper HELPER = new HttpMessageHelper(true); private HttpMessagePredicate predicate;
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCsrfFormFilterTest.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpCsrfFormFilterTest.java Mon Oct 09 13:44:39 2017 +0200 @@ -46,8 +46,7 @@ filter.filterOutbound(req2, null, mockContext); - ByteBuffDataSource content = (ByteBuffDataSource) req2.getContent(); - HttpParameters form = HttpMessageHelper.STRICT.decodeFormUrlencoded(req2); + HttpParameters form = HttpMessageHelper.get().decodeFormUrlencoded(req2); assertEquals("newToken123", form.get("_token").toString()); assertEquals(34, req2.getContent().available()); }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFormLoginFilterTest.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpFormLoginFilterTest.java Mon Oct 09 13:44:39 2017 +0200 @@ -129,7 +129,7 @@ static void assertContent(HttpMessage msg, String content) throws IOException { assertEquals(readDataSource(msg), content); - assertEquals((int) HttpMessageHelper.NOT_STRICT.getContentLength(msg), content.length()); + assertEquals((int) HttpMessageHelper.get().getContentLength(msg), content.length()); } static String readDataSource(HttpMessage msg) throws IOException {
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpMessageModificationFilterTest.java Mon Oct 09 13:44:39 2017 +0200 @@ -34,8 +34,6 @@ */ public class HttpMessageModificationFilterTest { - private final HttpMessageHelper helper = HttpMessageHelper.NOT_STRICT; - @BeforeClass public static void beforeClass() { AppUtils.registerAll(); @@ -85,7 +83,7 @@ assertEquals("Header1Value3a", headers.get("Header3").toString()); assertEquals("myCookie1=myValue1;myCookie2=myValue2ab;myCookie4=myValue4;myCookie6=myValue6", headers.get("Cookie").toString()); - HttpParameters params = helper.decodeFormUrlencoded(req); + HttpParameters params = HttpMessageHelper.get().decodeFormUrlencoded(req); assertEquals("param1=value1¶m5=value5¶m6=value6a¶m6=value6b¶m2=value2a", params.toString()); }
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java Mon Oct 09 12:55:52 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSessionCookieFilterTest.java Mon Oct 09 13:44:39 2017 +0200 @@ -25,7 +25,7 @@ public class HttpSessionCookieFilterTest { private static final String COOKIE_NAME = "PHPSESSID"; - private final HttpMessageHelper mh = HttpMessageHelper.NOT_STRICT; + private final HttpMessageHelper mh = HttpMessageHelper.get(); private final String resp1s = "HTTP/1.1 200 OK\r\n" + "Set-Cookie: PHPSESSID=pcap_pre; path=/; HttpOnly\r\n"