@Test
public void testNoLeader() throws Exception {
final int requestBatchSize = 10;
CreateTableOptions options = getBasicCreateTableOptions();
KuduTable table = client.createTable(
"testNoLeader-" + System.currentTimeMillis(),
basicSchema,
options);
List<LocatedTablet> tablets = asyncClient
.locateTable(table, null, null, requestBatchSize, DEFAULT_SLEEP)
.join(DEFAULT_SLEEP);
LocatedTablet tablet = tablets.get(0);
LocatedTablet.Replica leader = tablet.getLeaderReplica();
List<Master.TabletLocationsPB> tabletLocations = new ArrayList<>();
Master.TabletLocationsPB.Builder tabletPb = Master.TabletLocationsPB.newBuilder();
tabletPb.setPartition(ProtobufUtils.getFakePartitionPB());
tabletPb.setTabletId(ByteString.copyFrom(tablet.getTabletId()));
tabletPb.addReplicas(ProtobufUtils.getFakeTabletReplicaPB(
"master", leader.getRpcHost(), leader.getRpcPort(), Metadata.RaftPeerPB.Role.FOLLOWER));
tabletLocations.add(tabletPb.build());
try {
asyncClient.discoverTablets(table, new byte[0], requestBatchSize, tabletLocations, 1000);
fail("discoverTablets should throw an exception if there's no leader");
} catch (NoLeaderFoundException ex) {
}
}