@Test
public void testLockCleanByClientTTl() throws IOException {

  boolean[] cleanLocksOptions = new boolean[]{false, true};
  for (boolean cleanLocks : cleanLocksOptions) {
    Configuration testConf = HBaseConfiguration.create(conf);
    // lock should be cleaned but clean fail
    ThemisLock lc = getLock(COLUMN);
    writeLockAndData(COLUMN);
    Mockito.when(mockRegister.isWorkerAlive(lc.getClientAddress())).thenReturn(true);
    // lock could be cleaned because client lock ttl is set
    // make sure the lock is expired by client ttl
    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);
    
    // lock should be cleaned after retry
    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);
  }
}