zentol commented on a change in pull request #14851: URL: https://github.com/apache/flink/pull/14851#discussion_r570167904
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/allocator/SharedSlotTest.java ########## @@ -0,0 +1,181 @@ +/* + * 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.declarative.allocator; + +import org.apache.flink.runtime.jobmanager.scheduler.Locality; +import org.apache.flink.runtime.jobmaster.LogicalSlot; +import org.apache.flink.runtime.jobmaster.SlotRequestId; +import org.apache.flink.runtime.jobmaster.TestingLogicalSlotBuilder; +import org.apache.flink.runtime.jobmaster.slotpool.PhysicalSlot; +import org.apache.flink.runtime.scheduler.TestingPhysicalSlot; +import org.apache.flink.util.TestLogger; + +import org.junit.Test; + +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; + +/** Tests for the {@link SharedSlot}. */ +public class SharedSlotTest extends TestLogger { + + @Test + public void testConstructorAssignsPayload() { + final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build(); + + new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {}); + + assertThat(physicalSlot.getPayload(), not(nullValue())); + } + + @Test(expected = IllegalStateException.class) + public void testConstructorFailsIfSlotAlreadyHasAssignedPayload() { + final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build(); + physicalSlot.tryAssignPayload(new TestPhysicalSlotPayload()); + + new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {}); + } + + @Test + public void testAllocateLogicalSlot() { + final TestingPhysicalSlot physicalSlot = TestingPhysicalSlot.builder().build(); + final SharedSlot sharedSlot = + new SharedSlot(new SlotRequestId(), physicalSlot, false, () -> {}); + + final LogicalSlot logicalSlot = sharedSlot.allocateLogicalSlot(); + + assertThat(logicalSlot.getAllocationId(), equalTo(physicalSlot.getAllocationId())); + assertThat(logicalSlot.getSlotSharingGroupId(), nullValue()); + assertThat(logicalSlot.getLocality(), is(Locality.UNKNOWN)); + assertThat(logicalSlot.getPayload(), nullValue()); + assertThat(logicalSlot.getPhysicalSlotNumber(), is(physicalSlot.getPhysicalSlotNumber())); Review comment: The slot number can probably be removed fairly easily; it isn't used on the TM side. The `AllocationID` is currently required by the Execution because it is encoded into the TDD and the TM needs to know which slot should be used. I'll open a follow-up for the slot number. ---------------------------------------------------------------- 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]
