mumrah commented on code in PR #17019:
URL: https://github.com/apache/kafka/pull/17019#discussion_r1736185782


##########
core/src/test/java/kafka/test/junit/ClusterTestExtensions.java:
##########
@@ -163,82 +174,135 @@ private Store getStore(ExtensionContext context) {
         return context.getStore(Namespace.create(context.getUniqueId()));
     }
 
+    private int getTestRepeatCount() {
+        int count;
+        try {
+            String repeatCount = 
System.getProperty(CLUSTER_TEST_REPEAT_SYSTEM_PROP, "1");
+            count = Integer.parseInt(repeatCount);
+        } catch (NumberFormatException e) {
+            count = 1;
+        }
+        return count;
+    }
+
     List<TestTemplateInvocationContext> 
processClusterTemplate(ExtensionContext context, ClusterTemplate annot) {
         if (annot.value().trim().isEmpty()) {
             throw new IllegalStateException("ClusterTemplate value can't be 
empty string.");
         }
 
         String baseDisplayName = context.getRequiredTestMethod().getName();
-        List<TestTemplateInvocationContext> contexts = 
generateClusterConfigurations(context, annot.value())
-                .stream().flatMap(config -> config.clusterTypes().stream()
-                        .map(type -> type.invocationContexts(baseDisplayName, 
config))).collect(Collectors.toList());
+        int repeatCount = getTestRepeatCount();
+        List<TestTemplateInvocationContext> contexts = 
generateClusterConfigurations(repeatCount, context, annot.value())
+            .stream()
+            .flatMap(config -> config.clusterTypes().stream().map(type -> 
type.invocationContexts(baseDisplayName, config)))
+            .collect(Collectors.toList());
 
         if (contexts.isEmpty()) {
             throw new IllegalStateException("ClusterConfig generator method 
should provide at least one config");
         }
 
-        return contexts;
+        return repeatTestContexts(contexts);
     }
 
     @SuppressWarnings("unchecked")
-    private List<ClusterConfig> generateClusterConfigurations(ExtensionContext 
context, String generateClustersMethods) {
+    private List<ClusterConfig> generateClusterConfigurations(
+        int repeatCount,
+        ExtensionContext context,
+        String generateClustersMethods
+    ) {
         Object testInstance = context.getTestInstance().orElse(null);
         Method method = 
ReflectionUtils.getRequiredMethod(context.getRequiredTestClass(), 
generateClustersMethods);
-        return (List<ClusterConfig>) ReflectionUtils.invokeMethod(method, 
testInstance);
+        List<ClusterConfig> configs = new ArrayList<>();
+        for (int i = 0; i < repeatCount; i++) {
+            configs.addAll((List<ClusterConfig>) 
ReflectionUtils.invokeMethod(method, testInstance));
+        }
+        return configs;
     }
 
-    private List<TestTemplateInvocationContext> 
processClusterTests(ExtensionContext context, ClusterTests annots, 
ClusterTestDefaults defaults) {
-
-        List<TestTemplateInvocationContext> ret = Arrays.stream(annots.value())
-                .flatMap(annot -> processClusterTestInternal(context, annot, 
defaults).stream()).collect(Collectors.toList());
+    private List<TestTemplateInvocationContext> processClusterTests(
+        ExtensionContext context,
+        ClusterTest[] clusterTests,
+        ClusterTestDefaults defaults
+    ) {
+        int repeatCount = getTestRepeatCount();
+        List<TestTemplateInvocationContext> ret = 
repeatedClusterTests(repeatCount, clusterTests)

Review Comment:
   nice 👍 



-- 
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