Search in sources :

Example 1 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class DOMForwardedWriteTransaction method submit.

@Override
@SuppressWarnings("checkstyle:illegalcatch")
public CheckedFuture<Void, TransactionCommitFailedException> submit() {
    final AbstractDOMForwardedTransactionFactory<?> impl = IMPL_UPDATER.getAndSet(this, null);
    checkRunning(impl);
    final Collection<T> txns = getSubtransactions();
    final Collection<DOMStoreThreePhaseCommitCohort> cohorts = new ArrayList<>(txns.size());
    CheckedFuture<Void, TransactionCommitFailedException> ret;
    try {
        for (DOMStoreWriteTransaction txn : txns) {
            cohorts.add(txn.ready());
        }
        ret = impl.submit(this, cohorts);
    } catch (RuntimeException e) {
        ret = Futures.immediateFailedCheckedFuture(TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER.apply(e));
    }
    FUTURE_UPDATER.lazySet(this, ret);
    return ret;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) ArrayList(java.util.ArrayList) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 2 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class InMemoryDataStoreTest method testReadyWithMissingMandatoryData.

@Test
public void testReadyWithMissingMandatoryData() throws InterruptedException {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    NormalizedNode<?, ?> testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.MANDATORY_DATA_TEST_QNAME)).addChild(ImmutableNodes.leafNode(TestModel.OPTIONAL_QNAME, "data")).build();
    writeTx.write(TestModel.MANDATORY_DATA_TEST_PATH, testNode);
    DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
    try {
        ready.canCommit().get();
        Assert.fail("Expected exception on canCommit");
    } catch (ExecutionException e) {
    // nop
    }
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ExecutionException(java.util.concurrent.ExecutionException) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 3 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class InMemoryDataStoreTest method testWriteWithTransactionReady.

@Test(expected = IllegalStateException.class)
public void testWriteWithTransactionReady() throws Exception {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    writeTx.ready();
    // Should throw ex
    writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) Test(org.junit.Test)

Example 4 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class InMemoryDataStoreTest method testReadyWithTransactionAlreadyReady.

@Test(expected = IllegalStateException.class)
public void testReadyWithTransactionAlreadyReady() throws Exception {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    writeTx.ready();
    // Should throw ex
    writeTx.ready();
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) Test(org.junit.Test)

Example 5 with DOMStoreWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction in project controller by opendaylight.

the class DeleteModificationTest method testApply.

@Test
public void testApply() throws Exception {
    // Write something into the datastore
    DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
    WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    writeModification.apply(writeTransaction);
    commitTransaction(writeTransaction);
    // Check if it's in the datastore
    Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
    Assert.assertTrue(data.isPresent());
    // Delete stuff from the datastore
    DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
    DeleteModification deleteModification = new DeleteModification(TestModel.TEST_PATH);
    deleteModification.apply(deleteTransaction);
    commitTransaction(deleteTransaction);
    data = readData(TestModel.TEST_PATH);
    Assert.assertFalse(data.isPresent());
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DOMStoreWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction)7 Test (org.junit.Test)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DOMStoreThreePhaseCommitCohort (org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMStoreReadWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1