mateczagany commented on code in PR #27891:
URL: https://github.com/apache/flink/pull/27891#discussion_r3085536024


##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/rescales/JobRescalesOverviewHandlerTest.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.rest.handler.job.rescales;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.HandlerRequestException;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache;
+import 
org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.JobIDPathParameter;
+import org.apache.flink.runtime.rest.messages.JobMessageParameters;
+import org.apache.flink.runtime.rest.messages.job.rescales.JobRescalesOverview;
+import 
org.apache.flink.runtime.rest.messages.job.rescales.JobRescalesOverviewHeaders;
+import org.apache.flink.runtime.scheduler.ExecutionGraphInfo;
+import org.apache.flink.runtime.scheduler.adaptive.timeline.Rescale;
+import org.apache.flink.runtime.scheduler.adaptive.timeline.RescaleIdInfo;
+import 
org.apache.flink.runtime.scheduler.adaptive.timeline.RescalesStatsSnapshot;
+import org.apache.flink.runtime.scheduler.adaptive.timeline.RescalesSummary;
+import 
org.apache.flink.runtime.scheduler.adaptive.timeline.RescalesSummarySnapshot;
+import org.apache.flink.runtime.scheduler.adaptive.timeline.TerminatedReason;
+import org.apache.flink.runtime.scheduler.adaptive.timeline.TriggerCause;
+import org.apache.flink.testutils.TestingUtils;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Test for {@link JobRescalesOverviewHandler}. */
+class JobRescalesOverviewHandlerTest {
+    private final JobRescalesOverviewHandler testInstance =
+            new JobRescalesOverviewHandler(
+                    CompletableFuture::new,
+                    TestingUtils.TIMEOUT,
+                    Map.of(),
+                    JobRescalesOverviewHeaders.getInstance(),
+                    new DefaultExecutionGraphCache(TestingUtils.TIMEOUT, 
TestingUtils.TIMEOUT),
+                    Executors.directExecutor());
+
+    @Test
+    void testSchedulerNotEnabledRescalesOverview() throws 
HandlerRequestException {
+        final ExecutionGraphInfo 
executionGraphInfoWithNullRescalesStatsSnapshot =
+                new ExecutionGraphInfo(
+                        new ArchivedExecutionGraphBuilder().build(), 
List.of(), null);
+        final HandlerRequest<EmptyRequestBody> request =
+                
createRequest(executionGraphInfoWithNullRescalesStatsSnapshot.getJobId());
+        assertThatThrownBy(
+                        () ->
+                                testInstance.handleRequest(
+                                        request, 
executionGraphInfoWithNullRescalesStatsSnapshot))
+                .isInstanceOf(RestHandlerException.class);
+    }
+
+    @Test
+    void testRequestNormalJobRescaleOverview()
+            throws HandlerRequestException, RestHandlerException {
+        Rescale rescale =
+                new Rescale(new RescaleIdInfo(new 
RescaleIdInfo.ResourceRequirementsID(), 1L))
+                        .setStartTimestamp(1L)
+                        .setEndTimestamp(100L)
+                        .setTriggerCause(TriggerCause.INITIAL_SCHEDULE)
+                        .setStringifiedException("mocked exception")
+                        .setTerminatedReason(TerminatedReason.SUCCEEDED);
+
+        RescalesSummary rescalesSummary = new RescalesSummary(2);
+        rescalesSummary.addTerminated(rescale);
+        RescalesSummarySnapshot rescalesSummarySnapshot = 
rescalesSummary.createSnapshot();
+        RescalesStatsSnapshot rescalesStatsSnapshot =
+                new RescalesStatsSnapshot(
+                        List.of(rescale),
+                        Map.of(rescale.getTerminalState(), rescale),
+                        rescalesSummarySnapshot);
+
+        final ExecutionGraphInfo executionGraphInfo =
+                new ExecutionGraphInfo(
+                        new ArchivedExecutionGraphBuilder().build(),
+                        List.of(),
+                        JobManagerOptions.SchedulerType.Adaptive,
+                        null,
+                        rescalesStatsSnapshot);
+        final HandlerRequest<EmptyRequestBody> request =
+                createRequest(executionGraphInfo.getJobId());
+
+        JobRescalesOverview actual = testInstance.handleRequest(request, 
executionGraphInfo);
+        JobRescalesOverview expected =
+                
JobRescalesOverview.fromRescalesStatsSnapshot(rescalesStatsSnapshot);

Review Comment:
   Just a minor request, the expected `JobRescalesOverview` should be manually 
constructed, to be able to also catch potential bugs in 
`JobRescalesOverview#fromRescalesStatsSnapshot`, as this method is also going 
to be called by the handler.
   
   Aside from this, the PR looks solid!



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

Reply via email to