Search in sources :

Example 16 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class AdaptiveSchedulerSimpleITCase method testSchedulingOfSimpleJob.

@Test
public void testSchedulingOfSimpleJob() throws Exception {
    final MiniCluster miniCluster = MINI_CLUSTER_RESOURCE.getMiniCluster();
    final JobGraph jobGraph = createJobGraph();
    miniCluster.submitJob(jobGraph).join();
    final JobResult jobResult = miniCluster.requestJobResult(jobGraph.getJobID()).join();
    final JobExecutionResult jobExecutionResult = jobResult.toJobExecutionResult(getClass().getClassLoader());
    assertTrue(jobResult.isSuccess());
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobResult(org.apache.flink.runtime.jobmaster.JobResult) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) Test(org.junit.Test)

Example 17 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class CommonTestUtils method waitForSubtasksToFinish.

public static void waitForSubtasksToFinish(MiniCluster miniCluster, JobID job, JobVertexID id, boolean allSubtasks) throws Exception {
    Predicate<AccessExecutionVertex> subtaskPredicate = subtask -> {
        ExecutionState state = subtask.getExecutionState();
        if (state == ExecutionState.FINISHED) {
            return true;
        } else if (state.isTerminal()) {
            throw new RuntimeException(format("Sub-Task %s is already in a terminal state %s", subtask, state));
        } else {
            return false;
        }
    };
    waitUntilCondition(() -> {
        AccessExecutionGraph graph = getGraph(miniCluster, job);
        if (graph.getState() != JobStatus.RUNNING) {
            return false;
        }
        Stream<AccessExecutionVertex> vertexStream = Arrays.stream(graph.getAllVertices().values().stream().filter(jv -> jv.getJobVertexId().equals(id)).findAny().orElseThrow(() -> new RuntimeException("Vertex not found " + id)).getTaskVertices());
        return allSubtasks ? vertexStream.allMatch(subtaskPredicate) : vertexStream.anyMatch(subtaskPredicate);
    }, Deadline.fromNow(Duration.of(1, ChronoUnit.MINUTES)));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Deadline(org.apache.flink.api.common.time.Deadline) Arrays(java.util.Arrays) BufferedInputStream(java.io.BufferedInputStream) FileUtils(org.apache.flink.util.FileUtils) AccessExecutionVertex(org.apache.flink.runtime.executiongraph.AccessExecutionVertex) TimeoutException(java.util.concurrent.TimeoutException) JobStatus(org.apache.flink.api.common.JobStatus) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) Duration(java.time.Duration) Map(java.util.Map) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) ManagementFactory(java.lang.management.ManagementFactory) PrintWriter(java.io.PrintWriter) RuntimeMXBean(java.lang.management.RuntimeMXBean) Predicate(java.util.function.Predicate) JobDetailsInfo(org.apache.flink.runtime.rest.messages.job.JobDetailsInfo) StringWriter(java.io.StringWriter) Collection(java.util.Collection) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) FileWriter(java.io.FileWriter) ErrorInfo(org.apache.flink.runtime.executiongraph.ErrorInfo) IOException(java.io.IOException) JobClient(org.apache.flink.core.execution.JobClient) File(java.io.File) String.format(java.lang.String.format) AccessExecutionGraph(org.apache.flink.runtime.executiongraph.AccessExecutionGraph) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) JobID(org.apache.flink.api.common.JobID) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) SupplierWithException(org.apache.flink.util.function.SupplierWithException) InputStream(java.io.InputStream) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) AccessExecutionGraph(org.apache.flink.runtime.executiongraph.AccessExecutionGraph) AccessExecutionVertex(org.apache.flink.runtime.executiongraph.AccessExecutionVertex)

Example 18 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class UnalignedCheckpointFailureHandlingITCase method testCheckpointSuccessAfterFailure.

