diff options
author | Jim Hahn <jrh3@att.com> | 2019-09-27 11:22:47 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-10-22 16:06:10 -0400 |
commit | ac5c19ddbed1ff5905d16a6359ee23b4888c717a (patch) | |
tree | acd501248ae73dcd90b2318695acc535a9bb9dcc /controlloop/templates/template.demo/src/test/java | |
parent | 636a1b2fcafa5249cf2bf380dfb6e20f6fe98691 (diff) |
Modify drools-applications to use new Lock API
Modified code to use new Lock API.
Also deleted TargetLock and PolicyGuard, as they are no longer needed.
Issue-ID: POLICY-2113
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I5bc9b7732f9cfc6056789b2902d9f6f838b560be
Diffstat (limited to 'controlloop/templates/template.demo/src/test/java')
-rw-r--r-- | controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java index 0793b8825..db5da1e4a 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java @@ -48,6 +48,8 @@ public class ControlLoopFailureTest extends ControlLoopBase implements TopicList private UUID requestId2; private UUID requestId3; private int eventCount; + private int nsuccess = 0; + private int nreject = 0; /** * Setup simulator. @@ -106,19 +108,25 @@ public class ControlLoopFailureTest extends ControlLoopBase implements TopicList sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vnf01"); /* - * Send a second event requesting an action for a different target entity + * Send a second event for a different target to ensure there are no problems with obtaining + * a lock */ sendEvent(pair.first, requestId2, ControlLoopEventStatus.ONSET, "vnf02"); /* - * Send a second event for a different target to ensure there are no problems with obtaining - * a lock for a different + * Send a third event requesting an action for a duplicate target entity */ + sendEvent(pair.first, requestId3, ControlLoopEventStatus.ONSET, "vnf01"); + kieSession.fireUntilHalt(); // allow object clean-up kieSession.fireAllRules(); + // should be one success and one failure for vnf01 + assertEquals(1, nsuccess); + assertEquals(1, nreject); + /* * The only fact in memory should be Params */ @@ -136,7 +144,7 @@ public class ControlLoopFailureTest extends ControlLoopBase implements TopicList * @see org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.String) */ @Override - public void onTopicEvent(CommInfrastructure commType, String topic, String event) { + public synchronized void onTopicEvent(CommInfrastructure commType, String topic, String event) { /* * Pull the object that was sent out to DMAAP and make sure it is a ControlLoopNoticiation * of type active @@ -156,6 +164,17 @@ public class ControlLoopFailureTest extends ControlLoopBase implements TopicList if (policyName.endsWith("EVENT")) { logger.debug("Rule Fired: " + notification.getPolicyName()); assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification())); + } else if (policyName.endsWith("DENIED")) { + logger.debug("Rule Fired: " + notification.getPolicyName()); + assertTrue(ControlLoopNotificationType.REJECTED.equals(notification.getNotification())); + assertNotNull(notification.getMessage()); + assertTrue(notification.getMessage().contains("is already locked")); + if (requestId.equals(notification.getRequestId()) || requestId3.equals(notification.getRequestId())) { + ++nreject; + } + if (++eventCount == 3) { + kieSession.halt(); + } } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) { logger.debug("Rule Fired: " + notification.getPolicyName()); assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification())); @@ -181,18 +200,16 @@ public class ControlLoopFailureTest extends ControlLoopBase implements TopicList assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification())); assertNotNull(notification.getMessage()); assertTrue(notification.getMessage().startsWith("actor=APPC")); - if (requestId.equals(notification.getRequestId())) { - sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED, "vnf01"); + if (requestId.equals(notification.getRequestId()) || requestId3.equals(notification.getRequestId())) { + sendEvent(pair.first, notification.getRequestId(), ControlLoopEventStatus.ABATED, "vnf01"); } else if (requestId2.equals(notification.getRequestId())) { sendEvent(pair.first, requestId2, ControlLoopEventStatus.ABATED, "vnf02"); } } else if (policyName.endsWith("EVENT.MANAGER")) { logger.debug("Rule Fired: " + notification.getPolicyName()); - if (requestId3.equals(notification.getRequestId())) { - /* - * The event with the duplicate target should be rejected - */ - assertTrue(ControlLoopNotificationType.REJECTED.equals(notification.getNotification())); + if (requestId.equals(notification.getRequestId()) || requestId3.equals(notification.getRequestId())) { + assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification())); + ++nsuccess; } else { assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification())); } |