xiaochen-zhou commented on code in PR #9597:
URL: https://github.com/apache/seatunnel/pull/9597#discussion_r2220899785


##########
seatunnel-connectors-v2/connector-kafka/src/test/java/org/apache/seatunnel/connectors/seatunnel/kafka/source/KafkaTransactionalStoppingConditionTest.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.kafka.source;
+
+import org.apache.seatunnel.api.source.SourceReader;
+import org.apache.seatunnel.connectors.seatunnel.kafka.config.StartMode;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.MockConsumer;
+import org.apache.kafka.clients.consumer.OffsetResetStrategy;
+import org.apache.kafka.common.TopicPartition;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
+
+/** Test class demonstrating the fix for transactional message stopping 
condition. */
+public class KafkaTransactionalStoppingConditionTest {
+
+    private static final String TOPIC = "test-topic";
+    private static final int PARTITION = 0;
+    private static final TopicPartition TOPIC_PARTITION = new 
TopicPartition(TOPIC, PARTITION);
+
+    private MockConsumer<byte[], byte[]> mockConsumer;
+
+    @Mock private SourceReader.Context readerContext;
+
+    @Mock private KafkaSourceConfig kafkaSourceConfig;
+
+    @BeforeEach
+    void setUp() {
+        MockitoAnnotations.openMocks(this);
+
+        mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
+        // Setup mock config
+        Properties properties = new Properties();
+        properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "test-group");
+        properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, 
"localhost:9092");
+
+        when(kafkaSourceConfig.getProperties()).thenReturn(properties);
+        when(kafkaSourceConfig.getConsumerGroup()).thenReturn("test-group");
+        when(kafkaSourceConfig.getBootstrap()).thenReturn("localhost:9092");
+        when(kafkaSourceConfig.isCommitOnCheckpoint()).thenReturn(false);
+        when(kafkaSourceConfig.getPollTimeout()).thenReturn(1000L);
+
+        Map<String, ConsumerMetadata> mapMetadata = new HashMap<>();
+        ConsumerMetadata metadata = new ConsumerMetadata();
+        metadata.setTopic(TOPIC);
+        metadata.setStartMode(StartMode.EARLIEST);
+        mapMetadata.put(TOPIC, metadata);
+    }
+
+    /**
+     * Test the core issue: control messages can cause infinite blocking when 
using last record
+     * offset as stopping condition.
+     *
+     * <p>Note: MockConsumer cannot directly simulate control messages since 
they are invisible to
+     * consumers. Instead, we simulate the EFFECT of control messages: 
consumer position advancing
+     * beyond the last visible record.
+     */
+    @Test
+    @DisplayName("Test stopping condition with control messages - demonstrates 
the fix")
+    void testStoppingConditionWithControlMessages() {

Review Comment:
   > This test only verifies the consumer behavior of Kafka, but does not 
ensure that our connector behaves normally through the test case. Please modify 
the test case to verify that KafkaPartitionSplitReader::fetch will end normally.
   
   OK.



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