Search in sources :

Example 1 with RequestTimeoutException

use of org.opendaylight.controller.cluster.access.client.RequestTimeoutException in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testTransactionCommitFailureWithNoShardLeader.

@SuppressWarnings("checkstyle:IllegalCatch")
private void testTransactionCommitFailureWithNoShardLeader(final boolean writeOnly, final String testName) throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            final String shardName = "default";
            // We don't want the shard to become the leader so prevent shard
            // elections.
            datastoreContextBuilder.customRaftPolicyImplementation("org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy");
            // The ShardManager uses the election timeout for FindPrimary so
            // reset it low so it will timeout quickly.
            datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1).shardInitializationTimeout(200, TimeUnit.MILLISECONDS).frontendRequestTimeoutInSeconds(2);
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, testName, false, shardName)) {
                final Object result = dataStore.getActorContext().executeOperation(dataStore.getActorContext().getShardManager(), new FindLocalShard(shardName, true));
                assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
                // Create the write Tx.
                DOMStoreWriteTransaction writeTxToClose = null;
                try {
                    writeTxToClose = writeOnly ? dataStore.newWriteOnlyTransaction() : dataStore.newReadWriteTransaction();
                    final DOMStoreWriteTransaction writeTx = writeTxToClose;
                    assertNotNull("newReadWriteTransaction returned null", writeTx);
                    // Do some modifications and ready the Tx on a separate
                    // thread.
                    final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
                    final AtomicReference<Exception> caughtEx = new AtomicReference<>();
                    final CountDownLatch txReady = new CountDownLatch(1);
                    final Thread txThread = new Thread(() -> {
                        try {
                            writeTx.write(TestModel.JUNK_PATH, ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
                            txCohort.set(writeTx.ready());
                        } catch (Exception e) {
                            caughtEx.set(e);
                        } finally {
                            txReady.countDown();
                        }
                    });
                    txThread.start();
                    // Wait for the Tx operations to complete.
                    boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
                    if (caughtEx.get() != null) {
                        throw caughtEx.get();
                    }
                    assertEquals("Tx ready", true, done);
                    // exception cause.
                    try {
                        txCohort.get().canCommit().get(10, TimeUnit.SECONDS);
                        fail("Expected NoShardLeaderException");
                    } catch (final ExecutionException e) {
                        final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
                        if (DistributedDataStore.class.equals(testParameter)) {
                            assertTrue(Throwables.getRootCause(e) instanceof NoShardLeaderException);
                        } else {
                            assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
                        }
                    }
                } finally {
                    try {
                        if (writeTxToClose != null) {
                            writeTxToClose.close();
                        }
                    } catch (Exception e) {
                    // FIXME TransactionProxy.close throws IllegalStateException:
                    // Transaction is ready, it cannot be closed
                    }
                }
            }
        }
    };
}
Also used : LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) AtomicReference(java.util.concurrent.atomic.AtomicReference) AddressFromURIString(akka.actor.AddressFromURIString) CountDownLatch(java.util.concurrent.CountDownLatch) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) 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) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with RequestTimeoutException

use of org.opendaylight.controller.cluster.access.client.RequestTimeoutException in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method testTransactionWithCreateTxFailureDueToNoLeader.

@Test
public void testTransactionWithCreateTxFailureDueToNoLeader() throws Exception {
    followerDatastoreContextBuilder.frontendRequestTimeoutInSeconds(2);
    initDatastoresWithCars("testTransactionWithCreateTxFailureDueToNoLeader");
    // Do an initial read to get the primary shard info cached.
    final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
    readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
    // Shutdown the leader and try to create a new tx.
    TestKit.shutdownActorSystem(leaderSystem, true);
    Cluster.get(followerSystem).leave(MEMBER_1_ADDRESS);
    Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
    sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder.operationTimeoutInMillis(10).shardElectionTimeoutFactor(1).customRaftPolicyImplementation(null));
    final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
    rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
    try {
        followerTestKit.doCommit(rwTx.ready());
        fail("Exception expected");
    } catch (final ExecutionException e) {
        final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
        if (DistributedDataStore.class.equals(testParameter)) {
            assertTrue(msg, Throwables.getRootCause(e) instanceof NoShardLeaderException);
        } else {
            assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
        }
    }
}
Also used : RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AddressFromURIString(akka.actor.AddressFromURIString) ExecutionException(java.util.concurrent.ExecutionException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) Test(org.junit.Test)

Example 3 with RequestTimeoutException

use of org.opendaylight.controller.cluster.access.client.RequestTimeoutException in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method testTransactionWithShardLeaderNotResponding.

@Test
public void testTransactionWithShardLeaderNotResponding() throws Exception {
    followerDatastoreContextBuilder.frontendRequestTimeoutInSeconds(2);
    followerDatastoreContextBuilder.shardElectionTimeoutFactor(50);
    initDatastoresWithCars("testTransactionWithShardLeaderNotResponding");
    // Do an initial read to get the primary shard info cached.
    final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
    readTx.read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
    // Shutdown the leader and try to create a new tx.
    TestKit.shutdownActorSystem(leaderSystem, true);
    followerDatastoreContextBuilder.operationTimeoutInMillis(50).shardElectionTimeoutFactor(1);
    sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder);
    final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
    rwTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
    try {
        followerTestKit.doCommit(rwTx.ready());
        fail("Exception expected");
    } catch (final ExecutionException e) {
        final String msg = "Unexpected exception: " + Throwables.getStackTraceAsString(e.getCause());
        if (DistributedDataStore.class.equals(testParameter)) {
            assertTrue(msg, Throwables.getRootCause(e) instanceof NoShardLeaderException || e.getCause() instanceof ShardLeaderNotRespondingException);
        } else {
            assertTrue(msg, Throwables.getRootCause(e) instanceof RequestTimeoutException);
        }
    }
}
Also used : RequestTimeoutException(org.opendaylight.controller.cluster.access.client.RequestTimeoutException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) AddressFromURIString(akka.actor.AddressFromURIString) ExecutionException(java.util.concurrent.ExecutionException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) Test(org.junit.Test)

Aggregations

AddressFromURIString (akka.actor.AddressFromURIString)3 ExecutionException (java.util.concurrent.ExecutionException)3 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)3 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)3 Test (org.junit.Test)2 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)2 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)1 ShardLeaderNotRespondingException (org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException)1 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)1 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)1 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)1 TransactionChainClosedException (org.opendaylight.mdsal.common.api.TransactionChainClosedException)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)1 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)1