zhijiangW commented on a change in pull request #10083: 
[FLINK-14472][runtime]Implement back-pressure monitor with non-blocking outputs.
URL: https://github.com/apache/flink/pull/10083#discussion_r344027326
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/backpressure/BackPressureRequestCoordinatorTest.java
 ##########
 @@ -0,0 +1,311 @@
+/*
+ * 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.legacy.backpressure;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.Execution;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.ExecutionVertex;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.messages.TaskBackPressureResponse;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for the {@link BackPressureRequestCoordinator}.
+ */
+public class BackPressureRequestCoordinatorTest extends TestLogger {
+
+       private static final long requestTimeout = 10000;
+       private static final double backPressureRatio = 0.5;
+
+       private static ScheduledExecutorService executorService;
+       private BackPressureRequestCoordinator coord;
+
+       @BeforeClass
+       public static void setUp() throws Exception {
+               executorService = new ScheduledThreadPoolExecutor(1);
+       }
+
+       @AfterClass
+       public static void tearDown() throws Exception {
+               if (executorService != null) {
+                       executorService.shutdown();
+               }
+       }
+
+       @Before
+       public void init() throws Exception {
+               coord = new BackPressureRequestCoordinator(executorService, 
requestTimeout);
+       }
+
+       /** Tests simple request of task back pressure stats. */
+       @Test(timeout = 10000L)
+       public void testTriggerBackPressureRequest() throws Exception {
+               ExecutionVertex[] vertices = 
createExecutionVertices(ExecutionState.RUNNING, CompletionType.SUCCESSFULLY);
+
+               CompletableFuture<BackPressureStats> requestFuture = 
coord.triggerBackPressureRequest(vertices);
+               BackPressureStats backPressureStats = requestFuture.get();
+
+               // verify the request result
+               assertEquals(0, backPressureStats.getRequestId());
+               assertTrue(backPressureStats.getEndTime() >= 
backPressureStats.getStartTime());
+
+               Map<ExecutionAttemptID, Double> tracesByTask = 
backPressureStats.getBackPressureRatios();
+               for (ExecutionVertex executionVertex : vertices) {
+                       ExecutionAttemptID executionId = 
executionVertex.getCurrentExecutionAttempt().getAttemptId();
+                       assertEquals(backPressureRatio, 
tracesByTask.get(executionId), 0.0);
+               }
+
+               // verify no more pending request
+               assertEquals(0, coord.getNumberOfPendingRequests());
+
+               // verify no error on late collect
+               coord.collectTaskBackPressureStat(0, 
vertices[0].getCurrentExecutionAttempt().getAttemptId(), 0.0);
 
 Review comment:
   We should re-arrange the relevant tests in this class. In the 
`createExecutionVertices` we define the different task state and the complete 
type, then we can only verify the results based on these conditions. The final 
verified results can be ratio value, pending requests, etc. 
   
   But we do not need to expose the methods of 
`coord#collectTaskBackPressureStat` and `coord#cancelBackPressureRequest` to 
call from the tests, because these methods are already covered by handling the 
rpc response logic internally. We can verify the final results to cover them.
   
   From coordinator aspect, only `coord#triggerBackPressureRequest` and 
`coord#shutdown` are stable for interacting with outside world, and all the 
internal methods could be refactored to break/merge future. So it is not proper 
to call these internal methods. Also it seems strange to call them separately 
in the tests .

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to