jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch bug_64553 updated: Add test cases for new method addCumulated
Date Mon, 17 Aug 2020 15:20:39 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch bug_64553
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/bug_64553 by this push:
     new 72b2587  Add test cases for new method addCumulated
72b2587 is described below

commit 72b2587ba79bb4850a5d217200bf71f5f3623078
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Mon Aug 17 17:20:16 2020 +0200

    Add test cases for new method addCumulated
---
 .../backend/SamplerMetricFixedModeTest.java        | 62 ++++++++++++++++++++
 .../backend/SamplerMetricTimedModeTest.java        | 68 +++++++++++++++++++++-
 2 files changed, 127 insertions(+), 3 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
index 6f479f3..61ed8a0 100644
--- a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricFixedModeTest.java
@@ -19,6 +19,9 @@ package org.apache.jmeter.visualizers.backend;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
+
+import org.apache.jmeter.control.TransactionController;
 import org.apache.jmeter.samplers.SampleResult;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -103,4 +106,63 @@ public class SamplerMetricFixedModeTest {
         result.setResponseMessage(errorMessage);
         return result;
     }
+
+    private SampleResult createSampleResultWithSubresults(boolean success) {
+        SampleResult result = new SampleResult();
+        result.sampleStart();
+        result.setSampleCount(1);
+        result.setErrorCount(success ? 0 : 1);
+        result.setSuccessful(success);
+        result.addSubResult(createSampleResult(success));
+        result.addSubResult(createSampleResult(success));
+        result.setEndTime(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getEndTime).max().orElse(0));
+        result.setBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getBytesAsLong).sum());
+        result.setSentBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getSentBytes).sum());
+        result.setResponseMessage("Number of samples in transaction : "); // This is a constant
in TransactionController
+        return result;
+    }
+
+    @Test
+    public void checkAddCumulatedOk() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(true);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset hits", 2, metric.getHits(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
0.0);
+        assertEquals("After reset in TIMED mode all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
0.0);
+        assertEquals("After reset hits", 0, metric.getHits(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
+
+    @Test
+    public void checkAddCumulatedKo() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(false);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset failures", 1, metric.getFailures(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
2.0);
+        assertEquals("After reset in TIMED mode all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.0);
+        assertEquals("After reset failures", 0, metric.getFailures(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
 }
diff --git a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
index 82ca45d..17a90a7 100644
--- a/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
+++ b/src/components/src/test/java/org/apache/jmeter/visualizers/backend/SamplerMetricTimedModeTest.java
@@ -19,6 +19,9 @@ package org.apache.jmeter.visualizers.backend;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
+
+import org.apache.jmeter.control.TransactionController;
 import org.apache.jmeter.samplers.SampleResult;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -29,7 +32,7 @@ public class SamplerMetricTimedModeTest {
 
     @BeforeEach
     public void initMode() throws Exception {
-        //noinspection deprecation
+        // noinspection deprecation
         SamplerMetric.setDefaultWindowMode(WindowMode.TIMED);
     }
 
@@ -41,7 +44,7 @@ public class SamplerMetricTimedModeTest {
         metric.add(createSampleResult(true));
         assertEquals("Before reset  ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
0.001);
         assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
0.001);
-        assertEquals("Before reset failure", 1, metric.getHits(), 0.0);
+        assertEquals("Before reset hits", 1, metric.getHits(), 0.0);
         assertEquals("Before reset sent bytes", 1000, metric.getSentBytes(), 0.0);
         assertEquals("Before reset received bytes", 2000, metric.getReceivedBytes(), 0.0);
 
@@ -49,7 +52,7 @@ public class SamplerMetricTimedModeTest {
 
         assertEquals("After reset in TIMED mode ok.max", Double.NaN, metric.getOkMaxTime(),
0.0);
         assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(),
0.0);
-        assertEquals("After reset failure", 0, metric.getHits(), 0.0);
+        assertEquals("After reset hits", 0, metric.getHits(), 0.0);
         assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
         assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
     }
@@ -86,4 +89,63 @@ public class SamplerMetricTimedModeTest {
         return result;
     }
 
+    private SampleResult createSampleResultWithSubresults(boolean success) {
+        SampleResult result = new SampleResult();
+        result.sampleStart();
+        result.setSampleCount(1);
+        result.setErrorCount(success ? 0 : 1);
+        result.setSuccessful(success);
+        result.addSubResult(createSampleResult(success));
+        result.addSubResult(createSampleResult(success));
+        result.setEndTime(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getEndTime).max().orElse(0));
+        result.setBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getBytesAsLong).sum());
+        result.setSentBytes(Arrays.stream(result.getSubResults()).mapToLong(SampleResult::getSentBytes).sum());
+        result.setResponseMessage("Number of samples in transaction : "); // This is a constant
in TransactionController
+        return result;
+    }
+
+    @Test
+    public void checkAddCumulatedOk() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(true);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ok.max", DEFAULT_ELAPSED_TIME, metric.getOkMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset hits", 2, metric.getHits(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ok.max", Double.NaN, metric.getOkMaxTime(),
0.0);
+        assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(),
0.0);
+        assertEquals("After reset hits", 0, metric.getHits(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
+
+    @Test
+    public void checkAddCumulatedKo() throws Exception {
+        SamplerMetric metric = new SamplerMetric();
+        SampleResult sample = createSampleResultWithSubresults(false);
+        assertEquals("We are recognized as a TransactionController made sample", Boolean.TRUE,
+                Boolean.valueOf(TransactionController.isFromTransactionController(sample)));
+        metric.addCumulated(sample);
+        assertEquals("Before reset  ko.max", DEFAULT_ELAPSED_TIME, metric.getKoMaxTime(),
2.001);
+        assertEquals("Before reset all.max", DEFAULT_ELAPSED_TIME, metric.getAllMaxTime(),
2.001);
+        assertEquals("Before reset failures", 1, metric.getFailures(), 0.0);
+        assertEquals("Before reset sent bytes", 2000, metric.getSentBytes(), 0.0);
+        assertEquals("Before reset received bytes", 4000, metric.getReceivedBytes(), 0.0);
+
+        metric.resetForTimeInterval();
+
+        assertEquals("After reset in TIMED mode ko.max", Double.NaN, metric.getKoMaxTime(),
0.0);
+        assertEquals("After reset in TIMED mode all.max", Double.NaN, metric.getAllMaxTime(),
0.0);
+        assertEquals("After reset failures", 0, metric.getFailures(), 0.0);
+        assertEquals("After reset sent bytes", 0, metric.getSentBytes(), 0.0);
+        assertEquals("After reset received bytes", 0, metric.getReceivedBytes(), 0.0);
+    }
+
 }


Mime
View raw message