summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/openecomp/sparky/analytics
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/openecomp/sparky/analytics')
-rw-r--r--src/test/java/org/openecomp/sparky/analytics/AveragingRingBufferTest.java133
-rw-r--r--src/test/java/org/openecomp/sparky/analytics/HistogramSamplerTest.java90
-rw-r--r--src/test/java/org/openecomp/sparky/analytics/TransactionRateControllerTest.java217
3 files changed, 440 insertions, 0 deletions
diff --git a/src/test/java/org/openecomp/sparky/analytics/AveragingRingBufferTest.java b/src/test/java/org/openecomp/sparky/analytics/AveragingRingBufferTest.java
new file mode 100644
index 0000000..d8a558c
--- /dev/null
+++ b/src/test/java/org/openecomp/sparky/analytics/AveragingRingBufferTest.java
@@ -0,0 +1,133 @@
+/*
+* ============LICENSE_START=======================================================
+* SPARKY (AAI UI service)
+* ================================================================================
+* Copyright © 2017 AT&T Intellectual Property.
+* Copyright © 2017 Amdocs
+* All rights reserved.
+* ================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*
+* ECOMP and OpenECOMP are trademarks
+* and service marks of AT&T Intellectual Property.
+*/
+
+package org.openecomp.sparky.analytics;
+
+import static org.junit.Assert.assertEquals;
+
+import java.security.SecureRandom;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ * The Class AveragingRingBufferTest.
+ */
+@RunWith(PowerMockRunner.class)
+public class AveragingRingBufferTest {
+
+ protected SecureRandom random = new SecureRandom();
+
+ /**
+ * Inits the.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void init() throws Exception {
+ // nothing at the moment
+ }
+
+ /**
+ * Validate pre index roll averaging.
+ */
+ @Test
+ public void validatePreIndexRollAveraging() {
+
+ AveragingRingBuffer arb = new AveragingRingBuffer(5);
+ assertEquals(0, arb.getAvg());
+
+ /*
+ * On initial buffer fill, the average will be re-calculated on the fly for the first nth data
+ * points until the data buffer has been filled the first time, and then the buffer
+ * automatically recalculates the average every time the buffer index rolls over, to the keep
+ * the average relative to the last "nth" data points.
+ */
+
+ // [ 1, 0, 0, 0, 0 ], sum = 1, avg = 1/1 =1
+ arb.addSample(1);
+ assertEquals(1, arb.getAvg());
+
+ // [ 1, 2, 0, 0, 0 ], sum = 3, avg = 3/2 = 1
+ arb.addSample(2);
+ assertEquals(1, arb.getAvg());
+
+ // [ 1, 2, 3, 0, 0 ], sum = 6, avg = 6/3 = 2
+ arb.addSample(3);
+ assertEquals(2, arb.getAvg());
+
+ // [ 1, 2, 3, 4, 0 ], sum = 10, avg = 10/4 = 2
+ arb.addSample(4);
+ assertEquals(2, arb.getAvg());
+
+ // [ 1, 2, 3, 4, 5 ], sum = 15, avg = 15/5 = 3
+ arb.addSample(5);
+ assertEquals(3, arb.getAvg());
+
+ }
+
+ /**
+ * Validate post index roll averaging.
+ */
+ @Test
+ public void validatePostIndexRollAveraging() {
+
+ AveragingRingBuffer arb = new AveragingRingBuffer(5);
+ arb.addSample(1);
+ arb.addSample(2);
+ arb.addSample(3);
+ arb.addSample(4);
+ arb.addSample(5);
+
+ /*
+ * The behavior switches, and now doesn't re-calculate the average until each nth data point, to
+ * reduce the computational over-head of re-calculating on each value.
+ */
+
+ // [ 10, 2, 3, 4, 5 ],
+ arb.addSample(10);
+ assertEquals(3, arb.getAvg());
+
+ // [ 10, 20, 3, 4, 5 ],
+ arb.addSample(20);
+ assertEquals(3, arb.getAvg());
+
+ // [ 10, 20, 30, 4, 5 ],
+ arb.addSample(30);
+ assertEquals(3, arb.getAvg());
+
+ // [ 10, 20, 30, 40, 5 ],
+ arb.addSample(40);
+ assertEquals(3, arb.getAvg());
+
+ // [ 10, 20, 30, 40, 50 ], s=150, avg=150/5=30
+ arb.addSample(50);
+ assertEquals(30, arb.getAvg());
+
+ }
+
+}
diff --git a/src/test/java/org/openecomp/sparky/analytics/HistogramSamplerTest.java b/src/test/java/org/openecomp/sparky/analytics/HistogramSamplerTest.java
new file mode 100644
index 0000000..70e9e3c
--- /dev/null
+++ b/src/test/java/org/openecomp/sparky/analytics/HistogramSamplerTest.java
@@ -0,0 +1,90 @@
+/*
+* ============LICENSE_START=======================================================
+* SPARKY (AAI UI service)
+* ================================================================================
+* Copyright © 2017 AT&T Intellectual Property.
+* Copyright © 2017 Amdocs
+* All rights reserved.
+* ================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*
+* ECOMP and OpenECOMP are trademarks
+* and service marks of AT&T Intellectual Property.
+*/
+
+package org.openecomp.sparky.analytics;
+
+import java.security.SecureRandom;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+/**
+ * The Class HistogramSamplerTest.
+ */
+@RunWith(PowerMockRunner.class)
+public class HistogramSamplerTest {
+
+ protected SecureRandom random = new SecureRandom();
+
+ /**
+ * Inits the.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void init() throws Exception {
+ // nothing at the moment
+ }
+
+ /**
+ * Validate basic construction and delimited reporting.
+ */
+ @Test
+ public void validateBasicConstructionAndDelimitedReporting() {
+
+ HistogramSampler histoSampler = new HistogramSampler("[File byte size]", 500000, 22, 3);
+
+ SecureRandom random = new SecureRandom();
+
+ for (int x = 0; x < 100000; x++) {
+ histoSampler.track(random.nextInt(9999999));
+ }
+
+ System.out.println(histoSampler.getStats(false, " "));
+
+ }
+
+
+ /**
+ * Validate basic construction and formatted reporting.
+ */
+ @Test
+ public void validateBasicConstructionAndFormattedReporting() {
+
+ HistogramSampler histoSampler = new HistogramSampler("[Queue Length Samples]", 100000, 15, 3);
+
+ SecureRandom random = new SecureRandom();
+
+ for (int x = 0; x < 100000; x++) {
+ histoSampler.track(random.nextInt(9999999));
+ }
+
+ System.out.println(histoSampler.getStats(true, " "));
+
+ }
+
+}
diff --git a/src/test/java/org/openecomp/sparky/analytics/TransactionRateControllerTest.java b/src/test/java/org/openecomp/sparky/analytics/TransactionRateControllerTest.java
new file mode 100644
index 0000000..c5f14e6
--- /dev/null
+++ b/src/test/java/org/openecomp/sparky/analytics/TransactionRateControllerTest.java
@@ -0,0 +1,217 @@
+/*
+* ============LICENSE_START=======================================================
+* SPARKY (AAI UI service)
+* ================================================================================
+* Copyright © 2017 AT&T Intellectual Property.
+* Copyright © 2017 Amdocs
+* All rights reserved.
+* ================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*
+* ECOMP and OpenECOMP are trademarks
+* and service marks of AT&T Intellectual Property.
+*/
+
+package org.openecomp.sparky.analytics;
+
+import org.junit.Before;
+
+
+/**
+ * The Class TransactionRateControllerTest.
+ */
+public class TransactionRateControllerTest {
+
+ /**
+ * Inits the.
+ *
+ * @throws Exception the exception
+ */
+ @Before
+ public void init() throws Exception {
+ // nothing at the moment
+ }
+ /*
+ * @Test public void tenTPS_oneThread_validateRateEnforcementWhenAvgResposneTimeIsUnderBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(10.0, 1, 5);
+ *
+ * trc.trackResponseTime(25); trc.trackResponseTime(35); trc.trackResponseTime(45);
+ * trc.trackResponseTime(55); trc.trackResponseTime(70);
+ *
+ * // avg should be 46 ms
+ *
+ * assertEquals(54, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void tenTPS_oneThread_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(10.0, 1, 5);
+ *
+ * trc.trackResponseTime(75); trc.trackResponseTime(125); trc.trackResponseTime(250);
+ * trc.trackResponseTime(105); trc.trackResponseTime(23);
+ *
+ * // avg should be 115 ms
+ *
+ * assertEquals(0, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void oneTPS_oneThread_validateRateEnforcementWhenAvgResposneTimeIsUnderBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(1.0, 1, 5);
+ *
+ * trc.trackResponseTime(25); trc.trackResponseTime(35); trc.trackResponseTime(45);
+ * trc.trackResponseTime(55); trc.trackResponseTime(70);
+ *
+ * // avg should be 46 ms
+ *
+ * assertEquals(954, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void oneTPS_oneThread_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(1.0, 1, 5);
+ *
+ * trc.trackResponseTime(75); trc.trackResponseTime(125); trc.trackResponseTime(250);
+ * trc.trackResponseTime(105); trc.trackResponseTime(23);
+ *
+ * // avg should be 115 ms
+ *
+ * assertEquals(885, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void halfTPS_oneThread_validateRateEnforcementWhenAvgResposneTimeIsUnderBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(0.5, 1, 5);
+ *
+ * trc.trackResponseTime(25); trc.trackResponseTime(35); trc.trackResponseTime(45);
+ * trc.trackResponseTime(55); trc.trackResponseTime(70);
+ *
+ * // avg should be 46 ms
+ *
+ * assertEquals(1954, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void halfTPS_oneThread_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(0.5, 1, 5);
+ *
+ * trc.trackResponseTime(75); trc.trackResponseTime(125); trc.trackResponseTime(250);
+ * trc.trackResponseTime(105); trc.trackResponseTime(23);
+ *
+ * // avg should be 115 ms
+ *
+ * assertEquals(1885, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void tenTPS_tenThreads_validateRateEnforcementWhenAvgResposneTimeIsUnderBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(10.0, 10, 5);
+ *
+ * trc.trackResponseTime(25); trc.trackResponseTime(35); trc.trackResponseTime(45);
+ * trc.trackResponseTime(55); trc.trackResponseTime(70);
+ *
+ * // avg should be 46 ms
+ *
+ * assertEquals(540, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void tenTPS_tenThreads_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(10.0, 10, 5);
+ *
+ * trc.trackResponseTime(75); trc.trackResponseTime(125); trc.trackResponseTime(250);
+ * trc.trackResponseTime(105); trc.trackResponseTime(23);
+ *
+ * // avg should be 115 ms
+ *
+ * assertEquals(0, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void oneTPS_tenThreads_validateRateEnforcementWhenAvgResposneTimeIsUnderBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(1.0, 10, 5);
+ *
+ * trc.trackResponseTime(25); trc.trackResponseTime(35); trc.trackResponseTime(45);
+ * trc.trackResponseTime(55); trc.trackResponseTime(70);
+ *
+ * // avg should be 46 ms
+ *
+ * assertEquals(9540, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void oneTPS_tenThreads_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(1.0, 10, 5);
+ *
+ * trc.trackResponseTime(75); trc.trackResponseTime(125); trc.trackResponseTime(250);
+ * trc.trackResponseTime(105); trc.trackResponseTime(23);
+ *
+ * // avg should be 115 ms
+ *
+ * assertEquals(8850, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void halfTPS_tenThreads_validateRateEnforcementWhenAvgResposneTimeIsUnderBudget()
+ * {
+ *
+ * TransactionRateController trc = new TransactionRateController(0.5, 10, 5);
+ *
+ * trc.trackResponseTime(25); trc.trackResponseTime(35); trc.trackResponseTime(45);
+ * trc.trackResponseTime(55); trc.trackResponseTime(70);
+ *
+ * // avg should be 46 ms
+ *
+ * assertEquals(19540, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void halfTPS_tenThreads_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(0.5, 10, 5);
+ *
+ * trc.trackResponseTime(75); trc.trackResponseTime(125); trc.trackResponseTime(250);
+ * trc.trackResponseTime(105); trc.trackResponseTime(23);
+ *
+ * // avg should be 115 ms
+ *
+ * assertEquals(18850, trc.getFixedDelayInMs());
+ *
+ * }
+ *
+ * @Test public void oneTPS_fiveThreads_validateRateEnforcementWhenAvgResposneTimeIsOverBudget() {
+ *
+ * TransactionRateController trc = new TransactionRateController(1, 5, 5);
+ *
+ * trc.trackResponseTime(0); trc.trackResponseTime(0); trc.trackResponseTime(0);
+ * trc.trackResponseTime(0); trc.trackResponseTime(0);
+ *
+ * // avg should be 0 ms
+ *
+ * assertEquals(5000, trc.getFixedDelayInMs());
+ *
+ * }
+ */
+
+}