From 803e17a01fec50c7a692333739b6240159c08b38 Mon Sep 17 00:00:00 2001 From: Sam Barker Date: Thu, 28 Sep 2023 15:07:21 +1300 Subject: [PATCH 1/2] `findLastUsedClusterId` can return `null` by definition that doesn't fit the starting prefix... Signed-off-by: Sam Barker --- .../junit5ext/KafkaClusterExtension.java | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/junit5-extension/src/main/java/io/kroxylicious/testing/kafka/junit5ext/KafkaClusterExtension.java b/junit5-extension/src/main/java/io/kroxylicious/testing/kafka/junit5ext/KafkaClusterExtension.java index ea7cf725..151e4ff7 100644 --- a/junit5-extension/src/main/java/io/kroxylicious/testing/kafka/junit5ext/KafkaClusterExtension.java +++ b/junit5-extension/src/main/java/io/kroxylicious/testing/kafka/junit5ext/KafkaClusterExtension.java @@ -5,28 +5,10 @@ */ package io.kroxylicious.testing.kafka.junit5ext; -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Objects; -import java.util.ServiceLoader; -import java.util.UUID; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; - +import io.kroxylicious.testing.kafka.api.KafkaCluster; +import io.kroxylicious.testing.kafka.api.KafkaClusterConstraint; +import io.kroxylicious.testing.kafka.api.KafkaClusterProvisioningStrategy; +import io.kroxylicious.testing.kafka.api.KroxyliciousTestInfo; import org.apache.kafka.clients.admin.Admin; import org.apache.kafka.clients.consumer.Consumer; import org.apache.kafka.clients.consumer.KafkaConsumer; @@ -75,10 +57,27 @@ import org.junit.platform.commons.util.ExceptionUtils; import org.junit.platform.commons.util.ReflectionUtils; -import io.kroxylicious.testing.kafka.api.KafkaCluster; -import io.kroxylicious.testing.kafka.api.KafkaClusterConstraint; -import io.kroxylicious.testing.kafka.api.KafkaClusterProvisioningStrategy; -import io.kroxylicious.testing.kafka.api.KroxyliciousTestInfo; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.ServiceLoader; +import java.util.UUID; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static java.lang.System.Logger.Level.TRACE; import static org.junit.platform.commons.support.ReflectionSupport.findFields; @@ -756,7 +755,7 @@ private static KafkaCluster findClusterFromContext( } else { clusterName = findLastUsedClusterId(store, uuidsFrom(STARTING_PREFIX)); - if (!clusterName.equals(STARTING_PREFIX)) { + if (clusterName == null || !clusterName.equals(STARTING_PREFIX)) { throw new AmbiguousKafkaClusterException( "KafkaCluster to associate with " + description + " is ambiguous, " + "use @Name on the intended cluster and this element to disambiguate"); From 4237e8ca6d6114f7b1ad7cb7839f8295b00fb6e9 Mon Sep 17 00:00:00 2001 From: Sam Barker Date: Fri, 29 Sep 2023 09:33:06 +1300 Subject: [PATCH 2/2] update changelog for PR#186 Signed-off-by: Sam Barker --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cf2f859..e857a2fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,11 @@ Please enumerate all user-facing changes using format `: ## 1.0.0 + + ## 0.6.0 +* [#186](https://github.com/kroxylicious/kroxylicious-junit5-extension/pull/186): Replace a Null Pointer Exception with a more meaningful one when there is no existing cluster * [#182](https://github.com/kroxylicious/kroxylicious-junit5-extension/issues/182): Prevent possibility of loop when performing consistency test (workaround KAFKA-15507) * [#180](https://github.com/kroxylicious/kroxylicious-junit5-extension/pull/180): Update kafka version range in testVersions to include 3.5.1