summaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-16 17:52:17 -0400
committerJim Hahn <jrh3@att.com>2020-06-17 14:41:01 -0400
commit5cfff2b468a13e7b5ce068e58e899fcfe36537b3 (patch)
tree95a3f9f64443cb7028afa90632bd412048ed05a0 /main/src/test/java
parent169dd4b89bb02a4a644b748a07a0294a324715cb (diff)
PAP should discard old PDP messages
Modified PAP to discard any messages old than 10 minutes so that if PAP is unable to communicate with DMaaP and then suddently gets flooded, it will discard old messages. Updates per review comments - made the "max message age" configurable, with a default of 10 minutes Issue-ID: POLICY-2170 Change-Id: I541c03aabf29482af12a07f51eeb5888bbafbf31 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java22
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java14
2 files changed, 32 insertions, 4 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
index 7dd7eefa..14396602 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +28,6 @@ import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
-
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.CoderException;
@@ -39,6 +39,7 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.pap.main.parameters.PdpParameters;
import org.onap.policy.pap.main.rest.e2e.End2EndBase;
/**
@@ -62,7 +63,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
@Test
public void testPdpHeartbeatListener() throws CoderException, PfModelException {
addGroups("PdpGroups.json");
- pdpHeartbeatListener = new PdpHeartbeatListener();
+ pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters());
// Testing pdp registration success case
final PdpStatus status1 = new PdpStatus();
@@ -158,6 +159,21 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status7);
verifyPdpGroup(DEFAULT_GROUP, 2);
+ // Testing old message for pdp_1 - should have no effect
+ final PdpStatus status7b = new PdpStatus();
+ status7b.setTimestampMs(System.currentTimeMillis() - PdpParameters.DEFAULT_MAX_AGE_MS - 1);
+ status7b.setName(PDP_NAME);
+ status7b.setState(PdpState.TERMINATED);
+ status7b.setPdpGroup(DEFAULT_GROUP);
+ status7b.setPdpType(APEX_TYPE);
+ status7b.setPdpSubgroup(APEX_TYPE);
+ status7b.setHealthy(PdpHealthStatus.HEALTHY);
+ final List<ToscaPolicyIdentifier> idents7b =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status7b.setPolicies(idents7b);
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status7b);
+ verifyPdpGroup(DEFAULT_GROUP, 2);
+
// Testing pdp termination case for pdp_1
final PdpStatus status8 = new PdpStatus();
status8.setName(PDP_NAME);
@@ -190,7 +206,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
@Test
public void testPdpStatistics() throws CoderException, PfModelException, ParseException {
addGroups("PdpGroups.json");
- pdpHeartbeatListener = new PdpHeartbeatListener();
+ pdpHeartbeatListener = new PdpHeartbeatListener(new PdpParameters());
timeStamp = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01");
// init default pdp group
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java
index 1474bbfb..c47b5301 100644
--- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -48,6 +48,11 @@ public class TestPdpParameters {
assertEquals(5, state.getMaxWaitMs());
assertEquals(6L, params.getHeartBeatMs());
+
+ assertEquals(20000L, params.getMaxMessageAgeMs());
+
+ // check default value
+ assertEquals(600000L, new PdpParameters().getMaxMessageAgeMs());
}
@Test
@@ -67,6 +72,13 @@ public class TestPdpParameters {
assertTrue(result.getResult().contains(
"field 'heartBeatMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"')));
+ // invalid max message age
+ json2 = json.replaceFirst(": 20000", ": 0");
+ result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains(
+ "field 'maxMessageAgeMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"')));
+
// no update params
json2 = testData.nullifyField(json, "updateParameters");
result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();