Search in sources :

Example 6 with AddShardReplica

use of org.opendaylight.controller.cluster.datastore.messages.AddShardReplica in project controller by opendaylight.

the class ShardManagerTest method testAddShardReplicaWithFindPrimaryTimeout.

@Test
public void testAddShardReplicaWithFindPrimaryTimeout() throws Exception {
    LOG.info("testAddShardReplicaWithFindPrimaryTimeout starting");
    datastoreContextBuilder.shardInitializationTimeout(100, TimeUnit.MILLISECONDS);
    new TestKit(getSystem()) {

        {
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("astronauts", Arrays.asList("member-2")).build());
            final ActorRef newReplicaShardManager = actorFactory.createActor(newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
            newReplicaShardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            MockClusterWrapper.sendMemberUp(newReplicaShardManager, "member-2", AddressFromURIString.parse("akka://non-existent@127.0.0.1:5").toString());
            newReplicaShardManager.tell(new AddShardReplica("astronauts"), getRef());
            Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
            assertEquals("Failure obtained", true, resp.cause() instanceof RuntimeException);
        }
    };
    LOG.info("testAddShardReplicaWithFindPrimaryTimeout 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) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) 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) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 7 with AddShardReplica

use of org.opendaylight.controller.cluster.datastore.messages.AddShardReplica 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)

Example 8 with AddShardReplica

use of org.opendaylight.controller.cluster.datastore.messages.AddShardReplica in project controller by opendaylight.

the class ShardManagerTest method testAddShardReplicaForNonExistentShardConfig.

@Test
public void testAddShardReplicaForNonExistentShardConfig() throws Exception {
    new TestKit(getSystem()) {

        {
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.tell(new AddShardReplica("model-inventory"), getRef());
            Status.Failure resp = expectMsgClass(duration("2 seconds"), Status.Failure.class);
            assertEquals("Failure obtained", true, resp.cause() instanceof IllegalArgumentException);
        }
    };
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) 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) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) Failure(akka.actor.Status.Failure) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 9 with AddShardReplica

use of org.opendaylight.controller.cluster.datastore.messages.AddShardReplica in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testEntityOwnershipShardBootstrapping.

/**
 * Tests bootstrapping the entity-ownership shard when there's no shards initially configured for local
 * member. The entity-ownership shard is initially created as inactive (ie remains a follower), requiring
 * an AddShardReplica request to join it to an existing leader.
 */
@Test
public void testEntityOwnershipShardBootstrapping() throws Exception {
    String name = "testEntityOwnershipShardBootstrapping";
    String moduleShardsConfig = MODULE_SHARDS_MEMBER_1_CONFIG;
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore follower1DistributedDataStore = follower1Node.configDataStore();
    follower1DistributedDataStore.waitTillReady();
    leaderNode.waitForMembersUp("member-2");
    follower1Node.waitForMembersUp("member-1");
    DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1DistributedDataStore);
    leaderEntityOwnershipService.registerListener(ENTITY_TYPE1, leaderMockListener);
    // Register a candidate for follower1 - should get queued since follower1 has no leader
    final DOMEntityOwnershipCandidateRegistration candidateReg = follower1EntityOwnershipService.registerCandidate(ENTITY1);
    Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
    verify(leaderMockListener, never()).ownershipChanged(ownershipChange(ENTITY1));
    // Add replica in follower1
    AddShardReplica addReplica = new AddShardReplica(ENTITY_OWNERSHIP_SHARD_NAME);
    follower1DistributedDataStore.getActorContext().getShardManager().tell(addReplica, follower1Node.kit().getRef());
    Object reply = follower1Node.kit().expectMsgAnyClassOf(follower1Node.kit().duration("5 sec"), Success.class, Failure.class);
    if (reply instanceof Failure) {
        throw new AssertionError("AddShardReplica failed", ((Failure) reply).cause());
    }
    // The queued candidate registration should proceed
    verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
    reset(leaderMockListener);
    candidateReg.close();
    verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, false));
    reset(leaderMockListener);
    // Restart follower1 and verify the entity ownership shard is re-instated by registering.
    Cluster.get(leaderNode.kit().getSystem()).down(Cluster.get(follower1Node.kit().getSystem()).selfAddress());
    follower1Node.cleanup();
    follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verify(leaderMockListener, timeout(20000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
    verifyRaftState(follower1Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME, raftState -> {
        assertNull("Custom RaftPolicy class name", raftState.getCustomRaftPolicyClassName());
        assertEquals("Peer count", 1, raftState.getPeerAddresses().keySet().size());
        assertThat("Peer Id", Iterables.<String>getLast(raftState.getPeerAddresses().keySet()), org.hamcrest.CoreMatchers.containsString("member-1"));
    });
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Aggregations

AddShardReplica (org.opendaylight.controller.cluster.datastore.messages.AddShardReplica)9 Test (org.junit.Test)8 Failure (akka.actor.Status.Failure)7 TestKit (akka.testkit.javadsl.TestKit)7 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)7 ActorRef (akka.actor.ActorRef)6 AddressFromURIString (akka.actor.AddressFromURIString)6 TestActorRef (akka.testkit.TestActorRef)6 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)6 Status (akka.actor.Status)4 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)4 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)4 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)4 AddServerReply (org.opendaylight.controller.cluster.raft.messages.AddServerReply)4 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)4 ServerChangeStatus (org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus)4 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)3 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)3 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)3 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)3