@@ -0,0 +1,3670 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.flink.runtime.scheduler.declarative;%0A%0Aimport org.apache.flink.api.common.JobStatus;%0Aimport org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;%0Aimport org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;%0Aimport org.apache.flink.util.TestLogger;%0A%0Aimport org.junit.Test;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.hamcrest.CoreMatchers.nullValue;%0Aimport static org.junit.Assert.assertThat;%0A%0A/** Tests for declarative scheduler's %7B@link Finished%7D state. */%0Apublic class FinishedTest extends TestLogger %7B%0A    private final JobStatus testJobStatus = JobStatus.FAILED;%0A%0A    @Test%0A    public void testOnFinishedCallOnEnter() throws Exception %7B%0A        MockFinishedContext ctx = new MockFinishedContext();%0A        Finished finished = createFinishedState(ctx);%0A        finished.onEnter();%0A%0A        assertThat(ctx.getArchivedExecutionGraph().getState(), is(testJobStatus));%0A    %7D%0A%0A    @Test%0A    public void testCancelIgnored() throws Exception %7B%0A        MockFinishedContext ctx = new MockFinishedContext();%0A        createFinishedState(ctx).cancel();%0A        ctx.assertNoStateTransition();%0A    %7D%0A%0A    @Test%0A    public void testSuspendIgnored() throws Exception %7B%0A        MockFinishedContext ctx = new MockFinishedContext();%0A        createFinishedState(ctx).suspend(new RuntimeException());%0A        ctx.assertNoStateTransition();%0A    %7D%0A%0A    @Test%0A    public void testGlobalFailureIgnored() %7B%0A        MockFinishedContext ctx = new MockFinishedContext();%0A        createFinishedState(ctx).handleGlobalFailure(new RuntimeException());%0A        ctx.assertNoStateTransition();%0A    %7D%0A%0A    @Test%0A    public void testGetJobStatus() %7B%0A        MockFinishedContext ctx = new MockFinishedContext();%0A        assertThat(createFinishedState(ctx).getJobStatus(), is(testJobStatus));%0A    %7D%0A%0A    private Finished createFinishedState(MockFinishedContext ctx) %7B%0A        final ArchivedExecutionGraph archivedExecutionGraph =%0A                new ArchivedExecutionGraphBuilder().setState(testJobStatus).build();%0A        return new Finished(ctx, archivedExecutionGraph, log);%0A    %7D%0A%0A    private static class MockFinishedContext implements Finished.Context %7B%0A%0A        private ArchivedExecutionGraph archivedExecutionGraph = null;%0A%0A        @Override%0A        public void onFinished(ArchivedExecutionGraph archivedExecutionGraph) %7B%0A            if (archivedExecutionGraph != null) %7B%0A                this.archivedExecutionGraph = archivedExecutionGraph;%0A            %7D else %7B%0A                throw new AssertionError(%22Transitioned to onFinished twice%22);%0A            %7D%0A        %7D%0A%0A        private void assertNoStateTransition() %7B%0A            assertThat(archivedExecutionGraph, nullValue());%0A        %7D%0A%0A        private ArchivedExecutionGraph getArchivedExecutionGraph() %7B%0A            return archivedExecutionGraph;%0A        %7D%0A    %7D%0A%7D%0A

Add tests for Finished state