-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acceptance tests: Replace embedded ES with docker testcontainer
Testcontainers is a Java 8 library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. This change replaces ES integration test that currently uses embedded ES mode with ES docker image using Testcontainers library. All this is done from within acceptance tests. This change removes dependency on ES server stack for the test code. As the consequence, this stack can be removed. Prerequisite for this change is installed docker service on the SUT. If docker service is not installed, assumption violation is raised so that the tests don't fail. Unfortunately, due to this missing Bazel feature, JUnit assumption violations are not reflected on the Bazel UI: [1] yet. [1] bazelbuild/bazel#3476 Change-Id: Iccf44310292cc44bff9173f2a4ea757b43f77183
- Loading branch information
1 parent
6547ded
commit 8add7b7
Showing
6 changed files
with
104 additions
and
167 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...elasticsearch/src/main/java/com/google/gerrit/elasticsearch/testing/ElasticContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) 2018 The Android Open Source Project | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.gerrit.elasticsearch.testing; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import java.util.Set; | ||
import org.apache.http.HttpHost; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
/* Helper class for running ES integration tests in docker container */ | ||
public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends GenericContainer<SELF> { | ||
private static final String NAME = "elasticsearch"; | ||
private static final String VERSION = "2.4.6-alpine"; | ||
private static final int ELASTICSEARCH_DEFAULT_PORT = 9200; | ||
|
||
public ElasticContainer() { | ||
this(NAME + ":" + VERSION); | ||
} | ||
|
||
public ElasticContainer(String dockerImageName) { | ||
super(dockerImageName); | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
addExposedPort(ELASTICSEARCH_DEFAULT_PORT); | ||
|
||
// https://github.com/docker-library/elasticsearch/issues/58 | ||
addEnv("-Ees.network.host", "0.0.0.0"); | ||
} | ||
|
||
@Override | ||
protected Set<Integer> getLivenessCheckPorts() { | ||
return ImmutableSet.of(getMappedPort(ELASTICSEARCH_DEFAULT_PORT)); | ||
} | ||
|
||
public HttpHost getHttpHost() { | ||
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.