org.apache.flink.runtime.taskexecutor.exceptions.TaskSubmissionException Java Examples

The following examples show how to use org.apache.flink.runtime.taskexecutor.exceptions.TaskSubmissionException. 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: TaskExecutorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that accepted slots go into state assigned and the others are returned to the resource
 * manager.
 */
@Test
public void testSlotAcceptance() throws Exception {
	final InstanceID registrationId = new InstanceID();
	final OneShotLatch taskExecutorIsRegistered = new OneShotLatch();
	final CompletableFuture<Tuple3<InstanceID, SlotID, AllocationID>> availableSlotFuture = new CompletableFuture<>();
	final TestingResourceManagerGateway resourceManagerGateway =
		createRmWithTmRegisterAndNotifySlotHooks(registrationId, taskExecutorIsRegistered, availableSlotFuture);

	final AllocationID allocationId1 = new AllocationID();
	final AllocationID allocationId2 = new AllocationID();

	final SlotOffer offer1 = new SlotOffer(allocationId1, 0, ResourceProfile.ANY);

	final OneShotLatch offerSlotsLatch = new OneShotLatch();
	final OneShotLatch taskInTerminalState = new OneShotLatch();
	final CompletableFuture<Collection<SlotOffer>> offerResultFuture = new CompletableFuture<>();
	final TestingJobMasterGateway jobMasterGateway =
		createJobMasterWithSlotOfferAndTaskTerminationHooks(offerSlotsLatch, taskInTerminalState, offerResultFuture);

	rpc.registerGateway(resourceManagerGateway.getAddress(), resourceManagerGateway);
	rpc.registerGateway(jobMasterGateway.getAddress(), jobMasterGateway);

	final TaskSlotTable<Task> taskSlotTable = TaskSlotUtils.createTaskSlotTable(2);
	final TaskManagerServices taskManagerServices = createTaskManagerServicesWithTaskSlotTable(taskSlotTable);
	final TestingTaskExecutor taskManager = createTestingTaskExecutor(taskManagerServices);

	try {
		taskManager.start();
		taskManager.waitUntilStarted();

		final TaskExecutorGateway tmGateway = taskManager.getSelfGateway(TaskExecutorGateway.class);

		// wait until registered at the RM
		taskExecutorIsRegistered.await();

		// request 2 slots for the given allocation ids
		requestSlots(
			tmGateway,
			Arrays.asList(allocationId1, allocationId2),
			resourceManagerGateway.getFencingToken(),
			jobMasterGateway.getAddress());

		// notify job leader to start slot offering
		jobManagerLeaderRetriever.notifyListener(jobMasterGateway.getAddress(), jobMasterGateway.getFencingToken().toUUID());

		// wait until slots have been offered
		offerSlotsLatch.await();
		offerResultFuture.complete(Collections.singletonList(offer1));

		final Tuple3<InstanceID, SlotID, AllocationID> instanceIDSlotIDAllocationIDTuple3 = availableSlotFuture.get();

		final Tuple3<InstanceID, SlotID, AllocationID> expectedResult = Tuple3.of(registrationId, new SlotID(unresolvedTaskManagerLocation.getResourceID(), 1), allocationId2);

		assertThat(instanceIDSlotIDAllocationIDTuple3, equalTo(expectedResult));
		// the slot 1 can be activate for task submission
		submitNoOpInvokableTask(allocationId1, jobMasterGateway, tmGateway);
		// wait for the task completion
		taskInTerminalState.await();
		// the slot 2 can NOT be activate for task submission
		try {
			submitNoOpInvokableTask(allocationId2, jobMasterGateway, tmGateway);
			fail("It should not be possible to submit task to acquired by JM slot with index 1 (allocationId2)");
		} catch (CompletionException e) {
			assertThat(e.getCause(), instanceOf(TaskSubmissionException.class));
		}
		// the slot 2 is free to request
		tmGateway
			.requestSlot(
				new SlotID(unresolvedTaskManagerLocation.getResourceID(), 1),
				jobId,
				allocationId2,
				ResourceProfile.UNKNOWN,
				jobMasterGateway.getAddress(),
				resourceManagerGateway.getFencingToken(),
				timeout)
			.join();
	} finally {
		RpcUtils.terminateRpcEndpoint(taskManager, timeout);
	}
}