Source:
<code>public void testOnStartContainerError() throws Exception { new Context() {{ final List<CompletableFuture<Void>> addContainerRequestFutures = new ArrayList<>(); addContainerRequestFutures.add(new CompletableFuture<>()); addContainerRequestFutures.add(new CompletableFuture<>()); final AtomicInteger addContainerRequestFuturesNumCompleted = new AtomicInteger(0); final CompletableFuture<Void> removeContainerRequestFuture = new CompletableFuture<>(); final CompletableFuture<Void> releaseAssignedContainerFuture = new CompletableFuture<>(); final CompletableFuture<Void> startContainerAsyncFuture = new CompletableFuture<>(); testingYarnAMRMClientAsyncBuilder.setGetMatchingRequestsFunction(ignored -> Collections.singletonList(Collections.singletonList(YarnResourceManagerDriver.getContainerRequest(testingResource)))); testingYarnAMRMClientAsyncBuilder.setAddContainerRequestConsumer((ignored1, ignored2) -> addContainerRequestFutures.get(addContainerRequestFuturesNumCompleted.getAndIncrement()).complete(null)); testingYarnAMRMClientAsyncBuilder.setRemoveContainerRequestConsumer((ignored1, ignored2) -> removeContainerRequestFuture.complete(null)); testingYarnAMRMClientAsyncBuilder.setReleaseAssignedContainerConsumer((ignored1, ignored2) -> releaseAssignedContainerFuture.complete(null)); testingYarnNMClientAsyncBuilder.setStartContainerAsyncConsumer((ignored1, ignored2, ignored3) -> startContainerAsyncFuture.complete(null)); resourceEventHandlerBuilder.setOnWorkerTerminatedConsumer((ignore1, ignore2) -> getDriver().requestResource(testingTaskExecutorProcessSpec)); runTest(() -> { <START> getDriver().requestResource(testingTaskExecutorProcessSpec); <END> ((YarnResourceManagerDriver) getDriver()).getYarnContainerEventHandler().onContainersAllocated(ImmutableList.of(testingContainer)); verifyFutureCompleted(addContainerRequestFutures.get(0)); verifyFutureCompleted(removeContainerRequestFuture); verifyFutureCompleted(startContainerAsyncFuture); ((YarnResourceManagerDriver) getDriver()).getYarnContainerEventHandler().onStartContainerError(testingContainer.getId(), new Exception("start error")); verifyFutureCompleted(releaseAssignedContainerFuture); verifyFutureCompleted(addContainerRequestFutures.get(1)); }); }}; }</code><technical_language>This interface invoked main thread</technical_language>

Target:
public void testOnStartContainerError() throws Exception { new Context() {{ addContainerRequestFutures.add(new CompletableFuture<>()); addContainerRequestFutures.add(new CompletableFuture<>()); testingYarnAMRMClientAsyncBuilder.setAddContainerRequestConsumer((ignored1, ignored2) -> addContainerRequestFutures.get(addContainerRequestFuturesNumCompleted.getAndIncrement()).complete(null)); resourceEventHandlerBuilder.setOnWorkerTerminatedConsumer((ignore1, ignore2) -> getDriver().requestResource(testingTaskExecutorProcessSpec)); runTest(() -> { runInMainThread(() -> getDriver().requestResource(testingTaskExecutorProcessSpec)); resourceManagerClientCallbackHandler.onContainersAllocated(ImmutableList.of(testingContainer)); nodeManagerClientCallbackHandler.onStartContainerError(testingContainer.getId(), new Exception("start error")); verifyFutureCompleted(releaseAssignedContainerFuture); verifyFutureCompleted(addContainerRequestFutures.get(1)); }); }}; }