|
32 | 32 | import org.apache.flink.runtime.slots.ResourceRequirement;
|
33 | 33 | import org.apache.flink.runtime.slots.ResourceRequirements;
|
34 | 34 | import org.apache.flink.runtime.taskexecutor.SlotReport;
|
| 35 | +import org.apache.flink.runtime.taskexecutor.SlotStatus; |
35 | 36 | import org.apache.flink.runtime.taskexecutor.TaskExecutorGateway;
|
36 | 37 | import org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder;
|
37 | 38 |
|
@@ -737,6 +738,86 @@ public void testMaxTotalResourceCpuExceeded() throws Exception {
|
737 | 738 | testMaxTotalResourceExceededRegisterResource(maxTotalResourceSetter);
|
738 | 739 | }
|
739 | 740 |
|
| 741 | + @Test |
| 742 | + public void testGetResourceOverview() throws Exception { |
| 743 | + final TaskExecutorConnection taskExecutorConnection1 = createTaskExecutorConnection(); |
| 744 | + final TaskExecutorConnection taskExecutorConnection2 = createTaskExecutorConnection(); |
| 745 | + final ResourceID resourceId1 = ResourceID.generate(); |
| 746 | + final ResourceID resourceId2 = ResourceID.generate(); |
| 747 | + |
| 748 | + final SlotID slotId1 = new SlotID(resourceId1, 0); |
| 749 | + final SlotID slotId2 = new SlotID(resourceId2, 0); |
| 750 | + final ResourceProfile resourceProfile1 = ResourceProfile.fromResources(1, 10); |
| 751 | + final ResourceProfile resourceProfile2 = ResourceProfile.fromResources(2, 20); |
| 752 | + final SlotStatus slotStatus1 = |
| 753 | + new SlotStatus(slotId1, resourceProfile1, new JobID(), new AllocationID()); |
| 754 | + final SlotStatus slotStatus2 = |
| 755 | + new SlotStatus(slotId2, resourceProfile2, new JobID(), new AllocationID()); |
| 756 | + final SlotReport slotReport1 = new SlotReport(slotStatus1); |
| 757 | + final SlotReport slotReport2 = new SlotReport(slotStatus2); |
| 758 | + |
| 759 | + new Context() { |
| 760 | + { |
| 761 | + runTest( |
| 762 | + () -> { |
| 763 | + final CompletableFuture<Boolean> registerTaskManagerFuture1 = |
| 764 | + new CompletableFuture<>(); |
| 765 | + final CompletableFuture<Boolean> registerTaskManagerFuture2 = |
| 766 | + new CompletableFuture<>(); |
| 767 | + runInMainThread( |
| 768 | + () -> { |
| 769 | + registerTaskManagerFuture1.complete( |
| 770 | + getSlotManager() |
| 771 | + .registerTaskManager( |
| 772 | + taskExecutorConnection1, |
| 773 | + slotReport1, |
| 774 | + resourceProfile1.multiply(2), |
| 775 | + resourceProfile1)); |
| 776 | + registerTaskManagerFuture2.complete( |
| 777 | + getSlotManager() |
| 778 | + .registerTaskManager( |
| 779 | + taskExecutorConnection2, |
| 780 | + slotReport2, |
| 781 | + resourceProfile2.multiply(2), |
| 782 | + resourceProfile2)); |
| 783 | + }); |
| 784 | + assertThat( |
| 785 | + assertFutureCompleteAndReturn(registerTaskManagerFuture1), |
| 786 | + is(true)); |
| 787 | + assertThat( |
| 788 | + assertFutureCompleteAndReturn(registerTaskManagerFuture2), |
| 789 | + is(true)); |
| 790 | + assertThat( |
| 791 | + getSlotManager().getFreeResource(), |
| 792 | + equalTo(resourceProfile1.merge(resourceProfile2))); |
| 793 | + assertThat( |
| 794 | + getSlotManager() |
| 795 | + .getFreeResourceOf( |
| 796 | + taskExecutorConnection1.getInstanceID()), |
| 797 | + equalTo(resourceProfile1)); |
| 798 | + assertThat( |
| 799 | + getSlotManager() |
| 800 | + .getFreeResourceOf( |
| 801 | + taskExecutorConnection2.getInstanceID()), |
| 802 | + equalTo(resourceProfile2)); |
| 803 | + assertThat( |
| 804 | + getSlotManager().getRegisteredResource(), |
| 805 | + equalTo(resourceProfile1.merge(resourceProfile2).multiply(2))); |
| 806 | + assertThat( |
| 807 | + getSlotManager() |
| 808 | + .getRegisteredResourceOf( |
| 809 | + taskExecutorConnection1.getInstanceID()), |
| 810 | + equalTo(resourceProfile1.multiply(2))); |
| 811 | + assertThat( |
| 812 | + getSlotManager() |
| 813 | + .getRegisteredResourceOf( |
| 814 | + taskExecutorConnection2.getInstanceID()), |
| 815 | + equalTo(resourceProfile2.multiply(2))); |
| 816 | + }); |
| 817 | + } |
| 818 | + }; |
| 819 | + } |
| 820 | + |
740 | 821 | @Test
|
741 | 822 | public void testMaxTotalResourceMemoryExceeded() throws Exception {
|
742 | 823 | Consumer<SlotManagerConfigurationBuilder> maxTotalResourceSetter =
|
|
0 commit comments