Run reindex test against Elasticsearch in addition to Lucene

Bug: Issue 8771
Change-Id: I657672f3bd899423ad460281ae2d9d71158c1aed
This commit is contained in:
Hugo Arès 2018-04-17 13:50:01 +02:00
parent db9c8ad778
commit 767f8f2198
10 changed files with 75 additions and 31 deletions

View File

@ -7,6 +7,8 @@ java_library(
"//gerrit-acceptance-framework:lib",
"//gerrit-common:annotations",
"//gerrit-common:server",
"//gerrit-elasticsearch:elasticsearch",
"//gerrit-elasticsearch:elasticsearch_test_utils",
"//gerrit-extension-api:api",
"//gerrit-gpg:testutil",
"//gerrit-httpd:httpd",

View File

@ -19,14 +19,37 @@ import static com.google.common.truth.Truth8.assertThat;
import com.google.common.io.MoreFiles;
import com.google.gerrit.acceptance.NoHttpd;
import com.google.gerrit.acceptance.StandaloneSiteTest;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.common.ChangeInput;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.testutil.ConfigSuite;
import java.nio.file.Files;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import org.eclipse.jgit.lib.Config;
import org.junit.AfterClass;
import org.junit.Test;
@NoHttpd
public class ReindexIT extends StandaloneSiteTest {
@ConfigSuite.Config
public static Config elasticsearch() throws InterruptedException, ExecutionException {
if (elasticNodeInfo == null) {
elasticNodeInfo = ElasticTestUtils.startElasticsearchNode();
}
String indicesPrefix = UUID.randomUUID().toString();
ElasticTestUtils.createAllIndexes(elasticNodeInfo, indicesPrefix);
Config cfg = new Config();
ElasticTestUtils.configure(cfg, elasticNodeInfo.port, indicesPrefix);
return cfg;
}
private static ElasticNodeInfo elasticNodeInfo;
@Test
public void reindexFromScratch() throws Exception {
Project.NameKey project = new Project.NameKey("project");
@ -55,4 +78,13 @@ public class ReindexIT extends StandaloneSiteTest {
.containsExactly(changeId);
}
}
@AfterClass
public static void stopElasticServer() {
if (elasticNodeInfo != null) {
elasticNodeInfo.node.close();
elasticNodeInfo.elasticDir.delete();
elasticNodeInfo = null;
}
}
}

View File

@ -1,6 +1,9 @@
java_library(
name = "elasticsearch",
srcs = glob(["src/main/java/**/*.java"]),
srcs = glob(
["src/main/java/**/*.java"],
exclude = ["**/testing/**"],
),
visibility = ["//visibility:public"],
deps = [
"//gerrit-antlr:query_exception",
@ -27,7 +30,8 @@ load("//tools/bzl:junit.bzl", "junit_tests")
java_library(
name = "elasticsearch_test_utils",
testonly = 1,
srcs = glob(["src/test/java/**/ElasticTestUtils.java"]),
srcs = glob(["src/main/java/com/google/gerrit/elasticsearch/testing/*.java"]),
visibility = ["//visibility:public"],
deps = [
":elasticsearch",
"//gerrit-reviewdb:client",

View File

@ -60,15 +60,15 @@ import org.slf4j.LoggerFactory;
public class ElasticAccountIndex extends AbstractElasticIndex<Account.Id, AccountState>
implements AccountIndex {
static class AccountMapping {
public static class AccountMapping {
MappingProperties accounts;
AccountMapping(Schema<AccountState> schema) {
public AccountMapping(Schema<AccountState> schema) {
this.accounts = ElasticMapping.createMapping(schema);
}
}
static final String ACCOUNTS = "accounts";
public static final String ACCOUNTS = "accounts";
private static final Logger log = LoggerFactory.getLogger(ElasticAccountIndex.class);

View File

@ -78,24 +78,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Secondary index implementation using Elasticsearch. */
class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
public class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
implements ChangeIndex {
private static final Logger log = LoggerFactory.getLogger(ElasticChangeIndex.class);
static class ChangeMapping {
MappingProperties openChanges;
MappingProperties closedChanges;
public static class ChangeMapping {
public MappingProperties openChanges;
public MappingProperties closedChanges;
ChangeMapping(Schema<ChangeData> schema) {
public ChangeMapping(Schema<ChangeData> schema) {
MappingProperties mapping = ElasticMapping.createMapping(schema);
this.openChanges = mapping;
this.closedChanges = mapping;
}
}
static final String CHANGES = "changes";
static final String OPEN_CHANGES = "open_" + CHANGES;
static final String CLOSED_CHANGES = "closed_" + CHANGES;
public static final String CHANGES = "changes";
public static final String OPEN_CHANGES = "open_" + CHANGES;
public static final String CLOSED_CHANGES = "closed_" + CHANGES;
private final ChangeMapping mapping;
private final Provider<ReviewDb> db;

View File

@ -57,15 +57,15 @@ import org.slf4j.LoggerFactory;
public class ElasticGroupIndex extends AbstractElasticIndex<AccountGroup.UUID, AccountGroup>
implements GroupIndex {
static class GroupMapping {
public static class GroupMapping {
MappingProperties groups;
GroupMapping(Schema<AccountGroup> schema) {
public GroupMapping(Schema<AccountGroup> schema) {
this.groups = ElasticMapping.createMapping(schema);
}
}
static final String GROUPS = "groups";
public static final String GROUPS = "groups";
private static final Logger log = LoggerFactory.getLogger(ElasticGroupIndex.class);

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.elasticsearch;
package com.google.gerrit.elasticsearch.testing;
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.elasticsearch.ElasticAccountIndex.ACCOUNTS;
@ -23,8 +23,10 @@ import static com.google.gerrit.elasticsearch.ElasticGroupIndex.GROUPS;
import com.google.common.base.Strings;
import com.google.common.io.Files;
import com.google.gerrit.elasticsearch.ElasticAccountIndex;
import com.google.gerrit.elasticsearch.ElasticAccountIndex.AccountMapping;
import com.google.gerrit.elasticsearch.ElasticChangeIndex.ChangeMapping;
import com.google.gerrit.elasticsearch.ElasticGroupIndex;
import com.google.gerrit.elasticsearch.ElasticGroupIndex.GroupMapping;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.server.account.AccountState;
@ -48,16 +50,16 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
final class ElasticTestUtils {
public final class ElasticTestUtils {
static final Gson gson =
new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
static class ElasticNodeInfo {
final Node node;
final String port;
final File elasticDir;
public static class ElasticNodeInfo {
public final Node node;
public final String port;
public final File elasticDir;
private ElasticNodeInfo(Node node, File rootDir, String port) {
this.node = node;
@ -66,7 +68,7 @@ final class ElasticTestUtils {
}
}
static void configure(Config config, String port, String prefix) {
public static void configure(Config config, String port, String prefix) {
config.setEnum("index", null, "type", IndexType.ELASTICSEARCH);
config.setString("elasticsearch", "test", "protocol", "http");
config.setString("elasticsearch", "test", "hostname", "localhost");
@ -74,7 +76,8 @@ final class ElasticTestUtils {
config.setString("elasticsearch", null, "prefix", prefix);
}
static ElasticNodeInfo startElasticsearchNode() throws InterruptedException, ExecutionException {
public static ElasticNodeInfo startElasticsearchNode()
throws InterruptedException, ExecutionException {
File elasticDir = Files.createTempDir();
Path elasticDirPath = elasticDir.toPath();
Settings settings =
@ -106,19 +109,19 @@ final class ElasticTestUtils {
return new ElasticNodeInfo(node, elasticDir, getHttpPort(node));
}
static void deleteAllIndexes(ElasticNodeInfo nodeInfo) {
public static void deleteAllIndexes(ElasticNodeInfo nodeInfo) {
nodeInfo.node.client().admin().indices().prepareDelete("_all").execute();
}
static class NodeInfo {
public static class NodeInfo {
String httpAddress;
}
static class Info {
public static class Info {
Map<String, NodeInfo> nodes;
}
static void createAllIndexes(ElasticNodeInfo nodeInfo, String prefix) {
public static void createAllIndexes(ElasticNodeInfo nodeInfo, String prefix) {
Schema<ChangeData> changeSchema = ChangeSchemaDefinitions.INSTANCE.getLatest();
ChangeMapping openChangesMapping = new ChangeMapping(changeSchema);
ChangeMapping closedChangesMapping = new ChangeMapping(changeSchema);

View File

@ -14,7 +14,8 @@
package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.account.AbstractQueryAccountsTest;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.inject.Guice;

View File

@ -14,7 +14,8 @@
package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.change.AbstractQueryChangesTest;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.gerrit.testutil.InMemoryRepositoryManager.Repo;

View File

@ -14,7 +14,8 @@
package com.google.gerrit.elasticsearch;
import com.google.gerrit.elasticsearch.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
import com.google.gerrit.server.query.group.AbstractQueryGroupsTest;
import com.google.gerrit.testutil.InMemoryModule;
import com.google.inject.Guice;