aboutsummaryrefslogtreecommitdiffstats
path: root/feature-distributed-locking
diff options
context:
space:
mode:
Diffstat (limited to 'feature-distributed-locking')
-rw-r--r--feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java10
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java26
2 files changed, 26 insertions, 10 deletions
diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java
index 7d58b8d5..528fa7cb 100644
--- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java
+++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockManager.java
@@ -341,7 +341,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
DistributedLock lock = lockref.get();
if (lock != null) {
logger.debug("removed lock from map {}", lock);
- lock.deny(DistributedLock.LOCK_LOST_MSG, false);
+ lock.deny(DistributedLock.LOCK_LOST_MSG);
}
}
}
@@ -473,7 +473,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
scheduleRequest(this::doExtend);
} else {
- deny(NOT_LOCKED_MSG, true);
+ deny(NOT_LOCKED_MSG);
}
}
@@ -639,7 +639,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
}
if (success) {
- grant(true);
+ grant();
return;
}
}
@@ -690,7 +690,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
* the record, thus we have to try to insert, if the update fails
*/
if (doDbUpdate(conn) || doDbInsert(conn)) {
- grant(true);
+ grant();
return;
}
}
@@ -790,7 +790,7 @@ public class DistributedLockManager extends LockManager<DistributedLockManager.D
synchronized (this) {
if (!isUnavailable()) {
- deny(LOCK_LOST_MSG, true);
+ deny(LOCK_LOST_MSG);
}
}
}
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
index c996d8d9..5351f004 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
@@ -68,11 +68,13 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.kie.api.runtime.KieSession;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.common.utils.services.OrderedServiceImpl;
import org.onap.policy.distributed.locking.DistributedLockManager.DistributedLock;
+import org.onap.policy.drools.core.PolicySession;
import org.onap.policy.drools.core.lock.Lock;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockState;
@@ -120,6 +122,9 @@ public class DistributedLockManagerTest {
private PolicyEngine engine;
@Mock
+ private KieSession kieSess;
+
+ @Mock
private ScheduledExecutorService exsvc;
@Mock
@@ -132,6 +137,7 @@ public class DistributedLockManagerTest {
private BasicDataSource datasrc;
private DistributedLock lock;
+ private PolicySession session;
private AtomicInteger nactive;
private AtomicInteger nsuccesses;
@@ -180,6 +186,16 @@ public class DistributedLockManagerTest {
public void setUp() throws SQLException {
MockitoAnnotations.initMocks(this);
+ // grant() and deny() calls will come through here and be immediately executed
+ session = new PolicySession(null, null, kieSess) {
+ @Override
+ public void insertDrools(Object object) {
+ ((Runnable) object).run();
+ }
+ };
+
+ session.setPolicySession();
+
nactive = new AtomicInteger(0);
nsuccesses = new AtomicInteger(0);
@@ -443,9 +459,9 @@ public class DistributedLockManagerTest {
assertTrue(lock5.isUnavailable());
// allow callbacks
- runLock(5, 2);
- runLock(6, 1);
- runLock(7, 0);
+ runLock(2, 2);
+ runLock(3, 1);
+ runLock(4, 0);
verify(callback).lockUnavailable(lock);
verify(callback3).lockUnavailable(lock3);
verify(callback5).lockUnavailable(lock5);
@@ -565,8 +581,8 @@ public class DistributedLockManagerTest {
assertTrue(lock3.isWaiting());
assertTrue(lock4.isUnavailable());
- runLock(5, 0);
- verify(exsvc, times(PRE_LOCK_EXECS + 6)).execute(any());
+ runLock(4, 0);
+ verify(exsvc, times(PRE_LOCK_EXECS + 5)).execute(any());
verify(callback).lockUnavailable(lock);
verify(callback2, never()).lockUnavailable(lock2);