jigar-bhati commented on code in PR #267:
URL:
https://github.com/apache/flink-connector-kafka/pull/267#discussion_r3684943956
##########
flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/table/KafkaConnectorOptionsUtil.java:
##########
@@ -115,6 +119,28 @@ public static void validateTableSinkOptions(ReadableConfig
tableOptions) {
validateSinkPartitioner(tableOptions);
}
+ static void validateAutoOffsetResetStrategy(Properties properties) {
+ String resetStrategy =
properties.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG);
+ if (resetStrategy == null) {
+ return;
+ }
+
+ boolean valid =
+ Arrays.stream(OffsetResetStrategy.values())
+ .anyMatch(strategy ->
strategy.name().equalsIgnoreCase(resetStrategy));
Review Comment:
Thanks for catching this; it was a real regression. I normalized valid table
reset values to lowercase during validation before they reach the Kafka
consumer, and added coverage for uppercase `EARLIEST`. This preserves the
existing `group-offsets` behavior and avoids a later TaskManager failure.
##########
flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/dynamic/source/DynamicKafkaSourceBuilderTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.dynamic.source;
+
+import org.apache.flink.connector.kafka.dynamic.metadata.KafkaMetadataService;
+import org.apache.flink.connector.kafka.dynamic.metadata.KafkaStream;
+import
org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
+import
org.apache.flink.connector.kafka.source.reader.deserializer.KafkaRecordDeserializationSchema;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link DynamicKafkaSourceBuilder}. */
+class DynamicKafkaSourceBuilderTest {
+
+ @Test
+ void testAutoOffsetResetIsNotMaterializedWhenAbsent() throws Exception {
+ assertThat(
+ extractProperties(baseBuilder().build())
+
.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
+ .isNull();
+ }
+
+ @Test
+ void testAutoOffsetResetUsesExplicitProperty() throws Exception {
+ assertThat(
+ extractProperties(
+ baseBuilder()
+ .setProperty(
+
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
+ "none")
+ .build())
+
.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
+ .isEqualTo("none");
+ }
+
+ @Test
+ void testAutoOffsetResetExplicitPropertyOverridesInitializerStrategy()
throws Exception {
+ assertThat(
+ extractProperties(
+ baseBuilder()
+
.setStartingOffsets(OffsetsInitializer.latest())
+ .setProperty(
+
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
+ "none")
+ .build())
+
.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
+ .isEqualTo("none");
+ }
+
+ private DynamicKafkaSourceBuilder<Integer> baseBuilder() {
+ return DynamicKafkaSource.<Integer>builder()
+ .setStreamIds(Collections.singleton("stream-1"))
+ .setKafkaMetadataService(NoOpKafkaMetadataService.INSTANCE)
+ .setDeserializer(
+
KafkaRecordDeserializationSchema.valueOnly(IntegerDeserializer.class));
+ }
+
+ private static Properties extractProperties(DynamicKafkaSource<?> source)
throws Exception {
+ Field field = DynamicKafkaSource.class.getDeclaredField("properties");
Review Comment:
Thanks, agreed. I replaced the reflection helper with a package-private
`@VisibleForTesting` accessor on `DynamicKafkaSource` and removed the
reflection import/helper from the test.
##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/KafkaPropertiesUtil.java:
##########
@@ -36,6 +39,25 @@ public static void copyProperties(@Nonnull Properties from,
@Nonnull Properties
}
}
+ /** Resolves an explicit global or cluster reset strategy before the
initializer default. */
Review Comment:
Thanks for pointing this out; that precedence was inconsistent with the rest
of the dynamic source. I changed it to explicit cluster property > explicit
global property > effective initializer strategy. An explicit global value
still wins over a cluster initializer, because the initializer remains only the
fallback when neither property is configured.
--
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]