@Override public void after() { try { shutdownStrategy().shutdown(this); logCollector().stopCollecting(); } catch (IOException | InterruptedException e) { throw new RuntimeException("Error cleaning up docker compose cluster", e); } }
@Override public void after() { try { shutdownStrategy().shutdown(this.dockerCompose(), this.docker()); logCollector().stopCollecting(); } catch (IOException | InterruptedException e) { throw new RuntimeException("Error cleaning up docker compose cluster", e); } }
@Override public void after() { try { shutdownStrategy().shutdown(this.dockerCompose(), this.docker()); logCollector().stopCollecting(); } catch (IOException | InterruptedException e) { throw new RuntimeException("Error cleaning up docker compose cluster", e); } }
void after(ExtensionContext extensionContext, Class<?> testClass, Compose compose) throws Exception { ExtensionContext.Namespace namespace = namespace(extensionContext); ExtensionContext.Store store = extensionContext.getStore(namespace); DockerCompose dockerCompose = dockerCompose(store, compose); Docker docker = docker(store, compose); LogCollector collector = logCollector(extensionContext, testClass, store, compose); collector.stopCollecting(); try { ShutdownStrategy.KILL_DOWN.shutdown(dockerCompose, docker); } catch (IOException | InterruptedException e) { throw new RuntimeException("Error cleaning up docker compose cluster", e); } }
@Test public void call_kill_then_down() throws Exception { DockerCompose dockerCompose = mock(DockerCompose.class); Docker docker = mock(Docker.class); ShutdownStrategy.KILL_DOWN.shutdown(dockerCompose, docker); InOrder inOrder = inOrder(dockerCompose, docker); inOrder.verify(dockerCompose).kill(); inOrder.verify(dockerCompose).down(); inOrder.verify(docker).pruneNetworks(); inOrder.verifyNoMoreInteractions(); } }
@Test public void call_down_then_kill_then_rm() throws Exception { DockerCompose dockerCompose = mock(DockerCompose.class); Docker docker = mock(Docker.class); ShutdownStrategy.GRACEFUL.shutdown(dockerCompose, docker); InOrder inOrder = inOrder(dockerCompose, docker); inOrder.verify(dockerCompose).down(); inOrder.verify(dockerCompose).kill(); inOrder.verify(dockerCompose).rm(); inOrder.verify(docker).pruneNetworks(); inOrder.verifyNoMoreInteractions(); } }
@Test public void docker_compose_down_should_be_called_despite_docker_rm_throwing_exception() throws Exception { doThrow(new DockerExecutionException(error_msg)) .when(mockDocker) .rm(anyListOf(String.class)); ShutdownStrategy.AGGRESSIVE_WITH_NETWORK_CLEANUP.shutdown(mockDockerCompose, mockDocker); verify(mockDockerCompose, times(1)).down(); }
@Test public void first_btrfs_error_should_be_caught_silently_and_retried() throws Exception { doThrow(new DockerExecutionException(btrfs_message)) .doNothing() .when(mockDocker) .rm(anyListOf(String.class)); ShutdownStrategy.AGGRESSIVE.shutdown(mockDockerCompose, mockDocker); verify(mockDocker, times(2)).rm(anyListOf(String.class)); }
@Test public void after_two_btrfs_failures_we_should_just_log_and_continue() throws Exception { doThrow(new DockerExecutionException(btrfs_message)) .doThrow(new DockerExecutionException(btrfs_message)) .when(mockDocker) .rm(anyListOf(String.class)); ShutdownStrategy.AGGRESSIVE.shutdown(mockDockerCompose, mockDocker); verify(mockDocker, times(2)).rm(anyListOf(String.class)); }
@Test public void calls_shutdownStrategy_in_after_method() throws IOException, InterruptedException { ShutdownStrategy shutdownStrategy = mock(ShutdownStrategy.class); rule = DockerComposeRule.builder() .dockerCompose(dockerCompose) .files(mockFiles) .shutdownStrategy(shutdownStrategy) .build(); rule.after(); verify(shutdownStrategy).shutdown(dockerCompose, rule.docker()); }