Skip to content
Closed
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 @@ -29,10 +29,14 @@ public class ElasticsearchContainer extends GenericContainer<ElasticsearchContai
private static final int ELASTICSEARCH_DEFAULT_TCP_PORT = 9300;

/**
* Elasticsearch Docker base image
* Elasticsearch Docker base image: default distribution with built-in free basic elastic license
*/
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch");
private static final DockerImageName DEFAULT_OSS_IMAGE_NAME = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch-oss");
public static final DockerImageName ELASTICSEARCH_IMAGE = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch");

/**
* Elasticsearch Docker base image: oss distribution under Apache2 license
*/
public static final DockerImageName ELASTICSEARCH_OSS_IMAGE = DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch-oss");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image has been removed after 7.10.2. So I believe that I should update the PR and remove entirely this field.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't images distributed over Docker Hub again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. There's no -oss package after 7.10.2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there's the default distribution as it has always been 😊


/**
* Elasticsearch Default version
Expand All @@ -46,7 +50,7 @@ public class ElasticsearchContainer extends GenericContainer<ElasticsearchContai
*/
@Deprecated
public ElasticsearchContainer() {
this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG));
this(ELASTICSEARCH_IMAGE.withTag(DEFAULT_TAG));
}

/**
Expand All @@ -64,9 +68,9 @@ public ElasticsearchContainer(String dockerImageName) {
public ElasticsearchContainer(final DockerImageName dockerImageName) {
super(dockerImageName);

dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME, DEFAULT_OSS_IMAGE_NAME);
dockerImageName.assertCompatibleWith(ELASTICSEARCH_IMAGE, ELASTICSEARCH_OSS_IMAGE);

if (dockerImageName.isCompatibleWith(DEFAULT_OSS_IMAGE_NAME)) {
if (dockerImageName.isCompatibleWith(ELASTICSEARCH_OSS_IMAGE)) {
this.isOss = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.After;
import org.junit.Test;
import org.testcontainers.utility.DockerImageName;

public class ElasticsearchContainerTest {

/**
* Elasticsearch version which should be used for the Tests
*/
private static final String ELASTICSEARCH_VERSION = "7.9.2";
private static final DockerImageName ELASTICSEARCH_IMAGE =
DockerImageName
.parse("docker.elastic.co/elasticsearch/elasticsearch")
.withTag(ELASTICSEARCH_VERSION);

/**
* Elasticsearch default username, when secured
Expand All @@ -61,7 +56,6 @@ public void stopRestClient() throws IOException {
}
}

@SuppressWarnings("deprecation") // Using deprecated constructor for verification of backwards compatibility
Copy link
Copy Markdown
Contributor Author

@dadoonet dadoonet Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change is not related to the goal of this PR and is a leftover from #2320

@Test
@Deprecated // We will remove this test in the future
public void elasticsearchDeprecatedCtorTest() throws IOException {
Expand All @@ -88,7 +82,9 @@ public void elasticsearchDeprecatedCtorTest() throws IOException {
@Test
public void elasticsearchDefaultTest() throws IOException {
// Create the elasticsearch container.
try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)
try (ElasticsearchContainer container = new ElasticsearchContainer(
ElasticsearchContainer.ELASTICSEARCH_IMAGE
.withTag(ELASTICSEARCH_VERSION))
.withEnv("foo", "bar") // dummy env for compiler checking correct generics usage
) {
// Start the container. This step might take some time...
Expand All @@ -109,7 +105,9 @@ public void elasticsearchDefaultTest() throws IOException {

@Test
public void elasticsearchSecuredTest() throws IOException {
try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)
try (ElasticsearchContainer container = new ElasticsearchContainer(
ElasticsearchContainer.ELASTICSEARCH_IMAGE
.withTag(ELASTICSEARCH_VERSION))
.withPassword(ELASTICSEARCH_PASSWORD)) {
container.start();

Expand All @@ -127,7 +125,10 @@ public void elasticsearchSecuredTest() throws IOException {

@Test
public void elasticsearchVersion() throws IOException {
try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)) {
try (ElasticsearchContainer container = new ElasticsearchContainer(
ElasticsearchContainer.ELASTICSEARCH_IMAGE
.withTag(ELASTICSEARCH_VERSION)
)) {
container.start();
Response response = getClient(container).performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), is(200));
Expand All @@ -141,8 +142,7 @@ public void elasticsearchOssImage() throws IOException {
try (ElasticsearchContainer container =
// ossContainer {
new ElasticsearchContainer(
DockerImageName
.parse("docker.elastic.co/elasticsearch/elasticsearch-oss")
ElasticsearchContainer.ELASTICSEARCH_OSS_IMAGE
.withTag(ELASTICSEARCH_VERSION)
)
// }
Expand All @@ -161,7 +161,10 @@ public void elasticsearchOssImage() throws IOException {
public void restClientClusterHealth() throws IOException {
// httpClientContainer {
// Create the elasticsearch container.
try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)) {
try (ElasticsearchContainer container = new ElasticsearchContainer(
ElasticsearchContainer.ELASTICSEARCH_IMAGE
.withTag(ELASTICSEARCH_VERSION)
)) {
// Start the container. This step might take some time...
container.start();

Expand All @@ -187,7 +190,9 @@ public void restClientClusterHealth() throws IOException {
public void restClientSecuredClusterHealth() throws IOException {
// httpClientSecuredContainer {
// Create the elasticsearch container.
try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)
try (ElasticsearchContainer container = new ElasticsearchContainer(
ElasticsearchContainer.ELASTICSEARCH_IMAGE
.withTag(ELASTICSEARCH_VERSION))
// With a password
.withPassword(ELASTICSEARCH_PASSWORD)) {
// Start the container. This step might take some time...
Expand Down Expand Up @@ -216,7 +221,9 @@ public void restClientSecuredClusterHealth() throws IOException {
public void transportClientClusterHealth() {
// transportClientContainer {
// Create the elasticsearch container.
try (ElasticsearchContainer container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE)){
try (ElasticsearchContainer container = new ElasticsearchContainer(
ElasticsearchContainer.ELASTICSEARCH_IMAGE
.withTag(ELASTICSEARCH_VERSION))) {
// Start the container. This step might take some time...
container.start();

Expand All @@ -242,8 +249,7 @@ public void incompatibleSettingsTest() {
assertThrows("We should not be able to activate security with an OSS License",
IllegalArgumentException.class,
() -> new ElasticsearchContainer(
DockerImageName
.parse("docker.elastic.co/elasticsearch/elasticsearch-oss")
ElasticsearchContainer.ELASTICSEARCH_OSS_IMAGE
.withTag(ELASTICSEARCH_VERSION))
.withPassword("foo")
);
Expand Down