LockCleaner extends ServerLockCleaner { public static void checkLockExpired(ThemisLock lock, ThemisCoprocessorClient cpClient, int clientLockTTL) throws IOException { if (clientLockTTL == 0) { lock.setLockExpired(cpClient.isLockExpired(lock.getColumn().getTableName(), lock.getColumn() .getRow(), lock.getTimestamp())); } else { lock.setLockExpired(TransactionTTL.isLockExpired(lock.getTimestamp(), clientLockTTL)); LOG.info("check lock expired by client lock ttl, lock=" + lock + ", clientLockTTL=" + clientLockTTL + ", type=" + TransactionTTL.timestampType); } } LockCleaner(Configuration conf, HConnection conn, WorkerRegister register,
      ThemisCoprocessorClient cpClient); static LockCleaner getLockCleaner(Configuration conf, HConnection conn,
      WorkerRegister register, ThemisCoprocessorClient cpClient); boolean shouldCleanLock(ThemisLock lock); static List<ThemisLock> constructLocks(byte[] tableName, List<KeyValue> lockKvs,
      ThemisCoprocessorClient cpClient, int clientLockTTL); static void checkLockExpired(ThemisLock lock, ThemisCoprocessorClient cpClient,
      int clientLockTTL); void tryToCleanLocks(byte[] tableName, List<KeyValue> lockColumns); boolean checkLockExpiredAndTryToCleanLock(ThemisLock lock); boolean tryToCleanLock(ThemisLock lock);  }
@Test public void testLockCleanByClientTTl() throws IOException { boolean[] cleanLocksOptions = new boolean[]{false, true}; for (boolean cleanLocks : cleanLocksOptions) { Configuration testConf = HBaseConfiguration.create(conf); ThemisLock lc = getLock(COLUMN); writeLockAndData(COLUMN); Mockito.when(mockRegister.isWorkerAlive(lc.getClientAddress())).thenReturn(true); Assert.assertTrue(System.currentTimeMillis() - lc.getTimestamp() > 1); testConf.set(TransactionConstant.CLIENT_LOCK_TTL_KEY, String.valueOf("1")); testConf.setInt(TransactionConstant.THEMIS_PAUSE, 500); lockCleaner = new LockCleaner(testConf, connection, mockRegister, cpClient); if (!cleanLocks) { LockCleaner.checkLockExpired(lc, cpClient, 1); } long startTs = System.currentTimeMillis(); invokeTryToCleanLock(lc, cleanLocks); checkColumnRollback(COLUMN); Assert.assertTrue(System.currentTimeMillis() - startTs < 500); lc.setTimestamp(System.currentTimeMillis()); testConf.set(TransactionConstant.CLIENT_LOCK_TTL_KEY, String.valueOf("500")); lockCleaner = new LockCleaner(testConf, connection, mockRegister, cpClient); if (!cleanLocks) { LockCleaner.checkLockExpired(lc, cpClient, 500); } startTs = System.currentTimeMillis(); invokeTryToCleanLock(lc, cleanLocks); checkColumnRollback(COLUMN); Assert.assertTrue(System.currentTimeMillis() - startTs >= 500); } }