use of org.apache.flink.util.FlinkException in project flink by apache.
the class JobMasterTest method testTaskExecutorNotReleasedOnFailedAllocationIfPartitionIsAllocated.
@Test
public void testTaskExecutorNotReleasedOnFailedAllocationIfPartitionIsAllocated() throws Exception {
final JobManagerSharedServices jobManagerSharedServices = new TestingJobManagerSharedServicesBuilder().build();
final JobGraph jobGraph = JobGraphTestUtils.singleNoOpJobGraph();
final LocalUnresolvedTaskManagerLocation taskManagerUnresolvedLocation = new LocalUnresolvedTaskManagerLocation();
final AtomicBoolean isTrackingPartitions = new AtomicBoolean(true);
final TestingJobMasterPartitionTracker partitionTracker = new TestingJobMasterPartitionTracker();
partitionTracker.setIsTrackingPartitionsForFunction(ignored -> isTrackingPartitions.get());
final JobMaster jobMaster = new JobMasterBuilder(jobGraph, rpcService).withConfiguration(configuration).withHighAvailabilityServices(haServices).withJobManagerSharedServices(jobManagerSharedServices).withHeartbeatServices(heartbeatServices).withPartitionTrackerFactory(ignored -> partitionTracker).createJobMaster();
final CompletableFuture<JobID> disconnectTaskExecutorFuture = new CompletableFuture<>();
final CompletableFuture<AllocationID> freedSlotFuture = new CompletableFuture<>();
final TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setFreeSlotFunction((allocationID, throwable) -> {
freedSlotFuture.complete(allocationID);
return CompletableFuture.completedFuture(Acknowledge.get());
}).setDisconnectJobManagerConsumer((jobID, throwable) -> disconnectTaskExecutorFuture.complete(jobID)).createTestingTaskExecutorGateway();
try {
jobMaster.start();
final JobMasterGateway jobMasterGateway = jobMaster.getSelfGateway(JobMasterGateway.class);
final Collection<SlotOffer> slotOffers = registerSlotsAtJobMaster(1, jobMasterGateway, jobGraph.getJobID(), testingTaskExecutorGateway, taskManagerUnresolvedLocation);
// check that we accepted the offered slot
assertThat(slotOffers, hasSize(1));
final AllocationID allocationId = slotOffers.iterator().next().getAllocationId();
jobMasterGateway.failSlot(taskManagerUnresolvedLocation.getResourceID(), allocationId, new FlinkException("Fail allocation test exception"));
// we should free the slot, but not disconnect from the TaskExecutor as we still have an
// allocated partition
assertThat(freedSlotFuture.get(), equalTo(allocationId));
// trigger some request to guarantee ensure the slotAllocationFailure processing if
// complete
jobMasterGateway.requestJobStatus(Time.seconds(5)).get();
assertThat(disconnectTaskExecutorFuture.isDone(), is(false));
} finally {
RpcUtils.terminateRpcEndpoint(jobMaster, testingTimeout);
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class JobMasterServiceLeadershipRunnerTest method testJobMasterServiceProcessClosingExceptionIsForwardedToResultFuture.
@Test
public void testJobMasterServiceProcessClosingExceptionIsForwardedToResultFuture() throws Exception {
final CompletableFuture<Void> terminationFuture = new CompletableFuture<>();
final JobMasterServiceLeadershipRunner jobManagerRunner = newJobMasterServiceLeadershipRunnerBuilder().withSingleJobMasterServiceProcess(TestingJobMasterServiceProcess.newBuilder().setTerminationFuture(terminationFuture).withManualTerminationFutureCompletion().build()).build();
jobManagerRunner.start();
leaderElectionService.isLeader(UUID.randomUUID());
leaderElectionService.notLeader();
final FlinkException testException = new FlinkException("Test exception");
terminationFuture.completeExceptionally(testException);
assertThat(jobManagerRunner.getResultFuture(), FlinkMatchers.futureWillCompleteExceptionally(cause -> ExceptionUtils.findThrowable(cause, testException::equals).isPresent(), Duration.ofMillis(5L), "Result future should be completed exceptionally."));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class JobMasterServiceLeadershipRunnerTest method testJobMasterCreationFailureCompletesJobManagerRunnerWithInitializationError.
@Test
public void testJobMasterCreationFailureCompletesJobManagerRunnerWithInitializationError() throws Exception {
final FlinkException testException = new FlinkException("Test exception");
final CompletableFuture<JobManagerRunnerResult> completedResultFuture = CompletableFuture.completedFuture(JobManagerRunnerResult.forInitializationFailure(createFailedExecutionGraphInfo(testException), testException));
final JobMasterServiceLeadershipRunner jobManagerRunner = newJobMasterServiceLeadershipRunnerBuilder().withSingleJobMasterServiceProcess(TestingJobMasterServiceProcess.newBuilder().setJobManagerRunnerResultFuture(completedResultFuture).build()).build();
jobManagerRunner.start();
leaderElectionService.isLeader(UUID.randomUUID());
final JobManagerRunnerResult jobManagerRunnerResult = jobManagerRunner.getResultFuture().join();
assertTrue(jobManagerRunnerResult.isInitializationFailure());
assertThat(jobManagerRunnerResult.getInitializationFailure(), containsCause(testException));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class JobMasterServiceLeadershipRunnerTest method testExceptionallyCompletedResultFutureFromJobMasterServiceProcessIsForwarded.
@Test
public void testExceptionallyCompletedResultFutureFromJobMasterServiceProcessIsForwarded() throws Exception {
final CompletableFuture<JobManagerRunnerResult> resultFuture = new CompletableFuture<>();
final TestingJobMasterServiceProcess testingJobMasterServiceProcess = TestingJobMasterServiceProcess.newBuilder().setJobManagerRunnerResultFuture(resultFuture).build();
JobManagerRunner jobManagerRunner = newJobMasterServiceLeadershipRunnerBuilder().withSingleJobMasterServiceProcess(testingJobMasterServiceProcess).build();
jobManagerRunner.start();
leaderElectionService.isLeader(UUID.randomUUID()).get();
final FlinkException cause = new FlinkException("The JobMasterService failed unexpectedly.");
resultFuture.completeExceptionally(cause);
assertThat(jobManagerRunner.getResultFuture(), FlinkMatchers.futureWillCompleteExceptionally(cause::equals, Duration.ofMillis(5L), "Wrong cause of failed result future"));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class JobMasterServiceLeadershipRunnerTest method testCancellationFailsWhenInitializationFails.
@Test
public void testCancellationFailsWhenInitializationFails() throws Exception {
final FlinkException testException = new FlinkException("test exception");
runCancellationFailsTest(resultFuture -> resultFuture.complete(JobManagerRunnerResult.forInitializationFailure(createFailedExecutionGraphInfo(testException), testException)));
}
Aggregations