Search in sources :

Example 1 with LockInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder 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 2 with LockInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder 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 3 with LockInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder 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 4 with LockInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder 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)

Example 5 with LockInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInputBuilder in project genius by opendaylight.

the class LockManagerTest method testLockAndUnLock.

@Test
public void testLockAndUnLock() throws InterruptedException, ExecutionException, TimeoutException {
    LockInput lockInput = new LockInputBuilder().setLockName("testLock").build();
    assertVoidRpcSuccess(lockManager.lock(lockInput));
    UnlockInput unlockInput = new UnlockInputBuilder().setLockName("testLock").build();
    assertVoidRpcSuccess(lockManager.unlock(unlockInput));
}
Also used : UnlockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInput) TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) LockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput) UnlockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.UnlockInputBuilder) 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)

Aggregations

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