Search in sources :

Example 6 with Failure

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

the class RemoteTransactionContextTest method testLimiterOnOverflowFailure.

/**
 * OperationLimiter gives up throttling at some point -- {@link RemoteTransactionContext} needs to deal with that
 * case, too.
 */
@Test
public void testLimiterOnOverflowFailure() throws TimeoutException, InterruptedException {
    txContext.executeModification(DELETE);
    txContext.executeModification(DELETE);
    txContext.executeModification(DELETE);
    txContext.executeModification(DELETE);
    assertEquals(0, limiter.availablePermits());
    txContext.executeModification(DELETE);
    // Last acquire should have failed ...
    assertEquals(0, limiter.availablePermits());
    Future<Object> future = txContext.sendBatchedModifications();
    assertEquals(0, limiter.availablePermits());
    BatchedModifications msg = kit.expectMsgClass(BatchedModifications.class);
    // ... so we are sending 5 modifications ...
    assertEquals(5, 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);
            // ... but they account for only 4 permits.
            assertEquals(4, limiter.availablePermits());
        }
    });
    kit.expectNoMsg();
}
Also used : Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 7 with Failure

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

the class RaftActorTest method testGetSnapshot.

@Test
public void testGetSnapshot() throws Exception {
    TEST_LOG.info("testGetSnapshot starting");
    final TestKit kit = new TestKit(getSystem());
    String persistenceId = factory.generateActorId("test-actor-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
    long term = 3;
    long seqN = 1;
    InMemoryJournal.addEntry(persistenceId, seqN++, new UpdateElectionTerm(term, "member-1"));
    InMemoryJournal.addEntry(persistenceId, seqN++, new SimpleReplicatedLogEntry(0, term, new MockRaftActorContext.MockPayload("A")));
    InMemoryJournal.addEntry(persistenceId, seqN++, new SimpleReplicatedLogEntry(1, term, new MockRaftActorContext.MockPayload("B")));
    InMemoryJournal.addEntry(persistenceId, seqN++, new ApplyJournalEntries(1));
    InMemoryJournal.addEntry(persistenceId, seqN++, new SimpleReplicatedLogEntry(2, term, new MockRaftActorContext.MockPayload("C")));
    TestActorRef<MockRaftActor> raftActorRef = factory.createTestActor(MockRaftActor.props(persistenceId, ImmutableMap.<String, String>builder().put("member1", "address").build(), config).withDispatcher(Dispatchers.DefaultDispatcherId()), persistenceId);
    MockRaftActor mockRaftActor = raftActorRef.underlyingActor();
    mockRaftActor.waitForRecoveryComplete();
    mockRaftActor.snapshotCohortDelegate = mock(RaftActorSnapshotCohort.class);
    raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
    ArgumentCaptor<ActorRef> replyActor = ArgumentCaptor.forClass(ActorRef.class);
    verify(mockRaftActor.snapshotCohortDelegate, timeout(5000)).createSnapshot(replyActor.capture(), eq(java.util.Optional.empty()));
    byte[] stateSnapshot = new byte[] { 1, 2, 3 };
    replyActor.getValue().tell(new CaptureSnapshotReply(ByteState.of(stateSnapshot), java.util.Optional.empty()), ActorRef.noSender());
    GetSnapshotReply reply = kit.expectMsgClass(GetSnapshotReply.class);
    assertEquals("getId", persistenceId, reply.getId());
    Snapshot replySnapshot = reply.getSnapshot();
    assertEquals("getElectionTerm", term, replySnapshot.getElectionTerm());
    assertEquals("getElectionVotedFor", "member-1", replySnapshot.getElectionVotedFor());
    assertEquals("getLastAppliedIndex", 1L, replySnapshot.getLastAppliedIndex());
    assertEquals("getLastAppliedTerm", term, replySnapshot.getLastAppliedTerm());
    assertEquals("getLastIndex", 2L, replySnapshot.getLastIndex());
    assertEquals("getLastTerm", term, replySnapshot.getLastTerm());
    assertEquals("getState", ByteState.of(stateSnapshot), replySnapshot.getState());
    assertEquals("getUnAppliedEntries size", 1, replySnapshot.getUnAppliedEntries().size());
    assertEquals("UnApplied entry index ", 2L, replySnapshot.getUnAppliedEntries().get(0).getIndex());
    // Test with timeout
    mockRaftActor.getSnapshotMessageSupport().setSnapshotReplyActorTimeout(Duration.create(200, TimeUnit.MILLISECONDS));
    reset(mockRaftActor.snapshotCohortDelegate);
    raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
    Failure failure = kit.expectMsgClass(akka.actor.Status.Failure.class);
    assertEquals("Failure cause type", TimeoutException.class, failure.cause().getClass());
    mockRaftActor.getSnapshotMessageSupport().setSnapshotReplyActorTimeout(Duration.create(30, TimeUnit.SECONDS));
    // Test with persistence disabled.
    mockRaftActor.setPersistence(false);
    reset(mockRaftActor.snapshotCohortDelegate);
    raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
    reply = kit.expectMsgClass(GetSnapshotReply.class);
    verify(mockRaftActor.snapshotCohortDelegate, never()).createSnapshot(anyObject(), anyObject());
    assertEquals("getId", persistenceId, reply.getId());
    replySnapshot = reply.getSnapshot();
    assertEquals("getElectionTerm", term, replySnapshot.getElectionTerm());
    assertEquals("getElectionVotedFor", "member-1", replySnapshot.getElectionVotedFor());
    assertEquals("getLastAppliedIndex", -1L, replySnapshot.getLastAppliedIndex());
    assertEquals("getLastAppliedTerm", -1L, replySnapshot.getLastAppliedTerm());
    assertEquals("getLastIndex", -1L, replySnapshot.getLastIndex());
    assertEquals("getLastTerm", -1L, replySnapshot.getLastTerm());
    assertEquals("getState type", EmptyState.INSTANCE, replySnapshot.getState());
    assertEquals("getUnAppliedEntries size", 0, replySnapshot.getUnAppliedEntries().size());
    TEST_LOG.info("testGetSnapshot ending");
}
Also used : CaptureSnapshotReply(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) ByteString(com.google.protobuf.ByteString) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) UpdateElectionTerm(org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) Failure(akka.actor.Status.Failure) GetSnapshotReply(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply) Test(org.junit.Test)

