Search in sources :

Example 6 with DOMStoreReadWriteTransaction

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

the class WriteModificationTest 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());
}
Also used : DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 7 with DOMStoreReadWriteTransaction

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

the class InMemoryDataStoreTest method testTransactionAbort.

@Test
public void testTransactionAbort() throws InterruptedException, ExecutionException {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    assertTestContainerWrite(writeTx);
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    assertTrue(cohort.canCommit().get().booleanValue());
    cohort.preCommit().get();
    cohort.abort().get();
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertFalse(afterCommitRead.isPresent());
}
Also used : DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 8 with DOMStoreReadWriteTransaction

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

the class InMemoryDataStoreTest method testTransactionCommit.

@Test
public void testTransactionCommit() throws InterruptedException, ExecutionException {
    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());
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    assertThreePhaseCommit(cohort);
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", testNode, afterCommitRead.get());
}
Also used : Optional(com.google.common.base.Optional) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 9 with DOMStoreReadWriteTransaction

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

the class SchemaUpdateForTransactionTest method testTransactionSchemaUpdate.

/**
 * Test suite tests allocating transaction when schema context
 * does not contain module necessary for client write,
 * then triggering update of global schema context
 * and then performing write (according to new module).
 *
 * <p>
 * If transaction between allocation and schema context was
 * unmodified, it is safe to change its schema context
 * to new one (e.g. it will be same as if allocated after
 * schema context update.)
 */
@Test
public void testTransactionSchemaUpdate() throws Exception {
    assertNotNull(this.domStore);
    // We allocate transaction, initial schema context does not
    // contain Lists model
    final DOMStoreReadWriteTransaction writeTx = this.domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    // we trigger schema context update to contain Lists model
    loadSchemas(RockTheHouseInput.class, Top.class);
    /*
         * Writes /test in writeTx, this write should not fail
         * with IllegalArgumentException since /test is in
         * schema context.
         */
    writeTx.write(TOP_PATH, ImmutableNodes.containerNode(Top.QNAME));
}
Also used : DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) Test(org.junit.Test)

Example 10 with DOMStoreReadWriteTransaction

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction 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

DOMStoreReadWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction)20 Test (org.junit.Test)12 DOMStoreThreePhaseCommitCohort (org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)12 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 DOMStoreReadTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction)4 Optional (com.google.common.base.Optional)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 Ignore (org.junit.Ignore)1 DOMStoreTransactionChain (org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain)1 DOMStoreWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1