You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ma...@apache.org on 2020/05/05 08:31:56 UTC
[kafka] branch trunk updated: MINOR: MockAdminClient should return
InvalidReplicationFactorException if brokers.size < replicationFactor
This is an automated email from the ASF dual-hosted git repository.
manikumar pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new dd3ea21 MINOR: MockAdminClient should return InvalidReplicationFactorException if brokers.size < replicationFactor
dd3ea21 is described below
commit dd3ea214303595020e5c6c54c7ab93cfc53d0262
Author: jeff kim <je...@confluent.io>
AuthorDate: Tue May 5 14:01:04 2020 +0530
MINOR: MockAdminClient should return InvalidReplicationFactorException if brokers.size < replicationFactor
* `MockAdminClient` should behave the same way as `Admin` for `createTopics()`
* Changed from throwing an `IllegalArgumentException` to `InvalidReplicationFactorException` when `brokers.size() < replicationFactor`
Author: jeff kim <je...@confluent.io>
Reviewers: Manikumar Reddy <ma...@gmail.com>
Closes #8617 from jeffkbkim/MockAdminClient-InvalidReplicationFactorException
---
.../java/org/apache/kafka/clients/admin/MockAdminClient.java | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/clients/src/test/java/org/apache/kafka/clients/admin/MockAdminClient.java b/clients/src/test/java/org/apache/kafka/clients/admin/MockAdminClient.java
index 8ef8129..23a5142 100644
--- a/clients/src/test/java/org/apache/kafka/clients/admin/MockAdminClient.java
+++ b/clients/src/test/java/org/apache/kafka/clients/admin/MockAdminClient.java
@@ -31,6 +31,7 @@ import org.apache.kafka.common.acl.AclBindingFilter;
import org.apache.kafka.common.acl.AclOperation;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.errors.InvalidRequestException;
+import org.apache.kafka.common.errors.InvalidReplicationFactorException;
import org.apache.kafka.common.errors.KafkaStorageException;
import org.apache.kafka.common.errors.ReplicaNotAvailableException;
import org.apache.kafka.common.errors.TimeoutException;
@@ -239,10 +240,12 @@ public class MockAdminClient extends AdminClient {
continue;
}
int replicationFactor = newTopic.replicationFactor();
- if (replicationFactor > brokers.size())
- throw new IllegalArgumentException(
- String.format("NewTopic %s cannot have a replication factor of %d that is larger than the number of brokers %s",
- newTopic, replicationFactor, brokers));
+ if (replicationFactor > brokers.size()) {
+ future.completeExceptionally(new InvalidReplicationFactorException(
+ String.format("Replication factor: %d is larger than brokers: %d", newTopic.replicationFactor(), brokers.size())));
+ createTopicResult.put(topicName, future);
+ continue;
+ }
List<Node> replicas = new ArrayList<>(replicationFactor);
for (int i = 0; i < replicationFactor; ++i) {