Search in sources :

Example 16 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class JobListenerITCase method testExecuteCallsJobListenerOnMainThreadOnBatchEnvironment.

@Test
public void testExecuteCallsJobListenerOnMainThreadOnBatchEnvironment() throws Exception {
    AtomicReference<Thread> threadReference = new AtomicReference<>();
    ExecutionEnvironment env = new ExecutionEnvironment(getClientConfiguration());
    env.registerJobListener(new JobListener() {

        @Override
        public void onJobSubmitted(JobClient jobClient, Throwable t) {
            threadReference.set(Thread.currentThread());
        }

        @Override
        public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {
        }
    });
    env.fromElements(1, 2, 3, 4, 5).output(new DiscardingOutputFormat<>());
    env.execute();
    assertThat(Thread.currentThread(), is(threadReference.get()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) Test(org.junit.Test)

Example 17 with JobClient

use of org.apache.flink.core.execution.JobClient 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()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 18 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class JobListenerITCase method testExecuteCallsJobListenerOnMainThreadOnStreamEnvironment.

@Test
public void testExecuteCallsJobListenerOnMainThreadOnStreamEnvironment() throws Exception {
    AtomicReference<Thread> threadReference = new AtomicReference<>();
    StreamExecutionEnvironment env = new StreamExecutionEnvironment(getClientConfiguration());
    env.registerJobListener(new JobListener() {

        @Override
        public void onJobSubmitted(JobClient jobClient, Throwable t) {
            threadReference.set(Thread.currentThread());
        }

        @Override
        public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {
        }
    });
    env.fromElements(1, 2, 3, 4, 5).addSink(new DiscardingSink<>());
    env.execute();
    assertThat(Thread.currentThread(), is(threadReference.get()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) Test(org.junit.Test)

Example 19 with JobClient

use of org.apache.flink.core.execution.JobClient 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()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 20 with JobClient

use of org.apache.flink.core.execution.JobClient in project flink by apache.

the class LocalExecutorITCase method testMiniClusterShutdownOnErrors.

@Test(timeout = 60_000)
public void testMiniClusterShutdownOnErrors() throws Exception {
    Plan runtimeExceptionPlan = getRuntimeExceptionPlan();
    runtimeExceptionPlan.setExecutionConfig(new ExecutionConfig());
    Configuration config = new Configuration();
    config.setBoolean(DeploymentOptions.ATTACHED, true);
    JobClient jobClient = executor.execute(runtimeExceptionPlan, config, ClassLoader.getSystemClassLoader()).get();
    assertThrows("Job execution failed.", Exception.class, () -> jobClient.getJobExecutionResult().get());
    assertThat(miniCluster.isRunning(), is(false));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Plan(org.apache.flink.api.common.Plan) JobClient(org.apache.flink.core.execution.JobClient) Test(org.junit.Test)

Aggregations

JobClient (org.apache.flink.core.execution.JobClient)70 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)36 Test (org.junit.Test)32 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)16 Configuration (org.apache.flink.configuration.Configuration)16 JobListener (org.apache.flink.core.execution.JobListener)14 ArrayList (java.util.ArrayList)12 List (java.util.List)10 JobID (org.apache.flink.api.common.JobID)10 ExecutionException (java.util.concurrent.ExecutionException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 DEFAULT_COLLECT_DATA_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_COLLECT_DATA_TIMEOUT)8 DEFAULT_JOB_STATUS_CHANGE_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_JOB_STATUS_CHANGE_TIMEOUT)8 IOException (java.io.IOException)7 DisplayName (org.junit.jupiter.api.DisplayName)7 TestTemplate (org.junit.jupiter.api.TestTemplate)7 Iterator (java.util.Iterator)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)6 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)6