diff --git a/src/main/java/de/rpr/testcontainers/infinispan/InfinispanContainer.java b/src/main/java/de/rpr/testcontainers/infinispan/InfinispanContainer.java index 76a18bd..134eedb 100644 --- a/src/main/java/de/rpr/testcontainers/infinispan/InfinispanContainer.java +++ b/src/main/java/de/rpr/testcontainers/infinispan/InfinispanContainer.java @@ -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 { +public class InfinispanContainer> extends GenericContainer { private static final String IMAGE_NAME = "jboss/infinispan-server"; + public static final String STANDALONE_MODE_CMD = "standalone"; private static Set incompatibleProtocolVersions = new HashSet<>(); @@ -35,14 +36,58 @@ public class InfinispanContainer extends GenericContainer { 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. + *

+ * 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. + *

+ * + * @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 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) {