summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/test/java
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2019-04-03 13:18:14 -0500
committerjhh <jorge.hernandez-herrero@att.com>2019-04-04 07:48:12 -0500
commitb91a1bd9db4f125fa3ce70c2a5d048da2d960ff2 (patch)
tree97060b6935c0e8569b76b143b3589f9fc36b54a7 /feature-lifecycle/src/test/java
parent964b127fc75e202d3c661454dbea58acf2b234c6 (diff)
Handle pap update messages
Addressing feedback from previos review. Issue-ID: POLICY-1608 Change-Id: I8e36c99b13a3eb81c72515c039e86aa9e32e6f14 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/test/java')
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java45
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java50
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java16
3 files changed, 94 insertions, 17 deletions
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 eb83bc61..c4d47d83 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
@@ -24,9 +24,11 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@@ -36,10 +38,12 @@ import org.junit.BeforeClass;
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.drools.persistence.SystemPersistence;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpMessageType;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -79,7 +83,7 @@ public class LifecycleStateActiveTest {
change.setPdpGroup("A");
change.setPdpSubgroup("a");
change.setState(PdpState.ACTIVE);
- change.setName("test");
+ change.setName(fsm.getName());
fsm.source.offer(new StandardCoder().encode(change));
}
@@ -101,8 +105,8 @@ public class LifecycleStateActiveTest {
private void assertActive() {
assertEquals(PdpState.ACTIVE, fsm.state());
- assertEquals("A", fsm.getPdpGroup());
- assertEquals("a", fsm.getPdpSubgroup());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
assertTrue(fsm.isAlive());
await().atMost(fsm.getStatusTimerSeconds() + 1, TimeUnit.SECONDS).until(isStatus(PdpState.ACTIVE));
}
@@ -161,17 +165,22 @@ public class LifecycleStateActiveTest {
public void stateChange() throws CoderException {
assertActive();
- /* dup */
+ /* no name and mismatching group info */
PdpStateChange change = new PdpStateChange();
change.setPdpGroup("B");
change.setPdpSubgroup("b");
change.setState(PdpState.ACTIVE);
- change.setName("test");
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
- assertEquals("B", fsm.getPdpGroup());
- assertEquals("b", fsm.getPdpSubgroup());
+ assertNotEquals("B", fsm.getGroup());
+ assertNotEquals("b", fsm.getSubgroup());
+
+ change.setName(fsm.getName());
+ fsm.source.offer(new StandardCoder().encode(change));
+ assertEquals(PdpState.ACTIVE, fsm.state());
+ assertEquals("B", fsm.getGroup());
+ assertEquals("b", fsm.getSubgroup());
change.setState(PdpState.SAFE);
fsm.source.offer(new StandardCoder().encode(change));
@@ -188,4 +197,26 @@ public class LifecycleStateActiveTest {
fsm.shutdown();
}
+
+ @Test
+ public void update() {
+ PdpUpdate update = new PdpUpdate();
+ update.setName(NetworkUtil.getHostname());
+ update.setPdpGroup("Z");
+ update.setPdpSubgroup("z");
+ update.setPolicies(Collections.emptyList());
+
+ long originalInterval = fsm.getStatusTimerSeconds();
+ long interval = 2 * originalInterval;
+ update.setPdpHeartbeatIntervalMs(interval * 1000L);
+
+ assertTrue(fsm.update(update));
+
+ assertEquals(PdpState.ACTIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertEquals("Z", fsm.getGroup());
+ assertEquals("z", fsm.getSubgroup());
+
+ fsm.shutdown();
+ }
}
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 fbc2eeba..376eb3a7 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
@@ -26,8 +26,10 @@ import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
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.util.Collections;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.awaitility.core.ConditionTimeoutException;
@@ -42,6 +44,7 @@ import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpMessageType;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -161,22 +164,49 @@ public class LifecycleStatePassiveTest {
@Test
public void update() {
- // TODO
+ PdpUpdate update = new PdpUpdate();
+ update.setName(NetworkUtil.getHostname());
+ update.setPdpGroup("Z");
+ update.setPdpSubgroup("z");
+ update.setPolicies(Collections.emptyList());
+
+ long interval = 2 * fsm.getStatusTimerSeconds();
+ update.setPdpHeartbeatIntervalMs(interval * 1000L);
+
+ assertTrue(fsm.update(update));
+
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertEquals("Z", fsm.getGroup());
+ assertEquals("z", fsm.getSubgroup());
+ assertBasicPassive();
+
fsm.shutdown();
}
@Test
public void stateChange() throws CoderException {
+ /* no name */
PdpStateChange change = new PdpStateChange();
change.setPdpGroup("A");
change.setPdpSubgroup("a");
change.setState(PdpState.ACTIVE);
+
+ /* invalid name */
change.setName("test");
+ fsm.source.offer(new StandardCoder().encode(change));
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
+
+ /* correct name */
+ change.setName(fsm.getName());
fsm.source.offer(new StandardCoder().encode(change));
- assertEquals(PdpState.ACTIVE, fsm.state.state());
- assertEquals("A", fsm.pdpGroup);
- assertEquals("a", fsm.pdpSubgroup);
+
+ assertEquals(PdpState.ACTIVE, fsm.state());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
fsm.shutdown();
}
@@ -192,17 +222,19 @@ public class LifecycleStatePassiveTest {
assertTrue(fsm.statusTask.isCancelled());
assertTrue(fsm.statusTask.isDone());
- assertEquals(1, fsm.client.getSink().getRecentEvents().length);
- PdpStatus status = new StandardCoder().decode(fsm.client.getSink().getRecentEvents()[0], PdpStatus.class);
+ String[] events = fsm.client.getSink().getRecentEvents();
+ PdpStatus status =
+ new StandardCoder().decode(events[events.length - 1], PdpStatus.class);
assertEquals("drools", status.getPdpType());
assertEquals(PdpState.TERMINATED, status.getState());
assertEquals(PdpHealthStatus.HEALTHY, status.getHealthy());
- assertEquals(NetworkUtil.getHostname(), status.getInstance());
+ assertEquals(NetworkUtil.getHostname(), status.getName());
+ assertEquals(fsm.getName(), status.getName());
assertEquals(PdpMessageType.PDP_STATUS, status.getMessageName());
assertThatThrownBy( () -> await()
- .atMost(fsm.statusTimerSeconds + 5, TimeUnit.SECONDS)
- .until(isStatus(PdpState.TERMINATED, 2))).isInstanceOf(ConditionTimeoutException.class);
+ .atMost(2 * fsm.statusTimerSeconds, TimeUnit.SECONDS)
+ .until(isStatus(PdpState.TERMINATED, events.length))).isInstanceOf(ConditionTimeoutException.class);
}
private void assertBasicPassive() {
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
index b77fdcd9..587098f8 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
@@ -23,16 +23,20 @@ package org.onap.policy.drools.lifecycle;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.util.Collections;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
+import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpState;
/**
@@ -133,7 +137,17 @@ public class LifecycleStateTerminatedTest {
@Test
public void update() {
- // TODO
+ PdpUpdate update = new PdpUpdate();
+ update.setName(NetworkUtil.getHostname());
+ update.setPdpGroup("A");
+ update.setPdpSubgroup("a");
+ update.setPolicies(Collections.emptyList());
+ update.setPdpHeartbeatIntervalMs(2 * 600000L);
+
+ assertFalse(fsm.update(update));
+
+ assertEquals(PdpState.TERMINATED, fsm.state.state());
+ assertNotEquals((2 * 60000L) / 1000L, fsm.getStatusTimerSeconds());
}
@Test