aboutsummaryrefslogtreecommitdiffstats
path: root/feature-distributed-locking/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'feature-distributed-locking/src/test')
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockingFeatureExceptionTest.java (renamed from feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/test/DistributedLockingFeatureExceptionTest.java)2
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java (renamed from feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/test/TargetLockTest.java)47
2 files changed, 40 insertions, 9 deletions
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/test/DistributedLockingFeatureExceptionTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockingFeatureExceptionTest.java
index ea53e522..5bc3ae5e 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/test/DistributedLockingFeatureExceptionTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockingFeatureExceptionTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.distributed.locking.test;
+package org.onap.policy.distributed.locking;
import static org.junit.Assert.assertEquals;
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/test/TargetLockTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
index e624afb9..2dc2ceb8 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/test/TargetLockTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.distributed.locking.test;
+package org.onap.policy.distributed.locking;
import org.junit.AfterClass;
import org.junit.Before;
@@ -70,7 +70,6 @@ public class TargetLockTest {
@Before
public void wipeDb() {
-
try (PreparedStatement lockDelete = conn.prepareStatement("DELETE FROM pooling.locks");){
lockDelete.executeUpdate();
} catch (SQLException e) {
@@ -101,16 +100,31 @@ public class TargetLockTest {
@Test
public void testExpiredLocks() throws InterruptedException, ExecutionException {
- CountDownLatch latch = new CountDownLatch(1);
-
+
+ CountDownLatch rowExpireLatch = new CountDownLatch(1);
+ CountDownLatch heartbeatLatch = new CountDownLatch(1);
+
+ //grab lock
distLockFeat.beforeLock("resource1", "owner1", null);
+ //Wait for lock to expire
try {
- latch.await(1000, TimeUnit.MILLISECONDS);
+ rowExpireLatch.await(150, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
logger.error("Error in testExpiredLocks", e);
}
+ // Grab reference to heartbeat object
+ Heartbeat heartbeat = distLockFeat.getHeartbeat();
+
+ // Pass heartbeat object countdown latch
+ try {
+ heartbeat.giveLatch(heartbeatLatch);
+ heartbeatLatch.await(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ logger.error("Error in testExpiredLocks", e);
+ }
+
//Heartbeat should keep it active
assertFalse(distLockFeat.beforeLock("resource1", "owner1", null).get());
}
@@ -169,16 +183,33 @@ public class TargetLockTest {
@Test
public void testHeartbeat() {
- CountDownLatch latch = new CountDownLatch(1);
+ CountDownLatch rowExpireLatch = new CountDownLatch(1);
+ CountDownLatch heartbeatLatch = new CountDownLatch(1);
+
+ //grab lock
distLockFeat.beforeLock("resource1", "owner1", null);
+
+ //Wait for lock to expire
try {
- latch.await(1000, TimeUnit.MILLISECONDS);
+ rowExpireLatch.await(150, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
logger.error("Error in testExpiredLocks", e);
}
- // This test always returns true.
+ //Grab reference to heartbeat object
+ Heartbeat heartbeat = distLockFeat.getHeartbeat();
+
+ //Pass heartbeat object countdown latch
+ try {
+ heartbeat.giveLatch(heartbeatLatch);
+ heartbeatLatch.await(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ logger.error("Error in testExpiredLocks", e);
+ }
+ //At this point the heartbeat object should hve
+ //refreshed the lock. assert that resource1 is
+ //locked
assertTrue(distLockFeat.beforeIsLocked("resource1"));
}