Search in sources :

Example 31 with Failure

use of akka.actor.Status.Failure in project controller by opendaylight.

the class RemoteTransactionContextTest method testLimiterOnFailure.

/**
 * OperationLimiter should be correctly released when a failure, like AskTimeoutException occurs. Future reads
 * need to complete immediately with the failure and modifications should not be throttled and thrown away
 * immediately.
 */
@Test
public void testLimiterOnFailure() throws TimeoutException, InterruptedException {
    txContext.executeModification(DELETE);
    txContext.executeModification(DELETE);
    assertEquals(2, limiter.availablePermits());
    Future<Object> future = txContext.sendBatchedModifications();
    assertEquals(2, limiter.availablePermits());
    BatchedModifications msg = kit.expectMsgClass(BatchedModifications.class);
    assertEquals(2, msg.getModifications().size());
    assertEquals(1, msg.getTotalMessagesSent());
    sendReply(new Failure(new NullPointerException()));
    assertFuture(future, new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object success) {
            assertTrue(failure instanceof NullPointerException);
            assertEquals(4, limiter.availablePermits());
            // The transaction has failed, no throttling should occur
            txContext.executeModification(DELETE);
            assertEquals(4, limiter.availablePermits());
            // Executing a read should result in immediate failure
            final SettableFuture<Boolean> readFuture = SettableFuture.create();
            txContext.executeRead(new DataExists(), readFuture);
            assertTrue(readFuture.isDone());
            try {
                readFuture.get();
                fail("Read future did not fail");
            } catch (ExecutionException | InterruptedException e) {
                assertTrue(e.getCause() instanceof NullPointerException);
            }
        }
    });
    future = txContext.directCommit();
    msg = kit.expectMsgClass(BatchedModifications.class);
    // Modification should have been thrown away by the dropped transmit induced by executeRead()
    assertEquals(0, msg.getModifications().size());
    assertTrue(msg.isDoCommitOnReady());
    assertTrue(msg.isReady());
    assertEquals(2, msg.getTotalMessagesSent());
    sendReply(new Failure(new IllegalStateException()));
    assertFuture(future, new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object success) {
            assertTrue(failure instanceof IllegalStateException);
        }
    });
    kit.expectNoMsg();
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Aggregations

Failure (akka.actor.Status.Failure)31 Test (org.junit.Test)21 ActorRef (akka.actor.ActorRef)15 TestKit (akka.testkit.javadsl.TestKit)14 TestActorRef (akka.testkit.TestActorRef)10 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)7 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 AddressFromURIString (akka.actor.AddressFromURIString)6 Status (akka.actor.Status)6 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)6 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)5 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)5 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)4 ServerChangeStatus (org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus)4 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)3 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)3 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)3 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)3