use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testChainWithReadOnlyTxAfterPreviousReady.
@Test
public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
// Create a write tx and submit.
final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
// Create read-only tx's and issue a read.
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 = txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 = txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
// Create another write tx and issue the write.
DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
writeTx2.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
// Ensure the reads succeed.
assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
// Ensure the writes succeed.
DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
doCommit(cohort1);
doCommit(cohort2);
assertEquals("isPresent", true, txChain.newReadOnlyTransaction().read(TestModel.OUTER_LIST_PATH).checkedGet(5, TimeUnit.SECONDS).isPresent());
}
}
};
}
use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testTransactionReadFailureWithShardNotInitialized.
@Test(expected = NotInitializedException.class)
@SuppressWarnings("checkstyle:IllegalCatch")
public void testTransactionReadFailureWithShardNotInitialized() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
final String testName = "testTransactionReadFailureWithShardNotInitialized";
final String shardName = "test-1";
// Set the shard initialization timeout low for the test.
datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
// Setup the InMemoryJournal to block shard recovery
// indefinitely.
final String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
final CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName)) {
// Create the read-write Tx
final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
assertNotNull("newReadWriteTransaction returned null", readWriteTx);
// Do a read on the Tx on a separate thread.
final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>> txReadFuture = new AtomicReference<>();
final AtomicReference<Exception> caughtEx = new AtomicReference<>();
final CountDownLatch txReadDone = new CountDownLatch(1);
final Thread txThread = new Thread(() -> {
try {
readWriteTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
readWriteTx.close();
} catch (Exception e) {
caughtEx.set(e);
} finally {
txReadDone.countDown();
}
});
txThread.start();
// Wait for the Tx operations to complete.
boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
if (caughtEx.get() != null) {
throw caughtEx.get();
}
assertEquals("Tx read done", true, done);
// have timed out and throw an appropriate exception cause.
try {
txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
fail("Expected NotInitializedException");
} catch (final ReadFailedException e) {
final Throwable root = Throwables.getRootCause(e);
Throwables.throwIfUnchecked(root);
throw new RuntimeException(root);
} finally {
blockRecoveryLatch.countDown();
}
}
}
};
}
use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.
the class RemoteProxyTransactionTest method testExists.
@Override
@Test
public void testExists() throws Exception {
final TransactionTester<RemoteProxyTransaction> tester = getTester();
final CheckedFuture<Boolean, ReadFailedException> exists = transaction.exists(PATH_1);
final ExistsTransactionRequest req = tester.expectTransactionRequest(ExistsTransactionRequest.class);
final boolean existsResult = true;
tester.replySuccess(new ExistsTransactionSuccess(TRANSACTION_ID, req.getSequence(), existsResult));
assertFutureEquals(existsResult, exists);
}
use of org.opendaylight.mdsal.common.api.ReadFailedException in project controller by opendaylight.
the class RemoteProxyTransactionTest method testRead.
@Override
@Test
public void testRead() throws Exception {
final TransactionTester<RemoteProxyTransaction> tester = getTester();
final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = transaction.read(PATH_2);
final ReadTransactionRequest req = tester.expectTransactionRequest(ReadTransactionRequest.class);
final Optional<NormalizedNode<?, ?>> result = Optional.of(DATA_1);
tester.replySuccess(new ReadTransactionSuccess(TRANSACTION_ID, req.getSequence(), result));
assertFutureEquals(result, read);
}
Aggregations