flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] eaglewatcherwb commented on a change in pull request #8498: [FLINK-12413] [runtime] Implement ExecutionFailureHandler
Date Thu, 23 May 2019 11:50:40 GMT
eaglewatcherwb commented on a change in pull request #8498: [FLINK-12413] [runtime] Implement
ExecutionFailureHandler
URL: https://github.com/apache/flink/pull/8498#discussion_r286902525
 
 

 ##########
 File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/ExecutionFailureHandlerTest.java
 ##########
 @@ -0,0 +1,170 @@
+/*
+ * 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.execution.SuppressRestartsException;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.util.TestLogger;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link ExecutionFailureHandler}.
+ */
+public class ExecutionFailureHandlerTest extends TestLogger {
+
+	/**
+	 * Tests the case that task restarting is accepted.
+	 */
+	@Test
+	public void testNormalFailureHandling() throws Exception {
+		ExecutionFailureHandler executionFailureHandler = createExecutionFailureHandler();
+		FailoverStrategy failoverStrategy = executionFailureHandler.getFailoverStrategy();
+		RestartBackoffTimeStrategy restartStrategy = executionFailureHandler.getRestartBackoffTimeStrategy();
+
+		Set<ExecutionVertexID> tasksToBeRestarted = new HashSet<>();
+		when(failoverStrategy.getTasksNeedingRestart(any(ExecutionVertexID.class), any(Throwable.class))).thenReturn(
+			tasksToBeRestarted);
+
+		long restartDelayMs = 1234;
+		when(restartStrategy.getBackoffTime()).thenReturn(restartDelayMs);
+
+		// accept restarts
+		when(restartStrategy.canRestart()).thenReturn(true);
+
+		FailureHandlingResult result = executionFailureHandler.getFailureHandlingResult(
+			new ExecutionVertexID(new JobVertexID(), 0),
+			new Exception("test failure"));
+
+		// verify results
+		assertTrue(result.canRestart());
+		assertEquals(restartDelayMs, result.getRestartDelayMS());
+		assertEquals(tasksToBeRestarted, result.getVerticesToRestart());
+		assertNull(result.getError());
+	}
+
+	/**
+	 * Tests the case that task restarting is suppressed.
+	 */
+	@Test
+	public void testRestartingSuppressedFailureHandlingResult() throws Exception {
+		ExecutionFailureHandler executionFailureHandler = createExecutionFailureHandler();
+		FailoverStrategy failoverStrategy = executionFailureHandler.getFailoverStrategy();
+		RestartBackoffTimeStrategy restartStrategy = executionFailureHandler.getRestartBackoffTimeStrategy();
+
+		Set<ExecutionVertexID> tasksToBeRestarted = new HashSet<>();
+		when(failoverStrategy.getTasksNeedingRestart(any(ExecutionVertexID.class), any(Throwable.class))).thenReturn(
+			tasksToBeRestarted);
+
+		long restartDelayMs = 1234;
+		when(restartStrategy.getBackoffTime()).thenReturn(restartDelayMs);
+
+		// suppress restarts
+		when(restartStrategy.canRestart()).thenReturn(false);
+
+		FailureHandlingResult result = executionFailureHandler.getFailureHandlingResult(
+			new ExecutionVertexID(new JobVertexID(), 0),
+			new Exception("test failure"));
+
+		// verify results
+		assertFalse(result.canRestart());
+		assertNotNull(result.getError());
+		try {
+			result.getVerticesToRestart();
+			fail("get tasks to restart is not allowed when restarting is suppressed");
+		} catch (IllegalStateException ex) {
+			// expected
+		}
+		try {
+			result.getRestartDelayMS();
+			fail("get restart delay is not allowed when restarting is suppressed");
+		} catch (IllegalStateException ex) {
+			// expected
+		}
+	}
+
+	/**
+	 * Tests the case that the failure is non-recoverable type.
+	 */
+	@Test
+	public void testNonRecoverableFailureHandlingResult() throws Exception {
 
 Review comment:
   Exception is not thrown.

----------------------------------------------------------------
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

Mime
View raw message