Java Code Examples for org.apache.flink.runtime.akka.AkkaUtils#getDefaultTimeout()

The following examples show how to use org.apache.flink.runtime.akka.AkkaUtils#getDefaultTimeout() . 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: ExecutionGraphTestUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static ExecutionJobVertex getExecutionVertex(
		JobVertexID id,
		ScheduledExecutorService executor,
		ScheduleMode scheduleMode) throws Exception {

	JobVertex ajv = new JobVertex("TestVertex", id);
	ajv.setInvokableClass(AbstractInvokable.class);

	ExecutionGraph graph = new TestingExecutionGraphBuilder(ajv)
		.setIoExecutor(executor)
		.setFutureExecutor(executor)
		.setScheduleMode(scheduleMode)
		.build();

	graph.start(ComponentMainThreadExecutorServiceAdapter.forMainThread());

	return new ExecutionJobVertex(graph, ajv, 1, AkkaUtils.getDefaultTimeout());
}
 
Example 2
Source File: ExecutionVertexInputConstraintTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static ExecutionGraph createExecutionGraph(
		List<JobVertex> orderedVertices,
		InputDependencyConstraint inputDependencyConstraint) throws Exception {

	final JobID jobId = new JobID();
	final String jobName = "Test Job Sample Name";
	final SlotProvider slotProvider = new SimpleSlotProvider(jobId, 20);

	for (JobVertex vertex : orderedVertices) {
		vertex.setInputDependencyConstraint(inputDependencyConstraint);
	}

	ExecutionGraph eg = new ExecutionGraph(
		new DummyJobInformation(
			jobId,
			jobName),
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		AkkaUtils.getDefaultTimeout(),
		TestRestartStrategy.directExecuting(),
		new RestartAllStrategy.Factory(),
		slotProvider);
	eg.attachJobGraph(orderedVertices);

	return eg;
}
 
Example 3
Source File: ExecutionVertexSchedulingTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleToDeploying() {
	try {
		final ExecutionJobVertex ejv = getExecutionVertex(new JobVertexID());
		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		final LogicalSlot slot = new TestingLogicalSlot();

		CompletableFuture<LogicalSlot> future = CompletableFuture.completedFuture(slot);

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());

		// try to deploy to the slot
		vertex.scheduleForExecution(
			new TestingSlotProvider(ignore -> future),
			false,
			LocationPreferenceConstraint.ALL,
			Collections.emptySet());
		assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 4
Source File: ExecutionVertexSchedulingTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleToDeploying() {
	try {
		final ExecutionJobVertex ejv = getExecutionJobVertex(new JobVertexID());
		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		final LogicalSlot slot = new TestingLogicalSlotBuilder().createTestingLogicalSlot();

		CompletableFuture<LogicalSlot> future = CompletableFuture.completedFuture(slot);

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());

		// try to deploy to the slot
		vertex.scheduleForExecution(
			TestingSlotProviderStrategy.from(new TestingSlotProvider(ignore -> future)),
			LocationPreferenceConstraint.ALL,
			Collections.emptySet());
		assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 5
Source File: ExecutionVertexCancelTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCancelFromRunning() {
	try {
		final JobVertexID jid = new JobVertexID();
		final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());

		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new CancelSequenceSimpleAckingTaskManagerGateway(1)).createTestingLogicalSlot();

		setVertexResource(vertex, slot);
		setVertexState(vertex, ExecutionState.RUNNING);

		assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());

		vertex.cancel();
		vertex.getCurrentExecutionAttempt().completeCancelling(); // response by task manager once actually canceled

		assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());

		assertFalse(slot.isAlive());

		assertNull(vertex.getFailureCause());

		assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELED) > 0);
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 6
Source File: ExecutionVertexDeploymentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeployFailedSynchronous() {
	try {
		final JobVertexID jid = new JobVertexID();
		final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());

		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
			AkkaUtils.getDefaultTimeout());

		final LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new SubmitFailingSimpleAckingTaskManagerGateway()).createTestingLogicalSlot();

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());

		vertex.deployToSlot(slot);

		assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
		assertNotNull(vertex.getFailureCause());
		assertTrue(vertex.getFailureCause().getMessage().contains(ERROR_MESSAGE));

		assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.DEPLOYING) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.FAILED) > 0);
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 7
Source File: ExecutionVertexDeploymentTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailExternallyDuringDeploy() {
	try {
		final JobVertexID jid = new JobVertexID();

		final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());

		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
			AkkaUtils.getDefaultTimeout());

		TestingLogicalSlot testingLogicalSlot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new SubmitBlockingSimpleAckingTaskManagerGateway()).createTestingLogicalSlot();

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());
		vertex.deployToSlot(testingLogicalSlot);
		assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());

		Exception testError = new Exception("test error");
		vertex.fail(testError);

		assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
		assertEquals(testError, vertex.getFailureCause());

		assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.DEPLOYING) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.FAILED) > 0);
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 8
Source File: ExecutionVertexSchedulingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSlotReleasedWhenScheduledQueued() {
	try {
		final ExecutionJobVertex ejv = getExecutionVertex(new JobVertexID());
		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		// a slot than cannot be deployed to
		final LogicalSlot slot = new TestingLogicalSlotBuilder().createTestingLogicalSlot();
		slot.releaseSlot(new Exception("Test Exception"));

		assertFalse(slot.isAlive());

		final CompletableFuture<LogicalSlot> future = new CompletableFuture<>();

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());
		// try to deploy to the slot
		vertex.scheduleForExecution(
			TestingSlotProviderStrategy.from(new TestingSlotProvider(ignore -> future), true),
			LocationPreferenceConstraint.ALL,
			Collections.emptySet());

		// future has not yet a slot
		assertEquals(ExecutionState.SCHEDULED, vertex.getExecutionState());

		future.complete(slot);

		// will have failed
		assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 9
Source File: ExecutionVertexCancelTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCancelFromRunningDidNotFindTask() {
	// this may happen when the task finished or failed while the call was in progress
	try {
		final JobVertexID jid = new JobVertexID();
		final ExecutionJobVertex ejv = ExecutionGraphTestUtils.getExecutionJobVertex(jid, new DirectScheduledExecutorService());

		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new CancelSequenceSimpleAckingTaskManagerGateway(1)).createTestingLogicalSlot();

		setVertexResource(vertex, slot);
		setVertexState(vertex, ExecutionState.RUNNING);

		assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());

		vertex.cancel();

		assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());

		assertNull(vertex.getFailureCause());

		assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 10
Source File: ExecutionVertexSchedulingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSlotReleasedWhenScheduledQueued() {
	try {
		final ExecutionJobVertex ejv = getExecutionJobVertex(new JobVertexID());
		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		// a slot than cannot be deployed to
		final LogicalSlot slot = new TestingLogicalSlotBuilder().createTestingLogicalSlot();
		slot.releaseSlot(new Exception("Test Exception"));

		assertFalse(slot.isAlive());

		final CompletableFuture<LogicalSlot> future = new CompletableFuture<>();

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());
		// try to deploy to the slot
		vertex.scheduleForExecution(
			TestingSlotProviderStrategy.from(new TestingSlotProvider(ignore -> future)),
			LocationPreferenceConstraint.ALL,
			Collections.emptySet());

		// future has not yet a slot
		assertEquals(ExecutionState.SCHEDULED, vertex.getExecutionState());

		future.complete(slot);

		// will have failed
		assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 11
Source File: ExecutionVertexDeploymentTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailExternallyDuringDeploy() {
	try {
		final JobVertexID jid = new JobVertexID();

		final ExecutionJobVertex ejv = getExecutionVertex(jid, new DirectScheduledExecutorService());

		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
			AkkaUtils.getDefaultTimeout());

		TestingLogicalSlot testingLogicalSlot = new TestingLogicalSlot(new SubmitBlockingSimpleAckingTaskManagerGateway());

		assertEquals(ExecutionState.CREATED, vertex.getExecutionState());
		vertex.deployToSlot(testingLogicalSlot);
		assertEquals(ExecutionState.DEPLOYING, vertex.getExecutionState());

		Exception testError = new Exception("test error");
		vertex.fail(testError);

		assertEquals(ExecutionState.FAILED, vertex.getExecutionState());
		assertEquals(testError, vertex.getFailureCause());

		assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.DEPLOYING) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.FAILED) > 0);
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 12
Source File: PointwisePatternTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private ExecutionGraph getDummyExecutionGraph() throws Exception {
	return new ExecutionGraph(
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		new JobID(),
		"Test Job Sample Name",
		new Configuration(),
		new SerializedValue<>(new ExecutionConfig()),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
		new TestingSlotProvider(ignored -> new CompletableFuture<>()));
}
 
