zhuzhurk commented on a change in pull request #8573: [FLINK-12670][runtime] Implement FailureRateRestartBackoffTimeStrategy URL: https://github.com/apache/flink/pull/8573#discussion_r292271205
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/FailureRateRestartBackoffTimeStrategyTest.java ########## @@ -0,0 +1,84 @@ +/* + * 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.executiongraph.failover.flip1; + +import org.apache.flink.runtime.util.clock.ManualClock; +import org.apache.flink.runtime.util.clock.SystemClock; +import org.apache.flink.util.TestLogger; + +import org.junit.Test; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Unit tests for {@link FailureRateRestartBackoffTimeStrategy}. + */ +public class FailureRateRestartBackoffTimeStrategyTest extends TestLogger { + + private final Exception failure = new Exception(); + + @Test + public void testManyFailuresWithinRate() { + final int numFailures = 3; + final long intervalMS = 1L; + + ManualClock clock = new ManualClock(); + + final FailureRateRestartBackoffTimeStrategy restartStrategy = + new FailureRateRestartBackoffTimeStrategy(clock, 1, intervalMS, 0); + + for (int failuresLeft = numFailures; failuresLeft > 0; failuresLeft--) { + assertTrue(restartStrategy.canRestart()); + restartStrategy.notifyFailure(failure); + clock.advanceTime(intervalMS + 1, TimeUnit.MILLISECONDS); + } + + assertTrue(restartStrategy.canRestart()); + } + + @Test + public void testFailuresExceedingRate() { + final int numFailures = 3; + final long intervalMS = 10_000L; + + final FailureRateRestartBackoffTimeStrategy restartStrategy = + new FailureRateRestartBackoffTimeStrategy(SystemClock.getInstance(), numFailures, intervalMS, 0); Review comment: It's better to use ManualClock here, as the system time elapsing is considered unstable in this case. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services