AbstractLauncher { public void setRetryContext(int maxRetries, int retryInterval, long failuresValidityInterval) { ContainerRetryContext retryContext = ContainerRetryContext .newInstance(ContainerRetryPolicy.RETRY_ON_ALL_ERRORS, null, maxRetries, retryInterval, failuresValidityInterval); containerLaunchContext.setContainerRetryContext(retryContext); } AbstractLauncher(ServiceContext context); void setYarnDockerMode(boolean yarnDockerMode); Map<String, String> getEnv(); List<String> getCommands(); void addLocalResource(String subPath, LocalResource resource); void addLocalResource(String subPath, LocalResource resource, String mountPath); void addCommand(String cmd); ContainerLaunchContext completeContainerLaunch(); void setRetryContext(int maxRetries, int retryInterval,
      long failuresValidityInterval); void setClasspath(ClasspathConstructor classpath); void setEnv(String var, String value); void putEnv(Map<String, String> map); void setDockerImage(String dockerImage); void setDockerNetwork(String dockerNetwork); void setDockerHostname(String dockerHostname); void setRunPrivilegedContainer(boolean runPrivilegedContainer); @VisibleForTesting String getDockerImage(); static final String CLASSPATH; static final String ENV_DOCKER_CONTAINER_MOUNTS; }
@Test public void testContainerRetries() throws Exception { DefaultProviderService providerService = new DefaultProviderService(); AbstractLauncher mockLauncher = mock(AbstractLauncher.class); ContainerLaunchService.ComponentLaunchContext componentLaunchContext = mock(ContainerLaunchService.ComponentLaunchContext.class); ComponentInstance componentInstance = mock(ComponentInstance.class); Component component = mock(Component.class); when(componentInstance.getComponent()).thenReturn(component); when(component.getRestartPolicyHandler()).thenReturn(NeverRestartPolicy .getInstance()); providerService.buildContainerRetry(mockLauncher, getConfig(), componentLaunchContext, componentInstance); verifyZeroInteractions(mockLauncher); when(component.getRestartPolicyHandler()).thenReturn(OnFailureRestartPolicy .getInstance()); when(componentLaunchContext.getConfiguration()).thenReturn(new Configuration()); providerService.buildContainerRetry(mockLauncher, getConfig(), componentLaunchContext, componentInstance); verify(mockLauncher).setRetryContext(DEFAULT_CONTAINER_RETRY_MAX, DEFAULT_CONTAINER_RETRY_INTERVAL, DEFAULT_CONTAINER_FAILURES_VALIDITY_INTERVAL); reset(mockLauncher); when(component.getRestartPolicyHandler()).thenReturn(AlwaysRestartPolicy .getInstance()); providerService.buildContainerRetry(mockLauncher, getConfig(), componentLaunchContext, componentInstance); verify(mockLauncher).setRetryContext(DEFAULT_CONTAINER_RETRY_MAX, DEFAULT_CONTAINER_RETRY_INTERVAL, DEFAULT_CONTAINER_FAILURES_VALIDITY_INTERVAL); }