ruanhang1993 commented on a change in pull request #18246:
URL: https://github.com/apache/flink/pull/18246#discussion_r776641725



##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/testutils/annotations/Topic.java
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kafka.testutils.annotations;
+
+import org.apache.flink.connector.kafka.testutils.extension.KafkaExtension;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * {@code @Topic} is used to create Kafka topics in tests extended with {@link 
KafkaExtension}.
+ *
+ * <p>This annotation can be used on both test classes and test methods, 
depending on the lifecycle
+ * of the topic.
+ *
+ * <p>If the lifecycle of topic is per-class (shared across test methods), 
please use this
+ * annotation on the test class:
+ *
+ * <pre>{@code
+ * @Topic(name = "shared-topic")
+ * @ExtendWith(KafkaTestExtension.class)

Review comment:
       @ExtendWith(KafkaTestExtension.class) -> @ Kafka 

##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/testutils/extension/KafkaContext.java
##########
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kafka.testutils.extension;
+
+import org.apache.kafka.clients.admin.AdminClient;
+import org.apache.kafka.clients.admin.AdminClientConfig;
+import org.apache.kafka.clients.admin.ListConsumerGroupOffsetsOptions;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.admin.RecordsToDelete;
+import org.apache.kafka.clients.admin.TopicDescription;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.clients.consumer.OffsetAndMetadata;
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.serialization.Deserializer;
+import org.apache.kafka.common.serialization.Serializer;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
+
+/**
+ * Context for interacting with {@link KafkaExtension}.
+ *
+ * <p>A typical usage of this context is to use as a parameter of test method 
with {@link
+ * KafkaExtension} registered in the test class.
+ *
+ * <pre>{@code
+ * @ExtendWith(KafkaTestExtension.class)

Review comment:
        @ExtendWith(KafkaTestExtension.class) -> @ Kafka

##########
File path: 
flink-end-to-end-tests/flink-end-to-end-tests-common-kafka/src/test/java/org/apache/flink/tests/util/kafka/KafkaSourceE2ECase.java
##########
@@ -62,10 +64,19 @@
     @SuppressWarnings("unused")
     @ExternalContextFactory
     KafkaSingleTopicExternalContext.Factory singleTopic =
-            new KafkaSingleTopicExternalContext.Factory(kafka.getContainer());
+            new KafkaSingleTopicExternalContext.Factory(() -> 
getBootstrapServer(kafka));
 
     @SuppressWarnings("unused")
     @ExternalContextFactory
     KafkaMultipleTopicExternalContext.Factory multipleTopic =
-            new 
KafkaMultipleTopicExternalContext.Factory(kafka.getContainer());
+            new KafkaMultipleTopicExternalContext.Factory(() -> 
getBootstrapServer(kafka));
+
+    private static String getBootstrapServer(
+            DefaultContainerizedExternalSystem<KafkaContainer> kafka) {
+        return kafka.getContainer().getBootstrapServers()
+                + ","
+                + kafka.getContainer().getNetworkAliases().stream()
+                        .map(host -> String.join(":", host, 
Integer.toString(9092)))

Review comment:
       Is there some fix constant to replace the `9092`?

##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/sink/KafkaTransactionLogITCase.java
##########
@@ -44,31 +44,27 @@
 import static 
org.apache.flink.connector.kafka.sink.KafkaTransactionLog.TransactionState.Ongoing;
 import static 
org.apache.flink.connector.kafka.sink.KafkaTransactionLog.TransactionState.PrepareAbort;
 import static 
org.apache.flink.connector.kafka.sink.KafkaTransactionLog.TransactionState.PrepareCommit;
-import static 
org.apache.flink.connector.kafka.sink.KafkaUtil.createKafkaContainer;
-import static org.apache.flink.util.DockerImageVersions.KAFKA;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsInAnyOrder;
 
 /** Tests for {@link KafkaTransactionLog} to retrieve abortable Kafka 
transactions. */
-public class KafkaTransactionLogITCase extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+class KafkaTransactionLogITCase extends TestLogger {

Review comment:
       remove `extends TestLogger`

##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/testutils/annotations/Topic.java
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kafka.testutils.annotations;
+
+import org.apache.flink.connector.kafka.testutils.extension.KafkaExtension;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * {@code @Topic} is used to create Kafka topics in tests extended with {@link 
KafkaExtension}.
+ *
+ * <p>This annotation can be used on both test classes and test methods, 
depending on the lifecycle
+ * of the topic.
+ *
+ * <p>If the lifecycle of topic is per-class (shared across test methods), 
please use this
+ * annotation on the test class:
+ *
+ * <pre>{@code
+ * @Topic(name = "shared-topic")
+ * @ExtendWith(KafkaTestExtension.class)
+ * public class KafkaTest {
+ *     ...
+ * }
+ * }</pre>
+ *
+ * <p>If the lifecycle of topic is per-method (only used in one test method), 
please use this
+ * annotation on the test method:
+ *
+ * <pre>{@code
+ * @ExtendWith(KafkaTestExtension.class)

Review comment:
       @ExtendWith(KafkaTestExtension.class) -> @ Kafka

##########
File path: 
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/sink/KafkaCommittableSerializerTest.java
##########
@@ -17,28 +17,29 @@
 
 package org.apache.flink.connector.kafka.sink;
 
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;

Review comment:
       Maybe need to use AssertJ.




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to