Skip to content

Commit 96bba6e

Browse files
committed
[hotfix][tests] De-duplicate operator ids in RestoreUpgradedJobITCase
With more frequent checkpoints, ids can be duplicated in RestoreUpgradedJobITCase. This change adds a sipmle deduplication before the assertion.
1 parent d941764 commit 96bba6e

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

flink-tests/src/test/java/org/apache/flink/test/checkpointing/RestoreUpgradedJobITCase.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import org.apache.flink.testutils.junit.SharedReference;
5454
import org.apache.flink.util.TestLogger;
5555

56+
import org.apache.flink.shaded.guava33.com.google.common.collect.Sets;
57+
5658
import org.junit.ClassRule;
5759
import org.junit.Rule;
5860
import org.junit.Test;
@@ -62,7 +64,7 @@
6264

6365
import javax.annotation.Nonnull;
6466

65-
import java.util.Iterator;
67+
import java.util.Set;
6668
import java.util.concurrent.ExecutionException;
6769
import java.util.concurrent.atomic.AtomicLong;
6870

@@ -376,18 +378,19 @@ public String map(String value) throws Exception {
376378
@Override
377379
public void initializeState(FunctionInitializationContext context) throws Exception {
378380
super.initializeState(context);
379-
Iterator<Integer> iterator = valueState.get().iterator();
381+
Set<Integer> restoredIds = Sets.newHashSet(valueState.get().iterator());
380382

381383
// id less than 0 represents operators which weren't presented in snapshot.
382384
if (id > 0) {
383-
checkState(iterator.hasNext(), "Value state can not be empty.");
384-
Integer state = iterator.next();
385+
// use set to eliminate potential duplicates emitted by multiple checkpoints
386+
checkState(restoredIds.size() == 1, "Value state can not be empty.");
385387
checkState(
386-
id == state,
387-
String.format("Value state(%s) should be equal to id(%s).", state, id));
388+
id == restoredIds.iterator().next(),
389+
String.format(
390+
"Value state(%s) should be equal to id(%s).", restoredIds, id));
391+
} else {
392+
checkState(restoredIds.isEmpty(), "Value state should be empty.");
388393
}
389-
390-
checkState(!iterator.hasNext(), "Value state should be empty.");
391394
}
392395
}
393396

0 commit comments

Comments
 (0)