Search in sources :

Example 16 with AddServerReply

use of org.opendaylight.controller.cluster.raft.messages.AddServerReply in project controller by opendaylight.

the class ShardManagerTest method testAddShardReplicaWithAddServerReplyFailure.

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

        {
            TestKit mockShardLeaderKit = new TestKit(getSystem());
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("astronauts", Arrays.asList("member-2")).build());
            ActorRef mockNewReplicaShardActor = newMockShardActor(getSystem(), "astronauts", "member-1");
            final TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newTestShardMgrBuilder(mockConfig).shardActor(mockNewReplicaShardActor).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
            shardManager.underlyingActor().setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            TestKit terminateWatcher = new TestKit(getSystem());
            terminateWatcher.watch(mockNewReplicaShardActor);
            shardManager.tell(new AddShardReplica("astronauts"), getRef());
            AddServer addServerMsg = mockShardLeaderKit.expectMsgClass(AddServer.class);
            assertEquals("AddServer serverId", "member-1-shard-astronauts-" + shardMrgIDSuffix, addServerMsg.getNewServerId());
            mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.TIMEOUT, null));
            Failure failure = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", TimeoutException.class, failure.cause().getClass());
            shardManager.tell(new FindLocalShard("astronauts", false), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
            terminateWatcher.expectTerminated(mockNewReplicaShardActor);
            shardManager.tell(new AddShardReplica("astronauts"), getRef());
            mockShardLeaderKit.expectMsgClass(AddServer.class);
            mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.NO_LEADER, null));
            failure = expectMsgClass(duration("5 seconds"), Failure.class);
            assertEquals("Failure cause", NoShardLeaderException.class, failure.cause().getClass());
        }
    };
    LOG.info("testAddShardReplicaWithAddServerReplyFailure ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AddServerReply(org.opendaylight.controller.cluster.raft.messages.AddServerReply) Failure(akka.actor.Status.Failure) AddServer(org.opendaylight.controller.cluster.raft.messages.AddServer) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

Test (org.junit.Test)16 AddServerReply (org.opendaylight.controller.cluster.raft.messages.AddServerReply)16 AddServer (org.opendaylight.controller.cluster.raft.messages.AddServer)15 ActorRef (akka.actor.ActorRef)11 TestActorRef (akka.testkit.TestActorRef)11 TestKit (akka.testkit.javadsl.TestKit)5 Follower (org.opendaylight.controller.cluster.raft.behaviors.Follower)5 AddressFromURIString (akka.actor.AddressFromURIString)4 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)4 AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)4 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)4 Failure (akka.actor.Status.Failure)3 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)3 InitiateCaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot)3 Status (akka.actor.Status)2 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)2 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)2 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)2 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)2 ShardManagerSnapshot (org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot)2