This is an automated email from the ASF dual-hosted git repository. zhuzh pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit 4b7d8db3aca409ae18dff635c70720d9a827cd06 Author: Zhu Zhu <[email protected]> AuthorDate: Sat Jun 6 02:13:36 2020 +0800 [hotfix][runtime] Move shared static test methods of physical slot into PhysicalSlotTestUtils --- .../slotpool/AllocatedSlotOccupationTest.java | 35 +++------------------- .../PhysicalSlotRequestBulkCheckerTest.java | 28 ++++------------- ...upationTest.java => PhysicalSlotTestUtils.java} | 33 +++++--------------- 3 files changed, 17 insertions(+), 79 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java index f68ff75..ce37266 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java @@ -18,18 +18,12 @@ package org.apache.flink.runtime.jobmaster.slotpool; -import org.apache.flink.runtime.clusterframework.types.AllocationID; -import org.apache.flink.runtime.clusterframework.types.ResourceProfile; -import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; -import org.apache.flink.runtime.jobmanager.scheduler.Locality; -import org.apache.flink.runtime.jobmanager.slots.TestingSlotOwner; -import org.apache.flink.runtime.jobmaster.LogicalSlot; -import org.apache.flink.runtime.jobmaster.SlotRequestId; -import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; import org.apache.flink.util.TestLogger; import org.junit.Test; +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; @@ -41,7 +35,7 @@ public class AllocatedSlotOccupationTest extends TestLogger { @Test public void testSingleTaskOccupyingSlotIndefinitely() { final PhysicalSlot physicalSlot = createPhysicalSlot(); - allocateSingleLogicalSlotFromPhysicalSlot(physicalSlot, true); + occupyPhysicalSlot(physicalSlot, true); assertThat(physicalSlot.willBeOccupiedIndefinitely(), is(true)); } @@ -49,29 +43,8 @@ public class AllocatedSlotOccupationTest extends TestLogger { @Test public void testSingleTaskNotOccupyingSlotIndefinitely() { final PhysicalSlot physicalSlot = createPhysicalSlot(); - allocateSingleLogicalSlotFromPhysicalSlot(physicalSlot, false); + occupyPhysicalSlot(physicalSlot, false); assertThat(physicalSlot.willBeOccupiedIndefinitely(), is(false)); } - - private static PhysicalSlot createPhysicalSlot() { - return new AllocatedSlot( - new AllocationID(), - new LocalTaskManagerLocation(), - 0, - ResourceProfile.ANY, - new SimpleAckingTaskManagerGateway()); - } - - private static LogicalSlot allocateSingleLogicalSlotFromPhysicalSlot( - final PhysicalSlot physicalSlot, - final boolean slotWillBeOccupiedIndefinitely) { - - return SingleLogicalSlot.allocateFromPhysicalSlot( - new SlotRequestId(), - physicalSlot, - Locality.UNKNOWN, - new TestingSlotOwner(), - slotWillBeOccupiedIndefinitely); - } } diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotRequestBulkCheckerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotRequestBulkCheckerTest.java index 557ba54..2c58f2f 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotRequestBulkCheckerTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotRequestBulkCheckerTest.java @@ -22,12 +22,8 @@ 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.clusterframework.types.SlotProfile; -import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway; -import org.apache.flink.runtime.jobmanager.scheduler.Locality; -import org.apache.flink.runtime.jobmanager.slots.TestingSlotOwner; import org.apache.flink.runtime.jobmaster.SlotInfo; import org.apache.flink.runtime.jobmaster.SlotRequestId; -import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; import org.apache.flink.util.TestLogger; import org.apache.flink.util.clock.ManualClock; @@ -41,6 +37,8 @@ import java.util.Set; import java.util.concurrent.TimeUnit; 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; @@ -99,7 +97,7 @@ public class PhysicalSlotRequestBulkCheckerTest extends TestLogger { Collections.singletonList(createPhysicalSlotRequest())); final PhysicalSlot slot = addOneSlot(); - occupySlot(slot, false); + occupyPhysicalSlot(slot, false); assertThat(checkBulkTimeout(bulk), is(PhysicalSlotRequestBulkChecker.TimeoutCheckResult.PENDING)); } @@ -153,7 +151,7 @@ public class PhysicalSlotRequestBulkCheckerTest extends TestLogger { final PhysicalSlot slot1 = addOneSlot(); addOneSlot(); - occupySlot(slot1, true); + occupyPhysicalSlot(slot1, true); assertThat(isFulfillable(bulk), is(false)); } @@ -166,7 +164,7 @@ public class PhysicalSlotRequestBulkCheckerTest extends TestLogger { final PhysicalSlot slot1 = addOneSlot(); addOneSlot(); - occupySlot(slot1, false); + occupyPhysicalSlot(slot1, false); assertThat(isFulfillable(bulk), is(true)); } @@ -178,22 +176,8 @@ public class PhysicalSlotRequestBulkCheckerTest extends TestLogger { true); } - private static void occupySlot(final PhysicalSlot slotToOccupy, final boolean slotWillBeOccupiedIndefinitely) { - SingleLogicalSlot.allocateFromPhysicalSlot( - new SlotRequestId(), - slotToOccupy, - Locality.UNKNOWN, - new TestingSlotOwner(), - slotWillBeOccupiedIndefinitely); - } - private PhysicalSlot addOneSlot() { - final PhysicalSlot slot = new AllocatedSlot( - new AllocationID(), - new LocalTaskManagerLocation(), - 0, - ResourceProfile.ANY, - new SimpleAckingTaskManagerGateway()); + final PhysicalSlot slot = createPhysicalSlot(); slots.add(slot); return slot; diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotTestUtils.java similarity index 66% copy from flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java copy to flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotTestUtils.java index f68ff75..a1bef43 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlotOccupationTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/PhysicalSlotTestUtils.java @@ -26,35 +26,13 @@ import org.apache.flink.runtime.jobmanager.slots.TestingSlotOwner; import org.apache.flink.runtime.jobmaster.LogicalSlot; import org.apache.flink.runtime.jobmaster.SlotRequestId; import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation; -import org.apache.flink.util.TestLogger; - -import org.junit.Test; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; /** - * Tests whether the slot occupation state of {@link AllocatedSlot} is correctly. + * Test utils of {@link PhysicalSlot}. */ -public class AllocatedSlotOccupationTest extends TestLogger { - - @Test - public void testSingleTaskOccupyingSlotIndefinitely() { - final PhysicalSlot physicalSlot = createPhysicalSlot(); - allocateSingleLogicalSlotFromPhysicalSlot(physicalSlot, true); - - assertThat(physicalSlot.willBeOccupiedIndefinitely(), is(true)); - } +public class PhysicalSlotTestUtils { - @Test - public void testSingleTaskNotOccupyingSlotIndefinitely() { - final PhysicalSlot physicalSlot = createPhysicalSlot(); - allocateSingleLogicalSlotFromPhysicalSlot(physicalSlot, false); - - assertThat(physicalSlot.willBeOccupiedIndefinitely(), is(false)); - } - - private static PhysicalSlot createPhysicalSlot() { + public static PhysicalSlot createPhysicalSlot() { return new AllocatedSlot( new AllocationID(), new LocalTaskManagerLocation(), @@ -63,7 +41,7 @@ public class AllocatedSlotOccupationTest extends TestLogger { new SimpleAckingTaskManagerGateway()); } - private static LogicalSlot allocateSingleLogicalSlotFromPhysicalSlot( + public static LogicalSlot occupyPhysicalSlot( final PhysicalSlot physicalSlot, final boolean slotWillBeOccupiedIndefinitely) { @@ -74,4 +52,7 @@ public class AllocatedSlotOccupationTest extends TestLogger { new TestingSlotOwner(), slotWillBeOccupiedIndefinitely); } + + private PhysicalSlotTestUtils() { + } }
