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();
}
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));
}
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();
}
}
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());
}
}
Aggregations