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
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 Content-Type: application/json; charset=UTF-8
{ {
"remove": [ "remove": {
{ "refs/*": {
"refs/*": { "permissions": {
"permissions": { "read": {
"read": { "rules": {
"rules": { "c2ce4749a32ceb82cd6adcce65b8216e12afb41c": {
"c2ce4749a32ceb82cd6adcce65b8216e12afb41c": { "action": "ALLOW"
"action": "ALLOW"
}
} }
} }
} }
} }
} }
] }
} }
---- ----

View File

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

View File

@@ -18,6 +18,7 @@ java_library(
"//lib/httpcomponents:httpcore", "//lib/httpcomponents:httpcore",
"//lib/jgit/org.eclipse.jgit:jgit", "//lib/jgit/org.eclipse.jgit:jgit",
"//lib/testcontainers", "//lib/testcontainers",
"//lib/testcontainers:testcontainers-elasticsearch",
], ],
) )
@@ -73,7 +74,10 @@ ELASTICSEARCH_TAGS = [
size = "large", size = "large",
srcs = [src], srcs = [src],
tags = ELASTICSEARCH_TAGS + ["flaky"], 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()] ) for name, src in ELASTICSEARCH_TESTS_V7.items()]
junit_tests( junit_tests(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -32,7 +32,7 @@ public class ElasticV7QueryAccountsTest extends AbstractQueryAccountsTest {
} }
private static ElasticNodeInfo nodeInfo; private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container; private static ElasticContainer container;
@BeforeClass @BeforeClass
public static void startIndexService() { 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.gerrit.testing.IndexConfig;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; 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.eclipse.jgit.lib.Config;
import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@@ -32,7 +37,8 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
} }
private static ElasticNodeInfo nodeInfo; private static ElasticNodeInfo nodeInfo;
private static ElasticContainer<?> container; private static ElasticContainer container;
private static CloseableHttpAsyncClient client;
@BeforeClass @BeforeClass
public static void startIndexService() { public static void startIndexService() {
@@ -43,6 +49,8 @@ public class ElasticV7QueryChangesTest extends AbstractQueryChangesTest {
container = ElasticContainer.createAndStart(ElasticVersion.V7_0); container = ElasticContainer.createAndStart(ElasticVersion.V7_0);
nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort()); nodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
client = HttpAsyncClients.createDefault();
client.start();
} }
@AfterClass @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 @Override
protected void initAfterLifecycleStart() throws Exception { protected void initAfterLifecycleStart() throws Exception {
super.initAfterLifecycleStart(); super.initAfterLifecycleStart();

View File

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

View File

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

View File

@@ -30,7 +30,10 @@ java_library(
java_library( java_library(
name = "httpasyncclient", name = "httpasyncclient",
data = ["//lib:LICENSE-Apache2.0"], 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"], exports = ["@httpasyncclient//jar"],
) )

View File

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