|
53 | 53 | import org.apache.flink.testutils.junit.SharedReference; |
54 | 54 | import org.apache.flink.util.TestLogger; |
55 | 55 |
|
| 56 | +import org.apache.flink.shaded.guava33.com.google.common.collect.Sets; |
| 57 | + |
56 | 58 | import org.junit.ClassRule; |
57 | 59 | import org.junit.Rule; |
58 | 60 | import org.junit.Test; |
|
62 | 64 |
|
63 | 65 | import javax.annotation.Nonnull; |
64 | 66 |
|
65 | | -import java.util.Iterator; |
| 67 | +import java.util.Set; |
66 | 68 | import java.util.concurrent.ExecutionException; |
67 | 69 | import java.util.concurrent.atomic.AtomicLong; |
68 | 70 |
|
@@ -376,18 +378,19 @@ public String map(String value) throws Exception { |
376 | 378 | @Override |
377 | 379 | public void initializeState(FunctionInitializationContext context) throws Exception { |
378 | 380 | super.initializeState(context); |
379 | | - Iterator<Integer> iterator = valueState.get().iterator(); |
| 381 | + Set<Integer> restoredIds = Sets.newHashSet(valueState.get().iterator()); |
380 | 382 |
|
381 | 383 | // id less than 0 represents operators which weren't presented in snapshot. |
382 | 384 | 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."); |
385 | 387 | 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."); |
388 | 393 | } |
389 | | - |
390 | | - checkState(!iterator.hasNext(), "Value state should be empty."); |
391 | 394 | } |
392 | 395 | } |
393 | 396 |
|
|
0 commit comments