zhuzhurk commented on code in PR #20082: URL: https://github.com/apache/flink/pull/20082#discussion_r910821180
########## flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/SpeculativeExecutionVertexTest.java: ########## @@ -0,0 +1,252 @@ +/* + * 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; + +import org.apache.flink.api.common.JobStatus; +import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter; +import org.apache.flink.runtime.execution.ExecutionState; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobGraphTestUtils; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.scheduler.TestingInternalFailuresListener; +import org.apache.flink.testutils.TestingUtils; +import org.apache.flink.testutils.executor.TestExecutorExtension; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ScheduledExecutorService; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for the {@link SpeculativeExecutionVertex}. */ +class SpeculativeExecutionVertexTest { + + @RegisterExtension + private static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE = + TestingUtils.defaultExecutorExtension(); + + private TestingInternalFailuresListener internalFailuresListener; + + @BeforeEach + void setUp() { + internalFailuresListener = new TestingInternalFailuresListener(); + } + + @Test + void testCreateSpeculativeExecution() throws Exception { + final SpeculativeExecutionVertex ev = createSpeculativeExecutionVertex(); + assertThat(ev.getCurrentExecutions()).hasSize(1); + + ev.createNewSpeculativeExecution(System.currentTimeMillis()); + assertThat(ev.getCurrentExecutions()).hasSize(2); + } + + @Test + void testResetExecutionVertex() throws Exception { + final SpeculativeExecutionVertex ev = createSpeculativeExecutionVertex(); + final Execution e1 = ev.getCurrentExecutionAttempt(); + final Execution e2 = ev.createNewSpeculativeExecution(System.currentTimeMillis()); + + e1.transitionState(ExecutionState.RUNNING); + e1.markFinished(); + e2.cancel(); + ev.resetForNewExecution(); + + assertThat(ev.getExecutionHistory().getHistoricalExecution(0).get().getAttemptId()) + .isEqualTo(e1.getAttemptId()); + assertThat(ev.getExecutionHistory().getHistoricalExecution(1).get().getAttemptId()) + .isEqualTo(e2.getAttemptId()); + assertThat(ev.getCurrentExecutions()).hasSize(1); + assertThat(ev.getCurrentExecutionAttempt().getAttemptNumber()).isEqualTo(2); + } + + @Test + void testCancel() throws Exception { Review Comment: I believe there is no need to rename it because the method to test is `cancel()`. ########## flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/SpeculativeExecutionVertexTest.java: ########## @@ -0,0 +1,252 @@ +/* + * 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; + +import org.apache.flink.api.common.JobStatus; +import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter; +import org.apache.flink.runtime.execution.ExecutionState; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobGraphTestUtils; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.scheduler.TestingInternalFailuresListener; +import org.apache.flink.testutils.TestingUtils; +import org.apache.flink.testutils.executor.TestExecutorExtension; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ScheduledExecutorService; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for the {@link SpeculativeExecutionVertex}. */ +class SpeculativeExecutionVertexTest { + + @RegisterExtension + private static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_RESOURCE = + TestingUtils.defaultExecutorExtension(); + + private TestingInternalFailuresListener internalFailuresListener; + + @BeforeEach + void setUp() { + internalFailuresListener = new TestingInternalFailuresListener(); + } + + @Test + void testCreateSpeculativeExecution() throws Exception { + final SpeculativeExecutionVertex ev = createSpeculativeExecutionVertex(); + assertThat(ev.getCurrentExecutions()).hasSize(1); + + ev.createNewSpeculativeExecution(System.currentTimeMillis()); + assertThat(ev.getCurrentExecutions()).hasSize(2); + } + + @Test + void testResetExecutionVertex() throws Exception { + final SpeculativeExecutionVertex ev = createSpeculativeExecutionVertex(); + final Execution e1 = ev.getCurrentExecutionAttempt(); + final Execution e2 = ev.createNewSpeculativeExecution(System.currentTimeMillis()); + + e1.transitionState(ExecutionState.RUNNING); + e1.markFinished(); + e2.cancel(); + ev.resetForNewExecution(); + + assertThat(ev.getExecutionHistory().getHistoricalExecution(0).get().getAttemptId()) + .isEqualTo(e1.getAttemptId()); + assertThat(ev.getExecutionHistory().getHistoricalExecution(1).get().getAttemptId()) + .isEqualTo(e2.getAttemptId()); + assertThat(ev.getCurrentExecutions()).hasSize(1); + assertThat(ev.getCurrentExecutionAttempt().getAttemptNumber()).isEqualTo(2); + } + + @Test + void testCancel() throws Exception { + final SpeculativeExecutionVertex ev = createSpeculativeExecutionVertex(); + final Execution e1 = ev.getCurrentExecutionAttempt(); + final Execution e2 = ev.createNewSpeculativeExecution(System.currentTimeMillis()); + + ev.cancel(); + assertThat(e1.getState()).isSameAs(ExecutionState.CANCELED); + assertThat(e2.getState()).isSameAs(ExecutionState.CANCELED); + } + + @Test + void testSuspend() throws Exception { Review Comment: I believe there is no need to rename it because the method to test is `suspend()`. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
