Search in sources :

Example 51 with JobClient

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

the class ReactiveModeITCase method testScaleDownOnTaskManagerLoss.

@Test
public void testScaleDownOnTaskManagerLoss() throws Exception {
    // test preparation: ensure we have 2 TaskManagers running
    startAdditionalTaskManager();
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    // configure exactly one restart to avoid restart loops in error cases
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 0L));
    final DataStream<String> input = env.addSource(new DummySource());
    input.addSink(new DiscardingSink<>());
    final JobClient jobClient = env.executeAsync();
    waitUntilParallelismForVertexReached(miniClusterResource.getRestClusterClient(), jobClient.getJobID(), NUMBER_SLOTS_PER_TASK_MANAGER * (INITIAL_NUMBER_TASK_MANAGERS + 1));
    // scale down to 1 TaskManagers:
    miniClusterResource.getMiniCluster().terminateTaskManager(0).get();
    waitUntilParallelismForVertexReached(miniClusterResource.getRestClusterClient(), jobClient.getJobID(), NUMBER_SLOTS_PER_TASK_MANAGER * NUMBER_SLOTS_PER_TASK_MANAGER);
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobClient(org.apache.flink.core.execution.JobClient) Test(org.junit.Test)

Example 52 with JobClient

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

the class JobListenerITCase method testExecuteCallsJobListenerOnStreamingEnvironment.

@Test
public void testExecuteCallsJobListenerOnStreamingEnvironment() throws Exception {
    AtomicReference<JobID> jobIdReference = new AtomicReference<>();
    OneShotLatch submissionLatch = new OneShotLatch();
    OneShotLatch executionLatch = 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) {
            executionLatch.trigger();
        }
    });
    env.fromElements(1, 2, 3, 4, 5).addSink(new DiscardingSink<>());
    JobExecutionResult jobExecutionResult = env.execute();
    submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
    executionLatch.await(2000L, TimeUnit.MILLISECONDS);
    assertThat(jobExecutionResult.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 53 with JobClient

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

the class JobListenerITCase method testExecuteAsyncCallsJobListenerOnMainThreadOnBatchEnvironment.

@Test
public void testExecuteAsyncCallsJobListenerOnMainThreadOnBatchEnvironment() 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.executeAsync();
    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 54 with JobClient

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

the class JobListenerITCase method testExecuteCallsJobListenerOnBatchEnvironment.

@Test
public void testExecuteCallsJobListenerOnBatchEnvironment() throws Exception {
    AtomicReference<JobID> jobIdReference = new AtomicReference<>();
    OneShotLatch submissionLatch = new OneShotLatch();
    OneShotLatch executionLatch = 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) {
            executionLatch.trigger();
        }
    });
    env.fromElements(1, 2, 3, 4, 5).output(new DiscardingOutputFormat<>());
    JobExecutionResult jobExecutionResult = env.execute();
    submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
    executionLatch.await(2000L, TimeUnit.MILLISECONDS);
    assertThat(jobExecutionResult.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 55 with JobClient

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

the class JobListenerITCase method testExecuteAsyncCallsJobListenerOnMainThreadOnStreamEnvironment.

@Test
public void testExecuteAsyncCallsJobListenerOnMainThreadOnStreamEnvironment() 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.executeAsync();
    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)

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