Search in sources :

Example 1 with LockInput

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));
}
Also used : TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) AbstractConcurrentDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 2 with 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");
}
Also used : TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) LockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) LockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder) AbstractConcurrentDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 3 with LockInput

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!");
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) LockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) LockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder) AbstractConcurrentDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 4 with LockInput

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));
}
Also used : TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) LockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) LockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder) AbstractConcurrentDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 5 with 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);
    }
}
Also used : LockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ExecutionException(java.util.concurrent.ExecutionException) LockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder)

Aggregations

Test (org.junit.Test)6 AbstractConcurrentDataBrokerTest (org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest)6 LockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput)6 LockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder)6 TryLockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput)6 TryLockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder)6 ExecutionException (java.util.concurrent.ExecutionException)1 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 UnlockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInput)1 UnlockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInputBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1