Search in sources :

Example 1 with TestingJobGraphStore

use of org.apache.flink.runtime.testutils.TestingJobGraphStore in project flink by apache.

the class DispatcherTest method testOnRemovedJobGraphDoesNotCleanUpHAFiles.

@Test
public void testOnRemovedJobGraphDoesNotCleanUpHAFiles() throws Exception {
    final CompletableFuture<JobID> removeJobGraphFuture = new CompletableFuture<>();
    final CompletableFuture<JobID> releaseJobGraphFuture = new CompletableFuture<>();
    final TestingJobGraphStore testingJobGraphStore = TestingJobGraphStore.newBuilder().setGlobalCleanupFunction((jobId, executor) -> {
        removeJobGraphFuture.complete(jobId);
        return FutureUtils.completedVoidFuture();
    }).setLocalCleanupFunction((jobId, executor) -> {
        releaseJobGraphFuture.complete(jobId);
        return FutureUtils.completedVoidFuture();
    }).build();
    testingJobGraphStore.start(null);
    dispatcher = createTestingDispatcherBuilder().setRecoveredJobs(Collections.singleton(jobGraph)).setJobGraphWriter(testingJobGraphStore).build();
    dispatcher.start();
    final CompletableFuture<Void> processFuture = dispatcher.onRemovedJobGraph(jobGraph.getJobID());
    processFuture.join();
    assertThat(releaseJobGraphFuture.get(), is(jobGraph.getJobID()));
    try {
        removeJobGraphFuture.get(10L, TimeUnit.MILLISECONDS);
        fail("onRemovedJobGraph should not remove the job from the JobGraphStore.");
    } catch (TimeoutException expected) {
    }
}
Also used : Arrays(java.util.Arrays) JobSubmissionException(org.apache.flink.runtime.client.JobSubmissionException) Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobManagerJobMetricGroupFactory(org.apache.flink.runtime.jobmaster.factories.JobManagerJobMetricGroupFactory) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) DefaultJobMasterServiceProcessFactory(org.apache.flink.runtime.jobmaster.factories.DefaultJobMasterServiceProcessFactory) Duration(java.time.Duration) Is.is(org.hamcrest.core.Is.is) TestingJobMasterGatewayBuilder(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder) TestingJobManagerRunner(org.apache.flink.runtime.jobmaster.TestingJobManagerRunner) Path(java.nio.file.Path) BlockingQueue(java.util.concurrent.BlockingQueue) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) CheckpointMetadata(org.apache.flink.runtime.checkpoint.metadata.CheckpointMetadata) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) TimeUtils(org.apache.flink.util.TimeUtils) Assert.assertFalse(org.junit.Assert.assertFalse) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) JobMasterServiceLeadershipRunner(org.apache.flink.runtime.jobmaster.JobMasterServiceLeadershipRunner) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) FlinkException(org.apache.flink.util.FlinkException) BlobServer(org.apache.flink.runtime.blob.BlobServer) JobStatus(org.apache.flink.api.common.JobStatus) LibraryCacheManager(org.apache.flink.runtime.execution.librarycache.LibraryCacheManager) RpcService(org.apache.flink.runtime.rpc.RpcService) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) PermanentBlobKey(org.apache.flink.runtime.blob.PermanentBlobKey) Before(org.junit.Before) JobManagerRunnerResult(org.apache.flink.runtime.jobmaster.JobManagerRunnerResult) CheckpointStorageLocation(org.apache.flink.runtime.state.CheckpointStorageLocation) Files(java.nio.file.Files) JobMasterServiceProcessFactory(org.apache.flink.runtime.jobmaster.factories.JobMasterServiceProcessFactory) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) ErrorInfo(org.apache.flink.runtime.executiongraph.ErrorInfo) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) JobResultEntry(org.apache.flink.runtime.highavailability.JobResultEntry) TestingJobMasterServiceFactory(org.apache.flink.runtime.jobmaster.factories.TestingJobMasterServiceFactory) JobID(org.apache.flink.api.common.JobID) Paths(java.nio.file.Paths) Assert(org.junit.Assert) ArrayDeque(java.util.ArrayDeque) TestingHighAvailabilityServices(org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices) Assert.assertEquals(org.junit.Assert.assertEquals) Deadline(org.apache.flink.api.common.time.Deadline) NoSuchFileException(java.nio.file.NoSuchFileException) URISyntaxException(java.net.URISyntaxException) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CheckpointStorage(org.apache.flink.runtime.state.CheckpointStorage) Assert.assertThat(org.junit.Assert.assertThat) InstantiationUtil(org.apache.flink.util.InstantiationUtil) After(org.junit.After) JobMasterService(org.apache.flink.runtime.jobmaster.JobMasterService) Assertions(org.assertj.core.api.Assertions) Checkpoints(org.apache.flink.runtime.checkpoint.Checkpoints) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) JobDetails(org.apache.flink.runtime.messages.webmonitor.JobDetails) CompletedCheckpointStorageLocation(org.apache.flink.runtime.state.CompletedCheckpointStorageLocation) Collection(java.util.Collection) FlinkJobTerminatedWithoutCancellationException(org.apache.flink.runtime.messages.FlinkJobTerminatedWithoutCancellationException) UUID(java.util.UUID) Preconditions(org.apache.flink.util.Preconditions) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) CheckpointMetadataOutputStream(org.apache.flink.runtime.state.CheckpointMetadataOutputStream) TestingCleanupRunnerFactory(org.apache.flink.runtime.dispatcher.cleanup.TestingCleanupRunnerFactory) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) Matchers.equalTo(org.hamcrest.Matchers.equalTo) JobManagerSharedServices(org.apache.flink.runtime.jobmaster.JobManagerSharedServices) Queue(java.util.Queue) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) CheckpointStorageCoordinatorView(org.apache.flink.runtime.state.CheckpointStorageCoordinatorView) LeaderElectionService(org.apache.flink.runtime.leaderelection.LeaderElectionService) Assert.assertThrows(org.junit.Assert.assertThrows) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobMasterGateway(org.apache.flink.runtime.jobmaster.JobMasterGateway) JobResult(org.apache.flink.runtime.jobmaster.JobResult) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) Nonnull(javax.annotation.Nonnull) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) JobGraphBuilder(org.apache.flink.runtime.jobgraph.JobGraphBuilder) TestingLeaderElectionService(org.apache.flink.runtime.leaderelection.TestingLeaderElectionService) ArchivedExecutionGraphBuilder(org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder) Configuration(org.apache.flink.configuration.Configuration) Matchers(org.hamcrest.Matchers) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) TestingJobMasterService(org.apache.flink.runtime.jobmaster.TestingJobMasterService) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) TimeUnit(java.util.concurrent.TimeUnit) MultipleJobsDetails(org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails) JobManagerRunner(org.apache.flink.runtime.jobmaster.JobManagerRunner) CommonTestUtils(org.apache.flink.runtime.testutils.CommonTestUtils) Collections(java.util.Collections) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException) NoOpInvokable(org.apache.flink.runtime.testtasks.NoOpInvokable) CompletableFuture(java.util.concurrent.CompletableFuture) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) JobID(org.apache.flink.api.common.JobID) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 2 with TestingJobGraphStore

