Skip to content

Fix SolrContainer start parameters for version >= 9.7.0 #9926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading