Search in sources :

Example 6 with ReadFailedException

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());
            }
        }
    };
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 7 with ReadFailedException

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();
                }
            }
        }
    };
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressFromURIString(akka.actor.AddressFromURIString) CountDownLatch(java.util.concurrent.CountDownLatch) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TransactionChainClosedException(org.opendaylight.mdsal.common.api.TransactionChainClosedException) RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) IOException(java.io.IOException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ExecutionException(java.util.concurrent.ExecutionException) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 8 with ReadFailedException

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);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) Test(org.junit.Test)

Example 9 with ReadFailedException

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);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) Test(org.junit.Test)

Aggregations

ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)9 Test (org.junit.Test)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 Optional (com.google.common.base.Optional)3 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)3 AddressFromURIString (akka.actor.AddressFromURIString)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)2 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)2 TransactionChainClosedException (org.opendaylight.mdsal.common.api.TransactionChainClosedException)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)2 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)2 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)2 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)1 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)1