use of org.apache.flink.runtime.testutils.TestingJobGraphStore in project flink by apache.

the class DispatcherTest method testPersistedJobGraphWhenDispatcherIsShutDown.

@Test
public void testPersistedJobGraphWhenDispatcherIsShutDown() throws Exception {
    final TestingJobGraphStore submittedJobGraphStore = TestingJobGraphStore.newBuilder().build();
    submittedJobGraphStore.start(null);
    haServices.setJobGraphStore(submittedJobGraphStore);
    dispatcher = createTestingDispatcherBuilder().setJobGraphWriter(submittedJobGraphStore).build();
    dispatcher.start();
    final DispatcherGateway dispatcherGateway = dispatcher.getSelfGateway(DispatcherGateway.class);
    dispatcherGateway.submitJob(jobGraph, TIMEOUT).get();
    assertThat(dispatcher.getNumberJobs(TIMEOUT).get(), Matchers.is(1));
    dispatcher.close();
    assertThat(submittedJobGraphStore.contains(jobGraph.getJobID()), Matchers.is(true));
}
Also used : TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) Test(org.junit.Test)

Example 3 with TestingJobGraphStore

use of org.apache.flink.runtime.testutils.TestingJobGraphStore in project flink by apache.

the class DispatcherResourceCleanerFactoryTest method createJobGraphWriter.

private JobGraphWriter createJobGraphWriter() throws Exception {
    jobGraphWriterLocalCleanupFuture = new CompletableFuture<>();
    jobGraphWriterGlobalCleanupFuture = new CompletableFuture<>();
    final TestingJobGraphStore jobGraphStore = TestingJobGraphStore.newBuilder().setGlobalCleanupFunction((jobId, executor) -> {
        jobGraphWriterGlobalCleanupFuture.complete(jobId);
        return FutureUtils.completedVoidFuture();
    }).setLocalCleanupFunction((jobId, ignoredExecutor) -> {
        jobGraphWriterLocalCleanupFuture.complete(jobId);
        return FutureUtils.completedVoidFuture();
    }).build();
    jobGraphStore.start(null);
    return jobGraphStore;
}
Also used : ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter) BeforeEach(org.junit.jupiter.api.BeforeEach) BlobServer(org.apache.flink.runtime.blob.BlobServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) JobGraphWriter(org.apache.flink.runtime.jobmanager.JobGraphWriter) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) Executor(java.util.concurrent.Executor) TestingJobManagerRunnerRegistry(org.apache.flink.runtime.dispatcher.TestingJobManagerRunnerRegistry) Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) TestingBlobStoreBuilder(org.apache.flink.runtime.blob.TestingBlobStoreBuilder) File(java.io.File) JobManagerRunnerRegistry(org.apache.flink.runtime.dispatcher.JobManagerRunnerRegistry) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Executors(org.apache.flink.util.concurrent.Executors) JobID(org.apache.flink.api.common.JobID) TestingHighAvailabilityServices(org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices) JobManagerMetricGroup(org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup) TestingJobGraphStore(org.apache.flink.runtime.testutils.TestingJobGraphStore)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 JobID (org.apache.flink.api.common.JobID)2 Configuration (org.apache.flink.configuration.Configuration)2 BlobServer (org.apache.flink.runtime.blob.BlobServer)2 TestingJobGraphStore (org.apache.flink.runtime.testutils.TestingJobGraphStore)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Duration (java.time.Duration)1 ArrayDeque (java.util.ArrayDeque)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1