Search in sources :

Example 21 with DirectScheduledExecutorService

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

the class ExecutionGraphDeploymentTest method setupExecution.

private Tuple2<ExecutionGraph, Map<ExecutionAttemptID, Execution>> setupExecution(JobVertex v1, int dop1, JobVertex v2, int dop2) throws Exception {
    final JobID jobId = new JobID();
    v1.setParallelism(dop1);
    v2.setParallelism(dop2);
    v1.setInvokableClass(BatchTask.class);
    v2.setInvokableClass(BatchTask.class);
    Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
    for (int i = 0; i < dop1 + dop2; i++) {
        scheduler.newInstanceAvailable(ExecutionGraphTestUtils.getInstance(new ActorTaskManagerGateway(new ExecutionGraphTestUtils.SimpleActorGateway(TestingUtils.directExecutionContext()))));
    }
    // execution graph that executes actions synchronously
    ExecutionGraph eg = new ExecutionGraph(new DirectScheduledExecutorService(), TestingUtils.defaultExecutor(), jobId, "some job", new Configuration(), new SerializedValue<>(new ExecutionConfig()), AkkaUtils.getDefaultTimeout(), new NoRestartStrategy(), scheduler);
    eg.setQueuedSchedulingAllowed(false);
    List<JobVertex> ordered = Arrays.asList(v1, v2);
    eg.attachJobGraph(ordered);
    assertEquals(dop1 + dop2, scheduler.getNumberOfAvailableSlots());
    // schedule, this triggers mock deployment
    eg.scheduleForExecution();
    Map<ExecutionAttemptID, Execution> executions = eg.getRegisteredExecutions();
    assertEquals(dop1 + dop2, executions.size());
    return new Tuple2<>(eg, executions);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) Scheduler(org.apache.flink.runtime.jobmanager.scheduler.Scheduler) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) NoRestartStrategy(org.apache.flink.runtime.executiongraph.restart.NoRestartStrategy) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) Tuple2(org.apache.flink.api.java.tuple.Tuple2) JobID(org.apache.flink.api.common.JobID)

Example 22 with DirectScheduledExecutorService

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

the class RetryingExecutorTest method testNoRetryDelayIfTimeout.

@Test
public void testNoRetryDelayIfTimeout() throws Exception {
    int delayAfterFailure = 123;
    int numAttempts = 2;
    testPolicy(numAttempts, RetryPolicy.fixed(Integer.MAX_VALUE, 0, delayAfterFailure), a -> {
        if (a < numAttempts) {
            throw new TimeoutException();
        }
    }, new DirectScheduledExecutorService() {

        @Override
        public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            fail("task should be executed directly without delay after timeout");
            return CompletedScheduledFuture.create(null);
        }
    });
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) TimeUnit(java.util.concurrent.TimeUnit) ScheduledFuture(java.util.concurrent.ScheduledFuture) CompletedScheduledFuture(org.apache.flink.core.testutils.CompletedScheduledFuture) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 23 with DirectScheduledExecutorService

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

the class RetryingExecutorTest method testRetryDelay.

@Test
public void testRetryDelay() throws Exception {
    int delayAfterFailure = 123;
    int numAttempts = 2;
    testPolicy(numAttempts, RetryPolicy.fixed(Integer.MAX_VALUE, 0, delayAfterFailure), a -> {
        if (a < numAttempts) {
            throw new IOException();
        }
    }, new DirectScheduledExecutorService() {

        @Override
        public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            assertEquals(delayAfterFailure, delay);
            command.run();
            return CompletedScheduledFuture.create(null);
        }
    });
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) TimeUnit(java.util.concurrent.TimeUnit) IOException(java.io.IOException) ScheduledFuture(java.util.concurrent.ScheduledFuture) CompletedScheduledFuture(org.apache.flink.core.testutils.CompletedScheduledFuture) Test(org.junit.Test)

Example 24 with DirectScheduledExecutorService

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

the class BatchingStateChangeUploaderTest method testErrorHandling.

@Test(expected = RejectedExecutionException.class)
public void testErrorHandling() throws Exception {
    TestingStateChangeUploader probe = new TestingStateChangeUploader();
    DirectScheduledExecutorService scheduler = new DirectScheduledExecutorService();
    try (BatchingStateChangeUploader store = new BatchingStateChangeUploader(Integer.MAX_VALUE, MAX_BYTES_IN_FLIGHT, MAX_BYTES_IN_FLIGHT, RetryPolicy.NONE, probe, scheduler, new RetryingExecutor(5, createUnregisteredChangelogStorageMetricGroup().getAttemptsPerUpload()), createUnregisteredChangelogStorageMetricGroup())) {
        scheduler.shutdown();
        upload(store, getChanges(4));
    }
}
Also used : DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) Test(org.junit.Test)

Example 25 with DirectScheduledExecutorService

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

the class DefaultExecutionGraphDeploymentWithSmallBlobCacheSizeLimitTest method createAndSetupExecutionGraph.

private ExecutionGraph createAndSetupExecutionGraph(int numberOfVertices, int parallelism) throws JobException, JobExecutionException {
    final List<JobVertex> vertices = new ArrayList<>();
    for (int i = 0; i < numberOfVertices; i++) {
        JobVertex vertex = new JobVertex(String.format("v%d", i + 1), new JobVertexID());
        vertex.setParallelism(parallelism);
        vertex.setInvokableClass(BatchTask.class);
        vertices.add(vertex);
    }
    for (int i = 1; i < numberOfVertices; i++) {
        vertices.get(i).connectNewDataSetAsInput(vertices.get(i - 1), DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
    }
    final JobGraph jobGraph = JobGraphTestUtils.batchJobGraph(vertices.toArray(new JobVertex[0]));
    final DirectScheduledExecutorService executor = new DirectScheduledExecutorService();
    final DefaultExecutionGraph eg = TestingDefaultExecutionGraphBuilder.newBuilder().setJobGraph(jobGraph).setFutureExecutor(executor).setIoExecutor(executor).setBlobWriter(blobWriter).build();
    eg.start(ComponentMainThreadExecutorServiceAdapter.forMainThread());
    return eg;
}
Also used : JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) DirectScheduledExecutorService(org.apache.flink.runtime.testutils.DirectScheduledExecutorService) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArrayList(java.util.ArrayList)

Aggregations

DirectScheduledExecutorService (org.apache.flink.runtime.testutils.DirectScheduledExecutorService)46 Test (org.junit.Test)32 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)17 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)15 SchedulerBase (org.apache.flink.runtime.scheduler.SchedulerBase)15 ArrayList (java.util.ArrayList)14 CompletableFuture (java.util.concurrent.CompletableFuture)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)9 Configuration (org.apache.flink.configuration.Configuration)8 IOException (java.io.IOException)7 Arrays (java.util.Arrays)7 Collection (java.util.Collection)7 List (java.util.List)7 TaskExecutionState (org.apache.flink.runtime.taskmanager.TaskExecutionState)7 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)6 RpcTaskManagerGateway (org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway)6 TestingPhysicalSlot (org.apache.flink.runtime.scheduler.TestingPhysicalSlot)6 TestingPhysicalSlotProvider (org.apache.flink.runtime.scheduler.TestingPhysicalSlotProvider)6 TestingTaskExecutorGateway (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGateway)6