Search in sources :

Example 1 with OPERATIONAL

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.

the class ManagedNewTransactionRunnerImplTest method testCallWithNewWriteOnlyTransactionAndSubmitPutButLaterException.

@Test
public void testCallWithNewWriteOnlyTransactionAndSubmitPutButLaterException() throws Exception {
    try {
        managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(writeTx -> {
            writeTx.put(OPERATIONAL, TEST_PATH, newTestDataObject());
            // We now throw an arbitrary kind of checked (not unchecked!) exception here
            throw new IOException("something didn't quite go as expected...");
        }).get();
        fail("This should have lead to an ExecutionException!");
    } catch (ExecutionException e) {
        assertThat(e.getCause() instanceof IOException).isTrue();
    }
    assertThat(singleTransactionDataBroker.syncReadOptional(OPERATIONAL, TEST_PATH)).isAbsent();
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ListsBindingUtils.topLevelList(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList) ContainerWithUsesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) AsyncWriteTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncWriteTransaction) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) TreeComplexUsesAugmentBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder) TOP_FOO_KEY(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) IOException(java.io.IOException) Test(org.junit.Test) TreeComplexUsesAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment) Truth.assertThat(com.google.common.truth.Truth.assertThat) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DataBrokerFailuresImpl(org.opendaylight.genius.datastoreutils.testutils.DataBrokerFailuresImpl) ListsBindingUtils.path(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path) DataBrokerTestModule(org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule) LogRule(org.opendaylight.infrautils.testutils.LogRule) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) LogCaptureRule(org.opendaylight.infrautils.testutils.LogCaptureRule) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with OPERATIONAL

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.

the class ManagedNewTransactionRunnerImplTest method testCallWithNewWriteOnlyTransactionOptimisticLockFailedException.

@Test
public void testCallWithNewWriteOnlyTransactionOptimisticLockFailedException() throws Exception {
    try {
        testableDataBroker.failSubmits(2, new OptimisticLockFailedException("bada boum bam!"));
        managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(writeTx -> writeTx.put(LogicalDatastoreType.OPERATIONAL, TEST_PATH, newTestDataObject())).get();
        fail("This should have lead to an ExecutionException!");
    } catch (ExecutionException e) {
        assertThat(e.getCause() instanceof OptimisticLockFailedException).isTrue();
    }
    assertThat(singleTransactionDataBroker.syncReadOptional(OPERATIONAL, TEST_PATH)).isAbsent();
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ListsBindingUtils.topLevelList(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList) ContainerWithUsesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) AsyncWriteTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncWriteTransaction) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) TreeComplexUsesAugmentBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder) TOP_FOO_KEY(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) IOException(java.io.IOException) Test(org.junit.Test) TreeComplexUsesAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment) Truth.assertThat(com.google.common.truth.Truth.assertThat) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DataBrokerFailuresImpl(org.opendaylight.genius.datastoreutils.testutils.DataBrokerFailuresImpl) ListsBindingUtils.path(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path) DataBrokerTestModule(org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule) LogRule(org.opendaylight.infrautils.testutils.LogRule) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) LogCaptureRule(org.opendaylight.infrautils.testutils.LogCaptureRule) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) ExecutionException(java.util.concurrent.ExecutionException) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) Test(org.junit.Test)

Example 3 with OPERATIONAL

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.

the class ManagedNewTransactionRunnerImplTest method testCallWithNewWriteOnlyTransactionCommitFailedException.

@Test
public void testCallWithNewWriteOnlyTransactionCommitFailedException() throws Exception {
    try {
        testableDataBroker.failSubmits(new TransactionCommitFailedException("bada boum bam!"));
        managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(writeTx -> writeTx.put(LogicalDatastoreType.OPERATIONAL, TEST_PATH, newTestDataObject())).get();
        fail("This should have lead to an ExecutionException!");
    } catch (ExecutionException e) {
        assertThat(e.getCause() instanceof TransactionCommitFailedException).isTrue();
    }
    assertThat(singleTransactionDataBroker.syncReadOptional(OPERATIONAL, TEST_PATH)).isAbsent();
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) ListsBindingUtils.topLevelList(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList) ContainerWithUsesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder) TopLevelList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList) AsyncWriteTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncWriteTransaction) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) TreeComplexUsesAugmentBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder) TOP_FOO_KEY(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) IOException(java.io.IOException) Test(org.junit.Test) TreeComplexUsesAugment(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment) Truth.assertThat(com.google.common.truth.Truth.assertThat) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DataBrokerFailuresImpl(org.opendaylight.genius.datastoreutils.testutils.DataBrokerFailuresImpl) ListsBindingUtils.path(org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path) DataBrokerTestModule(org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule) LogRule(org.opendaylight.infrautils.testutils.LogRule) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) LogCaptureRule(org.opendaylight.infrautils.testutils.LogCaptureRule) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with OPERATIONAL

use of org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL in project genius by opendaylight.

the class RetryingManagedNewTransactionRunnerTest method testCallWithNewWriteOnlyTransactionOptimisticLockFailedException.

@Override
public void testCallWithNewWriteOnlyTransactionOptimisticLockFailedException() 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!"));
    managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(writeTx -> writeTx.put(LogicalDatastoreType.OPERATIONAL, TEST_PATH, newTestDataObject())).get();
    singleTransactionDataBroker.syncRead(OPERATIONAL, TEST_PATH);
}
Also used : ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException) RetryingManagedNewTransactionRunner(org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner) OPERATIONAL(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) OptimisticLockFailedException(org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)

Aggregations

DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)4 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)4 OPERATIONAL (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL)4 OptimisticLockFailedException (org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException)4 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Assert.fail (org.junit.Assert.fail)3 Before (org.junit.Before)3 Rule (org.junit.Rule)3 Test (org.junit.Test)3 DataBrokerTestModule (org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule)3 AsyncWriteTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncWriteTransaction)3 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)3 TOP_FOO_KEY (org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY)3 ListsBindingUtils.path (org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path)3 ListsBindingUtils.topLevelList (org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList)3 SingleTransactionDataBroker (org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker)3 DataBrokerFailuresImpl (org.opendaylight.genius.datastoreutils.testutils.DataBrokerFailuresImpl)3