summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/websocketmanager/provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/websocketmanager/provider/src/test')
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java19
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java156
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java76
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java16
4 files changed, 227 insertions, 40 deletions
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java
index f3cf09545..df04c388f 100644
--- a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java
@@ -20,13 +20,11 @@ package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
-import java.nio.file.Paths;
+import java.nio.file.Files;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.AkkaConfig;
@@ -58,19 +56,6 @@ public class AkkaConfigTest {
public static String loadResourceContentAsString(String resourceName)
throws URISyntaxException, FileNotFoundException, IOException {
- StringBuilder sb = new StringBuilder();
-
- ClassLoader classLoader = AkkaConfigTest.class.getClassLoader();
- File file = Paths.get(classLoader.getResource(resourceName).toURI()).toFile();
- try (BufferedReader br = new BufferedReader(new FileReader(file))) {
- String line = br.readLine();
-
- while (line != null) {
- sb.append(line);
- sb.append(System.lineSeparator());
- line = br.readLine();
- }
- }
- return sb.toString();
+ return Files.readString(new File("src/test/resources/"+resourceName).toPath());
}
}
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java
index f4fab6810..d5a940f73 100644
--- a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/RateFilterTest.java
@@ -21,10 +21,15 @@
*/
package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import java.time.Duration;
import java.time.Instant;
+import java.util.Timer;
+import java.util.TimerTask;
import org.junit.Test;
-import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.RateFilter;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.RateFilterManager;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.RateFilterManager.RateFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,11 +38,13 @@ import org.slf4j.LoggerFactory;
*
* <pre>
* Testcase (e: 17 Event received, rateMaxCount=3)
- * eee e e e e e e e e e e e e e e
- * ---//--|--------------|-----//-------|--------------|--------------|--------------|---//----|--------------|
- * P1:1 P2:1 P1:2 P2:2 P3:2 P4:2 P1:3
- * 1000-1002 2000 3500 10 millis
- *Overload no no yes yes no no
+ * 1 3 4 5 6 7 8 9 10 11 14 15 16 17 18
+ * t t t t t t t t t
+ * eee e e e e e e e e e e e e e e e
+ * ---//--|--------------|-----//-------|--------------|--------------|--------------|---//----|--------------|
+ * P1:1 P2:1 P1:2 P2:2 P3:2 P4:2 P1:3
+ * ms 500 1000-1002 2000 3500 4500 5500 6500 7500 8500
+ *Overload no no yes yes no no
* </pre>
*
*/
@@ -45,37 +52,140 @@ public class RateFilterTest {
private static final Logger LOG = LoggerFactory.getLogger(RateFilterTest.class.getName());
- private static int MILLIS = 1000;
- private static long[] now = { 1000, 1001, 1002, //P1:1 0-2
- 3500, 3550, 3560, 3570, 3580, 3590, 3800, //P1:2 3500 3-9
- 4510, 4520, 4530, 4540, 4900, //P2:2 4500 10-14
- 5700, //P3:2 5500 15
- 7000, 8000};//P1:3 16-17
+ private static int INTEGRATIONTIMEMILLIS = 1000;
+ private static long EVENTS_PER_INTERVALL = 4;
+ private static long RATE_PER_MINUTE = EVENTS_PER_INTERVALL * 60;
+ /* Negative event time indicates timer event */
+ private static long[] now = {-500, 1000, 1010, 1020, //P1:1 1-3
+ -1500, -2500, -3500, 3500, 3550, 3560, 3570, 3580, 3590, 3800, //P1:2 3500 4-10
+ -4500, 4510, 4520, 4530, 4540, 4900, //P2:2 4500 11-15
+ -5500, 5700, //P3:2 5500 16
+ -6500, -7500, 7500, 8000};//P1:3 17-18
+ private static boolean[] overload = {false, false, false, false, //P1:1 1-3
+ false, false, false, false, false, false, false, false, false, false, //P1:2 3500 4-10
+ true, true, true, true, true, true, //P2:2 4500 11-15
+ true, true, //P3:2 5500 16
+ false, false, false, false};//P1:3 17-18
+
private static int idx;
+ private static long millis;
@Test
- public void test() {
- RateFilter rateFilter = new RateFilter(Duration.ofMillis(MILLIS), 4, () -> getNow());
+ public void testStates() {
+ reset();
+ RateFilterManager rateFilterManager =
+ new RateFilterManager(Duration.ofMillis(INTEGRATIONTIMEMILLIS), false, () -> getNow());
+ RateFilter rateFilter = rateFilterManager.getRateFilter(RATE_PER_MINUTE);
LOG.info("Init done");
+ assertEquals("Events per integration period", EVENTS_PER_INTERVALL, rateFilter.getMaxEventsPerIntegration());
- for (int t=0; t < 20; t++) {
- LOG.info("{}", t);
- rateFilter.filterEvent();
- LOG.info("{}", rateFilter.getOverloadStatus());
+ for (int t = 1; t < 30; t++) {
+ boolean expected = tick();
+ if (millis < 0) {
+ LOG.info("{} - timer {}", t, millis);
+ rateFilter.timer();
+ } else {
+ LOG.info("{} - event {}", t, millis);
+ rateFilter.event();
+ }
+ LOG.info("Overload={} {}", rateFilter.getOverloadStatus(), expected);
+ assertEquals("Filter activity", expected, rateFilter.getOverloadStatus());
}
+ rateFilter.close();
+ }
+
+ @Test
+ public void testThread() throws InterruptedException {
+ LOG.info("testThread");
+ reset();
+ RateFilterManager rateFilterManager = new RateFilterManager(Duration.ofMillis(INTEGRATIONTIMEMILLIS));
+ RateFilter rateFilter = rateFilterManager.getRateFilter(RATE_PER_MINUTE);
+
+ tick();
+ Thread.sleep(2000);
+
+ Object objectYouNeedToLockOn = new Object();
+ Timer timer = new Timer();
+ timer.scheduleAtFixedRate(new TimerTask() {
+ long localMillis;
+
+ @Override
+ public void run() {
+ long xLocalMillis = localMillis += 10;
+ long xMillis = Math.abs(millis);
+ if (xLocalMillis >= xMillis) {
+ LOG.info("aTime:{} Millis:{} Idx={}", xLocalMillis, xMillis, idx);
+ boolean expected = tick();
+ if (millis > 0) {
+ //Skip negatives .. handled by timer
+ rateFilter.event();
+ boolean actual = rateFilter.getOverloadStatus();
+ LOG.info("bTime:{} Millis:{} Idx={} Overload={} Expected={} {}", xLocalMillis, xMillis, idx,
+ actual, expected, actual == expected ? "" : "XXXX");
+ if (idx >= 30) {
+ LOG.info("Test is ending");
+ synchronized (objectYouNeedToLockOn) {
+ objectYouNeedToLockOn.notify();
+ }
+ timer.cancel();
+ }
+ assertEquals("Filter activity", expected, rateFilter.getOverloadStatus());
+ }
+ }
+ }
+ }, 0, 10);
+ synchronized (objectYouNeedToLockOn) {
+ objectYouNeedToLockOn.wait();
+ }
+ //rateFilter.close();
+ LOG.info("Test end");
+ }
+
+ @Test
+ public void testMultipleClients() {
+ RateFilterManager rateFilterManager = new RateFilterManager(Duration.ofMillis(INTEGRATIONTIMEMILLIS));
+ RateFilter rateFilter1 = rateFilterManager.getRateFilter(RATE_PER_MINUTE);
+ assertEquals("Multiple clients", 1, rateFilter1.getClients());
+ RateFilter rateFilter2 = rateFilterManager.getRateFilter(RATE_PER_MINUTE);
+ assertEquals("Multiple clients", 2, rateFilter1.getClients());
+ RateFilter rateFilter3 = rateFilterManager.getRateFilter(RATE_PER_MINUTE);
+ assertEquals("Multiple clients", 3, rateFilter1.getClients());
+
+ assertEquals("Similar instances", rateFilter1, rateFilter3);
+
+ RateFilter rateFilterOther = rateFilterManager.getRateFilter(2*RATE_PER_MINUTE);
+ assertNotEquals("Different instances", rateFilter1, rateFilterOther);
+ rateFilterOther.close();
+
+ rateFilter3.close();
+ assertEquals("Multiple clients", 2, rateFilter1.getClients());
+ rateFilter2.close();
+ assertEquals("Multiple clients", 1, rateFilter1.getClients());
+ rateFilter1.close();
+ assertEquals("Multiple clients", 0, rateFilter1.getClients());
+
+ rateFilterManager.close();
+ }
+
+ private Instant getNow() {
+ LOG.debug("Now:{}", millis);
+ return Instant.ofEpochMilli(Math.abs(millis));
+ }
+ private void reset() {
+ idx = 0;
}
- Instant getNow() {
- long res;
+ private boolean tick() {
if (idx < now.length) {
- res = now[idx];
+ millis = now[idx];
} else {
int lastIdx = now.length - 1;
- res = now[lastIdx] + (idx - lastIdx) * MILLIS;
+ millis = now[lastIdx] + (idx - lastIdx) * INTEGRATIONTIMEMILLIS;
}
+ boolean expected = idx < overload.length ? overload[idx] : false;
idx++;
- return Instant.ofEpochMilli(res);
+ return expected;
}
}
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
new file mode 100644
index 000000000..885ded348
--- /dev/null
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
@@ -0,0 +1,76 @@
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. 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==========================================================================
+ */
+package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.ReducedSchemaInfo;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.SchemaInfo;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.Scope;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.UserScopes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotification;
+import org.opendaylight.yangtools.yang.common.QName;
+
+public class UserScopeTest {
+
+
+ @Test
+ public void testAllNodes() {
+ UserScopes scopes1 = new UserScopes();
+ scopes1.setScopes(Arrays.asList(buildScope(null, ProblemNotification.QNAME)));
+
+ assertTrue(scopes1.hasScope(new ReducedSchemaInfo(ProblemNotification.QNAME)));
+ assertFalse(scopes1.hasScope("RoadmA", new ReducedSchemaInfo(ObjectCreationNotification.QNAME)));
+
+ assertTrue(scopes1.hasScope("RoadmA", new ReducedSchemaInfo(ProblemNotification.QNAME)));
+
+ }
+
+ @Test
+ public void testRevisionStar() {
+ UserScopes scopes1 = new UserScopes();
+ scopes1.setScopes(
+ Arrays.asList(buildScope(null, ProblemNotification.QNAME.getNamespace().toString(), "*", null)));
+
+ assertTrue(scopes1.hasScope(new ReducedSchemaInfo(ProblemNotification.QNAME)));
+ assertTrue(scopes1.hasScope("RoadmA", new ReducedSchemaInfo(ObjectCreationNotification.QNAME)));
+
+ assertTrue(scopes1.hasScope("RoadmA", new ReducedSchemaInfo(ProblemNotification.QNAME)));
+
+ }
+
+ private static final Scope buildScope(String nodeId, String namespace, String revision,
+ List<String> notifications) {
+ Scope scope = new Scope();
+ scope.setNodeId(nodeId);
+ scope.setSchema(new SchemaInfo(namespace, revision, notifications));
+ return scope;
+ }
+
+ private static final Scope buildScope(String nodeId, QName qname) {
+ Scope scope = new Scope();
+ scope.setNodeId(nodeId);
+ scope.setSchema(new SchemaInfo(qname));
+ return scope;
+ }
+
+}
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java
index bc3cd10f8..2e6462462 100644
--- a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java
@@ -17,11 +17,17 @@
*/
package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager.WebSocketManagerProvider;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ObjectCreationNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ProblemNotificationBuilder;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.osgi.service.http.HttpService;
public class WebsockerProviderTest extends Mockito {
@@ -42,4 +48,14 @@ public class WebsockerProviderTest extends Mockito {
}
+ @Test
+ public void testTypeAssertion() {
+
+ Notification problemNotification = new ProblemNotificationBuilder().build();
+ assertTrue(WebSocketManagerProvider.assertNotificationType(problemNotification, ProblemNotification.QNAME));
+ assertFalse(
+ WebSocketManagerProvider.assertNotificationType(problemNotification, ObjectCreationNotification.QNAME));
+
+ }
+
}