kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maniku...@apache.org
Subject [kafka] branch trunk updated: MINOR: MockAdminClient should return InvalidReplicationFactorException if brokers.size < replicationFactor
Date Tue, 05 May 2020 08:31:56 GMT
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 <jeff.kim@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 <jeff.kim@confluent.io>
    
    Reviewers: Manikumar Reddy <manikumar.reddy@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) {


Mime
View raw message