Search in sources :

Example 11 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException 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 12 with NoShardLeaderException

use of org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException 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

NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)12 Test (org.junit.Test)7 AddressFromURIString (akka.actor.AddressFromURIString)5 ExecutionException (java.util.concurrent.ExecutionException)4 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)3 ShardLeaderNotRespondingException (org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException)3 DataStoreUnavailableException (org.opendaylight.mdsal.common.api.DataStoreUnavailableException)3 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)3 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 TestKit (akka.testkit.javadsl.TestKit)2 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)2 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)2 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)2 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)2 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)2 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)2 Status (akka.actor.Status)1 Failure (akka.actor.Status.Failure)1