Skip to content

Commit

Permalink
Fix SolrContainer start parameters for version >= 9.7.0 (#9926)
Browse files Browse the repository at this point in the history
Fixes #9601

---------

Co-authored-by: Eddú Meléndez <[email protected]>
  • Loading branch information
mkr and eddumelendez authored Feb 13, 2025
1 parent 6139e5e commit df40cd8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.ComparableVersion;
import org.testcontainers.utility.DockerImageName;

import java.net.URL;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class SolrContainer extends GenericContainer<SolrContainer> {

private SolrContainerConfiguration configuration;

private final ComparableVersion imageVersion;

/**
* @deprecated use {@link #SolrContainer(DockerImageName)} instead
*/
Expand All @@ -63,6 +66,7 @@ public SolrContainer(final DockerImageName dockerImageName) {
.withRegEx(".*o\\.e\\.j\\.s\\.Server Started.*")
.withStartupTimeout(Duration.of(60, ChronoUnit.SECONDS));
this.configuration = new SolrContainerConfiguration();
this.imageVersion = new ComparableVersion(dockerImageName.getVersionPart());
}

public SolrContainer withZookeeper(boolean zookeeper) {
Expand Down Expand Up @@ -114,7 +118,11 @@ protected void configure() {
// Configure Zookeeper
if (configuration.isZookeeper()) {
this.addExposedPort(ZOOKEEPER_PORT);
command = "-DzkRun -h localhost";
if (this.imageVersion.isGreaterThanOrEqualTo("9.7.0")) {
command = "-DzkRun --host localhost";
} else {
command = "-DzkRun -h localhost";
}
}

// Apply generated Command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.junit.After;
import org.junit.Test;
import org.testcontainers.utility.DockerImageName;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Parameterized.class)
public class SolrContainerTest {

private static final DockerImageName SOLR_IMAGE = DockerImageName.parse("solr:8.3.0");
@Parameterized.Parameters(name = "{0}")
public static String[] getVersionsToTest() {
return new String[] { "solr:8.11.4", "solr:9.8.0" };
}

@Parameterized.Parameter
public String solrImage;

private SolrClient client = null;

Expand All @@ -28,7 +36,7 @@ public void stopRestClient() throws IOException {

@Test
public void solrCloudTest() throws IOException, SolrServerException {
try (SolrContainer container = new SolrContainer(SOLR_IMAGE)) {
try (SolrContainer container = new SolrContainer(solrImage)) {
container.start();
SolrPingResponse response = getClient(container).ping("dummy");
assertThat(response.getStatus()).isZero();
Expand All @@ -38,7 +46,7 @@ public void solrCloudTest() throws IOException, SolrServerException {

@Test
public void solrStandaloneTest() throws IOException, SolrServerException {
try (SolrContainer container = new SolrContainer(SOLR_IMAGE).withZookeeper(false)) {
try (SolrContainer container = new SolrContainer(solrImage).withZookeeper(false)) {
container.start();
SolrPingResponse response = getClient(container).ping("dummy");
assertThat(response.getStatus()).isZero();
Expand All @@ -50,7 +58,7 @@ public void solrStandaloneTest() throws IOException, SolrServerException {
public void solrCloudPingTest() throws IOException, SolrServerException {
// solrContainerUsage {
// Create the solr container.
SolrContainer container = new SolrContainer(SOLR_IMAGE);
SolrContainer container = new SolrContainer(solrImage);

// Start the container. This step might take some time...
container.start();
Expand Down

0 comments on commit df40cd8

Please sign in to comment.