@Test
public void testCheckpointSuccessAfterFailure() throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    TestCheckpointStorage storage = new TestCheckpointStorage(new JobManagerCheckpointStorage(), sharedObjects, temporaryFolder);
    configure(env, storage);
    buildGraph(env);
    JobClient jobClient = env.executeAsync();
    JobID jobID = jobClient.getJobID();
    MiniCluster miniCluster = miniClusterResource.getMiniCluster();
    waitForJobStatus(jobClient, singletonList(RUNNING), fromNow(Duration.ofSeconds(30)));
    waitForAllTaskRunning(miniCluster, jobID, false);
    triggerFailingCheckpoint(jobID, TestException.class, miniCluster);
    miniCluster.triggerCheckpoint(jobID).get();
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobClient(org.apache.flink.core.execution.JobClient) JobManagerCheckpointStorage(org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 19 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class CheckpointRestoreWithUidHashITCase method testRestoreFromSavepointBySetUidHash.

@Test
public void testRestoreFromSavepointBySetUidHash() throws Exception {
    final int maxNumber = 100;
    try (MiniCluster miniCluster = new MiniCluster(createMiniClusterConfig())) {
        miniCluster.start();
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        JobGraph firstJob = createJobGraph(env, StatefulSourceBehavior.HOLD_AFTER_CHECKPOINT_ON_FIRST_RUN, maxNumber, "test-uid", null, null);
        JobID jobId = miniCluster.submitJob(firstJob).get().getJobID();
        waitForAllTaskRunning(miniCluster, jobId, false);
        // The source would emit some records and start waiting for the checkpoint to happen.
        // With this latch we ensures the savepoint happens in a fixed position and no following
        // records are emitted after savepoint is triggered.
        startWaitingForCheckpointLatch.get().await();
        String savepointPath = miniCluster.triggerSavepoint(jobId, TMP_FOLDER.newFolder().getAbsolutePath(), true, SavepointFormatType.CANONICAL).get();
        // Get the operator id
        List<OperatorIDPair> operatorIds = firstJob.getVerticesSortedTopologicallyFromSources().get(0).getOperatorIDs();
        OperatorIDPair sourceOperatorIds = operatorIds.get(operatorIds.size() - 1);
        JobGraph secondJob = createJobGraph(env, StatefulSourceBehavior.PROCESS_ONLY, maxNumber, null, sourceOperatorIds.getGeneratedOperatorID().toHexString(), savepointPath);
        miniCluster.executeJobBlocking(secondJob);
    }
    assertThat(result.get(), contains(IntStream.range(0, maxNumber).boxed().toArray()));
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) JobID(org.apache.flink.api.common.JobID) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair) Test(org.junit.Test)

Example 20 with MiniCluster

use of org.apache.flink.runtime.minicluster.MiniCluster in project flink by apache.

the class CheckpointRestoreWithUidHashITCase method testRestoreCheckpointAfterFailoverWithUidHashSet.

@Test
public void testRestoreCheckpointAfterFailoverWithUidHashSet() throws Exception {
    final int maxNumber = 100;
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(2, 500));
    env.enableCheckpointing(500, CheckpointingMode.EXACTLY_ONCE);
    JobGraph jobGraph = createJobGraph(env, StatefulSourceBehavior.FAIL_AFTER_CHECKPOINT_ON_FIRST_RUN, maxNumber, null, new OperatorID().toHexString(), null);
    try (MiniCluster miniCluster = new MiniCluster(createMiniClusterConfig())) {
        miniCluster.start();
        miniCluster.executeJobBlocking(jobGraph);
    }
    assertThat(result.get(), contains(IntStream.range(0, maxNumber).boxed().toArray()));
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) Test(org.junit.Test)

Aggregations

MiniCluster (org.apache.flink.runtime.minicluster.MiniCluster)44 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)21 Configuration (org.apache.flink.configuration.Configuration)20 Test (org.junit.Test)18 MiniClusterConfiguration (org.apache.flink.runtime.minicluster.MiniClusterConfiguration)17 JobID (org.apache.flink.api.common.JobID)14 JobResult (org.apache.flink.runtime.jobmaster.JobResult)13 Deadline (org.apache.flink.api.common.time.Deadline)9 Duration (java.time.Duration)6 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)6 Test (org.junit.jupiter.api.Test)6 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)5 JobStatus (org.apache.flink.api.common.JobStatus)4 JobClient (org.apache.flink.core.execution.JobClient)4 EmbeddedHaServicesWithLeadershipControl (org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedHaServicesWithLeadershipControl)4 TestingMiniCluster (org.apache.flink.runtime.minicluster.TestingMiniCluster)4 TestingMiniClusterConfiguration (org.apache.flink.runtime.minicluster.TestingMiniClusterConfiguration)4 File (java.io.File)3 TimeUnit (java.util.concurrent.TimeUnit)3 MiniClusterClient (org.apache.flink.client.program.MiniClusterClient)3