Example 13
Source File: SlotPoolImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public SlotPoolImpl(JobID jobId) {
	this(
		jobId,
		SystemClock.getInstance(),
		AkkaUtils.getDefaultTimeout(),
		Time.milliseconds(JobManagerOptions.SLOT_IDLE_TIMEOUT.defaultValue()));
}
 
Example 14
Source File: ExecutionGraphDeploymentTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
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);

	final ArrayDeque<CompletableFuture<LogicalSlot>> slotFutures = new ArrayDeque<>();
	for (int i = 0; i < dop1 + dop2; i++) {
		slotFutures.addLast(CompletableFuture.completedFuture(new TestingLogicalSlot()));
	}

	final SlotProvider slotProvider = new TestingSlotProvider(ignore -> slotFutures.removeFirst());

	final JobInformation jobInformation = new DummyJobInformation(
		jobId,
		"some job");

	DirectScheduledExecutorService executorService = new DirectScheduledExecutorService();

	// execution graph that executes actions synchronously
	ExecutionGraph eg = new ExecutionGraph(
		jobInformation,
		executorService,
		TestingUtils.defaultExecutor(),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
		new RestartAllStrategy.Factory(),
		slotProvider,
		ExecutionGraph.class.getClassLoader(),
		blobWriter,
		AkkaUtils.getDefaultTimeout());
	checkJobOffloaded(eg);

	eg.start(TestingComponentMainThreadExecutorServiceAdapter.forMainThread());

	eg.setQueuedSchedulingAllowed(false);

	List<JobVertex> ordered = Arrays.asList(v1, v2);
	eg.attachJobGraph(ordered);

	// schedule, this triggers mock deployment
	eg.scheduleForExecution();

	Map<ExecutionAttemptID, Execution> executions = eg.getRegisteredExecutions();
	assertEquals(dop1 + dop2, executions.size());

	return new Tuple2<>(eg, executions);
}
 
Example 15
Source File: ExecutionGraphDeploymentTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that a blocking batch job fails if there are not enough resources left to schedule the
 * succeeding tasks. This test case is related to [FLINK-4296] where finished producing tasks
 * swallow the fail exception when scheduling a consumer task.
 */
@Test
public void testNoResourceAvailableFailure() throws Exception {
	final JobID jobId = new JobID();
	JobVertex v1 = new JobVertex("source");
	JobVertex v2 = new JobVertex("sink");

	int dop1 = 1;
	int dop2 = 1;

	v1.setParallelism(dop1);
	v2.setParallelism(dop2);

	v1.setInvokableClass(BatchTask.class);
	v2.setInvokableClass(BatchTask.class);

	v2.connectNewDataSetAsInput(v1, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);

	final ArrayDeque<CompletableFuture<LogicalSlot>> slotFutures = new ArrayDeque<>();
	for (int i = 0; i < dop1; i++) {
		slotFutures.addLast(CompletableFuture.completedFuture(new TestingLogicalSlot()));
	}

	final SlotProvider slotProvider = new TestingSlotProvider(ignore -> slotFutures.removeFirst());

	final JobInformation jobInformation = new DummyJobInformation(
		jobId,
		"failing test job");

	DirectScheduledExecutorService directExecutor = new DirectScheduledExecutorService();

	// execution graph that executes actions synchronously
	ExecutionGraph eg = new ExecutionGraph(
		jobInformation,
		directExecutor,
		TestingUtils.defaultExecutor(),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
		new RestartAllStrategy.Factory(),
		slotProvider,
		ExecutionGraph.class.getClassLoader(),
		blobWriter,
		AkkaUtils.getDefaultTimeout());

	eg.start(TestingComponentMainThreadExecutorServiceAdapter.forMainThread());

	checkJobOffloaded(eg);

	eg.setQueuedSchedulingAllowed(false);

	List<JobVertex> ordered = Arrays.asList(v1, v2);
	eg.attachJobGraph(ordered);

	// schedule, this triggers mock deployment
	eg.scheduleForExecution();

	ExecutionAttemptID attemptID = eg.getJobVertex(v1.getID()).getTaskVertices()[0].getCurrentExecutionAttempt().getAttemptId();
	eg.updateState(new TaskExecutionState(jobId, attemptID, ExecutionState.RUNNING));
	eg.updateState(new TaskExecutionState(jobId, attemptID, ExecutionState.FINISHED, null));

	assertEquals(JobStatus.FAILED, eg.getState());
}
 
Example 16
Source File: FailoverRegionTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that if a task reports the result of its preceding task is failed,
 * its preceding task will be considered as failed, and start to failover
 * TODO: as the report part is not finished yet, this case is ignored temporarily
 * @throws Exception
 */
@Ignore
@Test
public void testSucceedingNoticePreceding() throws Exception {
	final JobID jobId = new JobID();
	final String jobName = "Test Job Sample Name";

	final SimpleSlotProvider slotProvider = new SimpleSlotProvider(jobId, 14);

	JobVertex v1 = new JobVertex("vertex1");
	JobVertex v2 = new JobVertex("vertex2");

	v1.setParallelism(1);
	v2.setParallelism(1);

	v1.setInvokableClass(AbstractInvokable.class);
	v2.setInvokableClass(AbstractInvokable.class);

	v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);

	List<JobVertex> ordered = new ArrayList<>(Arrays.asList(v1, v2));

	ExecutionGraph eg = new ExecutionGraph(
		new DummyJobInformation(
			jobId,
			jobName),
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		AkkaUtils.getDefaultTimeout(),
		new InfiniteDelayRestartStrategy(10),
		new FailoverPipelinedRegionWithDirectExecutor(),
		slotProvider);
	try {
		eg.attachJobGraph(ordered);
	}
	catch (JobException e) {
		e.printStackTrace();
		fail("Job failed with exception: " + e.getMessage());
	}
	eg.setScheduleMode(ScheduleMode.EAGER);
	eg.scheduleForExecution();
	RestartPipelinedRegionStrategy strategy = (RestartPipelinedRegionStrategy)eg.getFailoverStrategy();

	ExecutionVertex ev11 = eg.getJobVertex(v2.getID()).getTaskVertices()[0];
	ExecutionVertex ev21 = eg.getJobVertex(v2.getID()).getTaskVertices()[0];
	ev21.getCurrentExecutionAttempt().fail(new Exception("Fail with v1"));

	assertEquals(JobStatus.CANCELLING, strategy.getFailoverRegion(ev21).getState());
	assertEquals(JobStatus.CANCELLING, strategy.getFailoverRegion(ev11).getState());
}
 
