unlock should always return TargetLock 87/55887/1
authorJim Hahn <jrh3@att.com>
Thu, 5 Jul 2018 14:36:49 +0000 (10:36 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 5 Jul 2018 14:36:49 +0000 (10:36 -0400)
ControlLoopEventManager.unlock only returns the TargetLock if
the PolicyGuard.unlock operation is successful.  However, if
the lock has already expired, then PolicyGuard.unlock will return
false, and ControlLoopEventManager.unlock will then return null.
As a result, the rules do not retract the TargetLock.  (The rules
do, however, retract any left-over TargetLock objects during the
clean-up phase.  Nevertheless, the earlier rules should not have
to depend on the clean-up rules to do that.)
Modified the code to address this issue.

Change-Id: I2e6099a4e3511053d2e6e1373cae4b480798d1b6
Issue-ID: POLICY-872
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java

index 5f36bcc..4817bec 100644 (file)
@@ -486,12 +486,14 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
         if (this.targetLock == null) {
             return null;
         }
-        if (PolicyGuard.unlockTarget(this.targetLock)) {
-            TargetLock returnLock = this.targetLock;
-            this.targetLock = null;
-            return returnLock;
-        }
-        return null;
+        
+        TargetLock returnLock = this.targetLock;
+        this.targetLock = null;
+        
+        PolicyGuard.unlockTarget(returnLock);
+        
+        // always return the old target lock so rules can retract it
+        return returnLock;
     }
 
     public enum NEW_EVENT_STATUS {
index 1af4a31..02dda20 100644 (file)
@@ -768,7 +768,7 @@ public class ControlLoopEventManagerTest {
         lockLock = manager.lockCurrentOperation();
         assertNotNull(lockLock);
         PolicyGuard.unlockTarget(lockLock.getB());
-        assertNull(manager.unlockCurrentOperation());
+        assertEquals(lockLock.getB(), manager.unlockCurrentOperation());
 
         clom.startOperation(event);