Java Code Examples for org.apache.flink.runtime.testingUtils.TestingUtils#defaultExecutionContext()

The following examples show how to use org.apache.flink.runtime.testingUtils.TestingUtils#defaultExecutionContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutionGraphRestartTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private Tuple2<ExecutionGraph, Instance> createExecutionGraph(RestartStrategy restartStrategy) throws Exception {
	Instance instance = ExecutionGraphTestUtils.getInstance(
		new ActorTaskManagerGateway(
			new SimpleActorGateway(TestingUtils.directExecutionContext())),
		NUM_TASKS);

	Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
	scheduler.newInstanceAvailable(instance);

	ExecutionGraph eg = createSimpleExecutionGraph(restartStrategy, scheduler);

	assertEquals(JobStatus.CREATED, eg.getState());

	eg.scheduleForExecution();
	assertEquals(JobStatus.RUNNING, eg.getState());
	return new Tuple2<>(eg, instance);
}
 
Example 2
Source File: ExecutionGraphRestartTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that it is possible to fail a graph via a call to
 * {@link ExecutionGraph#failGlobal(Throwable)} after cancellation.
 */
@Test
public void testFailExecutionGraphAfterCancel() throws Exception {
	Instance instance = ExecutionGraphTestUtils.getInstance(
		new ActorTaskManagerGateway(
			new SimpleActorGateway(TestingUtils.directExecutionContext())),
		2);

	Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
	scheduler.newInstanceAvailable(instance);

	JobVertex vertex = ExecutionGraphTestUtils.createJobVertex("Test Vertex", 1, NoOpInvokable.class);

	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.setRestartStrategy(RestartStrategies.fixedDelayRestart(
		Integer.MAX_VALUE, Integer.MAX_VALUE));
	JobGraph jobGraph = new JobGraph("Test Job", vertex);
	jobGraph.setExecutionConfig(executionConfig);

	ExecutionGraph eg = newExecutionGraph(new InfiniteDelayRestartStrategy(), scheduler);

	eg.attachJobGraph(jobGraph.getVerticesSortedTopologicallyFromSources());

	assertEquals(JobStatus.CREATED, eg.getState());

	eg.scheduleForExecution();
	assertEquals(JobStatus.RUNNING, eg.getState());

	// Fail right after cancel (for example with concurrent slot release)
	eg.cancel();
	assertEquals(JobStatus.CANCELLING, eg.getState());

	eg.failGlobal(new Exception("Test Exception"));
	assertEquals(JobStatus.FAILING, eg.getState());

	Execution execution = eg.getAllExecutionVertices().iterator().next().getCurrentExecutionAttempt();

	execution.completeCancelling();
	assertEquals(JobStatus.RESTARTING, eg.getState());
}
 
Example 3
Source File: LeaderElectionTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setup() {
	embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutionContext());
}
 
Example 4
Source File: TaskInputSplitProviderTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public NullInputSplitGateway() {
	super(TestingUtils.defaultExecutionContext());
}
 
Example 5
Source File: ExecutionGraphRestartTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testFailWhileRestarting() throws Exception {
	Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());

	Instance instance = ExecutionGraphTestUtils.getInstance(
		new ActorTaskManagerGateway(
			new SimpleActorGateway(TestingUtils.directExecutionContext())),
		NUM_TASKS);

	scheduler.newInstanceAvailable(instance);

	// Blocking program
	ExecutionGraph executionGraph = new ExecutionGraph(
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		new JobID(),
		"TestJob",
		new Configuration(),
		new SerializedValue<>(new ExecutionConfig()),
		AkkaUtils.getDefaultTimeout(),
		// We want to manually control the restart and delay
		new InfiniteDelayRestartStrategy(),
		scheduler);

	executionGraph.start(TestingComponentMainThreadExecutorServiceAdapter.forMainThread());

	JobVertex jobVertex = new JobVertex("NoOpInvokable");
	jobVertex.setInvokableClass(NoOpInvokable.class);
	jobVertex.setParallelism(NUM_TASKS);

	JobGraph jobGraph = new JobGraph("TestJob", jobVertex);

	executionGraph.attachJobGraph(jobGraph.getVerticesSortedTopologicallyFromSources());

	assertEquals(JobStatus.CREATED, executionGraph.getState());

	executionGraph.scheduleForExecution();

	assertEquals(JobStatus.RUNNING, executionGraph.getState());

	// Kill the instance and wait for the job to restart
	instance.markDead();

	assertEquals(JobStatus.RESTARTING, executionGraph.getState());

	// If we fail when being in RESTARTING, then we should try to restart again
	final long globalModVersion = executionGraph.getGlobalModVersion();
	final Exception testException = new Exception("Test exception");
	executionGraph.failGlobal(testException);

	assertNotEquals(globalModVersion, executionGraph.getGlobalModVersion());
	assertEquals(JobStatus.RESTARTING, executionGraph.getState());
	assertEquals(testException, executionGraph.getFailureCause()); // we should have updated the failure cause

	// but it should fail when sending a SuppressRestartsException
	executionGraph.failGlobal(new SuppressRestartsException(new Exception("Suppress restart exception")));

	assertEquals(JobStatus.FAILED, executionGraph.getState());

	// The restart has been aborted
	executionGraph.restart(executionGraph.getGlobalModVersion());

	assertEquals(JobStatus.FAILED, executionGraph.getState());
}
 
