summaryrefslogtreecommitdiffstats
path: root/feature-distributed-locking/src/test
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-07-17 14:04:29 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-17 14:04:29 +0000
commit16793df58db6620a59e89bd95f9b06d621300f6a (patch)
tree8471043d55bdea3c375509723cdfdccb354ae71e /feature-distributed-locking/src/test
parentf3c23f41a7ed7b85459c5688e5a1f3c177a1031a (diff)
parent1480379b0e9907c0d41e8a782468c30f0ee83196 (diff)
Merge "Distinguish lock from refresh"
Diffstat (limited to 'feature-distributed-locking/src/test')
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
index c1b46d67..6e33f224 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java
@@ -119,6 +119,32 @@ public class TargetLockTest {
assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeLock("resource1", "owner2", MAX_AGE_SEC));
}
+
+ @Test
+ public void testUpdateLock() throws InterruptedException, ExecutionException {
+ // not locked yet - refresh should fail
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeRefresh("resource1", "owner1", MAX_AGE_SEC));
+
+ // now lock it
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeLock("resource1", "owner1", MAX_AGE_SEC));
+
+ // refresh should work now
+ assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeRefresh("resource1", "owner1", MAX_AGE_SEC));
+
+ // expire the lock
+ try (PreparedStatement updateStatement = conn.prepareStatement("UPDATE pooling.locks SET expirationTime = timestampadd(second, -1, now()) WHERE resourceId = ?");)
+ {
+ updateStatement.setString(1, "resource1");
+ updateStatement.executeUpdate();
+
+ } catch (SQLException e) {
+ logger.error("Error in TargetLockTest.testGrabLockSuccess()", e);
+ throw new RuntimeException(e);
+ }
+
+ // refresh should fail now
+ assertEquals(OperResult.OPER_DENIED, distLockFeat.beforeRefresh("resource1", "owner1", MAX_AGE_SEC));
+ }
@Test