use of org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.
the class DataTreeEventCallbackRegistrarTest method testExceptionInCallbackMustBeLogged.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testExceptionInCallbackMustBeLogged() throws TransactionCommitFailedException, InterruptedException {
logCaptureRule.expectLastErrorMessageContains("Error invoking worker");
DataBroker spiedDataBroker = spy(db);
final DataTreeChangeListener mockListener = mock(DataTreeChangeListener.class, "TestListener");
doAnswer(invocation -> db.registerDataTreeChangeListener(invocation.getArgument(0), mockListener)).when(spiedDataBroker).registerDataTreeChangeListener(any(), any());
AtomicBoolean added = new AtomicBoolean(false);
DataTreeEventCallbackRegistrar dataTreeEventCallbackRegistrar = new DataTreeEventCallbackRegistrarImpl(spiedDataBroker);
dataTreeEventCallbackRegistrar.onAdd(OPERATIONAL, FOO_PATH, (Function<TopLevelList, NextAction>) topLevelList -> {
added.set(true);
throw new IllegalStateException("TEST");
});
ArgumentCaptor<DataTreeChangeListener> realListener = ArgumentCaptor.forClass(DataTreeChangeListener.class);
verify(spiedDataBroker).registerDataTreeChangeListener(any(), realListener.capture());
AtomicBoolean onDataTreeChangeDone = new AtomicBoolean(false);
doAnswer(invocation -> {
try {
realListener.getValue().onDataTreeChanged(invocation.getArgument(0));
} finally {
onDataTreeChangeDone.set(true);
}
return null;
}).when(mockListener).onDataTreeChanged(anyCollection());
db1.syncWrite(OPERATIONAL, FOO_PATH, FOO_DATA);
await().untilTrue(added);
await().untilTrue(onDataTreeChangeDone);
}
use of org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.
the class RetryingManagedNewTransactionRunnerTest method testApplyWithNewReadWriteTransactionOptimisticLockFailedException.
@Override
public void testApplyWithNewReadWriteTransactionOptimisticLockFailedException() throws Exception {
// contrary to the super() test implementation for (just) ManagedNewTransactionRunnerImpl, in the parent class
// here we expect the x2 OptimisticLockFailedException to be retried, and then eventually succeed:
testableDataBroker.failSubmits(2, new OptimisticLockFailedException("bada boum bam!"));
TopLevelList data = newTestDataObject();
assertEquals(1, (long) managedNewTransactionRunner.applyWithNewReadWriteTransactionAndSubmit(Datastore.OPERATIONAL, writeTx -> {
writeTx.put(TEST_PATH, data);
return 1;
}).get());
assertEquals(data, singleTransactionDataBroker.syncRead(OPERATIONAL, TEST_PATH));
}
use of org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.
the class RetryingManagedNewTransactionRunnerTest method testCallWithNewTypedReadWriteTransactionOptimisticLockFailedException.
@Override
public void testCallWithNewTypedReadWriteTransactionOptimisticLockFailedException() throws Exception {
// contrary to the super() test implementation for (just) ManagedNewTransactionRunnerImpl, in the parent class
// here we expect the x2 OptimisticLockFailedException to be retried, and then eventually succeed:
testableDataBroker.failSubmits(2, new OptimisticLockFailedException("bada boum bam!"));
TopLevelList data = newTestDataObject();
managedNewTransactionRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.OPERATIONAL, writeTx -> writeTx.put(TEST_PATH, data)).get();
assertEquals(data, singleTransactionDataBroker.syncRead(OPERATIONAL, TEST_PATH));
}
use of org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.
the class RetryingManagedNewTransactionRunnerTest method testCallWithNewReadWriteTransactionReadFailedException.
@Test
public void testCallWithNewReadWriteTransactionReadFailedException() throws Exception {
testableDataBroker.failReads(2, new ReadFailedException("bada boum bam!"));
TopLevelList data = newTestDataObject();
managedNewTransactionRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
tx.put(LogicalDatastoreType.OPERATIONAL, TEST_PATH, data);
assertEquals(data, tx.read(LogicalDatastoreType.OPERATIONAL, TEST_PATH).get().get());
}).get();
assertEquals(data, singleTransactionDataBroker.syncRead(OPERATIONAL, TEST_PATH));
}
use of org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.
the class RetryingManagedNewTransactionRunnerTest method testCallWithNewReadWriteTransactionOptimisticLockFailedException.
@Override
public void testCallWithNewReadWriteTransactionOptimisticLockFailedException() throws Exception {
// contrary to the super() test implementation for (just) ManagedNewTransactionRunnerImpl, in the parent class
// here we expect the x2 OptimisticLockFailedException to be retried, and then eventually succeed:
testableDataBroker.failSubmits(2, new OptimisticLockFailedException("bada boum bam!"));
TopLevelList data = newTestDataObject();
managedNewTransactionRunner.callWithNewReadWriteTransactionAndSubmit(writeTx -> writeTx.put(LogicalDatastoreType.OPERATIONAL, TEST_PATH, data)).get();
assertEquals(data, singleTransactionDataBroker.syncRead(OPERATIONAL, TEST_PATH));
}
Aggregations