Example 6
Source File: ExecutionGraphRestartTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that a graph is not restarted after cancellation via a call to
 * {@link ExecutionGraph#failGlobal(Throwable)}. This can happen when a slot is
 * released concurrently with cancellation.
 */
@Test
public void testFailExecutionAfterCancel() throws Exception {
	Instance instance = ExecutionGraphTestUtils.getInstance(
		new ActorTaskManagerGateway(
			new SimpleActorGateway(TestingUtils.directExecutionContext())),
		2);

	Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
	scheduler.newInstanceAvailable(instance);

	JobVertex vertex = ExecutionGraphTestUtils.createJobVertex("Test Vertex", 1, NoOpInvokable.class);

	ExecutionConfig executionConfig = new ExecutionConfig();
	executionConfig.setRestartStrategy(RestartStrategies.fixedDelayRestart(
		Integer.MAX_VALUE, Integer.MAX_VALUE));
	JobGraph jobGraph = new JobGraph("Test Job", vertex);
	jobGraph.setExecutionConfig(executionConfig);

	ExecutionGraph eg = newExecutionGraph(new InfiniteDelayRestartStrategy(), scheduler);

	eg.attachJobGraph(jobGraph.getVerticesSortedTopologicallyFromSources());

	assertEquals(JobStatus.CREATED, eg.getState());

	eg.scheduleForExecution();
	assertEquals(JobStatus.RUNNING, eg.getState());

	// Fail right after cancel (for example with concurrent slot release)
	eg.cancel();

	for (ExecutionVertex v : eg.getAllExecutionVertices()) {
		v.getCurrentExecutionAttempt().fail(new Exception("Test Exception"));
	}

	assertEquals(JobStatus.CANCELED, eg.getTerminationFuture().get());

	Execution execution = eg.getAllExecutionVertices().iterator().next().getCurrentExecutionAttempt();

	execution.completeCancelling();
	assertEquals(JobStatus.CANCELED, eg.getState());
}
 
Example 7
Source File: ExecutionGraphRestartTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that a suspend call while restarting a job, will abort the restarting.
 */
@Test
public void testSuspendWhileRestarting() throws Exception {

	Instance instance = ExecutionGraphTestUtils.getInstance(
		new ActorTaskManagerGateway(
			new SimpleActorGateway(TestingUtils.directExecutionContext())),
		NUM_TASKS);

	Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
	scheduler.newInstanceAvailable(instance);

	JobVertex sender = new JobVertex("Task");
	sender.setInvokableClass(NoOpInvokable.class);
	sender.setParallelism(NUM_TASKS);

	JobGraph jobGraph = new JobGraph("Pointwise job", sender);

	TestRestartStrategy controllableRestartStrategy = TestRestartStrategy.manuallyTriggered();

	ExecutionGraph eg = new ExecutionGraph(
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		new JobID(),
		"Test job",
		new Configuration(),
		new SerializedValue<>(new ExecutionConfig()),
		AkkaUtils.getDefaultTimeout(),
		controllableRestartStrategy,
		scheduler);

	eg.start(mainThreadExecutor);
	eg.attachJobGraph(jobGraph.getVerticesSortedTopologicallyFromSources());

	assertEquals(JobStatus.CREATED, eg.getState());

	eg.scheduleForExecution();

	assertEquals(JobStatus.RUNNING, eg.getState());

	instance.markDead();

	Assert.assertEquals(1, controllableRestartStrategy.getNumberOfQueuedActions());

	assertEquals(JobStatus.RESTARTING, eg.getState());

	eg.suspend(new Exception("Test exception"));

	assertEquals(JobStatus.SUSPENDED, eg.getState());

	controllableRestartStrategy.triggerAll().join();

	assertEquals(JobStatus.SUSPENDED, eg.getState());
}
 
Example 8
Source File: LeaderElectionTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setup() {
	embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutionContext());
}
 
Example 9
Source File: LeaderElectionTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setup() {
	embeddedLeaderService = new EmbeddedLeaderService(TestingUtils.defaultExecutionContext());
}