summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/test
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2021-02-16 18:09:46 -0600
committerjhh <jorge.hernandez-herrero@att.com>2021-02-18 08:51:11 -0600
commitcd1d0fb2229af043c36f8225d6e5d8a8e8fe78dd (patch)
tree2353a03baeb94d3ae4e17292e720b20494849842 /feature-lifecycle/src/test
parent65c7d3a4dcd2841c5fafab6e7b8d310e5ec1cb6c (diff)
deploy stats in lifecycle module
Issue-ID: POLICY-3033 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Iaa78aa48064e8288265aeb498279e9d8324538d8 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/test')
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java52
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java28
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java2
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java10
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java18
5 files changed, 94 insertions, 16 deletions
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
index a77b03f5..9dda01df 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.drools.lifecycle;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.nio.file.Files;
@@ -33,11 +34,14 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
+import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -159,6 +163,54 @@ public class LifecycleFsmTest {
assertEquals(List.of(artifactPolicy, artifact2Policy), fsm.getNativeArtifactPolicies(deployedPolicies));
}
+ @Test
+ public void testSetGroup() {
+ fsm.setGroup("bar");
+ assertEquals("bar", fsm.getGroup());
+ assertEquals("bar", fsm.getStats().getPdpGroupName());
+ }
+
+ @Test
+ public void testSetSubGroup() {
+ fsm.setSubGroup("foo");
+ assertEquals("foo", fsm.getSubGroup());
+ assertEquals("foo", fsm.getStats().getPdpSubGroupName());
+ }
+
+ @Test
+ public void testDeployedPolicyAction() {
+ fsm.deployedPolicyAction(controllerPolicy);
+ assertEquals(1, fsm.getStats().getPolicyDeploySuccessCount());
+
+ fsm.undeployedPolicyAction(controllerPolicy);
+ assertEquals(2, fsm.getStats().getPolicyDeploySuccessCount());
+ }
+
+ @Test
+ public void testRestDeployCountsAction() {
+ deployAllPolicies();
+ assertEquals(8, fsm.getStats().getPolicyDeploySuccessCount());
+
+ fsm.resetDeployCountsAction();
+ assertEquals(0, fsm.getStats().getPolicyDeploySuccessCount());
+ assertEquals(0, fsm.getStats().getPolicyDeployFailCount());
+ assertEquals(0, fsm.getStats().getPolicyDeployCount());
+ }
+
+ @Test
+ public void testStatusPayload() {
+ fsm.updateDeployCountsAction(8L, 6L, 2L);
+ PdpStatus status = fsm.statusPayload(PdpState.ACTIVE);
+
+ assertEquals(fsm.getGroup(), status.getStatistics().getPdpGroupName());
+ assertEquals(fsm.getSubGroup(), status.getStatistics().getPdpSubGroupName());
+ assertEquals(NetworkUtil.getHostname(), status.getStatistics().getPdpInstanceId());
+ assertEquals(6, status.getStatistics().getPolicyDeploySuccessCount());
+ assertEquals(2, status.getStatistics().getPolicyDeployFailCount());
+ assertEquals(8, status.getStatistics().getPolicyDeployCount());
+ assertNotNull(status.getStatistics().getTimeStamp());
+ }
+
protected void deployAllPolicies() {
fsm.deployedPolicyAction(controllerPolicy);
fsm.deployedPolicyAction(controller2Policy);
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
index 01500576..9ae43e21 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
@@ -186,7 +186,7 @@ public class LifecycleFsmUpdateTest {
change.setState(PdpState.ACTIVE);
change.setName(fsm.getName());
- fsm.setSubGroupAction("a");
+ fsm.setSubGroup("a");
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(0, fsm.getPoliciesMap().size());
@@ -212,21 +212,25 @@ public class LifecycleFsmUpdateTest {
assertEquals(0, fsm.getPoliciesMap().size());
assertEquals("ACTIVE", fsm.state().toString());
assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
+ verifyDeployStats(0, 0, 0);
// native controller policy - deploy
// Delta: +controllerPolicy
assertTrue(fsm.update(getPdpUpdate(List.of(controllerPolicy))));
verifyActivePolicies(List.of(controllerPolicy));
+ verifyDeployStats(1, 1, 0);
// no policies - undeploy
// Delta: []
assertTrue(fsm.update(getPdpUpdate(Collections.emptyList())));
verifyActivePolicies(Collections.emptyList());
+ verifyDeployStats(2, 2, 0);
// native controller + artifact policy (out of order) - deploy
// Delta: +artifactPolicy, +controllerPolicy
assertTrue(fsm.update(getPdpUpdate(List.of(artifactPolicy, controllerPolicy))));
verifyActivePolicies(List.of(artifactPolicy, controllerPolicy));
+ verifyDeployStats(4, 4, 0);
// attempt to deploy opPolicy but invalid controller
// Delta: +opPolicy
@@ -235,55 +239,65 @@ public class LifecycleFsmUpdateTest {
assertFalse(fsm.getActivePolicies().contains(opPolicy));
verifyExists(false, "lifecycle", List.of(opPolicy));
verifyActivePolicies(List.of(artifactPolicy, controllerPolicy));
+ verifyDeployStats(5, 4, 1);
// Delta: +opPolicy
opPolicy.getProperties().remove("controllerName");
assertTrue(fsm.update(getPdpUpdate(List.of(artifactPolicy, opPolicy, controllerPolicy))));
verifyExists(true, "lifecycle", List.of(opPolicy));
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
+ verifyDeployStats(6, 5, 1);
// Delta: -opPolicy
assertTrue(fsm.update(getPdpUpdate(List.of(artifactPolicy, controllerPolicy))));
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().exists(opPolicy));
verifyActivePolicies(List.of(controllerPolicy, artifactPolicy));
+ verifyDeployStats(7, 6, 1);
// Delta: -artifactPolicy
assertTrue(fsm.update(getPdpUpdate(List.of(controllerPolicy))));
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
verifyActivePolicies(List.of(controllerPolicy));
+ verifyDeployStats(8, 7, 1);
// Delta: -controllerPolicy
assertTrue(fsm.update(getPdpUpdate(Collections.emptyList())));
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
verifyActivePolicies(Collections.emptyList());
+ verifyDeployStats(9, 8, 1);
// Delta: +controllerPolicy, +artifactPolicy, and +opPolicy
assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, artifactPolicy, controllerPolicy))));
verifyExists(true, "lifecycle", List.of(opPolicy));
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
+ verifyDeployStats(12, 11, 1);
// Delta: -artifactPolicy
assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, controllerPolicy))));
assertEquals(1, PolicyControllerConstants.getFactory().inventory().size());
assertFalse(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
+ verifyDeployStats(13, 12, 1);
// Delta: +artifactPolicy
// from deltas, all delta updates should be successfully applied
assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, controllerPolicy, artifactPolicy))));
verifyExists(true, "lifecycle", List.of(opPolicy));
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
+ verifyDeployStats(14, 13, 1);
// Delta: -controllerPolicy
// from deltas, all delta updates should be successfully applied
assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, artifactPolicy))));
assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
+ verifyDeployStats(15, 14, 1);
// Delta: +controllerPolicy
// from deltas, all delta updates should be successfully applied
assertTrue(fsm.update(getPdpUpdate(List.of(opPolicy, controllerPolicy, artifactPolicy))));
verifyExists(true, "lifecycle", List.of(opPolicy));
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy));
+ verifyDeployStats(16, 15, 1);
// Delta: +op2Policy, +controller2Policy
// from deltas, all delta updates should be successfully applied
@@ -293,6 +307,7 @@ public class LifecycleFsmUpdateTest {
verifyExists(true, "lifecycle", List.of(opPolicy, op2Policy));
assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained());
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy, controller2Policy));
+ verifyDeployStats(18, 17, 1);
// Delta: +artifact2policy, +valPolicy, +unvalPolicy
// from deltas, all delta updates should be successfully applied
@@ -304,6 +319,7 @@ public class LifecycleFsmUpdateTest {
verifyExists(false, "foo", List.of(opPolicy, op2Policy));
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy,
controller2Policy, valPolicy, unvalPolicy, artifact2Policy));
+ verifyDeployStats(21, 20, 1);
// Delta: -artifact2Policy, +valPolicy
// from deltas, all delta updates should be successfully applied, and unvalPolicy disabled
@@ -315,6 +331,7 @@ public class LifecycleFsmUpdateTest {
assertFalse(PolicyControllerConstants.getFactory().get("foo").getDrools().isBrained());
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy,
controller2Policy, valPolicy));
+ verifyDeployStats(23, 22, 1);
// Delta: +artifact2Policy
// from deltas, all delta updates should be successfully applied, opPolicy, op2Policy and unvalPolicy
@@ -328,6 +345,7 @@ public class LifecycleFsmUpdateTest {
verifyExists(false, "foo", List.of(opPolicy, op2Policy, unvalPolicy));
verifyActivePolicies(List.of(opPolicy, artifactPolicy, controllerPolicy, op2Policy,
controller2Policy, valPolicy, artifact2Policy));
+ verifyDeployStats(24, 23, 1);
// Delta: -controllerPolicy, +artifactPolicy, +unvalPolicy
// from deltas, all delta updates should be successful
@@ -341,6 +359,7 @@ public class LifecycleFsmUpdateTest {
verifyActivePoliciesWithDisables(
List.of(opPolicy, op2Policy, controller2Policy, valPolicy, artifact2Policy, unvalPolicy),
List.of(opPolicy.getIdentifier(), op2Policy.getIdentifier()));
+ verifyDeployStats(27, 26, 1);
// Delta: -opPolicy, -op2Policy, -controller2Policy, -valPolicy, -artifact2Policy, -unvalPolicy
// from deltas, -opPolicy and -op2Policy undeploys will fail since there is not controller with that
@@ -350,6 +369,7 @@ public class LifecycleFsmUpdateTest {
assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("foo"));
assertEquals(0, PolicyControllerConstants.getFactory().inventory().size());
verifyActivePolicies(Collections.emptyList());
+ verifyDeployStats(33, 30, 3);
fsm.shutdown();
}
@@ -517,6 +537,12 @@ public class LifecycleFsmUpdateTest {
candidateNativeArtifactPolicies.isEmpty());
}
+ protected void verifyDeployStats(long count, long success, long fail) {
+ assertEquals(count, fsm.getStats().getPolicyDeployCount());
+ assertEquals(success, fsm.getStats().getPolicyDeploySuccessCount());
+ assertEquals(fail, fsm.getStats().getPolicyDeployFailCount());
+ }
+
protected List<NativeArtifactPolicy> getNativeArtifactPoliciesBut(List<ToscaPolicy> nativePolicies,
String controllerName) {
return
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
index d961dce3..2b105f91 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
@@ -80,7 +80,7 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
change.setState(PdpState.ACTIVE);
change.setName(fsm.getName());
- fsm.setSubGroupAction("a");
+ fsm.setSubGroup("a");
fsm.source.offer(new StandardCoder().encode(change));
controllerSupport.getController().start();
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
index 8a5ea6e4..0ce1f821 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
@@ -79,7 +79,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
change.setState(PdpState.ACTIVE);
change.setName(fsm.getName());
- fsm.setSubGroupAction("a");
+ fsm.setSubGroup("a");
fsm.source.offer(new StandardCoder().encode(change));
controllerSupport.getController().start();
}
@@ -102,7 +102,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
private void assertActive() {
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertEquals("a", fsm.getSubGroup());
assertTrue(fsm.isAlive());
waitUntil(fsm.getStatusTimerSeconds() + 1, TimeUnit.SECONDS, isStatus(PdpState.ACTIVE));
}
@@ -161,13 +161,13 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertNotEquals("b", fsm.getSubgroup());
+ assertNotEquals("b", fsm.getSubGroup());
change.setName(fsm.getName());
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertEquals("a", fsm.getSubGroup());
change.setState(PdpState.SAFE);
fsm.source.offer(new StandardCoder().encode(change));
@@ -201,7 +201,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("w", fsm.getSubgroup());
+ assertEquals("w", fsm.getSubGroup());
ToscaPolicy toscaPolicyRestartV1 =
getExamplesPolicy("policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
index afa89d68..6945f10a 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
@@ -164,7 +164,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("z", fsm.getSubgroup());
+ assertEquals("z", fsm.getSubGroup());
assertBasicPassive();
ToscaPolicy toscaPolicy =
@@ -177,7 +177,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("z", fsm.getSubgroup());
+ assertEquals("z", fsm.getSubGroup());
assertBasicPassive();
assertEquals(2, fsm.policyTypesMap.size());
@@ -191,7 +191,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertNull(fsm.getSubgroup());
+ assertNull(fsm.getSubGroup());
assertBasicPassive();
assertEquals(2, fsm.policyTypesMap.size());
assertTrue(fsm.policiesMap.isEmpty());
@@ -204,7 +204,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertEquals("a", fsm.getSubGroup());
assertBasicPassive();
assertEquals(2, fsm.policyTypesMap.size());
assertTrue(fsm.policiesMap.isEmpty());
@@ -220,7 +220,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertEquals("a", fsm.getSubGroup());
assertBasicPassive();
assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
@@ -245,7 +245,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertNull(fsm.getSubgroup());
+ assertNull(fsm.getSubGroup());
assertBasicPassive();
assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
@@ -266,7 +266,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertNull(fsm.getSubgroup());
+ assertNull(fsm.getSubGroup());
PdpUpdate update = new PdpUpdate();
update.setName(NetworkUtil.getHostname());
@@ -289,7 +289,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy);
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertEquals("a", fsm.getSubGroup());
assertBasicPassive();
assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
@@ -299,7 +299,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertEquals("a", fsm.getSubGroup());
waitUntil(5, TimeUnit.SECONDS, () -> controllerSupport.getController().getDrools().factCount("junits") == 1);