Search in sources :

Example 1 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class RemoveCachedShuffleDescriptorTest method setup.

@Before
public void setup() {
    scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    mainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(scheduledExecutorService);
    ioExecutor = new ManuallyTriggeredScheduledExecutorService();
}
Also used : ManuallyTriggeredScheduledExecutorService(org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService) Before(org.junit.Before)

Example 2 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class ExecutionGraphCoLocationRestartTest method testConstraintsAfterRestart.

@Test
public void testConstraintsAfterRestart() throws Exception {
    final long timeout = 5000L;
    JobVertex groupVertex = ExecutionGraphTestUtils.createNoOpVertex(NUM_TASKS);
    JobVertex groupVertex2 = ExecutionGraphTestUtils.createNoOpVertex(NUM_TASKS);
    groupVertex2.connectNewDataSetAsInput(groupVertex, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
    SlotSharingGroup sharingGroup = new SlotSharingGroup();
    groupVertex.setSlotSharingGroup(sharingGroup);
    groupVertex2.setSlotSharingGroup(sharingGroup);
    groupVertex.setStrictlyCoLocatedWith(groupVertex2);
    // initiate and schedule job
    final JobGraph jobGraph = JobGraphTestUtils.streamingJobGraph(groupVertex, groupVertex2);
    final ManuallyTriggeredScheduledExecutorService delayExecutor = new ManuallyTriggeredScheduledExecutorService();
    final SchedulerBase scheduler = SchedulerTestingUtils.newSchedulerBuilder(jobGraph, ComponentMainThreadExecutorServiceAdapter.forMainThread()).setExecutionSlotAllocatorFactory(SchedulerTestingUtils.newSlotSharingExecutionSlotAllocatorFactory(TestingPhysicalSlotProvider.create((ignored) -> CompletableFuture.completedFuture(TestingPhysicalSlot.builder().build())))).setDelayExecutor(delayExecutor).setRestartBackoffTimeStrategy(new FixedDelayRestartBackoffTimeStrategy.FixedDelayRestartBackoffTimeStrategyFactory(1, 0).create()).build();
    final ExecutionGraph eg = scheduler.getExecutionGraph();
    // enable the queued scheduling for the slot pool
    assertEquals(JobStatus.CREATED, eg.getState());
    scheduler.startScheduling();
    Predicate<AccessExecution> isDeploying = ExecutionGraphTestUtils.isInExecutionState(ExecutionState.DEPLOYING);
    ExecutionGraphTestUtils.waitForAllExecutionsPredicate(eg, isDeploying, timeout);
    assertEquals(JobStatus.RUNNING, eg.getState());
    // sanity checks
    validateConstraints(eg);
    eg.getAllExecutionVertices().iterator().next().fail(new FlinkException("Test exception"));
    assertEquals(JobStatus.RESTARTING, eg.getState());
    // trigger registration of restartTasks(...) callback to cancelFuture before completing the
    // cancellation. This ensures the restarting actions to be performed in main thread.
    delayExecutor.triggerNonPeriodicScheduledTask();
    for (ExecutionVertex vertex : eg.getAllExecutionVertices()) {
        if (vertex.getExecutionState() == ExecutionState.CANCELING) {
            vertex.getCurrentExecutionAttempt().completeCancelling();
        }
    }
    // wait until we have restarted
    ExecutionGraphTestUtils.waitUntilJobStatus(eg, JobStatus.RUNNING, timeout);
    ExecutionGraphTestUtils.waitForAllExecutionsPredicate(eg, isDeploying, timeout);
    // checking execution vertex properties
    validateConstraints(eg);
    ExecutionGraphTestUtils.finishAllVertices(eg);
    assertThat(eg.getState(), is(FINISHED));
}
Also used : ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter) TestingPhysicalSlotProvider(org.apache.flink.runtime.scheduler.TestingPhysicalSlotProvider) FlinkException(org.apache.flink.util.FlinkException) SchedulerBase(org.apache.flink.runtime.scheduler.SchedulerBase) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) Predicate(java.util.function.Predicate) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ManuallyTriggeredScheduledExecutorService(org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) Assert.assertThat(org.junit.Assert.assertThat) FINISHED(org.apache.flink.api.common.JobStatus.FINISHED) TestingPhysicalSlot(org.apache.flink.runtime.scheduler.TestingPhysicalSlot) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) Matchers.is(org.hamcrest.Matchers.is) FixedDelayRestartBackoffTimeStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.FixedDelayRestartBackoffTimeStrategy) SchedulerTestingUtils(org.apache.flink.runtime.scheduler.SchedulerTestingUtils) DistributionPattern(org.apache.flink.runtime.jobgraph.DistributionPattern) Assert.assertEquals(org.junit.Assert.assertEquals) FixedDelayRestartBackoffTimeStrategy(org.apache.flink.runtime.executiongraph.failover.flip1.FixedDelayRestartBackoffTimeStrategy) FlinkException(org.apache.flink.util.FlinkException) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) ManuallyTriggeredScheduledExecutorService(org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) SchedulerBase(org.apache.flink.runtime.scheduler.SchedulerBase) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) Test(org.junit.Test)

