StefanRRichter commented on a change in pull request #8322: [FLINK-12364] Introduce a CheckpointFailureManager to centralized manage checkpoint failure URL: https://github.com/apache/flink/pull/8322#discussion_r283725130
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/CheckpointFailureManagerTest.java ########## @@ -0,0 +1,110 @@ +/* + * 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.runtime.checkpoint; + +import org.apache.flink.util.TestLogger; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * Tests for the checkpoint failure manager. + */ +public class CheckpointFailureManagerTest extends TestLogger { + + @Test + public void testContinuousFailure() { + TestHandlerCallback callback = new TestHandlerCallback(); + CheckpointFailureManager failureManager = new CheckpointFailureManager(2, callback); + + + failureManager.handleCheckpointException(new CheckpointException(CheckpointFailureReason.EXCEPTION), -1); + assertTrue(!callback.invoked()); + + failureManager.handleCheckpointException( + new CheckpointException(CheckpointFailureReason.CHECKPOINT_DECLINED), -1); + assertTrue(!callback.invoked()); + + //ignore this + failureManager.handleCheckpointException( + new CheckpointException(CheckpointFailureReason.JOB_FAILOVER_REGION), -1); + assertTrue(!callback.invoked()); + + failureManager.handleCheckpointException( + new CheckpointException(CheckpointFailureReason.CHECKPOINT_EXPIRED), -1); + assertTrue(callback.invoked()); + } + + @Test + public void testBreakContinuousFailure() { + TestHandlerCallback callback = new TestHandlerCallback(); + CheckpointFailureManager failureManager = new CheckpointFailureManager(2, callback); + + failureManager.handleCheckpointException(new CheckpointException(CheckpointFailureReason.EXCEPTION), -1); + assertTrue(!callback.invoked()); + + failureManager.handleCheckpointException( + new CheckpointException(CheckpointFailureReason.CHECKPOINT_DECLINED), -1); + assertTrue(!callback.invoked()); + + //ignore this + failureManager.handleCheckpointException( + new CheckpointException(CheckpointFailureReason.JOB_FAILOVER_REGION), -1); + assertTrue(!callback.invoked()); + + //reset + failureManager.handleCheckpointSuccess(-1); + + failureManager.handleCheckpointException( + new CheckpointException(CheckpointFailureReason.CHECKPOINT_EXPIRED), -1); + assertTrue(!callback.invoked()); + } + + @Test + public void testTotalCountValue() { + CheckpointFailureManager.FailJobCallback callback = mock(CheckpointFailureManager.FailJobCallback.class); + CheckpointFailureManager failureManager = new CheckpointFailureManager(0, callback); + for (CheckpointFailureReason reason : CheckpointFailureReason.values()) { + failureManager.handleCheckpointException(new CheckpointException(reason), -1); + } + + verify(callback, times(6)).failJob(); + } + + /** + * A failure handler callback for testing. + */ + private static class TestHandlerCallback implements CheckpointFailureManager.FailJobCallback { + + private boolean invokeFlag = false; Review comment: If we use a counter instead of the boolean, you can spare the use of mockito in this test to evaluate how many times the callback was invoked. ---------------------------------------------------------------- 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
