@Test
public void testTryToCleanLockFail() throws Exception {

  // lock with null column
  ThemisLock nullColumnLock = getLock(COLUMN);
  nullColumnLock.setColumn(null);
  try {
    lockCleaner.tryToCleanLock(nullColumnLock);
    Assert.fail();
  } catch (ThemisFatalException e) {}
  
  boolean[] cleanLocksOptions = new boolean[]{false, true};
  for (boolean cleanLocks : cleanLocksOptions) {
    // lock should be cleaned but clean fail
    ThemisLock lc = getLock(COLUMN);
    writeLockAndData(COLUMN);
    Mockito.when(mockRegister.isWorkerAlive(lc.getClientAddress())).thenReturn(false);
    HBaseAdmin admin = new HBaseAdmin(connection.getConfiguration());
    admin.disableTable(TABLENAME);
    try {
      invokeTryToCleanLock(lc, cleanLocks);
    } catch (IOException e) {
      Assert.assertTrue(e.getCause() instanceof RetriesExhaustedException);
      admin.enableTable(TABLENAME);
      checkPrewriteColumnSuccess(COLUMN);
    } finally {
      admin.close();
    }
    // lock should not be cleaned after retry
    deleteOldDataAndUpdateTs();
    writeLockAndData(COLUMN);
    lc = getLock(COLUMN);
    Mockito.when(mockRegister.isWorkerAlive(lc.getClientAddress())).thenReturn(true);
    long startTs = System.currentTimeMillis();
    try {
      invokeTryToCleanLock(lc, cleanLocks);
      Assert.fail();
    } catch (LockConflictException e) {
      checkPrewriteColumnSuccess(COLUMN);
      Assert.assertTrue((System.currentTimeMillis() - startTs) >= 100);
    }
  }
}