XComp commented on a change in pull request #15049:
URL: https://github.com/apache/flink/pull/15049#discussion_r592583730



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/ExceptionHistoryEntryTest.java
##########
@@ -0,0 +1,176 @@
+/*
+ * 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.scheduler;
+
+import org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.AccessExecution;
+import org.apache.flink.runtime.executiongraph.ErrorInfo;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.IOMetrics;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import javax.annotation.Nullable;
+
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+/** {@code ExceptionHistoryEntryTest} tests the instantiation of {@link 
ExceptionHistoryEntry}. */
+public class ExceptionHistoryEntryTest extends TestLogger {
+
+    @Test
+    public void testFromGlobalFailure() {
+        final Throwable failureCause = new RuntimeException("failure cause");
+        final long timestamp = System.currentTimeMillis();
+
+        final ExceptionHistoryEntry testInstance =
+                ExceptionHistoryEntry.fromGlobalFailure(failureCause, 
timestamp);
+
+        assertThat(
+                
testInstance.getException().deserializeError(ClassLoader.getSystemClassLoader()),
+                is(failureCause));
+        assertThat(testInstance.getTimestamp(), is(timestamp));
+        assertThat(testInstance.getFailingTaskName(), is(nullValue()));
+        assertThat(testInstance.getAssignedResourceLocation(), 
is(nullValue()));
+    }
+
+    @Test
+    public void testFromFailedExecution() {
+        final Throwable failureCause = new RuntimeException("Expected 
failure");
+        final long failureTimestamp = System.currentTimeMillis();
+        final String taskNameWithSubTaskIndex = "task name";
+        final TaskManagerLocation taskManagerLocation = new 
LocalTaskManagerLocation();
+
+        final ExceptionHistoryEntry testInstance =
+                ExceptionHistoryEntry.fromFailedExecution(
+                        createExecutionWithFailure(
+                                failureCause, failureTimestamp, 
taskManagerLocation),
+                        taskNameWithSubTaskIndex);
+
+        assertThat(
+                
testInstance.getException().deserializeError(ClassLoader.getSystemClassLoader()),
+                is(failureCause));
+        assertThat(testInstance.getTimestamp(), is(failureTimestamp));
+        assertThat(testInstance.getFailingTaskName(), 
is(taskNameWithSubTaskIndex));
+        assertThat(testInstance.getAssignedResourceLocation(), 
is(taskManagerLocation));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testFromFailedExecutionWithoutFailure() {
+        
ExceptionHistoryEntry.fromFailedExecution(createExecutionWithoutFailure(), 
"task name");
+    }
+
+    /**
+     * Creates a {@link TestingExecution} that overwrites the relevant methods 
to emulate a {@link
+     * AccessExecution} without a failure.
+     *
+     * @return The {@code TestingExecution} instance.
+     */
+    private static TestingExecution createExecutionWithoutFailure() {
+        return new TestingExecution(null, new LocalTaskManagerLocation());

Review comment:
       Fair enough. Firstly, I wanted to oppose this because I think that the 
method name helps understanding what the constructor call does. But using a 
proper local variable name is good enough, I guess.




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


Reply via email to