@Override
    protected CompletableFuture<ProfilingInfoList> handleRequest(
            @Nonnull HandlerRequest<EmptyRequestBody> request,
            @Nonnull ResourceManagerGateway gateway)
            throws RestHandlerException {
        final ResourceID taskManagerId = request.getPathParameter(TaskManagerIdPathParameter.class);
        final ResourceManagerGateway resourceManagerGateway =
                getResourceManagerGateway(resourceManagerGatewayRetriever);
        final CompletableFuture<Collection<ProfilingInfo>> profilingListFuture =
                resourceManagerGateway.requestTaskManagerProfilingList(taskManagerId, getTimeout());

        return profilingListFuture
                .thenApply(ProfilingInfoList::new)
                .exceptionally(
                        (throwable) -> {
                            final Throwable strippedThrowable =
                                    ExceptionUtils.stripCompletionException(throwable);
                            if (strippedThrowable instanceof UnknownTaskExecutorException) {
                                throw new CompletionException(
                                        new RestHandlerException(
                                                "Could not find TaskExecutor " + taskManagerId,
                                                HttpResponseStatus.NOT_FOUND,
                                                strippedThrowable));
                            } else {
                                throw new CompletionException(throwable);
                            }
                        });
    }
@Test
    void testGetTaskManagerProfilingList() throws Exception {
        ProfilingInfoList profilingInfoList =
                new ProfilingInfoList(
                        Arrays.asList(
                                ProfilingInfo.create(30, ProfilingInfo.ProfilingMode.ITIMER),
                                ProfilingInfo.create(10, ProfilingInfo.ProfilingMode.CPU),
                                ProfilingInfo.create(15, ProfilingInfo.ProfilingMode.ALLOC)));
        resourceManagerGateway.setRequestProfilingListFunction(
                EXPECTED_TASK_MANAGER_ID ->
                        CompletableFuture.completedFuture(profilingInfoList.getProfilingInfos()));
        ProfilingInfoList profilingInfoListResp =
                taskManagerProfilingListHandler
                        .handleRequest(handlerRequest, resourceManagerGateway)
                        .get();
        assertThat(profilingInfoListResp.getProfilingInfos())
                .containsExactlyInAnyOrderElementsOf(profilingInfoList.getProfilingInfos());
    }