Example 17
Source File: AllVerticesIteratorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testAllVertices() {
	try {
		
		JobVertex v1 = new JobVertex("v1");
		JobVertex v2 = new JobVertex("v2");
		JobVertex v3 = new JobVertex("v3");
		JobVertex v4 = new JobVertex("v4");

		v1.setInvokableClass(AbstractInvokable.class);
		v2.setInvokableClass(AbstractInvokable.class);
		v3.setInvokableClass(AbstractInvokable.class);
		v4.setInvokableClass(AbstractInvokable.class);

		v1.setParallelism(1);
		v2.setParallelism(7);
		v3.setParallelism(3);
		v4.setParallelism(2);
		
		ExecutionGraph eg = Mockito.mock(ExecutionGraph.class);
		Configuration jobConf = new Configuration();
		Mockito.when(eg.getFutureExecutor()).thenReturn(TestingUtils.directExecutionContext());
		Mockito.when(eg.getJobConfiguration()).thenReturn(jobConf);

		ExecutionJobVertex ejv1 = new ExecutionJobVertex(eg, v1, 1,
				AkkaUtils.getDefaultTimeout());
		ExecutionJobVertex ejv2 = new ExecutionJobVertex(eg, v2, 1,
				AkkaUtils.getDefaultTimeout());
		ExecutionJobVertex ejv3 = new ExecutionJobVertex(eg, v3, 1,
				AkkaUtils.getDefaultTimeout());
		ExecutionJobVertex ejv4 = new ExecutionJobVertex(eg, v4, 1,
				AkkaUtils.getDefaultTimeout());
		
		AllVerticesIterator iter = new AllVerticesIterator(Arrays.asList(ejv1, ejv2, ejv3, ejv4).iterator());
		
		int numReturned = 0;
		while (iter.hasNext()) {
			iter.hasNext();
			Assert.assertNotNull(iter.next());
			numReturned++;
		}
		
		Assert.assertEquals(13, numReturned);
	}
	catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example 18
Source File: VertexSlotSharingTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testAssignSlotSharingGroup() {
	try {
		JobVertex v1 = new JobVertex("v1");
		JobVertex v2 = new JobVertex("v2");
		JobVertex v3 = new JobVertex("v3");
		JobVertex v4 = new JobVertex("v4");
		JobVertex v5 = new JobVertex("v5");
		
		v1.setParallelism(4);
		v2.setParallelism(5);
		v3.setParallelism(7);
		v4.setParallelism(1);
		v5.setParallelism(11);

		v1.setInvokableClass(AbstractInvokable.class);
		v2.setInvokableClass(AbstractInvokable.class);
		v3.setInvokableClass(AbstractInvokable.class);
		v4.setInvokableClass(AbstractInvokable.class);
		v5.setInvokableClass(AbstractInvokable.class);

		v2.connectNewDataSetAsInput(v1, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
		v5.connectNewDataSetAsInput(v4, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
		
		SlotSharingGroup jg1 = new SlotSharingGroup();
		v2.setSlotSharingGroup(jg1);
		v3.setSlotSharingGroup(jg1);
		
		SlotSharingGroup jg2 = new SlotSharingGroup();
		v4.setSlotSharingGroup(jg2);
		v5.setSlotSharingGroup(jg2);
		
		List<JobVertex> vertices = new ArrayList<JobVertex>(Arrays.asList(v1, v2, v3, v4, v5));
		
		ExecutionGraph eg = new ExecutionGraph(
			TestingUtils.defaultExecutor(),
			TestingUtils.defaultExecutor(),
			new JobID(),
			"test job",
			new Configuration(),
			new SerializedValue<>(new ExecutionConfig()),
			AkkaUtils.getDefaultTimeout(),
			new NoRestartStrategy(),
			new TestingSlotProvider(ignored -> new CompletableFuture<>()));
		eg.attachJobGraph(vertices);
		
		// verify that the vertices are all in the same slot sharing group
		SlotSharingGroup group1 = null;
		SlotSharingGroup group2 = null;
		
		// verify that v1 tasks have no slot sharing group
		assertNull(eg.getJobVertex(v1.getID()).getSlotSharingGroup());
		
		// v2 and v3 are shared
		group1 = eg.getJobVertex(v2.getID()).getSlotSharingGroup();
		assertNotNull(group1);
		assertEquals(group1, eg.getJobVertex(v3.getID()).getSlotSharingGroup());
		
		assertEquals(2, group1.getJobVertexIds().size());
		assertTrue(group1.getJobVertexIds().contains(v2.getID()));
		assertTrue(group1.getJobVertexIds().contains(v3.getID()));
		
		// v4 and v5 are shared
		group2 = eg.getJobVertex(v4.getID()).getSlotSharingGroup();
		assertNotNull(group2);
		assertEquals(group2, eg.getJobVertex(v5.getID()).getSlotSharingGroup());
		
		assertEquals(2, group1.getJobVertexIds().size());
		assertTrue(group2.getJobVertexIds().contains(v4.getID()));
		assertTrue(group2.getJobVertexIds().contains(v5.getID()));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 19
Source File: RestartPipelinedRegionStrategyTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
    * Creates a JobGraph of the following form:
    *
    * <pre>
    *  v1--->v2-->\
    *              \
    *               v4 --->|\
    *        ----->/        \
    *  v3-->/                v5
    *       \               /
    *        ------------->/
    * </pre>
    */
@Test
public void testSingleRegionWithMixedInput() throws Exception {
	final JobID jobId = new JobID();
	final String jobName = "Test Job Sample Name";

       JobVertex v1 = new JobVertex("vertex1");
       JobVertex v2 = new JobVertex("vertex2");
       JobVertex v3 = new JobVertex("vertex3");
       JobVertex v4 = new JobVertex("vertex4");
       JobVertex v5 = new JobVertex("vertex5");

       v1.setParallelism(3);
       v2.setParallelism(2);
       v3.setParallelism(2);
       v4.setParallelism(5);
       v5.setParallelism(2);

       v1.setInvokableClass(AbstractInvokable.class);
       v2.setInvokableClass(AbstractInvokable.class);
       v3.setInvokableClass(AbstractInvokable.class);
       v4.setInvokableClass(AbstractInvokable.class);
       v5.setInvokableClass(AbstractInvokable.class);

       v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
       v4.connectNewDataSetAsInput(v2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
       v4.connectNewDataSetAsInput(v3, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
       v5.connectNewDataSetAsInput(v3, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
       v5.connectNewDataSetAsInput(v4, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);

       List<JobVertex> ordered = new ArrayList<JobVertex>(Arrays.asList(v1, v2, v3, v4, v5));

	final JobInformation jobInformation = new DummyJobInformation(
		jobId,
		jobName);

	ExecutionGraph eg = new ExecutionGraph(
		jobInformation,
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
           new RestartPipelinedRegionStrategy.Factory(),
		new TestingSlotProvider(ignored -> new CompletableFuture<>()),
           ExecutionGraph.class.getClassLoader(),
		VoidBlobWriter.getInstance(),
		AkkaUtils.getDefaultTimeout());
	try {
		eg.attachJobGraph(ordered);
	}
	catch (JobException e) {
		e.printStackTrace();
		fail("Job failed with exception: " + e.getMessage());
	}

       // All in one failover region
       RestartPipelinedRegionStrategy strategy = (RestartPipelinedRegionStrategy)eg.getFailoverStrategy();
       ExecutionJobVertex ejv1 = eg.getJobVertex(v1.getID());
       ExecutionJobVertex ejv2 = eg.getJobVertex(v2.getID());
       ExecutionJobVertex ejv3 = eg.getJobVertex(v3.getID());
       ExecutionJobVertex ejv4 = eg.getJobVertex(v4.getID());
       ExecutionJobVertex ejv5 = eg.getJobVertex(v5.getID());
       FailoverRegion region1 = strategy.getFailoverRegion(ejv1.getTaskVertices()[1]);
       FailoverRegion region2 = strategy.getFailoverRegion(ejv2.getTaskVertices()[0]);
       FailoverRegion region4 = strategy.getFailoverRegion(ejv4.getTaskVertices()[3]);
       FailoverRegion region3 = strategy.getFailoverRegion(ejv3.getTaskVertices()[0]);
       FailoverRegion region5 = strategy.getFailoverRegion(ejv5.getTaskVertices()[1]);

       assertEquals(region1, region2);
       assertEquals(region2, region4);
       assertEquals(region3, region2);
       assertEquals(region1, region5);
   }
 
Example 20
Source File: ExecutionVertexCancelTest.java    From flink with Apache License 2.0 2 votes vote down vote up
@Test
public void testRepeatedCancelFromRunning() {
	try {

		final JobVertexID jid = new JobVertexID();
		final ExecutionJobVertex ejv = ExecutionGraphTestUtils.getExecutionJobVertex(jid, new DirectScheduledExecutorService());

		final ExecutionVertex vertex = new ExecutionVertex(ejv, 0, new IntermediateResult[0],
				AkkaUtils.getDefaultTimeout());

		LogicalSlot slot = new TestingLogicalSlotBuilder().setTaskManagerGateway(new CancelSequenceSimpleAckingTaskManagerGateway(1)).createTestingLogicalSlot();

		setVertexResource(vertex, slot);
		setVertexState(vertex, ExecutionState.RUNNING);

		assertEquals(ExecutionState.RUNNING, vertex.getExecutionState());

		vertex.cancel();

		assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());

		vertex.cancel();

		assertEquals(ExecutionState.CANCELING, vertex.getExecutionState());

		// callback by TaskManager after canceling completes
		vertex.getCurrentExecutionAttempt().completeCancelling();

		assertEquals(ExecutionState.CANCELED, vertex.getExecutionState());

		assertFalse(slot.isAlive());

		assertNull(vertex.getFailureCause());

		assertTrue(vertex.getStateTimestamp(ExecutionState.CREATED) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELING) > 0);
		assertTrue(vertex.getStateTimestamp(ExecutionState.CANCELED) > 0);
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}