use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.
the class FineGrainedSlotManagerTest method testSlotAllocationForPendingTaskManagerWillBeRespected.
@Test
public void testSlotAllocationForPendingTaskManagerWillBeRespected() throws Exception {
final JobID jobId = new JobID();
final CompletableFuture<Void> requestResourceFuture = new CompletableFuture<>();
final PendingTaskManager pendingTaskManager = new PendingTaskManager(DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_NUM_SLOTS_PER_WORKER);
final CompletableFuture<Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId>> requestSlotFuture = new CompletableFuture<>();
final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
requestSlotFuture.complete(tuple6);
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(ResourceID.generate(), taskExecutorGateway);
new Context() {
{
resourceAllocationStrategyBuilder.setTryFulfillRequirementsFunction(((jobIDCollectionMap, taskManagerResourceInfoProvider) -> ResourceAllocationResult.builder().addPendingTaskManagerAllocate(pendingTaskManager).addAllocationOnPendingResource(jobId, pendingTaskManager.getPendingTaskManagerId(), DEFAULT_SLOT_RESOURCE_PROFILE).build()));
resourceActionsBuilder.setAllocateResourceConsumer(ignored -> requestResourceFuture.complete(null));
runTest(() -> {
runInMainThread(() -> getSlotManager().processResourceRequirements(createResourceRequirements(jobId, 1)));
assertFutureCompleteAndReturn(requestResourceFuture);
runInMainThread(() -> getSlotManager().registerTaskManager(taskManagerConnection, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE));
final Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId> requestSlot = assertFutureCompleteAndReturn(requestSlotFuture);
assertEquals(jobId, requestSlot.f1);
assertEquals(DEFAULT_SLOT_RESOURCE_PROFILE, requestSlot.f3);
});
}
};
}
use of org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection in project flink by apache.
the class FineGrainedSlotManagerTest method testMaxTotalResourceExceededRegisterResource.
private void testMaxTotalResourceExceededRegisterResource(Consumer<SlotManagerConfigurationBuilder> maxTotalResourceSetter) throws Exception {
final TaskExecutorConnection taskManagerConnection1 = createTaskExecutorConnection();
final TaskExecutorConnection taskManagerConnection2 = createTaskExecutorConnection();
final CompletableFuture<Boolean> registerTaskManagerFuture1 = new CompletableFuture<>();
final CompletableFuture<Boolean> registerTaskManagerFuture2 = new CompletableFuture<>();
final CompletableFuture<InstanceID> releaseResourceFuture = new CompletableFuture<>();
new Context() {
{
maxTotalResourceSetter.accept(slotManagerConfigurationBuilder);
resourceActionsBuilder.setReleaseResourceConsumer((instanceId, ignore) -> releaseResourceFuture.complete(instanceId));
runTest(() -> {
runInMainThread(() -> registerTaskManagerFuture1.complete(getSlotManager().registerTaskManager(taskManagerConnection1, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE)));
assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture1), is(true));
assertFutureNotComplete(releaseResourceFuture);
assertThat(getTaskManagerTracker().getRegisteredTaskManagers().size(), equalTo(1));
assertTrue(getTaskManagerTracker().getRegisteredTaskManager(taskManagerConnection1.getInstanceID()).isPresent());
runInMainThread(() -> registerTaskManagerFuture2.complete(getSlotManager().registerTaskManager(taskManagerConnection2, new SlotReport(), DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE)));
assertThat(assertFutureCompleteAndReturn(registerTaskManagerFuture2), is(false));
assertThat(releaseResourceFuture.get(), is(taskManagerConnection2.getInstanceID()));
assertThat(getTaskManagerTracker().getRegisteredTaskManagers().size(), equalTo(1));
assertFalse(getTaskManagerTracker().getRegisteredTaskManager(taskManagerConnection2.getInstanceID()).isPresent());
});
}
};
}
Aggregations