From: Jim Hahn Date: Tue, 30 Apr 2019 18:39:43 +0000 (-0400) Subject: Cancel PDP timers in PAP X-Git-Tag: 2.0.0~6 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=8b35ccbcaa5c61fa9dfce1add0ec8b1d10f84c72;p=policy%2Fpap.git Cancel PDP timers in PAP When a response is received by PAP from a PDP, the associated timer (and listener) are not being cancelled. As a result, when the timer later expired, PAP was re-sending the request. Modified the code to fix this. Change-Id: Id63f76622c01d286c169b618f8369b849ff31085 Issue-ID: POLICY-1715 Signed-off-by: Jim Hahn --- diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java index c17d4086..1945b32d 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/RequestImpl.java @@ -258,6 +258,8 @@ public abstract class RequestImpl implements Request { return; } + svcmgr.stop(); + String reason = checkResponse(response); if (reason != null) { logger.info("{} PDP data mismatch via {} {}: {}", getName(), infra, topic, reason); diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java index 2446533e..3d90fcbb 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java @@ -109,6 +109,9 @@ public class RequestImplTest extends CommonRequestBase { PdpStateChange msg2 = new PdpStateChange(); req.reconfigure(msg2, null); + // should have cancelled the first timer + verify(timer).cancel(); + // should only be one token in the queue QueueToken token = queue.poll(); assertNotNull(token); @@ -133,6 +136,9 @@ public class RequestImplTest extends CommonRequestBase { PdpStateChange msg2 = new PdpStateChange(); req.reconfigure(msg2, null); + // should have cancelled the first timer + verify(timer).cancel(); + // should only be one token in the queue QueueToken token = queue.poll(); assertNotNull(token); @@ -193,6 +199,9 @@ public class RequestImplTest extends CommonRequestBase { verify(timers, times(1)).register(any(), any()); verify(publisher, times(1)).enqueue(any()); assertNull(queue.poll()); + + // should NOT have cancelled the timer + verify(timer, never()).cancel(); } @Test @@ -400,6 +409,7 @@ public class RequestImplTest extends CommonRequestBase { verify(listener).success(PDP1); verify(listener, never()).failure(any(), any()); + verify(timer).cancel(); } @Test @@ -424,6 +434,7 @@ public class RequestImplTest extends CommonRequestBase { verify(listener, never()).success(any()); verify(listener).failure(DIFFERENT, "PDP name does not match"); + verify(timer).cancel(); } @Test