changeset 556:d5c14b4259ea

in progress
author Devel 1
date Wed, 20 Sep 2017 13:29:12 +0200
parents 7b10dfafe23a
children f65e374eb0f8
files stress-tester-benchmark/pom.xml stress-tester-benchmark/src/main/java/com/passus/st/avro/AbstractAvroBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/avro/AvroRpcBenchmark.java stress-tester-reporter/src/test/java/com/passus/st/reporter/server/Test.java stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml
diffstat 7 files changed, 80 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester-benchmark/pom.xml	Tue Sep 19 11:26:31 2017 +0200
+++ b/stress-tester-benchmark/pom.xml	Wed Sep 20 13:29:12 2017 +0200
@@ -10,7 +10,7 @@
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <javac.target>1.8</javac.target>
-        <jmh.version>1.17.3</jmh.version>
+        <jmh.version>1.19</jmh.version>
         <uberjar.name>benchmarks</uberjar.name>
     </properties>
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/avro/AbstractAvroBenchmark.java	Wed Sep 20 13:29:12 2017 +0200
@@ -0,0 +1,28 @@
+package com.passus.st.avro;
+
+import static com.passus.commons.collection.FluentBuilder.e;
+import static com.passus.commons.collection.FluentBuilder.map;
+import com.passus.st.reporter.protocol.MetricRecord;
+import java.net.InetSocketAddress;
+import java.util.Map;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+public class AbstractAvroBenchmark {
+
+    protected final InetSocketAddress serverAddress = new InetSocketAddress(11111);
+    protected final MetricRecord bigMetricRecord;
+    protected final MetricRecord smallMetricRecord;
+
+    public AbstractAvroBenchmark() {
+        Map<CharSequence, Object> nested = map(e("null", null), e("double", 22.0), e("string", "twenty two"));
+        Map<CharSequence, Object> map = map(
+                e("null", null), e("int", 22), e("long", 22L), e("float", 22f),
+                e("double", 22.), e("string", "twenty two"), e("map", nested)
+        );
+        bigMetricRecord = new MetricRecord("big", map);
+        smallMetricRecord = new MetricRecord("small", nested);
+    }
+}
--- a/stress-tester-benchmark/src/main/java/com/passus/st/avro/AvroRpcBenchmark.java	Tue Sep 19 11:26:31 2017 +0200
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/avro/AvroRpcBenchmark.java	Wed Sep 20 13:29:12 2017 +0200
@@ -1,14 +1,10 @@
 package com.passus.st.avro;
 
-import static com.passus.commons.collection.FluentBuilder.e;
-import static com.passus.commons.collection.FluentBuilder.map;
 import com.passus.st.reporter.protocol.MetricRecord;
 import com.passus.st.reporter.protocol.MetricsCollectionRecord;
 import com.passus.st.reporter.protocol.Reporter;
 import com.passus.utils.AllocationUtils;
 import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import org.apache.avro.AvroRemoteException;
 import org.apache.avro.ipc.NettyServer;
@@ -42,25 +38,12 @@
 @Fork(value = 1)
 @Measurement(iterations = 7)
 @Warmup(iterations = 7)
