IgnasD commented on code in PR #97: URL: https://github.com/apache/flink-connector-kafka/pull/97#discussion_r1582739755
########## 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: 👍 Reused `DynamicKafkaSourceEnumerator` by mutating `MockKafkaMetadataService` -- 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