import static org.junit.Assert.assertTrue;
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.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
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() throws IOException, YangSyntaxErrorException, ReactorException {
+ public void setupStore() {
domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService());
schemaContext = TestModel.createTestContext();
domStore.onGlobalContextUpdated(schemaContext);
writeTx.merge(TestModel.TEST_PATH, containerNode);
- CheckedFuture<Boolean, ReadFailedException> exists =
- writeTx.exists(TestModel.TEST_PATH);
+ ListenableFuture<Boolean> exists = writeTx.exists(TestModel.TEST_PATH);
- assertEquals(true, exists.checkedGet());
+ assertEquals(Boolean.TRUE, exists.get());
DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
exists =
readTx.exists(TestModel.TEST_PATH);
- assertEquals(true, exists.checkedGet());
+ assertEquals(Boolean.TRUE, exists.get());
}
@Test
DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
- CheckedFuture<Boolean, ReadFailedException> exists =
- writeTx.exists(TestModel.TEST_PATH);
+ ListenableFuture<Boolean> exists = writeTx.exists(TestModel.TEST_PATH);
- assertEquals(false, exists.checkedGet());
+ assertEquals(Boolean.FALSE, exists.get());
DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
exists =
readTx.exists(TestModel.TEST_PATH);
- assertEquals(false, exists.checkedGet());
+ assertEquals(Boolean.FALSE, exists.get());
}
@Test(expected = ReadFailedException.class)
doReadAndThrowEx(readTx);
}
- @SuppressWarnings("checkstyle:IllegalThrows")
+ @SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:avoidHidingCauseException" })
private static void doReadAndThrowEx(final DOMStoreReadTransaction readTx) throws Throwable {
try {
readTx.read(TestModel.TEST_PATH).get();
writeTx.ready();
}
+ @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
+ }
+ }
+
@Test
public void testTransactionAbort() throws InterruptedException, ExecutionException {