@Test
public void testRemoveShardLeaderReplica() throws Exception {

    String name = "testRemoveShardLeaderReplica";
    String moduleShardsConfig = "module-shards-member1-and-2-and-3.conf";
    final MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name)
            .moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(
                    DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1))
            .build();
    final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name)
            .moduleShardsConfig(moduleShardsConfig).build();
    final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name)
            .moduleShardsConfig(moduleShardsConfig).build();
    leaderNode1.configDataStore().waitTillReady();
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2", "member-3");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1", "member-3");
    verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-1", "member-2");
    replicaNode2.waitForMembersUp("member-1", "member-3");
    replicaNode3.waitForMembersUp("member-1", "member-2");
    // Invoke RPC service on leader member-1 to remove it's local shard
    ClusterAdminRpcService service1 = new ClusterAdminRpcService(leaderNode1.configDataStore(),
            leaderNode1.operDataStore(), null);
    RpcResult<RemoveShardReplicaOutput> rpcResult = service1.removeShardReplica(new RemoveShardReplicaInputBuilder()
            .setShardName("cars").setMemberName("member-1").setDataStoreType(DataStoreType.Config).build())
            .get(10, TimeUnit.SECONDS);
    verifySuccessfulRpcResult(rpcResult);
    verifyRaftState(replicaNode2.configDataStore(), "cars", raftState ->
            assertThat("Leader Id", raftState.getLeader(), anyOf(containsString("member-2"),
                    containsString("member-3"))));
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-3");
    verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-2");
    verifyNoShardPresent(leaderNode1.configDataStore(), "cars");
}