summaryrefslogtreecommitdiffstats
path: root/controlloop/common/feature-controlloop-trans/src/test
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-03-23 01:14:12 -0500
committerJorge Hernandez <jh1730@att.com>2018-03-23 17:40:02 +0000
commitc9f47efdffe00fc5f823b1c982e6b12d92f90276 (patch)
treefbeea464665975960c53cd06a6f67fb6f58f6342 /controlloop/common/feature-controlloop-trans/src/test
parent5c4675e5f6f7fe9b8d9e87976ac5f603ff61c268 (diff)
transaction logging through a feature
This is the first of 2 code inspections. This review contains though most of the work. It keeps tracks of all in progress transactions by intercepting all notifications. From that appropriate metrics can be obtained and logged. The actual logging of the metrics and enablement of the feature at install time will come in a subsequent review. Change-Id: Ie5c8adfbdeae72758da7da8a1b4133cd4818c6fb Issue-ID: POLICY-533 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'controlloop/common/feature-controlloop-trans/src/test')
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java181
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties2
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/resources/metrics-controller.properties1
3 files changed, 184 insertions, 0 deletions
diff --git a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
new file mode 100644
index 000000000..6e3db3f97
--- /dev/null
+++ b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
@@ -0,0 +1,181 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T 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.policy.drools.apps.controlloop.feature.trans;
+
+import java.nio.file.Path;
+import java.util.UUID;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.controlloop.ControlLoopNotificationType;
+import org.onap.policy.controlloop.VirtualControlLoopNotification;
+import org.onap.policy.drools.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.drools.persistence.SystemPersistence;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngine;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * ControlLoopMetrics Tests
+ */
+public class ControlLoopMetricsFeatureTest {
+
+ private static final Path configPath = SystemPersistence.manager.getConfigurationPath();
+ private static PolicyController testController;
+
+ @BeforeClass
+ public static void setUp() {
+ SystemPersistence.manager.setConfigurationDir("src/test/resources");
+ testController =
+ PolicyEngine.manager.createPolicyController
+ ("metrics", SystemPersistence.manager.getControllerProperties("metrics"));
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ SystemPersistence.manager.setConfigurationDir(configPath.toString());
+ }
+
+ @Test
+ public void cacheDefaults() {
+ assertTrue(ControlLoopMetrics.manager.getCacheSize() == 3);
+ assertTrue(ControlLoopMetrics.manager.getTransactionTimeout() == 10);
+ assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == 0);
+ }
+
+ @Test
+ public void invalidNotifications() {
+ ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature();
+ VirtualControlLoopNotification notification = new VirtualControlLoopNotification();
+ feature.beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification);
+ this.cacheDefaults();
+
+ UUID requestId = UUID.randomUUID();
+ notification.setRequestID(requestId);
+
+ feature.beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification);
+ assertNull(ControlLoopMetrics.manager.getTransaction(requestId));
+ this.cacheDefaults();
+ }
+
+ @Test
+ public void validActiveNotification() {
+ ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature();
+ VirtualControlLoopNotification notification = new VirtualControlLoopNotification();
+ UUID requestId = UUID.randomUUID();
+ notification.setRequestID(requestId);
+ notification.setNotification(ControlLoopNotificationType.ACTIVE);
+
+ feature.beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification);
+ assertNotNull(ControlLoopMetrics.manager.getTransaction(requestId));
+ assertTrue(ControlLoopMetrics.manager.getTransaction(requestId).getFrom().contains(testController.getName()));
+ assertNotNull(ControlLoopMetrics.manager.getTransaction(requestId).getNotificationTime());
+ assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == 1);
+
+ /* let the entries expire */
+ try {
+ Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout()+5)*1000L);
+ } catch (InterruptedException e) {
+ /* nothing to do */
+ }
+
+ assertNull(ControlLoopMetrics.manager.getTransaction(requestId));
+ this.cacheDefaults();
+ }
+
+ @Test
+ public void reset() {
+ VirtualControlLoopNotification notification = this.generateNotification();
+ new ControlLoopMetricsFeature().beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification);
+
+ assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestID()));
+
+ ControlLoopMetrics.manager.resetCache(ControlLoopMetrics.manager.getCacheSize(), ControlLoopMetrics.manager.getTransactionTimeout());
+ assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestID()));
+ this.cacheDefaults();
+ }
+
+ @Test
+ public void removeTransaction() {
+ VirtualControlLoopNotification notification = this.generateNotification();
+ assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestID()));
+ ControlLoopMetrics.manager.removeTransaction(notification.getRequestID());
+
+ ControlLoopMetrics.manager.transactionEvent(testController, notification);
+ assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestID()));
+ ControlLoopMetrics.manager.removeTransaction(notification.getRequestID());
+ assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestID()));
+ }
+
+ @Test
+ public void eviction() {
+ ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature();
+ for (int i=0; i < ControlLoopMetrics.manager.getCacheSize(); i++) {
+ VirtualControlLoopNotification notification = generateNotification();
+ feature.beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification);
+ assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestID()));
+ }
+
+ assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheOccupancy());
+
+ VirtualControlLoopNotification overflowNotification = generateNotification();
+ feature.beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", overflowNotification);
+ assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheOccupancy());
+ assertNotNull(ControlLoopMetrics.manager.getTransaction(overflowNotification.getRequestID()));
+ assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager.getCacheSize());
+ assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheSize());
+ assertFalse(ControlLoopMetrics.manager.getTransactionIds().isEmpty());
+ assertFalse(ControlLoopMetrics.manager.getTransactions().isEmpty());
+
+ /* let the entries expire */
+ try {
+ Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout()+5)*1000L);
+ } catch (InterruptedException e) {
+ /* nothing to do */
+ }
+
+ ControlLoopMetrics.manager.refresh();
+ assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager.getCacheOccupancy());
+ assertFalse(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheSize());
+ assertTrue(ControlLoopMetrics.manager.getTransactionIds().isEmpty());
+ assertTrue(ControlLoopMetrics.manager.getTransactions().isEmpty());
+
+ this.cacheDefaults();
+ }
+
+ private VirtualControlLoopNotification generateNotification() {
+ VirtualControlLoopNotification notification = new VirtualControlLoopNotification();
+ UUID requestId = UUID.randomUUID();
+ notification.setRequestID(requestId);
+ notification.setNotification(ControlLoopNotificationType.ACTIVE);
+ return notification;
+ }
+
+ @Test
+ public void getSequenceNumber() {
+ ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature();
+ assertTrue(feature.getSequenceNumber() == ControlLoopMetricsFeature.FEATURE_SEQUENCE_PRIORITY);
+ }
+} \ No newline at end of file
diff --git a/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties b/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties
new file mode 100644
index 000000000..80bdc2ad3
--- /dev/null
+++ b/controlloop/common/feature-controlloop-trans/src/test/resources/feature-controlloop-trans.properties
@@ -0,0 +1,2 @@
+controlloop.cache.transactions.size=3
+controllop.cache.transactions.timeout.seconds=10 \ No newline at end of file
diff --git a/controlloop/common/feature-controlloop-trans/src/test/resources/metrics-controller.properties b/controlloop/common/feature-controlloop-trans/src/test/resources/metrics-controller.properties
new file mode 100644
index 000000000..9612315f6
--- /dev/null
+++ b/controlloop/common/feature-controlloop-trans/src/test/resources/metrics-controller.properties
@@ -0,0 +1 @@
+controller.name=metrics