diff options
author | Jim Hahn <jrh3@att.com> | 2019-11-14 15:16:13 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-11-14 16:42:52 -0500 |
commit | 58c3811bfba7e421af8c9d2d72f55e95b4b01a50 (patch) | |
tree | 23e35bdb304e17665aae1e5662494bac77a30772 /feature-distributed-locking/src/test | |
parent | 8bb11a84b833c7db1342af0c5823ee8309f15c1a (diff) |
Invoke lock callback in session thread
Injects the callback as a DroolsRunnable into the session, if
there is one. Otherwise, it invokes it via the engine's
thread pool.
Issue-ID: POLICY-2246
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I214480ae675d89e7335dde4eb4abe2684f7ef8ab
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-distributed-locking/src/test')
-rw-r--r-- | feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java | 26 |
1 files changed, 21 insertions, 5 deletions
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); |