import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
-import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedTransactions;
-import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
-
-import org.opendaylight.mdsal.common.api.ReadFailedException;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
+import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
+import org.opendaylight.mdsal.common.api.ReadFailedException;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
+import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedTransactions;
+import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
+import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class InMemoryDataStoreTest {
private InMemoryDOMDataStore domStore;
@Before
- public void setupStore() {
+ public void setupStore() throws IOException, YangSyntaxErrorException, ReactorException {
domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService());
schemaContext = TestModel.createTestContext();
domStore.onGlobalContextUpdated(schemaContext);
assertNotNull(writeTx);
/**
- * Writes /test in writeTx
+ * Writes /test in writeTx.
*/
NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
assertNotNull(writeTx);
/**
- * Writes /test in writeTx
+ * Writes /test in writeTx.
*/
NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
assertThreePhaseCommit( writeTx.ready() );
- Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().
- read(TestModel.TEST_PATH ).get();
+ Optional<NormalizedNode<?, ?>> afterCommitRead =
+ domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
assertEquals( "After commit read: isPresent", true, afterCommitRead.isPresent() );
// Delete /test and verify
assertThreePhaseCommit( writeTx.ready() );
- afterCommitRead = domStore.newReadOnlyTransaction().
- read(TestModel.TEST_PATH ).get();
+ afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
assertEquals( "After commit read: isPresent", false, afterCommitRead.isPresent() );
}
assertThreePhaseCommit( writeTx.ready() );
- Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().
- read(TestModel.TEST_PATH ).get();
+ Optional<NormalizedNode<?, ?>> afterCommitRead =
+ domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH ).get();
assertEquals( "After commit read: isPresent", true, afterCommitRead.isPresent() );
assertEquals( "After commit read: data", containerNode, afterCommitRead.get() );
assertEquals(false, exists.checkedGet());
}
- @Test(expected=ReadFailedException.class)
+ @Test(expected = ReadFailedException.class)
public void testExistsThrowsReadFailedException() throws Exception {
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
}
-
- @Test(expected=ReadFailedException.class)
+ @SuppressWarnings("checkstyle:IllegalThrows")
+ @Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionClosed() throws Throwable {
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
doReadAndThrowEx( readTx );
}
- @Test(expected=ReadFailedException.class)
+ @SuppressWarnings("checkstyle:IllegalThrows")
+ @Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionFailure() throws Throwable {
DataTreeSnapshot mockSnapshot = Mockito.mock( DataTreeSnapshot.class );
doReadAndThrowEx( readTx );
}
- @Test(expected=ReadFailedException.class)
+ @SuppressWarnings("checkstyle:IllegalThrows")
+ @Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionClosed() throws Throwable {
DOMStoreReadTransaction readTx = domStore.newReadWriteTransaction();
doReadAndThrowEx( readTx );
}
- @Test(expected=ReadFailedException.class)
+ @SuppressWarnings("checkstyle:IllegalThrows")
+ @Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionFailure() throws Throwable {
DataTreeSnapshot mockSnapshot = Mockito.mock( DataTreeSnapshot.class );
Mockito.doReturn( mockModification ).when( mockSnapshot ).newModification();
@SuppressWarnings("unchecked")
TransactionReadyPrototype<String> mockReady = Mockito.mock( TransactionReadyPrototype.class );
- DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction("1", false, mockSnapshot, mockReady);
+ DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction(
+ "1", false, mockSnapshot, mockReady);
doReadAndThrowEx( readTx );
}
+ @SuppressWarnings("checkstyle:IllegalThrows")
private static void doReadAndThrowEx( final DOMStoreReadTransaction readTx ) throws Throwable {
try {
readTx.read(TestModel.TEST_PATH).get();
- } catch( ExecutionException e ) {
+ } catch ( ExecutionException e ) {
throw e.getCause();
}
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testWriteWithTransactionReady() throws Exception {
DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
writeTx.write( TestModel.TEST_PATH, ImmutableNodes.containerNode( TestModel.TEST_QNAME ) );
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testReadyWithTransactionAlreadyReady() throws Exception {
DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
assertNotNull(txChain);
/**
- * We alocate new read-write transaction and write /test
- *
- *
+ * 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
+ * transactions.
*/
- DOMStoreThreePhaseCommitCohort firstWriteTxCohort = firstTx.ready();
+ final DOMStoreThreePhaseCommitCohort firstWriteTxCohort = firstTx.ready();
/**
* We alocate chained transaction - read transaction, note first one is
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
+ * We delete node in third transaction.
*/
thirdDeleteTx.delete(TestModel.TEST_PATH);
DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready();
/**
- * We commit first transaction
+ * We commit first transaction.
*
*/
assertThreePhaseCommit(firstWriteTxCohort);