You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/06/06 08:25:09 UTC

[GitHub] [flink] GJL commented on a change in pull request #8573: [FLINK-12670][runtime] Implement FailureRateRestartBackoffTimeStrategy

GJL commented on a change in pull request #8573: [FLINK-12670][runtime] Implement FailureRateRestartBackoffTimeStrategy
URL: https://github.com/apache/flink/pull/8573#discussion_r291071069
 
 

 ##########
 File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/FailureRateRestartBackoffTimeStrategyTest.java
 ##########
 @@ -0,0 +1,78 @@
+/*
+ * 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.util.TestLogger;
+
+import org.junit.Test;
+
+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() throws Exception {
+		final int numFailures = 3;
+		final long intervalMS = 1L;
+
+		final FailureRateRestartBackoffTimeStrategy restartStrategy =
+			new FailureRateRestartBackoffTimeStrategy(1, intervalMS, 0);
+
+		for (int failuresLeft = numFailures; failuresLeft > 0; failuresLeft--) {
+			assertTrue(restartStrategy.canRestart());
+			restartStrategy.notifyFailure(failure);
+			Thread.sleep(2 * intervalMS);
 
 Review comment:
   Imo sleep is not acceptable in unit tests. I think we need to be able to control the time, as such:
   
   https://github.com/apache/flink/blob/350846507450ba7afa0159a2c574bd2f44bacaac/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/sink/TwoPhaseCommitSinkFunctionTest.java#L190-L214
   
   You can use Flink's clock interface:
   
   https://github.com/apache/flink/blob/350846507450ba7afa0159a2c574bd2f44bacaac/flink-runtime/src/main/java/org/apache/flink/runtime/util/clock/Clock.java
   
   https://github.com/apache/flink/blob/350846507450ba7afa0159a2c574bd2f44bacaac/flink-runtime/src/test/java/org/apache/flink/runtime/util/clock/ManualClock.java

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services