Search in sources :

Example 1 with OPERATIONAL

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);
}
Also used : DataTreeChangeListener(org.opendaylight.mdsal.binding.api.DataTreeChangeListener) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ScheduledFuture(java.util.concurrent.ScheduledFuture) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ListsBindingUtils.topLevelList(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList) LoggerFactory(org.slf4j.LoggerFactory) AbstractConcurrentDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) OPERATIONAL(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) RetryingManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.RetryingManagedNewTransactionRunner) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Datastore(org.opendaylight.mdsal.binding.util.Datastore) Mockito.doReturn(org.mockito.Mockito.doReturn) Awaitility.await(org.awaitility.Awaitility.await) TOP_FOO_KEY(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY) ListsBindingUtils.path(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path) CountDownLatch(java.util.concurrent.CountDownLatch) LogCaptureRule(org.opendaylight.infrautils.testutils.LogCaptureRule) NextAction(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar.NextAction) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataTreeIdentifier(org.opendaylight.mdsal.binding.api.DataTreeIdentifier) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) Function(java.util.function.Function) ListsBindingUtils.complexUsesAugment(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment) ArgumentCaptor(org.mockito.ArgumentCaptor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ListeningScheduledExecutorService(com.google.common.util.concurrent.ListeningScheduledExecutorService) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) USES_ONE_KEY(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.USES_ONE_KEY) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LogRule(org.opendaylight.infrautils.testutils.LogRule) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) DataTreeEventCallbackRegistrarImpl(org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) DataTreeChangeListener(org.opendaylight.mdsal.binding.api.DataTreeChangeListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) DataTreeEventCallbackRegistrar(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar) SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) NextAction(org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar.NextAction) DataTreeEventCallbackRegistrarImpl(org.opendaylight.genius.datastoreutils.listeners.internal.DataTreeEventCallbackRegistrarImpl) AbstractConcurrentDataBrokerTest(org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest) Test(org.junit.Test)

Example 2 with OPERATIONAL

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));
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) OPERATIONAL(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Test(org.junit.Test) Datastore(org.opendaylight.genius.infra.Datastore) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) Assert.assertEquals(org.junit.Assert.assertEquals) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException)

Example 3 with OPERATIONAL

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));
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) OPERATIONAL(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Test(org.junit.Test) Datastore(org.opendaylight.genius.infra.Datastore) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) Assert.assertEquals(org.junit.Assert.assertEquals) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException)

Example 4 with OPERATIONAL

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));
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) OPERATIONAL(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Test(org.junit.Test) Datastore(org.opendaylight.genius.infra.Datastore) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) Assert.assertEquals(org.junit.Assert.assertEquals) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) Test(org.junit.Test)

Example 5 with OPERATIONAL

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));
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) OPERATIONAL(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Test(org.junit.Test) Datastore(org.opendaylight.genius.infra.Datastore) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) Assert.assertEquals(org.junit.Assert.assertEquals) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException)

Aggregations

Test (org.junit.Test)8 DataBroker (org.opendaylight.mdsal.binding.api.DataBroker)8 OPERATIONAL (org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL)8 TopLevelList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 Datastore (org.opendaylight.genius.infra.Datastore)7 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)7 RetryingManagedNewTransactionRunner (org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner)7 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)7 OptimisticLockFailedException (org.opendaylight.mdsal.common.api.OptimisticLockFailedException)7 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 ListeningScheduledExecutorService (com.google.common.util.concurrent.ListeningScheduledExecutorService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 Duration (java.time.Duration)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1