Thesharing commented on a change in pull request #12917: URL: https://github.com/apache/flink/pull/12917#discussion_r462896285
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SchedulerImplTest.java ########## @@ -0,0 +1,155 @@ +/* + * 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.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingComponentMainThreadExecutor; +import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; +import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.resourcemanager.SlotRequest; +import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.ExceptionUtils; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.flink.runtime.jobmaster.slotpool.AvailableSlotsTest.DEFAULT_TESTING_PROFILE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link SchedulerImpl}. + */ +public class SchedulerImplTest extends TestLogger { + + private static final Time timeout = Time.seconds(1L); + + @ClassRule + public static final TestingComponentMainThreadExecutor.Resource EXECUTOR_RESOURCE = + new TestingComponentMainThreadExecutor.Resource(10L); + + private final TestingComponentMainThreadExecutor testMainThreadExecutor = + EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor(); + + private TaskManagerLocation taskManagerLocation; + private SimpleAckingTaskManagerGateway taskManagerGateway; + private TestingResourceManagerGateway resourceManagerGateway; + private SlotPoolBuilder slotPoolBuilder; + + @Before + public void setUp() throws Exception { + taskManagerLocation = new LocalTaskManagerLocation(); + taskManagerGateway = new SimpleAckingTaskManagerGateway(); + resourceManagerGateway = new TestingResourceManagerGateway(); + slotPoolBuilder = new SlotPoolBuilder(testMainThreadExecutor.getMainThreadExecutor()) + .setResourceManagerGateway(resourceManagerGateway); + } + + @Test + public void testAllocateSlot() throws Exception { + CompletableFuture<SlotRequest> slotRequestFuture = new CompletableFuture<>(); + resourceManagerGateway.setRequestSlotConsumer(slotRequestFuture::complete); + + try (SlotPoolImpl slotPool = createAndSetUpSlotPool()) { + testMainThreadExecutor.execute(() -> slotPool.registerTaskManager(taskManagerLocation.getResourceID())); + + Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), slotPool); + scheduler.start(testMainThreadExecutor.getMainThreadExecutor()); + + SlotRequestId requestId = new SlotRequestId(); + CompletableFuture<LogicalSlot> future = testMainThreadExecutor.execute(() -> scheduler.allocateSlot( + requestId, + new DummyScheduledUnit(), + SlotProfile.noRequirements(), + timeout)); + assertFalse(future.isDone()); + + final SlotRequest slotRequest = slotRequestFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS); + + final SlotOffer slotOffer = new SlotOffer( + slotRequest.getAllocationId(), + 0, + DEFAULT_TESTING_PROFILE); + + assertTrue(testMainThreadExecutor.execute(() -> slotPool.offerSlot( Review comment: Okay, removed `assertTrue`. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SchedulerImplTest.java ########## @@ -0,0 +1,155 @@ +/* + * 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.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingComponentMainThreadExecutor; +import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; +import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.resourcemanager.SlotRequest; +import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.ExceptionUtils; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.flink.runtime.jobmaster.slotpool.AvailableSlotsTest.DEFAULT_TESTING_PROFILE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link SchedulerImpl}. + */ +public class SchedulerImplTest extends TestLogger { + + private static final Time timeout = Time.seconds(1L); + + @ClassRule + public static final TestingComponentMainThreadExecutor.Resource EXECUTOR_RESOURCE = + new TestingComponentMainThreadExecutor.Resource(10L); + + private final TestingComponentMainThreadExecutor testMainThreadExecutor = + EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor(); + + private TaskManagerLocation taskManagerLocation; + private SimpleAckingTaskManagerGateway taskManagerGateway; + private TestingResourceManagerGateway resourceManagerGateway; + private SlotPoolBuilder slotPoolBuilder; + + @Before + public void setUp() throws Exception { + taskManagerLocation = new LocalTaskManagerLocation(); + taskManagerGateway = new SimpleAckingTaskManagerGateway(); + resourceManagerGateway = new TestingResourceManagerGateway(); + slotPoolBuilder = new SlotPoolBuilder(testMainThreadExecutor.getMainThreadExecutor()) + .setResourceManagerGateway(resourceManagerGateway); + } + + @Test + public void testAllocateSlot() throws Exception { Review comment: Agreed. I'll do it when arranging the commit. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SchedulerImplTest.java ########## @@ -0,0 +1,155 @@ +/* + * 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.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingComponentMainThreadExecutor; +import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; +import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.resourcemanager.SlotRequest; +import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.ExceptionUtils; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.flink.runtime.jobmaster.slotpool.AvailableSlotsTest.DEFAULT_TESTING_PROFILE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link SchedulerImpl}. + */ +public class SchedulerImplTest extends TestLogger { + + private static final Time timeout = Time.seconds(1L); + + @ClassRule + public static final TestingComponentMainThreadExecutor.Resource EXECUTOR_RESOURCE = + new TestingComponentMainThreadExecutor.Resource(10L); + + private final TestingComponentMainThreadExecutor testMainThreadExecutor = + EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor(); + + private TaskManagerLocation taskManagerLocation; + private SimpleAckingTaskManagerGateway taskManagerGateway; + private TestingResourceManagerGateway resourceManagerGateway; + private SlotPoolBuilder slotPoolBuilder; + + @Before + public void setUp() throws Exception { + taskManagerLocation = new LocalTaskManagerLocation(); + taskManagerGateway = new SimpleAckingTaskManagerGateway(); + resourceManagerGateway = new TestingResourceManagerGateway(); + slotPoolBuilder = new SlotPoolBuilder(testMainThreadExecutor.getMainThreadExecutor()) + .setResourceManagerGateway(resourceManagerGateway); + } + + @Test + public void testAllocateSlot() throws Exception { + CompletableFuture<SlotRequest> slotRequestFuture = new CompletableFuture<>(); + resourceManagerGateway.setRequestSlotConsumer(slotRequestFuture::complete); + + try (SlotPoolImpl slotPool = createAndSetUpSlotPool()) { + testMainThreadExecutor.execute(() -> slotPool.registerTaskManager(taskManagerLocation.getResourceID())); Review comment: Done. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SchedulerImplTest.java ########## @@ -0,0 +1,155 @@ +/* + * 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.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingComponentMainThreadExecutor; +import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; +import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.resourcemanager.SlotRequest; +import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.ExceptionUtils; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.flink.runtime.jobmaster.slotpool.AvailableSlotsTest.DEFAULT_TESTING_PROFILE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link SchedulerImpl}. + */ +public class SchedulerImplTest extends TestLogger { + + private static final Time timeout = Time.seconds(1L); + + @ClassRule + public static final TestingComponentMainThreadExecutor.Resource EXECUTOR_RESOURCE = + new TestingComponentMainThreadExecutor.Resource(10L); + + private final TestingComponentMainThreadExecutor testMainThreadExecutor = + EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor(); + + private TaskManagerLocation taskManagerLocation; + private SimpleAckingTaskManagerGateway taskManagerGateway; + private TestingResourceManagerGateway resourceManagerGateway; + private SlotPoolBuilder slotPoolBuilder; + + @Before + public void setUp() throws Exception { + taskManagerLocation = new LocalTaskManagerLocation(); + taskManagerGateway = new SimpleAckingTaskManagerGateway(); + resourceManagerGateway = new TestingResourceManagerGateway(); + slotPoolBuilder = new SlotPoolBuilder(testMainThreadExecutor.getMainThreadExecutor()) + .setResourceManagerGateway(resourceManagerGateway); + } + + @Test + public void testAllocateSlot() throws Exception { + CompletableFuture<SlotRequest> slotRequestFuture = new CompletableFuture<>(); + resourceManagerGateway.setRequestSlotConsumer(slotRequestFuture::complete); + + try (SlotPoolImpl slotPool = createAndSetUpSlotPool()) { + testMainThreadExecutor.execute(() -> slotPool.registerTaskManager(taskManagerLocation.getResourceID())); + + Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), slotPool); + scheduler.start(testMainThreadExecutor.getMainThreadExecutor()); + + SlotRequestId requestId = new SlotRequestId(); + CompletableFuture<LogicalSlot> future = testMainThreadExecutor.execute(() -> scheduler.allocateSlot( + requestId, Review comment: Agreed. Done. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/TestingSlotPoolImpl.java ########## @@ -39,6 +43,10 @@ private ResourceProfile lastRequestedSlotResourceProfile; + private volatile Consumer<SlotRequestId> releaseSlotConsumer; Review comment: I get it. I'll do it when I rearrange the commits. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPoolBatchSlotRequestTest.java ########## @@ -81,8 +67,10 @@ public static void teardownClass() { */ @Test public void testPendingBatchSlotRequestTimeout() throws Exception { - try (final SlotPoolImpl slotPool = new SlotPoolBuilder(mainThreadExecutor) - .build()) { + try (final SlotPoolImpl slotPool = slotPoolBuilder + .setBatchSlotTimeout(Time.milliseconds(2L)) + .build()) { + final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot( slotPool, mainThreadExecutor, Review comment: Thanks for your consideration. I'm still working on this. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SchedulerImplTest.java ########## @@ -0,0 +1,155 @@ +/* + * 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.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingComponentMainThreadExecutor; +import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; +import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.resourcemanager.SlotRequest; +import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.ExceptionUtils; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.flink.runtime.jobmaster.slotpool.AvailableSlotsTest.DEFAULT_TESTING_PROFILE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link SchedulerImpl}. + */ +public class SchedulerImplTest extends TestLogger { + + private static final Time timeout = Time.seconds(1L); + + @ClassRule + public static final TestingComponentMainThreadExecutor.Resource EXECUTOR_RESOURCE = + new TestingComponentMainThreadExecutor.Resource(10L); + + private final TestingComponentMainThreadExecutor testMainThreadExecutor = + EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor(); + + private TaskManagerLocation taskManagerLocation; + private SimpleAckingTaskManagerGateway taskManagerGateway; + private TestingResourceManagerGateway resourceManagerGateway; + private SlotPoolBuilder slotPoolBuilder; + + @Before + public void setUp() throws Exception { + taskManagerLocation = new LocalTaskManagerLocation(); + taskManagerGateway = new SimpleAckingTaskManagerGateway(); + resourceManagerGateway = new TestingResourceManagerGateway(); + slotPoolBuilder = new SlotPoolBuilder(testMainThreadExecutor.getMainThreadExecutor()) + .setResourceManagerGateway(resourceManagerGateway); + } + + @Test + public void testAllocateSlot() throws Exception { + CompletableFuture<SlotRequest> slotRequestFuture = new CompletableFuture<>(); + resourceManagerGateway.setRequestSlotConsumer(slotRequestFuture::complete); + + try (SlotPoolImpl slotPool = createAndSetUpSlotPool()) { + testMainThreadExecutor.execute(() -> slotPool.registerTaskManager(taskManagerLocation.getResourceID())); + + Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), slotPool); + scheduler.start(testMainThreadExecutor.getMainThreadExecutor()); Review comment: Good idea. Done. ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SchedulerImplTest.java ########## @@ -0,0 +1,155 @@ +/* + * 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.SlotProfile; +import org.apache.flink.runtime.executiongraph.TestingComponentMainThreadExecutor; +import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; +import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.resourcemanager.SlotRequest; +import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway; +import org.apache.flink.runtime.taskexecutor.slot.SlotOffer; +import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; +import org.apache.flink.runtime.taskmanager.TaskManagerLocation; +import org.apache.flink.util.ExceptionUtils; +import org.apache.flink.util.TestLogger; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static org.apache.flink.runtime.jobmaster.slotpool.AvailableSlotsTest.DEFAULT_TESTING_PROFILE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests for the {@link SchedulerImpl}. + */ +public class SchedulerImplTest extends TestLogger { + + private static final Time timeout = Time.seconds(1L); + + @ClassRule + public static final TestingComponentMainThreadExecutor.Resource EXECUTOR_RESOURCE = + new TestingComponentMainThreadExecutor.Resource(10L); + + private final TestingComponentMainThreadExecutor testMainThreadExecutor = + EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor(); + + private TaskManagerLocation taskManagerLocation; + private SimpleAckingTaskManagerGateway taskManagerGateway; + private TestingResourceManagerGateway resourceManagerGateway; + private SlotPoolBuilder slotPoolBuilder; + + @Before + public void setUp() throws Exception { + taskManagerLocation = new LocalTaskManagerLocation(); + taskManagerGateway = new SimpleAckingTaskManagerGateway(); + resourceManagerGateway = new TestingResourceManagerGateway(); + slotPoolBuilder = new SlotPoolBuilder(testMainThreadExecutor.getMainThreadExecutor()) + .setResourceManagerGateway(resourceManagerGateway); + } + + @Test + public void testAllocateSlot() throws Exception { + CompletableFuture<SlotRequest> slotRequestFuture = new CompletableFuture<>(); + resourceManagerGateway.setRequestSlotConsumer(slotRequestFuture::complete); + + try (SlotPoolImpl slotPool = createAndSetUpSlotPool()) { + testMainThreadExecutor.execute(() -> slotPool.registerTaskManager(taskManagerLocation.getResourceID())); + + Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), slotPool); Review comment: Done. I also add `final` to other variables. ---------------------------------------------------------------- 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]
