tisonkun commented on code in PR #20725: URL: https://github.com/apache/flink/pull/20725#discussion_r965996490
########## flink-test-utils-parent/flink-connector-test-utils/src/main/java/org/apache/flink/connector/testframe/utils/UnorderedCollectIteratorAssert.java: ########## @@ -0,0 +1,140 @@ +/* + * 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.testframe.utils; + +import org.apache.flink.streaming.api.CheckpointingMode; + +import org.assertj.core.api.AbstractAssert; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import static java.util.stream.Collectors.toSet; +import static org.apache.flink.shaded.guava30.com.google.common.base.Predicates.not; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * This assertion used to compare records in the collect iterator to the target test data with + * different semantics (AT_LEAST_ONCE, EXACTLY_ONCE) for unordered messages. + * + * @param <T> The type of records in the test data and collect iterator + */ +public class UnorderedCollectIteratorAssert<T> + extends AbstractAssert<UnorderedCollectIteratorAssert<T>, Iterator<T>> { + + private final Iterator<T> collectorIterator; + private final Set<T> allRecords; + private final Set<T> matchedRecords; + + private Integer limit = null; + + protected UnorderedCollectIteratorAssert(Iterator<T> collectorIterator) { + super(collectorIterator, UnorderedCollectIteratorAssert.class); + this.collectorIterator = collectorIterator; + this.allRecords = new HashSet<>(); + this.matchedRecords = new HashSet<>(); + } + + public UnorderedCollectIteratorAssert<T> withNumRecordsLimit(int limit) { + this.limit = limit; + return this; + } + + public void matchesRecordsFromSource( + List<List<T>> recordsBySplitsFromSource, CheckpointingMode semantic) { + for (List<T> list : recordsBySplitsFromSource) { + for (T t : list) { + assertTrue(allRecords.add(t), "All the records should be unique."); + } + } + + if (limit != null && limit > allRecords.size()) { + throw new IllegalArgumentException( + "Limit validation size should be less than total number of records from source"); Review Comment: ```suggestion "Limit validation size should be less than or equal to total number of records from source"); ``` ? ########## flink-connectors/flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/source/reader/split/PulsarUnorderedPartitionSplitReader.java: ########## @@ -147,7 +136,11 @@ protected void afterCreatingConsumer(PulsarPartitionSplit split, Consumer<byte[] } } - public PulsarPartitionSplitState snapshotState(long checkpointId) { + public Optional<PulsarPartitionSplitState> snapshotState(long checkpointId) { Review Comment: It seems we don't use the parameter `checkpointId`? -- 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]
