From e87b2f7632dedf0067ea2417fb1157a8638df101 Mon Sep 17 00:00:00 2001 From: mmis Date: Mon, 23 Jul 2018 12:22:07 +0100 Subject: Copy policy-endpoints from drools-pdp to common Replaced references to classes deleted from drools-pdp with references to the corresponding in policy-common Issue-ID: POLICY-967 Change-Id: Ia9d2ac704e6b7c434e5a9e7aee6d7dcf9198e4f2 Signed-off-by: mmis --- .../common/feature-controlloop-trans/pom.xml | 6 ++++ .../feature/trans/ControlLoopMetricsFeature.java | 8 +++-- .../trans/ControlLoopMetricsFeatureTest.java | 35 ++++++++++++---------- 3 files changed, 30 insertions(+), 19 deletions(-) (limited to 'controlloop/common/feature-controlloop-trans') diff --git a/controlloop/common/feature-controlloop-trans/pom.xml b/controlloop/common/feature-controlloop-trans/pom.xml index e76a7a756..3dd7b9572 100644 --- a/controlloop/common/feature-controlloop-trans/pom.xml +++ b/controlloop/common/feature-controlloop-trans/pom.xml @@ -96,6 +96,12 @@ events ${project.version} + + org.onap.policy.common + policy-endpoints + ${project.version} + provided + org.onap.policy.drools-pdp policy-management diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java index 29630e33c..b15fb1479 100644 --- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java +++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java @@ -20,8 +20,8 @@ package org.onap.policy.drools.apps.controlloop.feature.trans; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.controlloop.VirtualControlLoopNotification; -import org.onap.policy.drools.event.comm.Topic.CommInfrastructure; import org.onap.policy.drools.features.PolicyControllerFeatureAPI; import org.onap.policy.drools.system.PolicyController; import org.slf4j.Logger; @@ -51,7 +51,8 @@ public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI { /** * transaction timeout in minutes */ - public static final String CL_CACHE_TRANS_TIMEOUT_SECONDS_PROPERTY = "controllop.cache.transactions.timeout.seconds"; + public static final String CL_CACHE_TRANS_TIMEOUT_SECONDS_PROPERTY = + "controllop.cache.transactions.timeout.seconds"; public static final long CL_CACHE_TRANS_TIMEOUT_SECONDS_DEFAULT = 1L * 60 * 60; @Override @@ -75,8 +76,9 @@ public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI { */ @Override public boolean beforeDeliver(PolicyController controller, CommInfrastructure protocol, String topic, Object event) { - if (event instanceof VirtualControlLoopNotification) + if (event instanceof VirtualControlLoopNotification) { ControlLoopMetrics.manager.transactionEvent(controller, (VirtualControlLoopNotification) event); + } /* do not take ownership */ return false; 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 index 4c113aca7..df93c7a5e 100644 --- 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 @@ -20,23 +20,24 @@ package org.onap.policy.drools.apps.controlloop.feature.trans; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + 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.common.endpoints.event.comm.Topic.CommInfrastructure; 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 */ @@ -48,9 +49,8 @@ public class ControlLoopMetricsFeatureTest { @BeforeClass public static void setUp() { SystemPersistence.manager.setConfigurationDir("src/test/resources"); - testController = - PolicyEngine.manager.createPolicyController - ("metrics", SystemPersistence.manager.getControllerProperties("metrics")); + testController = PolicyEngine.manager.createPolicyController("metrics", + SystemPersistence.manager.getControllerProperties("metrics")); } @AfterClass @@ -96,7 +96,7 @@ public class ControlLoopMetricsFeatureTest { /* let the entries expire */ try { - Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout()+5)*1000L); + Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout() + 5) * 1000L); } catch (InterruptedException e) { /* nothing to do */ } @@ -108,11 +108,13 @@ public class ControlLoopMetricsFeatureTest { @Test public void reset() { VirtualControlLoopNotification notification = this.generateNotification(); - new ControlLoopMetricsFeature().beforeDeliver(testController, CommInfrastructure.DMAAP, "POLICY-CL-MGT", notification); + 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()); + ControlLoopMetrics.manager.resetCache(ControlLoopMetrics.manager.getCacheSize(), + ControlLoopMetrics.manager.getTransactionTimeout()); assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId())); this.cacheDefaults(); } @@ -132,7 +134,7 @@ public class ControlLoopMetricsFeatureTest { @Test public void eviction() { ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature(); - for (int i=0; i < ControlLoopMetrics.manager.getCacheSize(); i++) { + 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())); @@ -151,13 +153,14 @@ public class ControlLoopMetricsFeatureTest { /* let the entries expire */ try { - Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout()+5)*1000L); + Thread.sleep((ControlLoopMetrics.manager.getTransactionTimeout() + 5) * 1000L); } catch (InterruptedException e) { /* nothing to do */ } ControlLoopMetrics.manager.refresh(); - assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager.getCacheOccupancy()); + 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()); @@ -178,4 +181,4 @@ public class ControlLoopMetricsFeatureTest { ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature(); assertTrue(feature.getSequenceNumber() == ControlLoopMetricsFeature.FEATURE_SEQUENCE_PRIORITY); } -} \ No newline at end of file +} -- cgit 1.2.3-korg