/** * Elect the preferred broker of the given {@code partitions} as leader, or * elect the preferred broker for all partitions as leader if the argument to {@code partitions} is null. * * This is a convenience method for {@link #electPreferredLeaders(Collection, ElectPreferredLeadersOptions)} * with default options. * See the overload for more details. * * @param partitions The partitions for which the preferred leader should be elected. * @return The ElectPreferredLeadersResult. */ public ElectPreferredLeadersResult electPreferredLeaders(Collection<TopicPartition> partitions) { return electPreferredLeaders(partitions, new ElectPreferredLeadersOptions()); }
responseData.replicaElectionResults().add(r); env.kafkaClient().prepareResponse(new ElectPreferredLeadersResponse(responseData)); ElectPreferredLeadersResult results = env.adminClient().electPreferredLeaders(asList(topic1, topic2)); results.partitionResult(topic1).get(); TestUtils.assertFutureError(results.partitionResult(topic2), ClusterAuthorizationException.class); env.kafkaClient().prepareResponse(new ElectPreferredLeadersResponse(responseData)); results = env.adminClient().electPreferredLeaders(asList(topic1, topic2)); results.partitionResult(topic1).get(); results.partitionResult(topic2).get(); results = env.adminClient().electPreferredLeaders(asList(topic1, topic2), new ElectPreferredLeadersOptions().timeoutMs(100)); TestUtils.assertFutureError(results.partitionResult(topic1), TimeoutException.class); TestUtils.assertFutureError(results.partitionResult(topic2), TimeoutException.class);