Package no.mnemonic.commons.junit.docker
Class SingletonDockerResourceWrapper<T extends DockerResource>
java.lang.Object
org.junit.rules.ExternalResource
no.mnemonic.commons.junit.docker.SingletonDockerResourceWrapper<T>
- Type Parameters:
T- wrappedDockerResourcetype
- All Implemented Interfaces:
org.junit.rules.TestRule
@Deprecated
public class SingletonDockerResourceWrapper<T extends DockerResource>
extends org.junit.rules.ExternalResource
Deprecated.
Use jupiter-docker instead
DockerResource is created with intention to be used as a ClassRule.
Since ClassRule is executed once per test class, having multiple test classes within single test
execution can cause high resource consumption (starting and stopping Docker container can have great impact on system
resources). This wrapper makes sure that single instance of Docker container, defined in wrapped resource, is started
just once.
WARNING: This resource does not call after() after completion of tests. Underlying resource should register JVM shutdown hook (default in DockerResource), which is used for shutting down of container.
After all tests are finished, either successfully, with an exception or by user cancellation, the wrapped resource will cleanup stale container.
Initialize SingletonDockerResourceWrapper in the following way as ClassRule:
@ClassRule
public static SingletonDockerResourceWrapper<DockerResource> docker = SingletonDockerResourceWrapper.builder()
.setDockerResource(DockerResource.builder()
.setImageName("busybox")
.setReachabilityTimeout(30)
.addApplicationPort(8080)
.build())
.build();
Created SingletonDockerResourceWrapper exposes getDockerResource method for retrieving underlying DockerResource
which can be used in test.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated.Builder to create aSingletonDockerResourceWrapper. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbefore()Deprecated.static <T extends DockerResource>
SingletonDockerResourceWrapper.Builder<T>builder()Deprecated.Create builder forSingletonDockerResourceWrapper.Deprecated.Return wrappedDockerResource.Methods inherited from class org.junit.rules.ExternalResource
after, apply
-
Method Details
-
before
Deprecated.- Overrides:
beforein classorg.junit.rules.ExternalResource- Throws:
Throwable
-
getDockerResource
Deprecated.Return wrappedDockerResource.- Returns:
- Wrapped
DockerResource
-
builder
Deprecated.Create builder forSingletonDockerResourceWrapper.- Returns:
- Builder object
-