Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  Fix invalid json example in POST access endpoint (remove array)
  ElasticV7QueryChangesTest: Close indices after test
  Upgrade Testcontainers to 1.10.2 and use ElasticsearchContainer

Adapt ElasticV{5,6,7}QueryProjectsTest accordingly, as these are only
implemented starting with stable-2.16.

Change-Id: I0666decbeda54cae6e59f7bba0caaaf5550f4318
This commit is contained in:
David Pursehouse 2018-12-05 08:48:30 +09:00 committed by Marco Miller
commit cb631bbdca
19 changed files with 71 additions and 43 deletions

View File

@ -1192,21 +1192,19 @@ entity is returned.
Content-Type: application/json; charset=UTF-8
{
"remove": [
{
"refs/*": {
"permissions": {
"read": {
"rules": {
"c2ce4749a32ceb82cd6adcce65b8216e12afb41c": {
"action": "ALLOW"
}
"remove": {
"refs/*": {
"permissions": {
"read": {
"rules": {
"c2ce4749a32ceb82cd6adcce65b8216e12afb41c": {
"action": "ALLOW"
}
}
}
}
}
]
}
}
----

View File

@ -1103,10 +1103,18 @@ maven_jar(
sha1 = "4b7f0e0dc527fab032e9800ed231080fdc3ac015",
)
TESTCONTAINERS_VERSION = "1.10.2"
maven_jar(
name = "testcontainers",
artifact = "org.testcontainers:testcontainers:1.8.0",
sha1 = "bc413912f7044f9f12aa0782853aef0a067ee52a",
artifact = "org.testcontainers:testcontainers:" + TESTCONTAINERS_VERSION,
sha1 = "dfe35b1887685000fecee7f102bd8ce55643665c",
)
maven_jar(
name = "testcontainers-elasticsearch",
artifact = "org.testcontainers:elasticsearch:" + TESTCONTAINERS_VERSION,
sha1 = "c6eb4a3a0ad114929b659fa59c2ee9fe1c1d6a58",
)
maven_jar(

View File

@ -18,6 +18,7 @@ java_library(
"//lib/httpcomponents:httpcore",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/testcontainers",
"//lib/testcontainers:testcontainers-elasticsearch",
],
)
@ -73,7 +74,10 @@ ELASTICSEARCH_TAGS = [
size = "large",
srcs = [src],
tags = ELASTICSEARCH_TAGS + ["flaky"],
deps = ELASTICSEARCH_DEPS + [QUERY_TESTS_DEP % name],
deps = ELASTICSEARCH_DEPS + [QUERY_TESTS_DEP % name] + [
"//lib/httpcomponents:httpasyncclient",
"//lib/httpcomponents:httpclient",
],
) for name, src in ELASTICSEARCH_TESTS_V7.items()]
junit_tests(

View File

@ -14,21 +14,19 @@
package com.google.gerrit.elasticsearch;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
import org.apache.http.HttpHost;
import org.junit.AssumptionViolatedException;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
/* Helper class for running ES integration tests in docker container */
public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends GenericContainer<SELF> {
public class ElasticContainer extends ElasticsearchContainer {
private static final int ELASTICSEARCH_DEFAULT_PORT = 9200;
public static ElasticContainer<?> createAndStart(ElasticVersion version) {
public static ElasticContainer createAndStart(ElasticVersion version) {
// Assumption violation is not natively supported by Testcontainers.
// See https://github.com/testcontainers/testcontainers-java/issues/343
try {
ElasticContainer<?> container = new ElasticContainer<>(version);
ElasticContainer container = new ElasticContainer(version);
container.start();
return container;
} catch (Throwable t) {
@ -58,16 +56,6 @@ public class ElasticContainer<SELF extends ElasticContainer<SELF>> extends Gener
super(getImageName(version));
}
@Override
protected void configure() {
addExposedPort(ELASTICSEARCH_DEFAULT_PORT);
}
@Override
public Set<Integer> getLivenessCheckPortNumbers() {
return ImmutableSet.of(getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
}
public HttpHost getHttpHost() {
return new HttpHost(getContainerIpAddress(), getMappedPort(ELASTICSEARCH_DEFAULT_PORT));
}

View File

@ -58,7 +58,7 @@ public final class ElasticTestUtils {
public static Config getConfig(ElasticVersion version) {
ElasticNodeInfo elasticNodeInfo;
ElasticContainer<?> container = ElasticContainer.createAndStart(version);
ElasticContainer container = ElasticContainer.createAndStart(version);
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
String indicesPrefix = UUID.randomUUID().toString();
Config cfg = new Config();

View File

@ -32,7 +32,7 @@ public class ElasticV5QueryAccountsTest extends AbstractQueryAccountsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV5QueryChangesTest extends AbstractQueryChangesTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV5QueryGroupsTest extends AbstractQueryGroupsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV5QueryProjectsTest extends AbstractQueryProjectsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV6QueryAccountsTest extends AbstractQueryAccountsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV6QueryChangesTest extends AbstractQueryChangesTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV6QueryGroupsTest extends AbstractQueryGroupsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV6QueryProjectsTest extends AbstractQueryProjectsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -21,7 +21,12 @@ import com.google.gerrit.testing.InMemoryModule;
import com.google.gerrit.testing.IndexConfig;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.eclipse.jgit.lib.Config;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -32,7 +37,8 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
private static CloseableHttpAsyncClient client;
@BeforeClass
public static void startIndexService() {
@ -43,6 +49,8 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
container = ElasticContainer.createAndStart(ElasticVersion.V7_0);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
client = HttpAsyncClients.createDefault();
client.start();
}
@AfterClass
@ -52,6 +60,16 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
}
}
@After
public void closeIndex() {
client.execute(
new HttpPost(
String.format(
"http://localhost:%d/%s*/_close", nodeInfo.port, getSanitizedMethodName())),
HttpClientContext.create(),
null);
}
@Override
protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart();

View File

@ -32,7 +32,7 @@ public class ElasticV7QueryGroupsTest extends AbstractQueryGroupsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -32,7 +32,7 @@ public class ElasticV7QueryProjectsTest extends AbstractQueryProjectsTest {
}
private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container;
private static ElasticContainer container;
@BeforeClass
public static void startIndexService() {

View File

@ -30,7 +30,10 @@ java_library(
java_library(
name = "httpasyncclient",
data = ["//lib:LICENSE-Apache2.0"],
visibility = ["//java/com/google/gerrit/elasticsearch:__pkg__"],
visibility = [
"//java/com/google/gerrit/elasticsearch:__pkg__",
"//javatests/com/google/gerrit/elasticsearch:__pkg__",
],
exports = ["@httpasyncclient//jar"],
)

View File

@ -35,3 +35,12 @@ java_library(
"//lib/log:ext",
],
)
java_library(
name = "testcontainers-elasticsearch",
testonly = 1,
data = ["//lib:LICENSE-testcontainers"],
visibility = ["//visibility:public"],
exports = ["@testcontainers-elasticsearch//jar"],
runtime_deps = [":testcontainers"],
)