ReindexIT: Split Elasticsearch test out to a separate class
Splitting the Elasticsearch reindex test out to a separate class will allow us to add tests for different versions of Elasticsearch, and to exclude the reindex test on Elasticsearch. These will be implemented in follow-up commits. Change-Id: I7c1461c45c2a18665b6a23268ef20e0d05d18f7d
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
// Copyright (C) 2014 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.acceptance.pgm;
|
||||
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
|
||||
import com.google.common.io.MoreFiles;
|
||||
import com.google.common.io.RecursiveDeleteOption;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.StandaloneSiteTest;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
import com.google.gerrit.extensions.common.ChangeInput;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.inject.Injector;
|
||||
import java.nio.file.Files;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@NoHttpd
|
||||
@Ignore
|
||||
public abstract class AbstractReindexIT extends StandaloneSiteTest {
|
||||
/** @param injector injector */
|
||||
public abstract void configureIndex(Injector injector) throws Exception;
|
||||
|
||||
@Test
|
||||
public void reindexFromScratch() throws Exception {
|
||||
Project.NameKey project = new Project.NameKey("project");
|
||||
String changeId;
|
||||
try (ServerContext ctx = startServer()) {
|
||||
configureIndex(ctx.getInjector());
|
||||
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
|
||||
gApi.projects().create("project");
|
||||
|
||||
ChangeInput in = new ChangeInput();
|
||||
in.project = project.get();
|
||||
in.branch = "master";
|
||||
in.subject = "Test change";
|
||||
in.newBranch = true;
|
||||
changeId = gApi.changes().create(in).info().changeId;
|
||||
}
|
||||
|
||||
MoreFiles.deleteRecursively(sitePaths.index_dir, RecursiveDeleteOption.ALLOW_INSECURE);
|
||||
Files.createDirectory(sitePaths.index_dir);
|
||||
assertServerStartupFails();
|
||||
|
||||
runGerrit("reindex", "-d", sitePaths.site_path.toString(), "--show-stack-trace");
|
||||
|
||||
try (ServerContext ctx = startServer()) {
|
||||
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
|
||||
assertThat(gApi.changes().query("message:Test").get().stream().map(c -> c.changeId))
|
||||
.containsExactly(changeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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.acceptance.pgm;
|
||||
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.elasticsearch.testing.ElasticContainer;
|
||||
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils;
|
||||
import com.google.gerrit.elasticsearch.testing.ElasticTestUtils.ElasticNodeInfo;
|
||||
import com.google.gerrit.testutil.ConfigSuite;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.After;
|
||||
|
||||
@NoHttpd
|
||||
public class ElasticReindexIT extends AbstractReindexIT {
|
||||
private static ElasticContainer<?> container;
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config elasticsearch() {
|
||||
ElasticNodeInfo elasticNodeInfo;
|
||||
try {
|
||||
container = ElasticContainer.createAndStart();
|
||||
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
String indicesPrefix = UUID.randomUUID().toString();
|
||||
Config cfg = new Config();
|
||||
ElasticTestUtils.configure(cfg, elasticNodeInfo.port, indicesPrefix);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureIndex(Injector injector) throws Exception {
|
||||
ElasticTestUtils.createAllIndexes(injector);
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopElasticServer() {
|
||||
if (container != null) {
|
||||
container.stop();
|
||||
container = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,91 +14,12 @@
|
||||
|
||||
package com.google.gerrit.acceptance.pgm;
|
||||
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static com.google.common.truth.TruthJUnit.assume;
|
||||
|
||||
import com.google.common.io.MoreFiles;
|
||||
import com.google.common.io.RecursiveDeleteOption;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.StandaloneSiteTest;
|
||||
import com.google.gerrit.elasticsearch.testing.ElasticContainer;
|
||||
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 org.eclipse.jgit.lib.Config;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
@NoHttpd
|
||||
public class ReindexIT extends StandaloneSiteTest {
|
||||
public class ReindexIT extends AbstractReindexIT {
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config elasticsearch() {
|
||||
elasticsearchTest = true;
|
||||
if (elasticNodeInfo == null) {
|
||||
try {
|
||||
container = ElasticContainer.createAndStart();
|
||||
elasticNodeInfo = new ElasticNodeInfo(container.getHttpHost().getPort());
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String indicesPrefix = UUID.randomUUID().toString();
|
||||
Config cfg = new Config();
|
||||
ElasticTestUtils.configure(cfg, elasticNodeInfo.port, indicesPrefix);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private static ElasticNodeInfo elasticNodeInfo;
|
||||
private static ElasticContainer<?> container;
|
||||
// TODO(davido): Retrieve elasticsearch config from test description
|
||||
private static boolean elasticsearchTest;
|
||||
|
||||
@Test
|
||||
public void reindexFromScratch() throws Exception {
|
||||
if (elasticsearchTest) {
|
||||
assume().that(elasticNodeInfo != null).isTrue();
|
||||
}
|
||||
Project.NameKey project = new Project.NameKey("project");
|
||||
String changeId;
|
||||
try (ServerContext ctx = startServer()) {
|
||||
if (elasticNodeInfo != null) {
|
||||
ElasticTestUtils.createAllIndexes(ctx.getInjector());
|
||||
}
|
||||
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
|
||||
gApi.projects().create("project");
|
||||
|
||||
ChangeInput in = new ChangeInput();
|
||||
in.project = project.get();
|
||||
in.branch = "master";
|
||||
in.subject = "Test change";
|
||||
in.newBranch = true;
|
||||
changeId = gApi.changes().create(in).info().changeId;
|
||||
}
|
||||
|
||||
MoreFiles.deleteRecursively(sitePaths.index_dir, RecursiveDeleteOption.ALLOW_INSECURE);
|
||||
Files.createDirectory(sitePaths.index_dir);
|
||||
assertServerStartupFails();
|
||||
|
||||
runGerrit("reindex", "-d", sitePaths.site_path.toString(), "--show-stack-trace");
|
||||
|
||||
try (ServerContext ctx = startServer()) {
|
||||
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
|
||||
assertThat(gApi.changes().query("message:Test").get().stream().map(c -> c.changeId))
|
||||
.containsExactly(changeId);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void stopElasticServer() {
|
||||
if (container != null) {
|
||||
container.stop();
|
||||
elasticsearchTest = false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void configureIndex(Injector injector) throws Exception {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user