Example 8 with Failure

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

the class ShardManagerGetSnapshotReplyActorTest method testGetSnapshotFailureReply.

@Test
public void testGetSnapshotFailureReply() {
    TestKit kit = new TestKit(getSystem());
    ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(Arrays.asList("shard1", "shard2"), "config", null, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.SECONDS)), "testGetSnapshotFailureReply");
    kit.watch(replyActor);
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(), Snapshot.create(ByteState.of(new byte[] { 1, 2, 3 }), Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
    replyActor.tell(new Failure(new RuntimeException()), ActorRef.noSender());
    kit.expectMsgClass(Failure.class);
    kit.expectTerminated(replyActor);
}
Also used : ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Failure(akka.actor.Status.Failure) GetSnapshotReply(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 9 with Failure

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

the class ShardManagerTest method testGetSnapshot.

@Test
public void testGetSnapshot() throws Exception {
    LOG.info("testGetSnapshot starting");
    TestKit kit = new TestKit(getSystem());
    MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("shard1", Arrays.asList("member-1")).put("shard2", Arrays.asList("member-1")).put("astronauts", Collections.<String>emptyList()).build());
    TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
    shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
    Failure failure = kit.expectMsgClass(Failure.class);
    assertEquals("Failure cause type", IllegalStateException.class, failure.cause().getClass());
    shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
    waitForShardInitialized(shardManager, "shard1", kit);
    waitForShardInitialized(shardManager, "shard2", kit);
    shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
    DatastoreSnapshot datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
    assertEquals("getType", shardMrgIDSuffix, datastoreSnapshot.getType());
    assertNull("Expected null ShardManagerSnapshot", datastoreSnapshot.getShardManagerSnapshot());
    Function<ShardSnapshot, String> shardNameTransformer = ShardSnapshot::getName;
    assertEquals("Shard names", Sets.newHashSet("shard1", "shard2"), Sets.newHashSet(Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer)));
    // Add a new replica
    TestKit mockShardLeaderKit = new TestKit(getSystem());
    TestShardManager shardManagerInstance = shardManager.underlyingActor();
    shardManagerInstance.setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
    shardManager.tell(new AddShardReplica("astronauts"), kit.getRef());
    mockShardLeaderKit.expectMsgClass(AddServer.class);
    mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.OK, ""));
    kit.expectMsgClass(Status.Success.class);
    waitForShardInitialized(shardManager, "astronauts", kit);
    // Send another GetSnapshot and verify
    shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
    datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
    assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer)));
    ShardManagerSnapshot snapshot = datastoreSnapshot.getShardManagerSnapshot();
    assertNotNull("Expected ShardManagerSnapshot", snapshot);
    assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(snapshot.getShardList()));
    LOG.info("testGetSnapshot ending");
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) Status(akka.actor.Status) ServerChangeStatus(org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) ShardSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot) ShardManagerSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) Failure(akka.actor.Status.Failure) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 10 with Failure

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

the class ShardManagerTest method testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader.

@Test
public void testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader() throws Exception {
    LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader starting");
    new TestKit(getSystem()) {

        {
            TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newPropsShardMgrWithMockShardActor(), shardMgrID);
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            String leaderId = "leader-member-shard-default-" + shardMrgIDSuffix;
            AddServerReply addServerReply = new AddServerReply(ServerChangeStatus.ALREADY_EXISTS, null);
            ActorRef leaderShardActor = shardManager.underlyingActor().getContext().actorOf(Props.create(MockRespondActor.class, AddServer.class, addServerReply), leaderId);
            MockClusterWrapper.sendMemberUp(shardManager, "leader-member", leaderShardActor.path().toString());
            String newReplicaId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(newReplicaId, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            shardManager.tell(new ShardLeaderStateChanged(newReplicaId, leaderId, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            MessageCollectorActor.expectFirstMatching(leaderShardActor, AddServer.class);
            Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            // Send message again to verify previous in progress state is
            // cleared
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            resp = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
            // Send message again with an AddServer timeout to verify the
            // pre-existing shard actor isn't terminated.
            shardManager.tell(newDatastoreContextFactory(datastoreContextBuilder.shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build()), getRef());
            leaderShardActor.tell(MockRespondActor.CLEAR_RESPONSE, ActorRef.noSender());
            shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
            expectMsgClass(duration("5 seconds"), Failure.class);
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
        }
    };
    LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

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