GJL commented on a change in pull request #8486: [FLINK-12372] [runtime] implement ExecutionSlotAllocator URL: https://github.com/apache/flink/pull/8486#discussion_r292374098
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/DefaultExecutionSlotAllocatorTest.java ########## @@ -0,0 +1,332 @@ +/* + * 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.scheduler; + +import org.apache.flink.api.common.time.Time; +import org.apache.flink.api.java.tuple.Tuple3; +import org.apache.flink.runtime.clusterframework.types.AllocationID; +import org.apache.flink.runtime.clusterframework.types.ResourceProfile; +import org.apache.flink.runtime.clusterframework.types.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingSlotProvider; +import org.apache.flink.runtime.instance.SlotSharingGroupId; +import org.apache.flink.runtime.jobgraph.JobVertexID; +import org.apache.flink.runtime.jobmanager.scheduler.CoLocationConstraint; +import org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroup; +import org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.jobmaster.TestingLogicalSlot; +import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; +import java.util.function.Function; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for {@link DefaultExecutionSlotAllocator}. + */ +public class DefaultExecutionSlotAllocatorTest extends TestLogger { + + private ParamsCapturedTestingSlotProvider slotProvider; + + private Queue<CompletableFuture<LogicalSlot>> slotFutures; Review comment: `slotFutures`, `receivedSlotRequestIds`, `cancelledSlotRequestIds` are strongly coupled fields. I propose to group them into a single class. There is also the pattern that we either complete the slot immediately or never so instead of `slotFutures.add(new CompletableFuture<>())` one could write `slotProvider.disableSlotAllocation()`: ``` private static class AllocationToggableSlotProvider implements SlotProvider { private final List<Tuple3<SlotRequestId, ScheduledUnit, SlotProfile>> slotAllocationRequests = new ArrayList<>(); private final List<SlotRequestId> cancelledSlotRequestIds = new ArrayList<>(); private boolean slotAllocationDisabled; @Override public CompletableFuture<LogicalSlot> allocateSlot( SlotRequestId slotRequestId, ScheduledUnit task, SlotProfile slotProfile, boolean allowQueued, Time timeout) { slotAllocationRequests.add(Tuple3.of(slotRequestId, task, slotProfile)); if (slotAllocationDisabled) { return new CompletableFuture<>(); } else { return CompletableFuture.completedFuture(new TestingLogicalSlot()); } } @Override public void cancelSlotRequest( final SlotRequestId slotRequestId, @Nullable final SlotSharingGroupId slotSharingGroupId, final Throwable cause) { cancelledSlotRequestIds.add(slotRequestId); } public List<Tuple3<SlotRequestId, ScheduledUnit, SlotProfile>> getSlotAllocationRequests() { return Collections.unmodifiableList(slotAllocationRequests); } public List<SlotRequestId> getReceivedSlotRequestIds() { return slotAllocationRequests.stream() .map(requestTuple -> requestTuple.f0) .collect(Collectors.toList()); } public List<SlotRequestId> getCancelledSlotRequestIds() { return Collections.unmodifiableList(cancelledSlotRequestIds); } public void disableSlotAllocation() { slotAllocationDisabled = true; } } ``` What do you think? ---------------------------------------------------------------- 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] With regards, Apache Git Services