-public class AvroRpcBenchmark {
+public class AvroRpcBenchmark extends AbstractAvroBenchmark {
 
-    private final InetSocketAddress serverAddress = new InetSocketAddress(11111);
-    private final MetricRecord bigMetricRecord;
-    private final MetricRecord smallMetricRecord;
     private NettyTransceiver client;
     private Reporter proxy;
     private Server server;
 
-    public AvroRpcBenchmark() {
-        Map<CharSequence, Object> nested = map(e("null", null), e("double", 22.0), e("string", "twenty two"));
-        Map<CharSequence, Object> map = map(
-                e("null", null), e("int", 22), e("long", 22L), e("float", 22f),
-                e("double", 22.), e("string", "twenty two"), e("map", nested)
-        );
-        bigMetricRecord = new MetricRecord("big", map);
-        smallMetricRecord = new MetricRecord("small", nested);
-    }
-
     @Setup
     public void setup() throws IOException {
         Responder responder = new SpecificResponder(Reporter.class, new DummyReporter());
--- a/stress-tester-reporter/src/test/java/com/passus/st/reporter/server/Test.java	Tue Sep 19 11:26:31 2017 +0200
+++ b/stress-tester-reporter/src/test/java/com/passus/st/reporter/server/Test.java	Wed Sep 20 13:29:12 2017 +0200
@@ -20,32 +20,28 @@
  */
 public class Test {
 
+    private static final Map<CharSequence, Object> FIELDS = map(
+            e("int_fld", 1), e("string_fld", "ok"), e("map_fld", smap("some", "entry")),
+            e("bstr_fld", ByteString.create("byte-string-value"))
+    );
+    private static final MetricRecord METRIC = new MetricRecord("metric-x", FIELDS);
+    private static final InetSocketAddress ADDRESS = new InetSocketAddress(ServerMain.PORT);
+
     public static void main(String[] args) throws IOException {
-        InetSocketAddress serverAddress = new InetSocketAddress(ServerMain.PORT);
         ReporterImpl reporter = new ReporterImpl();
         reporter.setVerbose(true);
         Responder responder = new SpecificResponder(Reporter.class, reporter);
-        Server server = new NettyServer(responder, serverAddress);
+        Server server = new NettyServer(responder, ADDRESS);
         System.out.println("server started");
 
-        try (NettyTransceiver client = new NettyTransceiver(serverAddress)) {
+        try (NettyTransceiver client = new NettyTransceiver(ADDRESS)) {
             Reporter proxy = (Reporter) SpecificRequestor.getClient(Reporter.class, client);
             System.out.println("Client built, got proxy");
-
-            ByteString bs = ByteString.create("byte-string-value");
-            Map<CharSequence, Object> nested = smap("some", "entry");
-            Map<CharSequence, Object> fields = map(
-                    e("int_fld", 1), e("string_fld", "ok"), e("map_fld", nested), e("bstr_fld", bs)
-            );
-            MetricRecord metric = new MetricRecord("metric-x", fields);
-            proxy.handleMetric(metric);
-            System.out.println(proxy.handleMetric(metric));
-
+            System.out.println(proxy.handleMetric(METRIC));
         } catch (IOException ex) {
             System.out.println(ex);
         }
 
         server.close();
-
     }
 }
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java	Tue Sep 19 11:26:31 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpSequenceFilter.java	Wed Sep 20 13:29:12 2017 +0200
@@ -62,6 +62,14 @@
             this.predicate = predicate;
         }
 
+        public Predicate getPredicate() {
+            return predicate;
+        }
+
+        public int getNum() {
+            return num;
+        }
+
         public void setNum(int num) {
             this.num = num;
         }
@@ -362,7 +370,7 @@
             seqItems[i].setNum(i);
         }
 
-        this.values = (Map<String, ValueExtractor>) config.get("values", Collections.EMPTY_MAP);
+        values = (Map<String, ValueExtractor>) config.get("values", Collections.EMPTY_MAP);
     }
 
     public static class NodeDefCreator implements NodeDefinitionCreator {
--- a/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java	Tue Sep 19 11:26:31 2017 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/http/filter/HttpSequenceFilterTest.java	Wed Sep 20 13:29:12 2017 +0200
@@ -2,6 +2,11 @@
 
 import com.passus.commons.utils.ResourceUtils;
 import com.passus.config.validation.Errors;
+import com.passus.filter.AndPredicate;
+import com.passus.filter.BeanValueExtractor;
+import com.passus.filter.ComparisonOperator;
+import com.passus.filter.ComparisonPredicate;
+import com.passus.filter.UnmutableValueExtractor;
 import com.passus.filter.ValueExtractor;
 import com.passus.filter.ValueExtractorParser;
 import com.passus.filter.config.PredicateNodeTransformer;
@@ -101,12 +106,33 @@
         assertEquals(0, errors.getErrorCount());
         assertEquals(1, filters.size());
         assertTrue(filters.get(0) instanceof HttpSequenceFilter);
-
         HttpSequenceFilter filter = (HttpSequenceFilter) filters.get(0);
-        filter.getSeqItems();
-        filter.getValues();
 
-        System.out.println("");
+        SequenceItem[] seqItems = filter.getSeqItems();
+        assertEquals(2, seqItems.length);
+        assertSeqItemValue(seqItems[0], 0, 10000, null);
+        assertSeqItemValue(seqItems[1], 1, 20000, "last");
+
+        AndPredicate p0 = (AndPredicate) seqItems[0].getPredicate();
+        assertEquals(2, p0.getSubPredicates().size());
+        ComparisonPredicate sp1 = (ComparisonPredicate) p0.getSubPredicates().get(1);
+        assertEquals(ComparisonOperator.EQUAL, sp1.getOperator());
+        assertEquals("resp.getCookie('id')", sp1.getFieldName());
+        UnmutableValueExtractor uve = (UnmutableValueExtractor) sp1.getPattern();
+        assertEquals(123, uve.extract(null));
+
+        Map<String, ValueExtractor> values = filter.getValues();
+        assertEquals(4, values.size());
+        ValueExtractor extractor = values.get("header");
+        assertTrue(extractor instanceof BeanValueExtractor);
+        BeanValueExtractor bve = (BeanValueExtractor) extractor;
+        assertEquals("_i1.req.getHeader('xyz')", bve.getFieldName());
+    }
+
+    private static void assertSeqItemValue(SequenceItem item, int num, long time, String alias) {
+        assertEquals("num", num, item.getNum());
+        assertEquals("time", time, item.getTime());
+        assertEquals("alias", alias, item.getAlias());
     }
 
     public static class TestHttpSequenceListener implements HttpSequenceListener {
--- a/stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml	Tue Sep 19 11:26:31 2017 +0200
+++ b/stress-tester/src/test/resources/com/passus/st/client/http/filter/sequence.yml	Wed Sep 20 13:29:12 2017 +0200
@@ -4,7 +4,7 @@
       - match: {"req.uri": "/res1", "resp.getCookie('id')": "123"}
       - match: {"req.getHeader('xyz')": "abc"}
         mustOccur: true
-        time: 10000
+        time: 20000
         alias: last
     values:
         code: $_i0.resp.status.code