use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class TaskExecutorExecutionDeploymentReconciliationTest method setupJobManagerGateway.
private static TestingJobMasterGateway setupJobManagerGateway(OneShotLatch slotOfferLatch, BlockingQueue<Set<ExecutionAttemptID>> deployedExecutionsFuture, CompletableFuture<Void> taskFinishedFuture, ResourceID jobManagerResourceId) {
return new TestingJobMasterGatewayBuilder().setRegisterTaskManagerFunction((ignoredJobId, ignoredTaskManagerRegistrationInformation) -> CompletableFuture.completedFuture(new JMTMRegistrationSuccess(jobManagerResourceId))).setOfferSlotsFunction((resourceID, slotOffers) -> {
slotOfferLatch.trigger();
return CompletableFuture.completedFuture(slotOffers);
}).setTaskManagerHeartbeatFunction((resourceID, taskExecutorToJobManagerHeartbeatPayload) -> {
ExecutionDeploymentReport executionDeploymentReport = taskExecutorToJobManagerHeartbeatPayload.getExecutionDeploymentReport();
deployedExecutionsFuture.add(executionDeploymentReport.getExecutions());
return FutureUtils.completedVoidFuture();
}).setUpdateTaskExecutionStateFunction(taskExecutionState -> {
if (taskExecutionState.getExecutionState() == ExecutionState.FINISHED) {
taskFinishedFuture.complete(null);
}
return CompletableFuture.completedFuture(Acknowledge.get());
}).build();
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class DefaultJobTableTest method closeJob_WillCloseJobServices.
@Test
public void closeJob_WillCloseJobServices() throws InterruptedException {
final OneShotLatch shutdownLibraryCacheManagerLatch = new OneShotLatch();
final TestingJobServices jobServices = TestingJobServices.newBuilder().setCloseRunnable(shutdownLibraryCacheManagerLatch::trigger).build();
final JobTable.Job job = jobTable.getOrCreateJob(jobId, () -> jobServices);
job.close();
shutdownLibraryCacheManagerLatch.await();
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class WebMonitorEndpointTest method cleansUpExpiredExecutionGraphs.
@Test
public void cleansUpExpiredExecutionGraphs() throws Exception {
final Configuration configuration = new Configuration();
configuration.setString(RestOptions.ADDRESS, "localhost");
configuration.setLong(WebOptions.REFRESH_INTERVAL, 5L);
final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
final long timeout = 10000L;
final OneShotLatch cleanupLatch = new OneShotLatch();
final TestingExecutionGraphCache executionGraphCache = TestingExecutionGraphCache.newBuilder().setCleanupRunnable(cleanupLatch::trigger).build();
try (final WebMonitorEndpoint<RestfulGateway> webMonitorEndpoint = new WebMonitorEndpoint<>(CompletableFuture::new, configuration, RestHandlerConfiguration.fromConfiguration(configuration), CompletableFuture::new, NoOpTransientBlobService.INSTANCE, executor, VoidMetricFetcher.INSTANCE, new TestingLeaderElectionService(), executionGraphCache, new TestingFatalErrorHandler())) {
webMonitorEndpoint.start();
// check that the cleanup will be triggered
cleanupLatch.await(timeout, TimeUnit.MILLISECONDS);
} finally {
ExecutorUtils.gracefulShutdown(timeout, TimeUnit.MILLISECONDS, executor);
}
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class JobListenerITCase method testExecuteAsyncCallsJobListenerOnStreamingEnvironment.
@Test
public void testExecuteAsyncCallsJobListenerOnStreamingEnvironment() throws Exception {
AtomicReference<JobID> jobIdReference = new AtomicReference<>();
OneShotLatch submissionLatch = new OneShotLatch();
StreamExecutionEnvironment env = new StreamExecutionEnvironment(getClientConfiguration());
env.registerJobListener(new JobListener() {
@Override
public void onJobSubmitted(JobClient jobClient, Throwable t) {
jobIdReference.set(jobClient.getJobID());
submissionLatch.trigger();
}
@Override
public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {
}
});
env.fromElements(1, 2, 3, 4, 5).addSink(new DiscardingSink<>());
JobClient jobClient = env.executeAsync();
submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
// when executing asynchronously we don't get an "executed" callback
assertThat(jobClient.getJobID(), is(jobIdReference.get()));
}
use of org.apache.flink.core.testutils.OneShotLatch in project flink by apache.
the class JobListenerITCase method testExecuteAsyncCallsJobListenerOnBatchEnvironment.
@Test
public void testExecuteAsyncCallsJobListenerOnBatchEnvironment() throws Exception {
AtomicReference<JobID> jobIdReference = new AtomicReference<>();
OneShotLatch submissionLatch = new OneShotLatch();
ExecutionEnvironment env = new ExecutionEnvironment(getClientConfiguration());
env.registerJobListener(new JobListener() {
@Override
public void onJobSubmitted(JobClient jobClient, Throwable t) {
jobIdReference.set(jobClient.getJobID());
submissionLatch.trigger();
}
@Override
public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {
}
});
env.fromElements(1, 2, 3, 4, 5).output(new DiscardingOutputFormat<>());
JobClient jobClient = env.executeAsync();
submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
// when executing asynchronously we don't get an "executed" callback
assertThat(jobClient.getJobID(), is(jobIdReference.get()));
}
Aggregations