@Test
  public void shouldSucceedInLockingIfLockMediatorSucceeds() throws BackendException {

    when(storeManager.getMetaDataSchema("hbase"))
        .thenReturn(new EntryMetaData[] {EntryMetaData.TIMESTAMP});
    when(storeManager.getStorageConfig()).thenReturn(storageConfig);
    when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE))
        .thenReturn(new StandardDuration(300L, TimeUnit.MILLISECONDS));
    when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT))
        .thenReturn(new StandardDuration(10L, TimeUnit.MILLISECONDS));
    when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3);
    KeyColumn lockID = new KeyColumn(key, column);
    when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class)))
        .thenReturn(true);

    HBaseKeyColumnValueStore hBaseKeyColumnValueStore =
        new HBaseKeyColumnValueStore(
            storeManager, connectionMask, "titan", "e", "hbase", localLockMediator);
    hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction);

    verify(transaction).updateLocks(lockID, expectedValue);
    verify(localLockMediator, times(1)).lock(eq(lockID), eq(transaction), any(Timepoint.class));
  }
  @Test(expectedExceptions = PermanentLockingException.class)
  public void shouldThrowExceptionAfterConfiguredRetriesIfLockMediationFails()
      throws BackendException {
    when(storeManager.getMetaDataSchema("hbase"))
        .thenReturn(new EntryMetaData[] {EntryMetaData.TIMESTAMP});
    when(storeManager.getStorageConfig()).thenReturn(storageConfig);
    when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE))
        .thenReturn(new StandardDuration(300L, TimeUnit.MILLISECONDS));
    when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT))
        .thenReturn(new StandardDuration(10L, TimeUnit.MILLISECONDS));
    when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3);
    KeyColumn lockID = new KeyColumn(key, column);
    when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class)))
        .thenReturn(false)
        .thenReturn(false)
        .thenReturn(false);

    HBaseKeyColumnValueStore hBaseKeyColumnValueStore =
        new HBaseKeyColumnValueStore(
            storeManager, connectionMask, "titan", "e", "hbase", localLockMediator);
    hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction);

    fail("Should fail as lock could not be acquired after 3 retries.");
  }