Example 3 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class MetricRegistryImplTest method testReporterIntervalParsingErrorFallsBackToDefaultValue.

@Test
public void testReporterIntervalParsingErrorFallsBackToDefaultValue() throws Exception {
    MetricConfig config = new MetricConfig();
    // in a prior implementation the time amount was applied even if the time unit was invalid
    // in this case this would imply using 1 SECOND as the interval (seconds is the default)
    config.setProperty(ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, "1 UNICORN");
    final ManuallyTriggeredScheduledExecutorService manuallyTriggeredScheduledExecutorService = new ManuallyTriggeredScheduledExecutorService();
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Collections.singletonList(ReporterSetup.forReporter("test", config, new TestReporter3())), manuallyTriggeredScheduledExecutorService);
    try {
        Collection<ScheduledFuture<?>> scheduledTasks = manuallyTriggeredScheduledExecutorService.getActiveScheduledTasks();
        ScheduledFuture<?> reportTask = Iterators.getOnlyElement(scheduledTasks.iterator());
        Assert.assertEquals(MetricOptions.REPORTER_INTERVAL.defaultValue().getSeconds(), reportTask.getDelay(TimeUnit.SECONDS));
    } finally {
        registry.shutdown().get();
    }
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) ManuallyTriggeredScheduledExecutorService(org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService) ScheduledFuture(java.util.concurrent.ScheduledFuture) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 4 with ManuallyTriggeredScheduledExecutorService

use of org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService in project flink by apache.

the class OperatorCoordinatorHolderTest method checkpointEventValueAtomicity.

private void checkpointEventValueAtomicity(final Function<OperatorCoordinator.Context, OperatorCoordinator> coordinatorCtor) throws Exception {
    final ManuallyTriggeredScheduledExecutorService executor = new ManuallyTriggeredScheduledExecutorService();
    final ComponentMainThreadExecutor mainThreadExecutor = new ComponentMainThreadExecutorServiceAdapter((ScheduledExecutorService) executor, Thread.currentThread());
    final EventReceivingTasks sender = EventReceivingTasks.createForRunningTasks();
    final OperatorCoordinatorHolder holder = createCoordinatorHolder(sender, coordinatorCtor, mainThreadExecutor);
    // give the coordinator some time to emit some events. This isn't strictly necessary,
    // but it randomly alters the timings between the coordinator's thread (event sender) and
    // the main thread (holder). This should produce a flaky test if we missed some corner
    // cases.
    Thread.sleep(new Random().nextInt(10));
    executor.triggerAll();
    // trigger the checkpoint - this should also shut the valve as soon as the future is
    // completed
    final CompletableFuture<byte[]> checkpointFuture = new CompletableFuture<>();
    holder.checkpointCoordinator(0L, checkpointFuture);
    executor.triggerAll();
    // give the coordinator some time to emit some events. Same as above, this adds some
    // randomization
    Thread.sleep(new Random().nextInt(10));
    holder.close();
    executor.triggerAll();
    assertTrue(checkpointFuture.isDone());
    final int checkpointedNumber = bytesToInt(checkpointFuture.get());
    assertEquals(checkpointedNumber, sender.getNumberOfSentEvents());
    for (int i = 0; i < checkpointedNumber; i++) {
        assertEquals(i, ((TestOperatorEvent) sender.getAllSentEvents().get(i).event).getValue());
    }
}
Also used : ManuallyTriggeredScheduledExecutorService(org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService) CompletableFuture(java.util.concurrent.CompletableFuture) ComponentMainThreadExecutor(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor) Random(java.util.Random) ComponentMainThreadExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter)

Aggregations

ManuallyTriggeredScheduledExecutorService (org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutorService)4 CompletableFuture (java.util.concurrent.CompletableFuture)2 ComponentMainThreadExecutorServiceAdapter (org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter)2 Test (org.junit.Test)2 Random (java.util.Random)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Predicate (java.util.function.Predicate)1 JobStatus (org.apache.flink.api.common.JobStatus)1 FINISHED (org.apache.flink.api.common.JobStatus.FINISHED)1 MetricConfig (org.apache.flink.metrics.MetricConfig)1 ComponentMainThreadExecutor (org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor)1 ExecutionState (org.apache.flink.runtime.execution.ExecutionState)1 FixedDelayRestartBackoffTimeStrategy (org.apache.flink.runtime.executiongraph.failover.flip1.FixedDelayRestartBackoffTimeStrategy)1 ResultPartitionType (org.apache.flink.runtime.io.network.partition.ResultPartitionType)1 DistributionPattern (org.apache.flink.runtime.jobgraph.DistributionPattern)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 JobGraphTestUtils (org.apache.flink.runtime.jobgraph.JobGraphTestUtils)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1 SlotSharingGroup (org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup)1 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)1