diff options
Diffstat (limited to 'policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java')
-rw-r--r-- | policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java index f4876a95..f9b101c3 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2021 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. @@ -64,12 +64,15 @@ import org.onap.policy.drools.core.lock.LockCallback; import org.onap.policy.drools.core.lock.PolicyResourceLockManager; import org.onap.policy.drools.features.PolicyControllerFeatureApi; import org.onap.policy.drools.features.PolicyEngineFeatureApi; +import org.onap.policy.drools.metrics.Metric; +import org.onap.policy.drools.metrics.TransMetric; import org.onap.policy.drools.persistence.SystemPersistence; import org.onap.policy.drools.properties.DroolsPropertyConstants; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.configuration.ControllerConfiguration; import org.onap.policy.drools.protocol.configuration.DroolsConfiguration; import org.onap.policy.drools.protocol.configuration.PdpdConfiguration; +import org.onap.policy.drools.stats.PolicyStatsManager; import org.onap.policy.drools.system.internal.SimpleLockManager; import org.onap.policy.drools.system.internal.SimpleLockProperties; @@ -115,7 +118,6 @@ public class PolicyEngineManagerTest { private HttpClientFactory clientFactory; private HttpClient client1; private HttpClient client2; - private List<HttpClient> clients; private TopicEndpoint endpoint; private PolicyController controller; private PolicyController controller2; @@ -143,6 +145,7 @@ public class PolicyEngineManagerTest { private PolicyEngineManager mgr; private ScheduledExecutorService exsvc; private PolicyResourceLockManager lockmgr; + private PolicyStatsManager statsManager; /** * Initializes the object to be tested. @@ -172,7 +175,6 @@ public class PolicyEngineManagerTest { serverFactory = mock(HttpServletServerFactory.class); client1 = mock(HttpClient.class); client2 = mock(HttpClient.class); - clients = Arrays.asList(client1, client2); clientFactory = mock(HttpClientFactory.class); endpoint = mock(TopicEndpoint.class); controller = mock(PolicyController.class); @@ -200,6 +202,8 @@ public class PolicyEngineManagerTest { pdpConfig = new PdpdConfiguration(); exsvc = mock(ScheduledExecutorService.class); lockmgr = mock(PolicyResourceLockManager.class); + statsManager = new PolicyStatsManager(); + statsManager.getGroupStat().setBirthTime(0L); when(lockmgr.start()).thenReturn(true); when(lockmgr.stop()).thenReturn(true); @@ -235,7 +239,7 @@ public class PolicyEngineManagerTest { when(client2.start()).thenReturn(true); when(client2.stop()).thenReturn(true); - when(clientFactory.inventory()).thenReturn(clients); + when(clientFactory.inventory()).thenReturn(List.of(client1, client2)); when(source1.getTopic()).thenReturn("source1-topic"); when(source1.start()).thenReturn(true); @@ -286,7 +290,7 @@ public class PolicyEngineManagerTest { when(endpoint.lock()).thenReturn(true); when(endpoint.unlock()).thenReturn(true); when(endpoint.getTopicSink(CommInfrastructure.NOOP, MY_TOPIC)).thenReturn(sink1); - when(endpoint.getTopicSinks(MY_TOPIC)).thenReturn(Arrays.asList(sink1)); + when(endpoint.getTopicSinks(MY_TOPIC)).thenReturn(Collections.singletonList(sink1)); when(coder.encode(any(), any())).thenReturn(MESSAGE); @@ -295,6 +299,7 @@ public class PolicyEngineManagerTest { when(engine.createPolicyController(CONTROLLER3, properties)).thenReturn(controller3); when(engine.createPolicyController(CONTROLLER4, properties)).thenReturn(controller4); + when(engine.getStats()).thenReturn(statsManager); config3.setName(CONTROLLER3); config3.setOperation(ControllerConfiguration.CONFIG_CONTROLLER_OPERATION_CREATE); @@ -574,7 +579,7 @@ public class PolicyEngineManagerTest { // source list of size 1 setUp(); - when(endpoint.addTopicSources(any(Properties.class))).thenReturn(Arrays.asList(source1)); + when(endpoint.addTopicSources(any(Properties.class))).thenReturn(Collections.singletonList(source1)); mgr.configure(properties); assertTrue(mgr.configure(pdpConfig)); @@ -671,7 +676,7 @@ public class PolicyEngineManagerTest { // force exception in the first controller with invalid operation setUp(); config3.setOperation("unknown-operation"); - assertEquals(Arrays.asList(controller4), mgr.updatePolicyControllers(pdpConfig.getControllers())); + assertEquals(Collections.singletonList(controller4), mgr.updatePolicyControllers(pdpConfig.getControllers())); // controller3 should NOT have been done verify(controllerFactory, never()).patch(controller3, drools3); @@ -1355,6 +1360,18 @@ public class PolicyEngineManagerTest { } @Test + public void testTransaction() { + mgr.metric("foo", "bar", new Metric()); + assertEquals(0, mgr.getStats().getGroupStat().getPolicyExecutedCount()); + assertEquals(0, mgr.getStats().getSubgroupStats().size()); + + mgr.transaction("foo", "bar", new TransMetric()); + assertEquals(1, mgr.getStats().getGroupStat().getPolicyExecutedCount()); + assertEquals(1, mgr.getStats().getSubgroupStats().size()); + assertEquals(1, mgr.getStats().getSubgroupStats().get("foo[bar]").getPolicyExecutedFailCount()); + } + + @Test public void testOnTopicEvent() { mgr.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, pdpConfigJson); @@ -1913,7 +1930,7 @@ public class PolicyEngineManagerTest { // remaining methods should not have been invoked assertThatThrownBy(() -> verifyBefore.accept(prov2)).isInstanceOf(AssertionError.class); - assertThatThrownBy(() -> verifyMiddle.run()).isInstanceOf(AssertionError.class); + assertThatThrownBy(verifyMiddle::run).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> verifyAfter.accept(prov1)).isInstanceOf(AssertionError.class); assertThatThrownBy(() -> verifyAfter.accept(prov2)).isInstanceOf(AssertionError.class); @@ -1995,6 +2012,11 @@ public class PolicyEngineManagerTest { return exsvc; } + @Override + public PolicyStatsManager getStats() { + return statsManager; + } + /** * Shutdown thread with overrides. */ @@ -2027,7 +2049,7 @@ public class PolicyEngineManagerTest { } @FunctionalInterface - private static interface RunnableWithEx { + private interface RunnableWithEx { void run() throws Exception; } } |