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());
}
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());
}
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());
}
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));
}
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());
}
Aggregations