Search in sources :

Example 1 with Failure

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

the class ShardManagerGetSnapshotReplyActor method onReceive.

@Override
public void onReceive(final Object message) {
    if (message instanceof GetSnapshotReply) {
        onGetSnapshotReply((GetSnapshotReply) message);
    } else if (message instanceof Failure) {
        LOG.debug("{}: Received {}", params.id, message);
        params.replyToActor.tell(message, getSelf());
        getSelf().tell(PoisonPill.getInstance(), getSelf());
    } else if (message instanceof ReceiveTimeout) {
        String msg = String.format("Timed out after %s ms while waiting for snapshot replies from %d shard(s). %d shard(s) %s " + "did not respond.", params.receiveTimeout.toMillis(), params.shardNames.size(), remainingShardNames.size(), remainingShardNames);
        LOG.warn("{}: {}", params.id, msg);
        params.replyToActor.tell(new Failure(new TimeoutException(msg)), getSelf());
        getSelf().tell(PoisonPill.getInstance(), getSelf());
    }
}
Also used : ReceiveTimeout(akka.actor.ReceiveTimeout) Failure(akka.actor.Status.Failure) GetSnapshotReply(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with Failure

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

the class ShardTest method testBatchedModificationsReadyWithIncorrectTotalMessageCount.

@Test(expected = IllegalStateException.class)
public void testBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsReadyWithIncorrectTotalMessageCount");
            waitUntilLeader(shard);
            final TransactionIdentifier transactionID = nextTransactionId();
            final BatchedModifications batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            shard.tell(batched, getRef());
            final Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            if (failure != null) {
                Throwables.propagateIfPossible(failure.cause(), Exception.class);
                throw new RuntimeException(failure.cause());
            }
        }
    };
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 3 with Failure

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

the class ShardTest method testAbortAfterReady.

@Test
public void testAbortAfterReady() throws Exception {
    dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testAbortAfterReady");
            waitUntilLeader(shard);
            final FiniteDuration duration = duration("5 seconds");
            // Ready a tx.
            final TransactionIdentifier transactionID1 = nextTransactionId();
            shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // Send the AbortTransaction message.
            shard.tell(new AbortTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, AbortTransactionReply.class);
            assertEquals("getPendingTxCommitQueueSize", 0, shard.underlyingActor().getPendingTxCommitQueueSize());
            // Now send CanCommitTransaction - should fail.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            final Throwable failure = expectMsgClass(duration, akka.actor.Status.Failure.class).cause();
            assertTrue("Failure type", failure instanceof IllegalStateException);
            // Ready and CanCommit another and verify success.
            final TransactionIdentifier transactionID2 = nextTransactionId();
            shard.tell(newBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true, false, 1), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            shard.tell(new CanCommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CanCommitTransactionReply.class);
        }
    };
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) AbortTransaction(org.opendaylight.controller.cluster.datastore.messages.AbortTransaction) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 4 with Failure

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

the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount.

@Test(expected = IllegalStateException.class)
public void testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
    new TestKit(getSystem()) {

        {
            final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount");
            TestKit watcher = new TestKit(getSystem());
            watcher.watch(transaction);
            BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            transaction.tell(batched, getRef());
            Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
            if (failure != null) {
                Throwables.throwIfInstanceOf(failure.cause(), Exception.class);
                Throwables.throwIfUnchecked(failure.cause());
                throw new RuntimeException(failure.cause());
            }
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 5 with Failure

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

the class RemoteTransactionContextTest method sendReply.

private void sendReply(final Object message) {
    final ActorRef askActor = kit.getLastSender();
    kit.watch(askActor);
    kit.reply(new Failure(new IllegalStateException()));
    kit.expectTerminated(askActor);
}
Also used : ActorRef(akka.actor.ActorRef) Failure(akka.actor.Status.Failure)

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