Overloading fluent command setters
We're overloading the fluent command setters, because we want to make sure that the "standalone" command is always present. If needed, setCommand() inherited from GenericContainer can still be used to bypass this behaviour.
This commit is contained in:
parent
02d34ceb75
commit
231b85696f
1 changed files with 56 additions and 11 deletions
|
@ -1,24 +1,25 @@
|
|||
package de.rpr.testcontainers.infinispan;
|
||||
|
||||
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.infinispan.client.hotrod.ProtocolVersion;
|
||||
import org.infinispan.client.hotrod.RemoteCacheManager;
|
||||
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.runner.Description;
|
||||
import org.testcontainers.containers.BindMode;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.wait.LogMessageWaitStrategy;
|
||||
import org.testcontainers.shaded.io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class InfinispanContainer extends GenericContainer<InfinispanContainer> {
|
||||
public class InfinispanContainer<SELF extends InfinispanContainer<SELF>> extends GenericContainer<SELF> {
|
||||
|
||||
private static final String IMAGE_NAME = "jboss/infinispan-server";
|
||||
public static final String STANDALONE_MODE_CMD = "standalone";
|
||||
|
||||
private static Set<ProtocolVersion> incompatibleProtocolVersions = new HashSet<>();
|
||||
|
||||
|
@ -35,14 +36,58 @@ public class InfinispanContainer extends GenericContainer<InfinispanContainer> {
|
|||
private RemoteCacheManager cacheManager;
|
||||
|
||||
public InfinispanContainer() {
|
||||
this("latest");
|
||||
this(IMAGE_NAME + ":latest");
|
||||
}
|
||||
|
||||
public InfinispanContainer(final String version) {
|
||||
super(IMAGE_NAME + ":" + version);
|
||||
withStartupTimeout(Duration.ofMillis(20000));
|
||||
withCommand("standalone");
|
||||
waitingFor(new LogMessageWaitStrategy().withRegEx(".*Infinispan Server.*started in.*\\s"));
|
||||
public InfinispanContainer(final String imageName) {
|
||||
super(imageName);
|
||||
|
||||
this.withCommand(STANDALONE_MODE_CMD);
|
||||
|
||||
this.waitStrategy = new LogMessageWaitStrategy()
|
||||
.withRegEx(".*Infinispan Server.*started in.*\\s")
|
||||
.withTimes(2)
|
||||
.withStartupTimeout(Duration.of(20, SECONDS));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading, because we want to make sure that the "standalone" command is always present.
|
||||
* <p>
|
||||
* The {@link org.testcontainers.containers.GenericContainer#setCommand} method splits on empty string.
|
||||
* In order to avoid dependency of that behaviour, we set the cmd first, then getting the commandParts
|
||||
* and ensuring that it contains the "standalone" command.
|
||||
* </p>
|
||||
*
|
||||
* @param cmd The command(s) to set. {@link org.testcontainers.containers.GenericContainer#setCommand}
|
||||
* @return The container instance
|
||||
*/
|
||||
@Override
|
||||
public SELF withCommand(String cmd) {
|
||||
super.setCommand(cmd);
|
||||
this.withCommand(ensureStandaloneCommand(getCommandParts()));
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading, because we want to make sure that the "standalone" command is always present.
|
||||
*
|
||||
* @param cmd
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SELF withCommand(String... commandParts) {
|
||||
this.setCommand(ensureStandaloneCommand(commandParts));
|
||||
return self();
|
||||
}
|
||||
|
||||
private String[] ensureStandaloneCommand(final String[] commandParts) {
|
||||
List<String> commands = Arrays.asList(commandParts);
|
||||
if (commands.contains(STANDALONE_MODE_CMD)) {
|
||||
return commands.toArray(new String[0]);
|
||||
} else {
|
||||
commands.add(STANDALONE_MODE_CMD);
|
||||
return commands.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public InfinispanContainer withProtocolVersion(final ProtocolVersion protocolVersion) {
|
||||
|
|
Loading…
Reference in a new issue