use of org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testAllocationUpdatesIgnoredIfTaskExecutorUnregistered.
// ---------------------------------------------------------------------------------------------
// Allocation update
// ---------------------------------------------------------------------------------------------
/**
* Verify that the ack of request slot form unregistered task manager will not cause system
* breakdown.
*/
@Test
public void testAllocationUpdatesIgnoredIfTaskExecutorUnregistered() throws Exception {
final CompletableFuture<Acknowledge> slotRequestFuture = new CompletableFuture<>();
final CompletableFuture<Void> slotRequestCallFuture = new CompletableFuture<>();
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(ignored -> {
slotRequestCallFuture.complete(null);
return slotRequestFuture;
}).createTestingTaskExecutorGateway();
// The fatal error handler will exit the system if there is any exceptions in handling the
// ack of request slot. We need the security manager to verify that would not happen.
final SystemExitTrackingSecurityManager trackingSecurityManager = new SystemExitTrackingSecurityManager();
System.setSecurityManager(trackingSecurityManager);
final JobID jobId = new JobID();
final ResourceID taskExecutorResourceId = ResourceID.generate();
final TaskExecutorConnection taskExecutionConnection = new TaskExecutorConnection(taskExecutorResourceId, taskExecutorGateway);
final SlotReport slotReport = new SlotReport();
new Context() {
{
runTest(() -> {
runInMainThread(() -> {
getSlotManager().processResourceRequirements(createResourceRequirements(jobId, 1));
getSlotManager().registerTaskManager(taskExecutionConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
});
assertFutureCompleteAndReturn(slotRequestCallFuture);
runInMainThread(() -> {
getSlotManager().unregisterTaskManager(taskExecutionConnection.getInstanceID(), TEST_EXCEPTION);
slotRequestFuture.complete(Acknowledge.get());
});
assertThat(trackingSecurityManager.getSystemExitFuture().isDone(), is(false));
});
}
};
System.setSecurityManager(null);
}
use of org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testSlotRequestFailure.
// ---------------------------------------------------------------------------------------------
// Slot allocation failure handling
// ---------------------------------------------------------------------------------------------
/**
* Tests that the SlotManager retries allocating a slot if the TaskExecutor#requestSlot call
* fails.
*/
@Test
public void testSlotRequestFailure() throws Exception {
final JobID jobId = new JobID();
final ResourceRequirements resourceRequirements = createResourceRequirementsForSingleSlot(jobId);
final CompletableFuture<Acknowledge> slotRequestFuture1 = new CompletableFuture<>();
final CompletableFuture<Acknowledge> slotRequestFuture2 = CompletableFuture.completedFuture(Acknowledge.get());
final Iterator<CompletableFuture<Acknowledge>> slotRequestFutureIterator = Arrays.asList(slotRequestFuture1, slotRequestFuture2).iterator();
final ArrayBlockingQueue<AllocationID> allocationIds = new ArrayBlockingQueue<>(2);
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(FunctionUtils.uncheckedFunction(requestSlotParameters -> {
allocationIds.put(requestSlotParameters.f2);
return slotRequestFutureIterator.next();
})).createTestingTaskExecutorGateway();
final ResourceID resourceId = ResourceID.generate();
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceId, taskExecutorGateway);
final SlotReport slotReport = new SlotReport();
new Context() {
{
runTest(() -> {
runInMainThread(() -> {
getSlotManager().registerTaskManager(taskManagerConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
getSlotManager().processResourceRequirements(resourceRequirements);
});
final AllocationID firstAllocationId = allocationIds.take();
assertThat(allocationIds, is(empty()));
// let the first attempt fail --> this should trigger a second attempt
runInMainThread(() -> slotRequestFuture1.completeExceptionally(new SlotAllocationException("Test exception.")));
final AllocationID secondAllocationId = allocationIds.take();
assertThat(allocationIds, is(empty()));
final TaskManagerSlotInformation slot = getTaskManagerTracker().getAllocatedOrPendingSlot(secondAllocationId).get();
assertEquals(jobId, slot.getJobId());
assertFalse(getTaskManagerTracker().getAllocatedOrPendingSlot(firstAllocationId).isPresent());
});
}
};
}
use of org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway in project flink by apache.
the class AbstractFineGrainedSlotManagerITCase method testAllocationUpdatesIgnoredIfSlotMarkedAsAllocatedAfterSlotReport.
@Test
public void testAllocationUpdatesIgnoredIfSlotMarkedAsAllocatedAfterSlotReport() throws Exception {
final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>();
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(tuple6 -> {
allocationIdFuture.complete(tuple6.f2);
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
// The fatal error handler will exit the system if there is any exceptions in handling the
// ack of request slot. We need the security manager to verify that would not happen.
final SystemExitTrackingSecurityManager trackingSecurityManager = new SystemExitTrackingSecurityManager();
System.setSecurityManager(trackingSecurityManager);
final TaskExecutorConnection taskExecutionConnection = new TaskExecutorConnection(ResourceID.generate(), taskExecutorGateway);
final SlotReport slotReport = new SlotReport();
new Context() {
{
runTest(() -> {
runInMainThread(() -> {
getSlotManager().processResourceRequirements(createResourceRequirements(new JobID(), 1));
getSlotManager().registerTaskManager(taskExecutionConnection, slotReport, DEFAULT_TOTAL_RESOURCE_PROFILE, DEFAULT_SLOT_RESOURCE_PROFILE);
});
final AllocationID allocationId = assertFutureCompleteAndReturn(allocationIdFuture);
runInMainThread(() -> getSlotManager().reportSlotStatus(taskExecutionConnection.getInstanceID(), new SlotReport(createAllocatedSlotStatus(allocationId, DEFAULT_SLOT_RESOURCE_PROFILE))));
assertThat(trackingSecurityManager.getSystemExitFuture().isDone(), is(false));
});
}
};
System.setSecurityManager(null);
}
use of org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway in project flink by apache.
the class DeclarativeSlotManagerTest method testAllocationUpdatesIgnoredIfSlotMarkedAsPendingForOtherJob.
@Test
public void testAllocationUpdatesIgnoredIfSlotMarkedAsPendingForOtherJob() throws Exception {
final DefaultSlotTracker slotTracker = new DefaultSlotTracker();
final CompletableFuture<AllocationID> firstSlotAllocationIdFuture = new CompletableFuture<>();
final CompletableFuture<Acknowledge> firstSlotRequestAcknowledgeFuture = new CompletableFuture<>();
final Iterator<CompletableFuture<Acknowledge>> slotRequestAcknowledgeFutures = Arrays.asList(firstSlotRequestAcknowledgeFuture, new CompletableFuture<Acknowledge>()).iterator();
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(requestSlotParameters -> {
firstSlotAllocationIdFuture.complete(requestSlotParameters.f2);
return slotRequestAcknowledgeFutures.next();
}).createTestingTaskExecutorGateway();
try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setSlotTracker(slotTracker).buildAndStart(ResourceManagerId.generate(), ComponentMainThreadExecutorServiceAdapter.forMainThread(), new TestingResourceActionsBuilder().build())) {
final TaskExecutorConnection taskExecutionConnection = createTaskExecutorConnection(taskExecutorGateway);
final SlotReport slotReport = createSlotReport(taskExecutionConnection.getResourceID(), 1);
final SlotID slotId = Iterators.getOnlyElement(slotReport.iterator()).getSlotID();
// register task executor
slotManager.registerTaskManager(taskExecutionConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
slotManager.reportSlotStatus(taskExecutionConnection.getInstanceID(), createSlotReport(taskExecutionConnection.getResourceID(), 1));
// triggers the allocation of a slot
final JobID firstJobId = new JobID();
slotManager.processResourceRequirements(createResourceRequirements(firstJobId, 1));
// clear requirements immediately to ensure the slot will not get re-allocated to the
// same job
slotManager.processResourceRequirements(ResourceRequirements.empty(firstJobId, "foobar"));
// when the slot is freed it will be re-assigned to this second job
slotManager.processResourceRequirements(createResourceRequirements(new JobID(), 1));
slotManager.freeSlot(slotId, firstSlotAllocationIdFuture.get());
// acknowledge the first allocation
// this should fail if the acknowledgement is not ignored
firstSlotRequestAcknowledgeFuture.complete(Acknowledge.get());
// sanity check that the acknowledge was really ignored
assertThat(slotTracker.getSlot(slotId).getJobId(), is(not(firstJobId)));
}
}
use of org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway in project flink by apache.
the class DeclarativeSlotManagerTest method testAllocationUpdatesIgnoredIfTaskExecutorUnregistered.
@Test
public void testAllocationUpdatesIgnoredIfTaskExecutorUnregistered() throws Exception {
final ManuallyTriggeredScheduledExecutorService executor = new ManuallyTriggeredScheduledExecutorService();
final ResourceTracker resourceTracker = new DefaultResourceTracker();
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(ignored -> CompletableFuture.completedFuture(Acknowledge.get())).createTestingTaskExecutorGateway();
final SystemExitTrackingSecurityManager trackingSecurityManager = new SystemExitTrackingSecurityManager();
System.setSecurityManager(trackingSecurityManager);
try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setResourceTracker(resourceTracker).buildAndStart(ResourceManagerId.generate(), executor, new TestingResourceActionsBuilder().build())) {
JobID jobId = new JobID();
slotManager.processResourceRequirements(createResourceRequirements(jobId, 1));
final TaskExecutorConnection taskExecutionConnection = createTaskExecutorConnection(taskExecutorGateway);
final SlotReport slotReport = createSlotReport(taskExecutionConnection.getResourceID(), 1);
slotManager.registerTaskManager(taskExecutionConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
slotManager.unregisterTaskManager(taskExecutionConnection.getInstanceID(), TEST_EXCEPTION);
executor.triggerAll();
assertThat(trackingSecurityManager.getSystemExitFuture().isDone(), is(false));
} finally {
System.setSecurityManager(null);
}
}
Aggregations