From e5fad68d3ab3b79d4e69820e485e50bece16494f Mon Sep 17 00:00:00 2001 From: Charles Cole Date: Fri, 27 Oct 2017 16:19:13 -0500 Subject: Send final failure on null vfc request Made sure a final failure is sent and the memroy is cleaned up if we cannot contruct a vfc request. Issue-Id: POLICY-350 Change-Id: Ia9bc827572042ae6ff2d2d2851d33034ee86fc49 Signed-off-by: Charles Cole --- .../policy/template/demo/VFCControlLoopTest.java | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'controlloop/templates/template.demo/src/test') diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java index 2581e3d80..39dac8131 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java @@ -161,6 +161,56 @@ public class VFCControlLoopTest implements TopicListener { */ assertEquals(1, kieSession.getFactCount()); + /* + * Print what's left in memory + */ + dumpFacts(kieSession); + } + + @Test + public void nullRequestTest() throws IOException { + + /* + * Allows the PolicyEngine to callback to this object to + * notify that there is an event ready to be pulled + * from the queue + */ + for (TopicSink sink : noopTopics) { + assertTrue(sink.start()); + sink.register(this); + } + + /* + * Create a unique requestId + */ + requestID = UUID.randomUUID(); + + /* + * Simulate an onset event the policy engine will + * receive from DCAE to kick off processing through + * the rules + */ + + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.closedLoopControlName = pair.a.getControlLoop().getControlLoopName(); + event.requestID = UUID.randomUUID(); + event.closedLoopEventClient = "tca.instance00009"; + event.target_type = ControlLoopTargetType.VM; + event.target = "vserver.vserver-name"; + event.from = "DCAE"; + event.closedLoopAlarmStart = Instant.now(); + event.AAI = new HashMap(); + event.AAI.put("vserver.vserver-name", "nullRequest"); + event.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + kieSession.insert(event); + + kieSession.fireUntilHalt(); + + /* + * The only fact in memory should be Params + */ + assertEquals(1, kieSession.getFactCount()); + /* * Print what's left in memory */ @@ -274,7 +324,12 @@ public class VFCControlLoopTest implements TopicListener { } else if (policyName.endsWith("EVENT.MANAGER")) { logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + if ("nullRequest".equals(notification.AAI.get("vserver.vserver-name"))){ + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + } + else { + assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.notification); + } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { @@ -304,7 +359,7 @@ public class VFCControlLoopTest implements TopicListener { event.requestID = UUID.randomUUID(); event.closedLoopEventClient = "tca.instance00009"; event.target_type = ControlLoopTargetType.VM; - event.target = "VM_NAME"; + event.target = "vserver.vserver-name"; event.from = "DCAE"; event.closedLoopAlarmStart = Instant.now(); event.AAI = new HashMap(); -- cgit 1.2.3-korg