chia7712 commented on code in PR #23699:
URL: https://github.com/apache/kafka/pull/23699#discussion_r4183076724


##########
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/ClusterInstance.java:
##########
@@ -329,26 +329,36 @@ default void waitTopicDeletion(String topic) throws 
InterruptedException {
         ), "Failed to hard-delete the delete directory");
     }
 
-    default void createTopic(String topicName, int partitions, short replicas) 
throws InterruptedException {
+    default void createTopic(String topicName, int partitions, short replicas) 
{
         createTopic(topicName, partitions, replicas, Map.of());
     }
 
-    default void createTopic(String topicName, int partitions, short replicas, 
Map<String, String> props) throws InterruptedException {
+    default void createTopic(String topicName, int partitions, short replicas, 
Map<String, String> props) {
         try (Admin admin = admin()) {
-            admin.createTopics(List.of(new NewTopic(topicName, partitions, 
replicas).configs(props)));
+            admin.createTopics(List.of(new NewTopic(topicName, partitions, 
replicas).configs(props))).all().get();
             waitTopicCreation(topicName, partitions);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new RuntimeException("Failed to create topic " + topicName, 
e);
+        } catch (ExecutionException e) {

Review Comment:
   We can throw the cause directly if it is a subtype of RuntimeException
   ```java
   } catch (ExecutionException e) {
       if (e.getCause() instanceof RuntimeException re) throw re;
       throw new RuntimeException("Failed to create topic " + topicName, 
e.getCause());
   }
   ```



##########
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/ClusterInstance.java:
##########
@@ -329,26 +329,36 @@ default void waitTopicDeletion(String topic) throws 
InterruptedException {
         ), "Failed to hard-delete the delete directory");
     }
 
-    default void createTopic(String topicName, int partitions, short replicas) 
throws InterruptedException {
+    default void createTopic(String topicName, int partitions, short replicas) 
{
         createTopic(topicName, partitions, replicas, Map.of());
     }
 
-    default void createTopic(String topicName, int partitions, short replicas, 
Map<String, String> props) throws InterruptedException {
+    default void createTopic(String topicName, int partitions, short replicas, 
Map<String, String> props) {
         try (Admin admin = admin()) {
-            admin.createTopics(List.of(new NewTopic(topicName, partitions, 
replicas).configs(props)));
+            admin.createTopics(List.of(new NewTopic(topicName, partitions, 
replicas).configs(props))).all().get();
             waitTopicCreation(topicName, partitions);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new RuntimeException("Failed to create topic " + topicName, 
e);
+        } catch (ExecutionException e) {
+            throw new RuntimeException("Failed to create topic " + topicName, 
e);
         }
     }
 
-    default void createTopicWithAssignment(String topicName, Map<Integer, 
List<Integer>> replicaAssignment) throws InterruptedException {
+    default void createTopicWithAssignment(String topicName, Map<Integer, 
List<Integer>> replicaAssignment) {
         createTopicWithAssignment(topicName, replicaAssignment, Map.of());
     }
 
-    default void createTopicWithAssignment(String topicName, Map<Integer, 
List<Integer>> replicaAssignment, Map<String, String> props) throws 
InterruptedException {
+    default void createTopicWithAssignment(String topicName, Map<Integer, 
List<Integer>> replicaAssignment, Map<String, String> props) {
         try (Admin admin = admin()) {
-            admin.createTopics(List.of(new NewTopic(topicName, 
replicaAssignment).configs(props)));
+            admin.createTopics(List.of(new NewTopic(topicName, 
replicaAssignment).configs(props))).all().get();
             int partitions = replicaAssignment.size();
             waitTopicCreation(topicName, partitions);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new RuntimeException("Failed to create topic " + topicName, 
e);
+        } catch (ExecutionException e) {

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to