use of org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway in project flink by apache.
the class DeclarativeSlotPoolServiceTest method testSlotOfferingOfKnownTaskManager.
@Test
public void testSlotOfferingOfKnownTaskManager() throws Exception {
final AtomicReference<Collection<? extends SlotOffer>> receivedSlotOffers = new AtomicReference<>();
try (DeclarativeSlotPoolService declarativeSlotPoolService = createDeclarativeSlotPoolService(new TestingDeclarativeSlotPoolFactory(new TestingDeclarativeSlotPoolBuilder().setOfferSlotsFunction((slotOffers, taskManagerLocation, taskManagerGateway, aLong) -> {
receivedSlotOffers.set(slotOffers);
return new ArrayList<>(slotOffers);
})))) {
final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
declarativeSlotPoolService.registerTaskManager(taskManagerLocation.getResourceID());
final Collection<SlotOffer> slotOffers = Collections.singletonList(new SlotOffer(new AllocationID(), 0, ResourceProfile.UNKNOWN));
declarativeSlotPoolService.offerSlots(taskManagerLocation, new RpcTaskManagerGateway(new TestingTaskExecutorGatewayBuilder().createTestingTaskExecutorGateway(), jobMasterId), slotOffers);
assertThat(receivedSlotOffers.get(), is(slotOffers));
}
}
use of org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway in project flink by apache.
the class DeclarativeSlotPoolServiceTest method testSlotOfferingOfUnknownTaskManagerIsIgnored.
@Test
public void testSlotOfferingOfUnknownTaskManagerIsIgnored() throws Exception {
try (DeclarativeSlotPoolService declarativeSlotPoolService = createDeclarativeSlotPoolService()) {
final Collection<SlotOffer> slotOffers = Collections.singletonList(new SlotOffer(new AllocationID(), 0, ResourceProfile.UNKNOWN));
final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
final Collection<SlotOffer> acceptedSlots = declarativeSlotPoolService.offerSlots(taskManagerLocation, new RpcTaskManagerGateway(new TestingTaskExecutorGatewayBuilder().createTestingTaskExecutorGateway(), jobMasterId), slotOffers);
assertThat(acceptedSlots, is(empty()));
}
}
use of org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway in project flink by apache.
the class DefaultExecutionGraphDeploymentTest method testExecutionGraphIsDeployedInTopologicalOrder.
/**
* Tests that the {@link ExecutionGraph} is deployed in topological order.
*/
@Test
public void testExecutionGraphIsDeployedInTopologicalOrder() throws Exception {
final int sourceParallelism = 2;
final int sinkParallelism = 1;
final JobVertex sourceVertex = new JobVertex("source");
sourceVertex.setInvokableClass(NoOpInvokable.class);
sourceVertex.setParallelism(sourceParallelism);
final JobVertex sinkVertex = new JobVertex("sink");
sinkVertex.setInvokableClass(NoOpInvokable.class);
sinkVertex.setParallelism(sinkParallelism);
sinkVertex.connectNewDataSetAsInput(sourceVertex, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
final int numberTasks = sourceParallelism + sinkParallelism;
final ArrayBlockingQueue<ExecutionAttemptID> submittedTasksQueue = new ArrayBlockingQueue<>(numberTasks);
TestingTaskExecutorGatewayBuilder testingTaskExecutorGatewayBuilder = new TestingTaskExecutorGatewayBuilder();
testingTaskExecutorGatewayBuilder.setSubmitTaskConsumer((taskDeploymentDescriptor, jobMasterId) -> {
submittedTasksQueue.offer(taskDeploymentDescriptor.getExecutionAttemptId());
return CompletableFuture.completedFuture(Acknowledge.get());
});
final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
final TestingTaskExecutorGateway taskExecutorGateway = testingTaskExecutorGatewayBuilder.createTestingTaskExecutorGateway();
final RpcTaskManagerGateway taskManagerGateway = new RpcTaskManagerGateway(taskExecutorGateway, JobMasterId.generate());
final JobGraph jobGraph = JobGraphTestUtils.streamingJobGraph(sourceVertex, sinkVertex);
final TestingPhysicalSlotProvider physicalSlotProvider = TestingPhysicalSlotProvider.createWithoutImmediatePhysicalSlotCreation();
final SchedulerBase scheduler = SchedulerTestingUtils.newSchedulerBuilder(jobGraph, ComponentMainThreadExecutorServiceAdapter.forMainThread()).setExecutionSlotAllocatorFactory(SchedulerTestingUtils.newSlotSharingExecutionSlotAllocatorFactory(physicalSlotProvider)).setFutureExecutor(new DirectScheduledExecutorService()).build();
final ExecutionGraph executionGraph = scheduler.getExecutionGraph();
scheduler.startScheduling();
// change the order in which the futures are completed
final List<CompletableFuture<TestingPhysicalSlot>> shuffledFutures = new ArrayList<>(physicalSlotProvider.getResponses().values());
Collections.shuffle(shuffledFutures);
for (CompletableFuture<TestingPhysicalSlot> slotFuture : shuffledFutures) {
slotFuture.complete(TestingPhysicalSlot.builder().withTaskManagerLocation(taskManagerLocation).withTaskManagerGateway(taskManagerGateway).build());
}
final List<ExecutionAttemptID> submittedTasks = new ArrayList<>(numberTasks);
for (int i = 0; i < numberTasks; i++) {
submittedTasks.add(submittedTasksQueue.take());
}
final Collection<ExecutionAttemptID> firstStage = new ArrayList<>(sourceParallelism);
for (ExecutionVertex taskVertex : executionGraph.getJobVertex(sourceVertex.getID()).getTaskVertices()) {
firstStage.add(taskVertex.getCurrentExecutionAttempt().getAttemptId());
}
final Collection<ExecutionAttemptID> secondStage = new ArrayList<>(sinkParallelism);
for (ExecutionVertex taskVertex : executionGraph.getJobVertex(sinkVertex.getID()).getTaskVertices()) {
secondStage.add(taskVertex.getCurrentExecutionAttempt().getAttemptId());
}
assertThat(submittedTasks, new ExecutionStageMatcher(Arrays.asList(firstStage, secondStage)));
}
use of org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway in project flink by apache.
the class DefaultSchedulerBatchSchedulingTest method testSchedulingOfJobWithFewerSlotsThanParallelism.
/**
* Tests that a batch job can be executed with fewer slots than its parallelism. See FLINK-13187
* for more information.
*/
@Test
public void testSchedulingOfJobWithFewerSlotsThanParallelism() throws Exception {
final int parallelism = 5;
final Time batchSlotTimeout = Time.milliseconds(5L);
final JobGraph jobGraph = createBatchJobGraph(parallelism);
try (final SlotPool slotPool = createSlotPool(mainThreadExecutor, batchSlotTimeout)) {
final ArrayBlockingQueue<ExecutionAttemptID> submittedTasksQueue = new ArrayBlockingQueue<>(parallelism);
TestingTaskExecutorGateway testingTaskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setSubmitTaskConsumer((tdd, ignored) -> {
submittedTasksQueue.offer(tdd.getExecutionAttemptId());
return CompletableFuture.completedFuture(Acknowledge.get());
}).createTestingTaskExecutorGateway();
final PhysicalSlotProvider slotProvider = new PhysicalSlotProviderImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), slotPool);
final GloballyTerminalJobStatusListener jobStatusListener = new GloballyTerminalJobStatusListener();
final SchedulerNG scheduler = createScheduler(jobGraph, mainThreadExecutor, slotProvider, batchSlotTimeout, jobStatusListener);
CompletableFuture.runAsync(scheduler::startScheduling, mainThreadExecutor).join();
// register a single slot at the slot pool
SlotPoolUtils.offerSlots(slotPool, mainThreadExecutor, Collections.singletonList(ResourceProfile.ANY), new RpcTaskManagerGateway(testingTaskExecutorGateway, JobMasterId.generate()));
// wait until the batch slot timeout has been reached
Thread.sleep(batchSlotTimeout.toMilliseconds());
final CompletableFuture<JobStatus> terminationFuture = jobStatusListener.getTerminationFuture();
for (int i = 0; i < parallelism; i++) {
final CompletableFuture<ExecutionAttemptID> submittedTaskFuture = CompletableFuture.supplyAsync(CheckedSupplier.unchecked(submittedTasksQueue::take));
// wait until one of them is completed
CompletableFuture.anyOf(submittedTaskFuture, terminationFuture).join();
if (submittedTaskFuture.isDone()) {
finishExecution(submittedTaskFuture.get(), scheduler, mainThreadExecutor);
} else {
fail(String.format("Job reached a globally terminal state %s before all executions were finished.", terminationFuture.get()));
}
}
assertThat(terminationFuture.get(), is(JobStatus.FINISHED));
}
}
Aggregations