AHeise commented on a change in pull request #11754: 
[FLINK-17156][checkpointing] support cancellation of unaligned checkpoints
URL: https://github.com/apache/flink/pull/11754#discussion_r408798980
 
 

 ##########
 File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/io/CheckpointBarrierUnalignerCancellationTest.java
 ##########
 @@ -0,0 +1,136 @@
+/*
+ * 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.streaming.runtime.io;
+
+import org.apache.flink.runtime.checkpoint.CheckpointMetaData;
+import org.apache.flink.runtime.checkpoint.CheckpointMetrics;
+import org.apache.flink.runtime.checkpoint.CheckpointOptions;
+import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.event.RuntimeEvent;
+import org.apache.flink.runtime.io.network.api.CancelCheckpointMarker;
+import org.apache.flink.runtime.io.network.api.CheckpointBarrier;
+import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
+import org.apache.flink.runtime.operators.testutils.DummyEnvironment;
+import org.apache.flink.util.function.RunnableWithException;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import javax.annotation.Nullable;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Future;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * {@link CheckpointBarrierUnaligner} cancellation test.
+ */
+@RunWith(Parameterized.class)
+public class CheckpointBarrierUnalignerCancellationTest {
+       private final List<RuntimeEvent> events;
+       private final boolean shouldTriggerCheckpoint;
+       private final boolean shouldAbortCheckpoint;
+
+       public CheckpointBarrierUnalignerCancellationTest(boolean 
shouldTriggerCheckpoint, boolean shouldAbortCheckpoint, List<RuntimeEvent> 
events) {
+               this.events = events;
+               this.shouldTriggerCheckpoint = shouldTriggerCheckpoint;
+               this.shouldAbortCheckpoint = shouldAbortCheckpoint;
+       }
+
+       @Parameterized.Parameters(name = "should trigger: {0}, should abort 
{1}, events: {2}")
+       public static Object[][] parameters() {
+               return new Object[][]{
+                               new Object[]{false, true, 
Arrays.asList(cancel(20), checkpoint(10))},
+                               new Object[]{false, true, 
Arrays.asList(cancel(10), checkpoint(10))},
+                               new Object[]{true, true, 
Arrays.asList(cancel(10), checkpoint(20))},
+                               new Object[]{true, true, 
Arrays.asList(checkpoint(10), cancel(10))},
+                               new Object[]{true, true, 
Arrays.asList(checkpoint(10), cancel(20))},
+               };
+       }
+
+       @Test
+       public void test() throws Exception {
+               TestInvokable invokable = new TestInvokable();
+               CheckpointBarrierUnaligner unaligner = new 
CheckpointBarrierUnaligner(new int[]{1}, ChannelStateWriter.NO_OP, "test", 
invokable);
+
+               for (RuntimeEvent e : events) {
+                       if (e instanceof CancelCheckpointMarker) {
+                               
unaligner.processCancellationBarrier((CancelCheckpointMarker) e);
+                       } else if (e instanceof CheckpointBarrier) {
+                               unaligner.processBarrier((CheckpointBarrier) e, 
0, 0);
+                       } else {
+                               throw new IllegalArgumentException("unexpected 
event type: " + e);
+                       }
+               }
+
+               assertEquals(shouldAbortCheckpoint, 
invokable.checkpointAborted);
+               assertEquals(shouldTriggerCheckpoint, 
invokable.checkpointTriggered);
+       }
+
+       private static CheckpointBarrier checkpoint(int checkpointId) {
+               return new CheckpointBarrier(checkpointId, 1, 
CheckpointOptions.forCheckpointWithDefaultLocation());
+       }
+
+       private static CancelCheckpointMarker cancel(int checkpointId) {
+               return new CancelCheckpointMarker(checkpointId);
+       }
+
+       private static class TestInvokable extends AbstractInvokable {
+               TestInvokable() {
+                       super(new DummyEnvironment());
+               }
+
+               private boolean checkpointAborted;
+               private boolean checkpointTriggered;
+
+               @Override
+               public void invoke() {
+               }
+
+               @Override
+               public Future<Boolean> 
triggerCheckpointAsync(CheckpointMetaData checkpointMetaData, CheckpointOptions 
checkpointOptions, boolean advanceToEndOfEventTime) {
 
 Review comment:
   This one is not used anymore (going over #runInTaskThread).

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to