@Override public void onError(Throwable throwable) { LoggingUtil.INSTANCE.error("Image '{}:{}' pull failed: ", virtualResource.value(), virtualResource.version(), throwable); latch.countDown(); }
@Override public void fireTestFailure(Failure failure) { Description description = failure.getDescription(); String methodName = description.getMethodName(); Throwable throwable = failure.getException(); if (methodName == null) { LoggingUtil.INSTANCE.error("Test method '{}' failed", methodName, throwable); } else { LoggingUtil.INSTANCE.error("Test method failed", throwable); } runNotifier.fireTestFailure(failure); }
@Override public void fireTestAssumptionFailed(Failure failure) { Description description = failure.getDescription(); String methodName = description.getMethodName(); Throwable throwable = failure.getException(); if (methodName == null) { LoggingUtil.INSTANCE.error("Test class assumption failed", throwable); } else { LoggingUtil.INSTANCE.error("Test method assumption failed", throwable); } runNotifier.fireTestAssumptionFailed(failure); }
clientProvider.destroy(clientInstance); } catch (Exception e) { LoggingUtil.INSTANCE.error( "Could not destroy client provider '{}'", clientProvider.getClass().getSimpleName(), e serverProvider.stop(serverInstance); } catch (Exception e) { LoggingUtil.INSTANCE.error( "Could not destroy server provider '{}'", serverProvider.getClass().getSimpleName(), e
/** * Remove the given container using the given retry policy. * * @param retryPolicy the retry policy in the event of failure * @param containerId the container id */ void removeContainer(String containerId, RetryPolicy retryPolicy) { Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.info( "Trying to remove Docker Container '{}'", containerId)) .onSuccess(result -> LoggingUtil.INSTANCE.info( "Docker Container '{}' removed", containerId)) .onFailure(throwable -> LoggingUtil.INSTANCE.error( "Docker Container '{}' could not be removed", containerId, throwable)) .run(() -> client.removeContainer(containerId)); }
/** * Stop the given container using the given retry policy. * * @param retryPolicy the retry policy in the event of failure * @param containerId the container id */ void stopContainer(String containerId, RetryPolicy retryPolicy) { Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.info( "Trying to stop Docker Container '{}'", containerId)) .onSuccess(result -> { LoggingUtil.INSTANCE .info("Docker Container '{}' stopped", containerId); removeContainer(containerId, retryPolicy); }) .onFailure(throwable -> LoggingUtil.INSTANCE.error( "Docker Container '{}' could not be stopped", containerId, throwable)) .run(() -> client.stopContainer(containerId, 8)); }
void pullImage(VirtualResource virtualResource, String image, String imageName, String imageTag, TestContext testContext) { RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withBackoff(virtualResource.delay(), virtualResource.maxDelay(), virtualResource.unit()) .withMaxRetries(virtualResource.maxRetries()); Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.warn("Retrying pull request of image '{}'", image, throwable) ) .onFailure(throwable -> LoggingUtil.INSTANCE.error("Image image '{}' could not be pulled: ", image, throwable)) .run(() -> { try { CountDownLatch latch = new CountDownLatch(1); client.pullImageCmd(imageName) .withTag(imageTag) .exec(new PullCallback(virtualResource, latch)); ExceptionUtil.INSTANCE.raise(!latch.await(virtualResource.timeout(), virtualResource.unit()), "Could not start virtual resource '{}' for test '{}'", imageName, testContext.getName() ); } catch (InterruptedException e) { LoggingUtil.INSTANCE.warn("Image '{}' pull request interrupted", image); Thread.currentThread().interrupt(); } }); }
/** * Pull the given virtual resource. * * @param virtualResource the virtual resource * @param image the image */ void pullImage(VirtualResource virtualResource, String image) { RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withDelay(virtualResource.delay(), virtualResource.unit()) .withMaxRetries(virtualResource.maxRetries()); Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.warn( "Retrying pull request of image '{}'", image, throwable)) .onFailure(throwable -> LoggingUtil.INSTANCE.error( "Image image '{}' could not be pulled: ", image, throwable)) .run(() -> client.pull(image, new AnsiProgressHandler())); }
void removeContainer(String containerId, VirtualResource virtualResource) { LoggingUtil.INSTANCE.info("Stopping and Removing Docker Container {}", containerId); if (client.inspectContainerCmd(containerId).exec().getState().getRunning()) { client.stopContainerCmd(containerId).exec(); try { client.waitContainerCmd(containerId) .exec(new WaitCallback(containerId)) .awaitCompletion(); } catch (InterruptedException e) { LoggingUtil.INSTANCE.warn("wating for container interrupted", e); Thread.currentThread().interrupt(); } } RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withBackoff(virtualResource.delay(), virtualResource.maxDelay(), virtualResource.unit()) .withMaxRetries(virtualResource.maxRetries()) .withMaxDuration(8000, TimeUnit.MILLISECONDS); Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.debug("Trying to remove Docker Container {}", containerId, throwable)) .onSuccess(result -> { LoggingUtil.INSTANCE.info("Docker Container '{}' Removed", containerId); client.removeVolumeCmd(containerId).exec(); }) .onFailure(throwable -> LoggingUtil.INSTANCE.error("Docker Container '{}' could not be removed", containerId, throwable)) .run(() -> client.removeContainerCmd(containerId).exec()); }