use of org.apache.flink.util.FlinkException in project flink by apache.
the class DefaultDeclarativeSlotPoolTest method testReleaseSlotReturnsSlot.
@Test
public void testReleaseSlotReturnsSlot() throws InterruptedException {
final NewSlotsService notifyNewSlots = new NewSlotsService();
final DefaultDeclarativeSlotPool slotPool = createDefaultDeclarativeSlotPoolWithNewSlotsListener(notifyNewSlots);
final ResourceCounter resourceRequirements = createResourceRequirements();
final FreeSlotConsumer freeSlotConsumer = new FreeSlotConsumer();
final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setFreeSlotFunction(freeSlotConsumer).createTestingTaskExecutorGateway();
increaseRequirementsAndOfferSlotsToSlotPool(slotPool, resourceRequirements, new LocalTaskManagerLocation(), testingTaskExecutorGateway);
final Collection<? extends PhysicalSlot> physicalSlots = notifyNewSlots.takeNewSlots();
final PhysicalSlot physicalSlot = physicalSlots.iterator().next();
slotPool.releaseSlot(physicalSlot.getAllocationId(), new FlinkException("Test failure"));
final AllocationID freedSlot = Iterables.getOnlyElement(freeSlotConsumer.drainFreedSlots());
assertThat(freedSlot, is(physicalSlot.getAllocationId()));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class SingleLogicalSlotTest method testSlotRelease.
/**
* Tests that the slot release is only signaled after the owner has taken it back.
*/
@Test
public void testSlotRelease() {
final CompletableFuture<LogicalSlot> returnedSlotFuture = new CompletableFuture<>();
final CompletableFuture<Boolean> returnSlotResponseFuture = new CompletableFuture<>();
final WaitingSlotOwner waitingSlotOwner = new WaitingSlotOwner(returnedSlotFuture, returnSlotResponseFuture);
final CompletableFuture<?> terminalStateFuture = new CompletableFuture<>();
final CompletableFuture<?> failFuture = new CompletableFuture<>();
final ManualTestingPayload dummyPayload = new ManualTestingPayload(failFuture, terminalStateFuture);
final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(waitingSlotOwner);
assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
final CompletableFuture<?> releaseFuture = singleLogicalSlot.releaseSlot(new FlinkException("Test exception"));
assertThat(releaseFuture.isDone(), is(false));
assertThat(returnedSlotFuture.isDone(), is(false));
assertThat(failFuture.isDone(), is(true));
terminalStateFuture.complete(null);
assertThat(returnedSlotFuture.isDone(), is(true));
returnSlotResponseFuture.complete(true);
assertThat(releaseFuture.isDone(), is(true));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class SingleLogicalSlotTest method testAlive.
@Test
public void testAlive() throws Exception {
final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot();
final DummyPayload dummyPayload = new DummyPayload();
assertThat(singleLogicalSlot.isAlive(), is(true));
assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
assertThat(singleLogicalSlot.isAlive(), is(true));
final CompletableFuture<?> releaseFuture = singleLogicalSlot.releaseSlot(new FlinkException("Test exception"));
assertThat(singleLogicalSlot.isAlive(), is(false));
releaseFuture.get();
assertThat(singleLogicalSlot.isAlive(), is(false));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class DeclarativeSlotManagerTest method testSlotRequestFailure.
/**
* Tests that the SlotManager retries allocating a slot if the TaskExecutor#requestSlot call
* fails.
*/
@Test
public void testSlotRequestFailure() throws Exception {
final DefaultSlotTracker slotTracker = new DefaultSlotTracker();
try (final DeclarativeSlotManager slotManager = createDeclarativeSlotManagerBuilder().setSlotTracker(slotTracker).buildAndStartWithDirectExec()) {
ResourceRequirements requirements = createResourceRequirementsForSingleSlot();
slotManager.processResourceRequirements(requirements);
final BlockingQueue<Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId>> requestSlotQueue = new ArrayBlockingQueue<>(1);
final BlockingQueue<CompletableFuture<Acknowledge>> responseQueue = new ArrayBlockingQueue<>(2);
final CompletableFuture<Acknowledge> firstManualSlotRequestResponse = new CompletableFuture<>();
responseQueue.offer(firstManualSlotRequestResponse);
final CompletableFuture<Acknowledge> secondManualSlotRequestResponse = new CompletableFuture<>();
responseQueue.offer(secondManualSlotRequestResponse);
final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setRequestSlotFunction(slotIDJobIDAllocationIDStringResourceManagerIdTuple6 -> {
requestSlotQueue.offer(slotIDJobIDAllocationIDStringResourceManagerIdTuple6);
try {
return responseQueue.take();
} catch (InterruptedException ignored) {
return FutureUtils.completedExceptionally(new FlinkException("Response queue was interrupted."));
}
}).createTestingTaskExecutorGateway();
final ResourceID taskExecutorResourceId = ResourceID.generate();
final TaskExecutorConnection taskExecutionConnection = new TaskExecutorConnection(taskExecutorResourceId, testingTaskExecutorGateway);
final SlotReport slotReport = new SlotReport(createFreeSlotStatus(new SlotID(taskExecutorResourceId, 0)));
slotManager.registerTaskManager(taskExecutionConnection, slotReport, ResourceProfile.ANY, ResourceProfile.ANY);
final Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId> firstRequest = requestSlotQueue.take();
// fail first request
firstManualSlotRequestResponse.completeExceptionally(new SlotAllocationException("Test exception"));
final Tuple6<SlotID, JobID, AllocationID, ResourceProfile, String, ResourceManagerId> secondRequest = requestSlotQueue.take();
assertThat(secondRequest.f1, equalTo(firstRequest.f1));
assertThat(secondRequest.f0, equalTo(firstRequest.f0));
secondManualSlotRequestResponse.complete(Acknowledge.get());
final DeclarativeTaskManagerSlot slot = slotTracker.getSlot(secondRequest.f0);
assertThat(slot.getState(), equalTo(SlotState.ALLOCATED));
assertThat(slot.getJobId(), equalTo(secondRequest.f1));
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class ResourceManagerTest method testDisconnectJobManagerClearsRequirements.
@Test
public void testDisconnectJobManagerClearsRequirements() throws Exception {
final TestingJobMasterGateway jobMasterGateway = new TestingJobMasterGatewayBuilder().setAddress(UUID.randomUUID().toString()).build();
rpcService.registerGateway(jobMasterGateway.getAddress(), jobMasterGateway);
final JobLeaderIdService jobLeaderIdService = TestingJobLeaderIdService.newBuilder().setGetLeaderIdFunction(jobId -> CompletableFuture.completedFuture(jobMasterGateway.getFencingToken())).build();
final CompletableFuture<JobID> clearRequirementsFuture = new CompletableFuture<>();
final SlotManager slotManager = new TestingSlotManagerBuilder().setClearRequirementsConsumer(clearRequirementsFuture::complete).createSlotManager();
resourceManager = new ResourceManagerBuilder().withJobLeaderIdService(jobLeaderIdService).withSlotManager(slotManager).buildAndStart();
final JobID jobId = JobID.generate();
final ResourceManagerGateway resourceManagerGateway = resourceManager.getSelfGateway(ResourceManagerGateway.class);
resourceManagerGateway.registerJobMaster(jobMasterGateway.getFencingToken(), ResourceID.generate(), jobMasterGateway.getAddress(), jobId, TIMEOUT).get();
resourceManagerGateway.declareRequiredResources(jobMasterGateway.getFencingToken(), ResourceRequirements.create(jobId, jobMasterGateway.getAddress(), Collections.singleton(ResourceRequirement.create(ResourceProfile.UNKNOWN, 1))), TIMEOUT).get();
resourceManagerGateway.disconnectJobManager(jobId, JobStatus.FINISHED, new FlinkException("Test exception"));
assertThat(clearRequirementsFuture.get(5, TimeUnit.SECONDS), is(jobId));
}
Aggregations