LinuxContainerExecutor extends ContainerExecutor { @Override public boolean reapContainer(ContainerReapContext ctx) throws IOException { Container container = ctx.getContainer(); String user = ctx.getUser(); String runAsUser = getRunAsUser(user); ContainerRuntimeContext runtimeContext = new ContainerRuntimeContext .Builder(container) .setExecutionAttribute(RUN_AS_USER, runAsUser) .setExecutionAttribute(USER, user) .build(); try { linuxContainerRuntime.reapContainer(runtimeContext); } catch (ContainerExecutionException e) { int retCode = e.getExitCode(); if (retCode != 0) { return false; } LOG.warn("Error in reaping container " + container.getContainerId().toString() + " exit = " + retCode, e); logOutput(e.getOutput()); throw new IOException("Error in reaping container " + container.getContainerId().toString() + " exit = " + retCode, e); } finally { postComplete(container.getContainerId()); } return true; } LinuxContainerExecutor();  LinuxContainerExecutor(LinuxContainerRuntime linuxContainerRuntime); @Override void setConf(Configuration conf); @Override void init(Context context); @Override void startLocalizer(LocalizerStartContext ctx); @VisibleForTesting void buildMainArgs(List<String> command, String user, String appId,
      String locId, InetSocketAddress nmAddr, List<String> localDirs); @Override void prepareContainer(ContainerPrepareContext ctx); @Override int launchContainer(ContainerStartContext ctx); @Override int relaunchContainer(ContainerStartContext ctx); @Override String[] getIpAndHost(Container container); @Override int reacquireContainer(ContainerReacquisitionContext ctx); @Override boolean signalContainer(ContainerSignalContext ctx); @Override boolean reapContainer(ContainerReapContext ctx); @Override void deleteAsUser(DeletionAsUserContext ctx); @Override void symLink(String target, String symlink); @Override boolean isContainerAlive(ContainerLivenessContext ctx); void mountCgroups(List<String> cgroupKVs, String hierarchy); @VisibleForTesting ResourceHandler getResourceHandler(); void removeDockerContainer(String containerId);  }
@Test public void testReapContainer() throws Exception { Container container = mock(Container.class); LinuxContainerRuntime containerRuntime = mock(LinuxContainerRuntime.class); LinuxContainerExecutor lce = spy(new LinuxContainerExecutor( containerRuntime)); ContainerReapContext.Builder builder = new ContainerReapContext.Builder(); builder.setContainer(container).setUser("foo"); ContainerReapContext ctx = builder.build(); lce.reapContainer(ctx); verify(lce, times(1)).reapContainer(ctx); verify(lce, times(1)).postComplete(anyObject()); }