diff options
author | Jim Hahn <jrh3@att.com> | 2018-06-29 10:54:00 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-06-29 12:25:04 -0400 |
commit | 1ed1beaaa4466fb55d7dba3e029b583b835b8aaf (patch) | |
tree | 0e5e1c3ff6cd5ca78ab76b491d21676c0b8ff111 /feature-distributed-locking/src/test/java | |
parent | ee2313141a40222a83d6bf39a15c3f9d4c3a239e (diff) |
Use DB time instead of jvm time
Modified distributed locking code to use the DB time (i.e., "now()") when
determining expiration times of locks. This will eliminate concerns that
may arise from different timestamps on different JVMs. As part of the
change, the expirationTime column was changed from BIGINT to TIMESTAMP.
Rename 1810 sql scripts to 1811, to match release date.
Change-Id: Ibfb15742f447133b001e4340027657ac202864a6
Issue-ID: POLICY-872
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-distributed-locking/src/test/java')
-rw-r--r-- | feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/TargetLockTest.java | 16 |
1 files changed, 7 insertions, 9 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 a4c292c1..c1b46d67 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 @@ -80,10 +80,9 @@ public class TargetLockTest { assertEquals(OperResult.OPER_ACCEPTED, distLockFeat.beforeLock("resource1", "owner1", MAX_AGE_SEC)); //attempt to grab expiredLock - try (PreparedStatement updateStatement = conn.prepareStatement("UPDATE pooling.locks SET expirationTime = ? WHERE resourceId = ?");) + try (PreparedStatement updateStatement = conn.prepareStatement("UPDATE pooling.locks SET expirationTime = timestampadd(second, -1, now()) WHERE resourceId = ?");) { - updateStatement.setLong(1, System.currentTimeMillis() - 1000); - updateStatement.setString(2, "resource1"); + updateStatement.setString(1, "resource1"); updateStatement.executeUpdate(); } catch (SQLException e) { @@ -104,8 +103,8 @@ public class TargetLockTest { distLockFeat.beforeLock("resource1", "owner1", MAX_AGE_SEC); //force lock to expire - try (PreparedStatement lockExpire = conn.prepareStatement("UPDATE pooling.locks SET expirationTime = ?");) { - lockExpire.setLong(1, System.currentTimeMillis() - MAX_AGE_SEC - 1); + try (PreparedStatement lockExpire = conn.prepareStatement("UPDATE pooling.locks SET expirationTime = timestampadd(second, -?, now())");) { + lockExpire.setInt(1, MAX_AGE_SEC + 1); lockExpire.executeUpdate(); } @@ -139,9 +138,8 @@ public class TargetLockTest { // isActive on expiredLock try (PreparedStatement updateStatement = conn - .prepareStatement("UPDATE pooling.locks SET expirationTime = ? WHERE resourceId = ?");) { - updateStatement.setLong(1, System.currentTimeMillis() - 5000); - updateStatement.setString(2, "resource1"); + .prepareStatement("UPDATE pooling.locks SET expirationTime = timestampadd(second, -5, now()) WHERE resourceId = ?");) { + updateStatement.setString(1, "resource1"); updateStatement.executeUpdate(); } catch (SQLException e) { @@ -183,7 +181,7 @@ public class TargetLockTest { } private static void createTable() { - String createString = "create table if not exists pooling.locks (resourceId VARCHAR(128), host VARCHAR(128), owner VARCHAR(128), expirationTime BIGINT, PRIMARY KEY (resourceId))"; + String createString = "create table if not exists pooling.locks (resourceId VARCHAR(128), host VARCHAR(128), owner VARCHAR(128), expirationTime TIMESTAMP DEFAULT 0, PRIMARY KEY (resourceId))"; try (PreparedStatement createStmt = conn.prepareStatement(createString);) { createStmt.executeUpdate(); |