mas-chen commented on code in PR #97:
URL:
https://github.com/apache/flink-connector-kafka/pull/97#discussion_r1581993642
##########
flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/dynamic/source/enumerator/DynamicKafkaSourceEnumeratorTest.java:
##########
@@ -464,6 +466,87 @@ public void testSnapshotState() throws Throwable {
}
}
+ @Test
+ public void testEnumeratorStateDoesNotContainStaleTopicPartitions() throws
Throwable {
+ final String topic2 = TOPIC + "_2";
+
+ DynamicKafkaSourceTestHelper.createTopic(topic2,
NUM_SPLITS_PER_CLUSTER, 1);
+ DynamicKafkaSourceTestHelper.produceToKafka(
+ topic2, NUM_SPLITS_PER_CLUSTER, NUM_RECORDS_PER_SPLIT);
+
+ final Set<KafkaStream> initialStreams =
+ Collections.singleton(
+ new KafkaStream(
+ TOPIC,
+
DynamicKafkaSourceTestHelper.getClusterMetadataMap(
+ 0, TOPIC, topic2)));
+
+ final DynamicKafkaSourceEnumState initialState;
+
+ try (KafkaMetadataService metadataService = new
MockKafkaMetadataService(initialStreams);
+ MockSplitEnumeratorContext<DynamicKafkaSourceSplit> context =
+ new MockSplitEnumeratorContext<>(NUM_SUBTASKS);
+ DynamicKafkaSourceEnumerator enumerator =
+ createEnumerator(context, metadataService)) {
+ enumerator.start();
+
+ mockRegisterReaderAndSendReaderStartupEvent(context, enumerator,
0);
+ mockRegisterReaderAndSendReaderStartupEvent(context, enumerator,
1);
+ runAllOneTimeCallables(context);
+
+ initialState = enumerator.snapshotState(-1);
+
+ assertThat(getFilteredTopicPartitions(initialState, TOPIC,
AssignmentStatus.ASSIGNED))
+ .hasSize(2);
+ assertThat(
+ getFilteredTopicPartitions(
+ initialState, TOPIC,
AssignmentStatus.UNASSIGNED_INITIAL))
+ .hasSize(1);
+ assertThat(getFilteredTopicPartitions(initialState, topic2,
AssignmentStatus.ASSIGNED))
+ .hasSize(2);
+ assertThat(
+ getFilteredTopicPartitions(
+ initialState, topic2,
AssignmentStatus.UNASSIGNED_INITIAL))
+ .hasSize(1);
+ }
+
+ // init enumerator with checkpoint state and removed topic2
+
+ final Set<KafkaStream> restartStreams =
+ Collections.singleton(
+ new KafkaStream(
+ TOPIC,
+
DynamicKafkaSourceTestHelper.getClusterMetadataMap(0, TOPIC)));
+
+ try (KafkaMetadataService metadataService = new
MockKafkaMetadataService(restartStreams);
Review Comment:
Instead of creating another `MockKafkaMetadataService` and
`DynamicKafkaSourceEnumerator`, can we mutate the original metadata service
with the metadata pertaining to `TOPIC` via the method `setKafkaStreams(...)`?
--
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]