use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput in project genius by opendaylight.
the class LockManagerTest method testTryLock.
@Test
public // tryLock() RPC will retry only specific number of times, and it will only return after that
void testTryLock() throws InterruptedException, ExecutionException, TimeoutException {
String uniqueId = lockManagerUtils.getBladeId() + ":2";
logCaptureRule.expectError("Failed to get lock testTryLock owner " + uniqueId + " after 3 retries");
TryLockInput lockInput = new TryLockInputBuilder().setLockName("testTryLock").setTime(3L).setTimeUnit(TimeUnits.Seconds).build();
assertVoidRpcSuccess(lockManager.tryLock(lockInput));
// The second acquireLock request will retry for 3 seconds
// and since the first lock is not unlocked, the request will fail.
lockInput = new TryLockInputBuilder().setLockName("testTryLock").setTime(3000L).setTimeUnit(TimeUnits.Milliseconds).build();
assertRpcErrorWithoutCausesOrMessages(lockManager.tryLock(lockInput));
// Try to unlock the key in a separate thread before retry expires, and see
// if lock gets acquired.
runUnlockTimerTask("testTryLock", 2000);
lockInput = new TryLockInputBuilder().setLockName("testTryLock").setTime(4000000L).setTimeUnit(TimeUnits.Microseconds).build();
assertVoidRpcSuccess(lockManager.tryLock(lockInput));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput in project genius by opendaylight.
the class LockManagerTest method testAskTimeOutException.
@Test
public void testAskTimeOutException() throws InterruptedException, ExecutionException, TimeoutException {
String lockName = "testLock";
logCaptureRule.expectError("Unable to acquire lock for " + lockName + ", try 1", 1);
dbFailureSimulator.failButSubmitsAnyways();
LockInput lockInput = new LockInputBuilder().setLockName(lockName).build();
assertRpcErrorCause(lockManager.lock(lockInput), TransactionCommitFailedException.class, "caused by simulated AskTimeoutException");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput in project genius by opendaylight.
the class LockManagerTest method testEternalTransactionCommitFailedExceptionOnLock.
@Test
public void testEternalTransactionCommitFailedExceptionOnLock() throws InterruptedException, ExecutionException, TimeoutException {
logCaptureRule.expectError("RPC lock() failed; input = LockInput{_lockName=testLock, augmentation=[]}");
dbFailureSimulator.failSubmits(new TransactionCommitFailedException("bada boum bam!"));
LockInput lockInput = new LockInputBuilder().setLockName("testLock").build();
assertRpcErrorCause(lockManager.lock(lockInput), TransactionCommitFailedException.class, "bada boum bam!");
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput in project genius by opendaylight.
the class LockManagerTest method test3sOptimisticLockFailedExceptionOnLock.
@Test
public void test3sOptimisticLockFailedExceptionOnLock() throws InterruptedException, ExecutionException, TimeoutException {
dbFailureSimulator.failSubmits(new OptimisticLockFailedException("bada boum bam!"));
LockInput lockInput = new LockInputBuilder().setLockName("testLock").build();
// see other tests above
runUnfailSubmitsTimerTask(3000);
assertVoidRpcSuccess(lockManager.lock(lockInput));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput in project genius by opendaylight.
the class IdUtils method lock.
public void lock(LockManagerService lockManager, String poolName) throws IdManagerException {
LockInput input = new LockInputBuilder().setLockName(poolName).build();
Future<RpcResult<Void>> result = lockManager.lock(input);
try {
if (result != null && result.get().isSuccessful()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Acquired lock {}", poolName);
}
} else {
throw new IdManagerException(String.format("Unable to getLock for pool %s", poolName));
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Unable to getLock for pool {}", poolName, e);
throw new RuntimeException(String.format("Unable to getLock for pool %s", poolName), e);
}
}
Aggregations