Search in sources :

Example 6 with DOMStoreReadTransaction

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

the class InMemoryDataStoreTest method testExistsForExistingData.

@Test
public void testExistsForExistingData() throws Exception {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    ContainerNode containerNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
    writeTx.merge(TestModel.TEST_PATH, containerNode);
    CheckedFuture<Boolean, ReadFailedException> exists = writeTx.exists(TestModel.TEST_PATH);
    assertEquals(true, exists.checkedGet());
    DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
    ready.preCommit().get();
    ready.commit().get();
    DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
    assertNotNull(readTx);
    exists = readTx.exists(TestModel.TEST_PATH);
    assertEquals(true, exists.checkedGet());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 7 with DOMStoreReadTransaction

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

the class InMemoryDataStoreTest method testTransactionIsolation.

@Test
public void testTransactionIsolation() throws InterruptedException, ExecutionException {
    assertNotNull(domStore);
    DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
    assertNotNull(readTx);
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    /*
         * Writes /test in writeTx
         */
    NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    writeTx.write(TestModel.TEST_PATH, testNode);
    /*
         * Reads /test from writeTx Read should return container.
         */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
    assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
    assertEquals("read: data", testNode, writeTxContainer.get().get());
    /*
         * Reads /test from readTx Read should return Absent.
         */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> readTxContainer = readTx.read(TestModel.TEST_PATH);
    assertEquals("read: isPresent", false, readTxContainer.get().isPresent());
}
Also used : Optional(com.google.common.base.Optional) DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) Test(org.junit.Test)

Example 8 with DOMStoreReadTransaction

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

the class InMemoryDataStoreTest method testReadWithReadWriteTransactionFailure.

@Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionFailure() throws Exception {
    DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
    DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
    Mockito.doThrow(new RuntimeException("mock ex")).when(mockModification).readNode(Mockito.any(YangInstanceIdentifier.class));
    Mockito.doReturn(mockModification).when(mockSnapshot).newModification();
    @SuppressWarnings("unchecked") TransactionReadyPrototype<String> mockReady = Mockito.mock(TransactionReadyPrototype.class);
    DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction("1", false, mockSnapshot, mockReady);
    doReadAndThrowEx(readTx);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 9 with DOMStoreReadTransaction

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

the class InMemoryDataStoreTest method testTransactionChain.

@Test
public void testTransactionChain() throws InterruptedException, ExecutionException {
    DOMStoreTransactionChain txChain = domStore.createTransactionChain();
    assertNotNull(txChain);
    /*
         * We alocate new read-write transaction and write /test
         */
    DOMStoreReadWriteTransaction firstTx = txChain.newReadWriteTransaction();
    assertTestContainerWrite(firstTx);
    /*
         * First transaction is marked as ready, we are able to allocate chained
         * transactions
         */
    final DOMStoreThreePhaseCommitCohort firstWriteTxCohort = firstTx.ready();
    /*
         * We alocate chained transaction - read transaction, note first one is
         * still not commited to datastore.
         */
    DOMStoreReadTransaction secondReadTx = txChain.newReadOnlyTransaction();
    /*
         * We test if we are able to read data from tx, read should not fail
         * since we are using chained transaction.
         */
    assertTestContainerExists(secondReadTx);
    /*
         * We alocate next transaction, which is still based on first one, but
         * is read-write.
         */
    DOMStoreReadWriteTransaction thirdDeleteTx = txChain.newReadWriteTransaction();
    /*
         * We test existence of /test in third transaction container should
         * still be visible from first one (which is still uncommmited).
         */
    assertTestContainerExists(thirdDeleteTx);
    /*
         * We delete node in third transaction
         */
    thirdDeleteTx.delete(TestModel.TEST_PATH);
    /*
         * third transaction is sealed.
         */
    DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready();
    /*
         * We commit first transaction
         */
    assertThreePhaseCommit(firstWriteTxCohort);
    // Alocates store transacion
    DOMStoreReadTransaction storeReadTx = domStore.newReadOnlyTransaction();
    /*
         * We verify transaction is commited to store, container should exists
         * in datastore.
         */
    assertTestContainerExists(storeReadTx);
    /*
         * We commit third transaction
         */
    assertThreePhaseCommit(thirdDeleteTxCohort);
}
Also used : DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) DOMStoreTransactionChain(org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 10 with DOMStoreReadTransaction

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

the class InMemoryDataStoreTest method testExistsForNonExistingData.

@Test
public void testExistsForNonExistingData() throws Exception {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    CheckedFuture<Boolean, ReadFailedException> exists = writeTx.exists(TestModel.TEST_PATH);
    assertEquals(false, exists.checkedGet());
    DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
    assertNotNull(readTx);
    exists = readTx.exists(TestModel.TEST_PATH);
    assertEquals(false, exists.checkedGet());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) Test(org.junit.Test)

Aggregations

DOMStoreReadTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction)10 Test (org.junit.Test)9 DOMStoreReadWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction)4 Optional (com.google.common.base.Optional)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 DOMStoreThreePhaseCommitCohort (org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)2 DOMStoreTransactionChain (org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1