azagrebin commented on a change in pull request #13181:
URL: https://github.com/apache/flink/pull/13181#discussion_r475569737



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotRequestBulkCheckerImplTest.java
##########
@@ -0,0 +1,257 @@
+/*
+ * 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.jobmaster.slotpool;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import 
org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
+import org.apache.flink.runtime.jobmaster.SlotInfo;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.clock.ManualClock;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Supplier;
+
+import static 
org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotTestUtils.createPhysicalSlot;
+import static 
org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlotTestUtils.occupyPhysicalSlot;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for {@link PhysicalSlotRequestBulkCheckerImpl}.
+ */
+public class PhysicalSlotRequestBulkCheckerImplTest extends TestLogger {
+
+       private static final Time TIMEOUT = Time.milliseconds(100L);
+
+       private static ScheduledExecutorService 
singleThreadScheduledExecutorService;
+
+       private static ComponentMainThreadExecutor mainThreadExecutor;
+
+       private final ManualClock clock = new ManualClock();
+
+       private PhysicalSlotRequestBulkCheckerImpl bulkChecker;
+
+       private Set<PhysicalSlot> slots;
+
+       private Supplier<Set<SlotInfo>> slotsRetriever;
+
+       @BeforeClass
+       public static void setupClass() {
+               singleThreadScheduledExecutorService = 
Executors.newSingleThreadScheduledExecutor();
+               mainThreadExecutor = 
ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(singleThreadScheduledExecutorService);
+       }
+
+       @AfterClass
+       public static void teardownClass() {
+               if (singleThreadScheduledExecutorService != null) {
+                       singleThreadScheduledExecutorService.shutdownNow();
+               }
+       }
+
+       @Before
+       public void setup() throws Exception {
+               slots = new HashSet<>();
+               slotsRetriever = () -> new HashSet<>(slots);
+               bulkChecker = new 
PhysicalSlotRequestBulkCheckerImpl(slotsRetriever, clock);
+               bulkChecker.start(mainThreadExecutor);
+       }
+
+       @Test
+       public void testPendingBulkIsNotCancelled() throws 
InterruptedException, ExecutionException {
+               final CompletableFuture<SlotRequestId> cancellationFuture = new 
CompletableFuture<>();
+               final PhysicalSlotRequestBulk bulk = 
createPhysicalSlotRequestBulkWithCancellationFuture(cancellationFuture, new 
SlotRequestId());
+               bulkChecker.schedulePendingRequestBulkTimeoutCheck(bulk, 
TIMEOUT);
+               checkNotCancelledAfter(cancellationFuture, 2 * 
TIMEOUT.toMilliseconds());
+       }
+
+       @Test
+       public void testFulfilledBulkIsNotCancelled() throws 
InterruptedException, ExecutionException {
+               final CompletableFuture<SlotRequestId> cancellationFuture = new 
CompletableFuture<>();
+               final PhysicalSlotRequestBulk bulk = 
createPhysicalSlotRequestBulkWithCancellationFuture(cancellationFuture, new 
SlotRequestId());
+               bulkChecker.schedulePendingRequestBulkTimeoutCheck(bulk, 
TIMEOUT);
+               checkNotCancelledAfter(cancellationFuture, 2  * 
TIMEOUT.toMilliseconds());
+       }
+
+       private static void checkNotCancelledAfter(
+                       CompletableFuture<?> cancellationFuture, long milli) 
throws ExecutionException, InterruptedException {
+               mainThreadExecutor.schedule(() -> {}, milli, 
TimeUnit.MILLISECONDS).get();
+               try {
+                       cancellationFuture.get(milli, TimeUnit.MILLISECONDS);

Review comment:
       True, I can add it. Although we have to wait in usual case.




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