use of org.apache.flink.runtime.entrypoint.ClusterInformation in project flink by apache.
the class TaskExecutorTest method testRegisterWithDefaultSlotResourceProfile.
@Test
public void testRegisterWithDefaultSlotResourceProfile() throws Exception {
final int numberOfSlots = 2;
final TaskExecutor taskExecutor = createTaskExecutor(numberOfSlots);
taskExecutor.start();
try {
final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
final CompletableFuture<ResourceProfile> registeredDefaultSlotResourceProfileFuture = new CompletableFuture<>();
final ResourceID ownResourceId = testingResourceManagerGateway.getOwnResourceId();
testingResourceManagerGateway.setRegisterTaskExecutorFunction(taskExecutorRegistration -> {
registeredDefaultSlotResourceProfileFuture.complete(taskExecutorRegistration.getDefaultSlotResourceProfile());
return CompletableFuture.completedFuture(new TaskExecutorRegistrationSuccess(new InstanceID(), ownResourceId, new ClusterInformation("localhost", 1234)));
});
rpc.registerGateway(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway);
resourceManagerLeaderRetriever.notifyListener(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway.getFencingToken().toUUID());
assertThat(registeredDefaultSlotResourceProfileFuture.get(), equalTo(TaskExecutorResourceUtils.generateDefaultSlotResourceProfile(TM_RESOURCE_SPEC, numberOfSlots)));
} finally {
RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
}
}
use of org.apache.flink.runtime.entrypoint.ClusterInformation in project flink by apache.
the class TaskExecutorTest method runResourceManagerHeartbeatTest.
private void runResourceManagerHeartbeatTest(HeartbeatServices heartbeatServices, Consumer<TestingResourceManagerGateway> setupResourceManagerGateway, TriConsumerWithException<TaskExecutorGateway, ResourceID, CompletableFuture<ResourceID>, Exception> heartbeatAction) throws Exception {
final String rmAddress = "rm";
final ResourceID rmResourceId = new ResourceID(rmAddress);
final ResourceManagerId rmLeaderId = ResourceManagerId.generate();
TestingResourceManagerGateway rmGateway = new TestingResourceManagerGateway(rmLeaderId, rmResourceId, rmAddress, rmAddress);
final TaskExecutorRegistrationSuccess registrationResponse = new TaskExecutorRegistrationSuccess(new InstanceID(), rmResourceId, new ClusterInformation("localhost", 1234));
final Queue<CompletableFuture<RegistrationResponse>> registrationResponses = new ArrayDeque<>(2);
registrationResponses.add(CompletableFuture.completedFuture(registrationResponse));
registrationResponses.add(new CompletableFuture<>());
final CompletableFuture<ResourceID> taskExecutorRegistrationFuture = new CompletableFuture<>();
final CountDownLatch registrationAttempts = new CountDownLatch(2);
rmGateway.setRegisterTaskExecutorFunction(registration -> {
taskExecutorRegistrationFuture.complete(registration.getResourceId());
registrationAttempts.countDown();
return registrationResponses.poll();
});
setupResourceManagerGateway.accept(rmGateway);
final CompletableFuture<ResourceID> taskExecutorDisconnectFuture = new CompletableFuture<>();
rmGateway.setDisconnectTaskExecutorConsumer(disconnectInfo -> taskExecutorDisconnectFuture.complete(disconnectInfo.f0));
rpc.registerGateway(rmAddress, rmGateway);
final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setUnresolvedTaskManagerLocation(unresolvedTaskManagerLocation).build();
final TaskExecutor taskManager = createTaskExecutor(taskManagerServices, heartbeatServices);
try {
taskManager.start();
final TaskExecutorGateway taskExecutorGateway = taskManager.getSelfGateway(TaskExecutorGateway.class);
// define a leader and see that a registration happens
resourceManagerLeaderRetriever.notifyListener(rmAddress, rmLeaderId.toUUID());
// register resource manager success will trigger monitoring heartbeat target between tm
// and rm
assertThat(taskExecutorRegistrationFuture.get(), equalTo(unresolvedTaskManagerLocation.getResourceID()));
heartbeatAction.accept(taskExecutorGateway, rmGateway.getOwnResourceId(), taskExecutorDisconnectFuture);
// heartbeat timeout should trigger disconnect TaskManager from ResourceManager
assertThat(taskExecutorDisconnectFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS), equalTo(unresolvedTaskManagerLocation.getResourceID()));
assertTrue("The TaskExecutor should try to reconnect to the RM", registrationAttempts.await(timeout.toMilliseconds(), TimeUnit.SECONDS));
} finally {
RpcUtils.terminateRpcEndpoint(taskManager, timeout);
}
}
Aggregations