Merge "Use fake index in integration tests, allow running against lucene/fake indices"
diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt
index 61565f8..c3237ed 100644
--- a/Documentation/dev-bazel.txt
+++ b/Documentation/dev-bazel.txt
@@ -365,6 +365,13 @@
bazel test --test_tag_filters=api,git //...
----
+To run the tests against a specific index backend (LUCENE, FAKE):
+----
+ bazel test --test_env=GERRIT_INDEX_TYPE=LUCENE //...
+----
+
+Elastic search is not currently supported in integration tests.
+
The following values are currently supported for the group name:
* annotation
diff --git a/java/com/google/gerrit/acceptance/BUILD b/java/com/google/gerrit/acceptance/BUILD
index 5ee1a08..fa62cd9 100644
--- a/java/com/google/gerrit/acceptance/BUILD
+++ b/java/com/google/gerrit/acceptance/BUILD
@@ -75,6 +75,7 @@
"//java/com/google/gerrit/extensions/restapi/testing:restapi-test-util",
"//java/com/google/gerrit/gpg/testing:gpg-test-util",
"//java/com/google/gerrit/git/testing",
+ "//java/com/google/gerrit/index/testing",
]
PGM_DEPLOY_ENV = [
diff --git a/java/com/google/gerrit/acceptance/GerritServer.java b/java/com/google/gerrit/acceptance/GerritServer.java
index 93c1237..085fef5 100644
--- a/java/com/google/gerrit/acceptance/GerritServer.java
+++ b/java/com/google/gerrit/acceptance/GerritServer.java
@@ -45,6 +45,8 @@
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.annotations.Exports;
import com.google.gerrit.extensions.config.FactoryModule;
+import com.google.gerrit.index.IndexType;
+import com.google.gerrit.index.testing.FakeIndexModule;
import com.google.gerrit.lucene.LuceneIndexModule;
import com.google.gerrit.pgm.Daemon;
import com.google.gerrit.pgm.Init;
@@ -449,9 +451,29 @@
cfg.setString("gitweb", null, "cgi", "");
cfg.setString(
"accountPatchReviewDb", null, "url", JdbcAccountPatchReviewStore.TEST_IN_MEMORY_URL);
+
+ String configuredIndexBackend = cfg.getString("index", null, "type");
+ IndexType indexType;
+ if (configuredIndexBackend != null) {
+ // Explicitly configured index backend from gerrit.config trumps any other ways to configure
+ // index backends so that Reindex tests can be explicit about the backend they want to test
+ // against.
+ indexType = new IndexType(configuredIndexBackend);
+ } else {
+ // Allow configuring the index backend based on sys/env variables so that integration tests
+ // can be run against different index backends.
+ indexType = IndexType.fromEnvironment().orElse(new IndexType("fake"));
+ }
+ if (indexType.isLucene()) {
+ daemon.setIndexModule(
+ LuceneIndexModule.singleVersionAllLatest(0, ReplicaUtil.isReplica(baseConfig)));
+ } else {
+ daemon.setIndexModule(FakeIndexModule.latestVersion(false));
+ }
+ // Elastic search is not supported in integration tests yet.
+
daemon.setEnableHttpd(desc.httpd());
- daemon.setLuceneModule(
- LuceneIndexModule.singleVersionAllLatest(0, ReplicaUtil.isReplica(baseConfig)));
+ daemon.setInMemory(true);
daemon.setDatabaseForTesting(
ImmutableList.of(
new InMemoryTestingDatabaseModule(cfg, site, inMemoryRepoManager),
@@ -476,6 +498,8 @@
String[] additionalArgs)
throws Exception {
requireNonNull(site);
+ daemon.addAdditionalSysModuleForTesting(
+ new ReindexProjectsAtStartup.Module(), new ReindexGroupsAtStartup.Module());
ExecutorService daemonService = Executors.newSingleThreadExecutor();
String[] args =
Stream.concat(
diff --git a/java/com/google/gerrit/httpd/init/WebAppInitializer.java b/java/com/google/gerrit/httpd/init/WebAppInitializer.java
index 079f306..91d032e 100644
--- a/java/com/google/gerrit/httpd/init/WebAppInitializer.java
+++ b/java/com/google/gerrit/httpd/init/WebAppInitializer.java
@@ -122,6 +122,8 @@
import com.google.inject.spi.Message;
import com.google.inject.util.Providers;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -365,6 +367,19 @@
return LuceneIndexModule.latestVersion(false);
} else if (indexType.isElasticsearch()) {
return ElasticIndexModule.latestVersion(false);
+ } else if (indexType.isFake()) {
+ // Use Reflection so that we can omit the fake index binary in production code. Test code does
+ // compile the component in.
+ try {
+ Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModule");
+ Method m = clazz.getMethod("latestVersion", boolean.class);
+ return (Module) m.invoke(null, false);
+ } catch (NoSuchMethodException
+ | ClassNotFoundException
+ | IllegalAccessException
+ | InvocationTargetException e) {
+ throw new IllegalStateException("can't create index", e);
+ }
} else {
throw new IllegalStateException("unsupported index.type = " + indexType);
}
diff --git a/java/com/google/gerrit/index/IndexType.java b/java/com/google/gerrit/index/IndexType.java
index cade439..0c3a76a 100644
--- a/java/com/google/gerrit/index/IndexType.java
+++ b/java/com/google/gerrit/index/IndexType.java
@@ -14,8 +14,12 @@
package com.google.gerrit.index;
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
+import java.util.Optional;
/**
* Index types supported by the secondary index.
@@ -28,12 +32,42 @@
* allows to not break that case upon core implementation changes.
*/
public class IndexType {
+ public static final String SYS_PROP = "gerrit.index.type";
+ private static final String ENV_VAR = "GERRIT_INDEX_TYPE";
+
private static final String LUCENE = "lucene";
private static final String ELASTICSEARCH = "elasticsearch";
private static final String FAKE = "fake";
private final String type;
+ /**
+ * Returns the index type in case it was set by an environment variable. This is useful to run
+ * tests against a certain index backend.
+ */
+ public static Optional<IndexType> fromEnvironment() {
+ String value = System.getenv(ENV_VAR);
+ if (Strings.isNullOrEmpty(value)) {
+ value = System.getProperty(SYS_PROP);
+ }
+ if (Strings.isNullOrEmpty(value)) {
+ return Optional.empty();
+ }
+ value = value.toUpperCase().replace("-", "_");
+ IndexType type = new IndexType(value);
+ if (!Strings.isNullOrEmpty(System.getenv(ENV_VAR))) {
+ checkArgument(
+ type != null, "Invalid value for env variable %s: %s", ENV_VAR, System.getenv(ENV_VAR));
+ } else {
+ checkArgument(
+ type != null,
+ "Invalid value for system property %s: %s",
+ SYS_PROP,
+ System.getProperty(SYS_PROP));
+ }
+ return Optional.of(type);
+ }
+
public IndexType(@Nullable String type) {
this.type = type == null ? getDefault() : type.toLowerCase();
}
diff --git a/java/com/google/gerrit/index/testing/FakeIndexModuleOnInit.java b/java/com/google/gerrit/index/testing/FakeIndexModuleOnInit.java
new file mode 100644
index 0000000..75d8de2
--- /dev/null
+++ b/java/com/google/gerrit/index/testing/FakeIndexModuleOnInit.java
@@ -0,0 +1,37 @@
+// Copyright (C) 2021 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.index.testing;
+
+import com.google.gerrit.index.testing.AbstractFakeIndex.FakeAccountIndex;
+import com.google.gerrit.index.testing.AbstractFakeIndex.FakeGroupIndex;
+import com.google.gerrit.server.index.account.AccountIndex;
+import com.google.gerrit.server.index.group.GroupIndex;
+import com.google.inject.AbstractModule;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
+public class FakeIndexModuleOnInit extends AbstractModule {
+ @Override
+ protected void configure() {
+ install(
+ new FactoryModuleBuilder()
+ .implement(AccountIndex.class, FakeAccountIndex.class)
+ .build(AccountIndex.Factory.class));
+
+ install(
+ new FactoryModuleBuilder()
+ .implement(GroupIndex.class, FakeGroupIndex.class)
+ .build(GroupIndex.Factory.class));
+ }
+}
diff --git a/java/com/google/gerrit/pgm/Daemon.java b/java/com/google/gerrit/pgm/Daemon.java
index 29c5788..2b4cfef 100644
--- a/java/com/google/gerrit/pgm/Daemon.java
+++ b/java/com/google/gerrit/pgm/Daemon.java
@@ -87,6 +87,7 @@
import com.google.gerrit.server.git.SearchingChangeCacheImpl;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.group.PeriodicGroupIndexer;
+import com.google.gerrit.server.index.AbstractIndexModule;
import com.google.gerrit.server.index.IndexModule;
import com.google.gerrit.server.index.OnlineUpgrader;
import com.google.gerrit.server.index.VersionManager;
@@ -128,6 +129,8 @@
import com.google.inject.Provider;
import com.google.inject.Stage;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -207,7 +210,7 @@
private Injector httpdInjector;
private Path runFile;
private boolean inMemoryTest;
- private AbstractModule luceneModule;
+ private AbstractModule indexModule;
private Module emailModule;
private List<Module> testSysModules = new ArrayList<>();
private List<Module> testSshModules = new ArrayList<>();
@@ -336,9 +339,13 @@
}
@VisibleForTesting
- public void setLuceneModule(LuceneIndexModule m) {
- luceneModule = m;
- inMemoryTest = true;
+ public void setIndexModule(AbstractIndexModule m) {
+ indexModule = m;
+ }
+
+ @VisibleForTesting
+ public void setInMemory(boolean inMemory) {
+ this.inMemoryTest = inMemory;
}
@VisibleForTesting
@@ -523,8 +530,8 @@
}
private Module createIndexModule() {
- if (luceneModule != null) {
- return luceneModule;
+ if (indexModule != null) {
+ return indexModule;
}
if (indexType.isLucene()) {
return LuceneIndexModule.latestVersion(replica);
@@ -532,6 +539,20 @@
if (indexType.isElasticsearch()) {
return ElasticIndexModule.latestVersion(replica);
}
+ if (indexType.isFake()) {
+ // Use Reflection so that we can omit the fake index binary in production code. Test code does
+ // compile the component in.
+ try {
+ Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModule");
+ Method m = clazz.getMethod("latestVersion", boolean.class);
+ return (Module) m.invoke(null, replica);
+ } catch (NoSuchMethodException
+ | ClassNotFoundException
+ | IllegalAccessException
+ | InvocationTargetException e) {
+ throw new IllegalStateException("can't create index", e);
+ }
+ }
throw new IllegalStateException("unsupported index.type = " + indexType);
}
diff --git a/java/com/google/gerrit/pgm/Reindex.java b/java/com/google/gerrit/pgm/Reindex.java
index 3935268..6e99007 100644
--- a/java/com/google/gerrit/pgm/Reindex.java
+++ b/java/com/google/gerrit/pgm/Reindex.java
@@ -39,6 +39,8 @@
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -154,6 +156,21 @@
} else if (indexType.isElasticsearch()) {
indexModule =
ElasticIndexModule.singleVersionWithExplicitVersions(versions, threads, replica);
+ } else if (indexType.isFake()) {
+ // Use Reflection so that we can omit the fake index binary in production code. Test code does
+ // compile the component in.
+ try {
+ Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModule");
+ Method m =
+ clazz.getMethod(
+ "singleVersionWithExplicitVersions", Map.class, int.class, boolean.class);
+ indexModule = (Module) m.invoke(null, versions, threads, replica);
+ } catch (NoSuchMethodException
+ | ClassNotFoundException
+ | IllegalAccessException
+ | InvocationTargetException e) {
+ throw new IllegalStateException("can't create index", e);
+ }
} else {
throw new IllegalStateException("unsupported index.type = " + indexType);
}
diff --git a/java/com/google/gerrit/pgm/init/BaseInit.java b/java/com/google/gerrit/pgm/init/BaseInit.java
index 62ff66a..c4b0040 100644
--- a/java/com/google/gerrit/pgm/init/BaseInit.java
+++ b/java/com/google/gerrit/pgm/init/BaseInit.java
@@ -32,6 +32,7 @@
import com.google.gerrit.pgm.init.api.InstallPlugins;
import com.google.gerrit.pgm.init.api.LibraryDownload;
import com.google.gerrit.pgm.init.index.IndexManagerOnInit;
+import com.google.gerrit.pgm.init.index.IndexModuleOnInit;
import com.google.gerrit.pgm.init.index.elasticsearch.ElasticIndexModuleOnInit;
import com.google.gerrit.pgm.init.index.lucene.LuceneIndexModuleOnInit;
import com.google.gerrit.pgm.util.SiteProgram;
@@ -57,6 +58,7 @@
import com.google.inject.util.Providers;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -418,6 +420,19 @@
modules.add(new LuceneIndexModuleOnInit());
} else if (indexType.isElasticsearch()) {
modules.add(new ElasticIndexModuleOnInit());
+ } else if (indexType.isFake()) {
+ try {
+ Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModuleOnInit");
+ Module indexOnInitModule = (Module) clazz.getDeclaredConstructor().newInstance();
+ modules.add(indexOnInitModule);
+ } catch (InstantiationException
+ | IllegalAccessException
+ | ClassNotFoundException
+ | NoSuchMethodException
+ | InvocationTargetException e) {
+ throw new IllegalStateException("unable to create fake index", e);
+ }
+ modules.add(new IndexModuleOnInit());
} else {
throw new IllegalStateException("unsupported index.type = " + indexType);
}
diff --git a/javatests/com/google/gerrit/acceptance/pgm/AbstractReindexTests.java b/javatests/com/google/gerrit/acceptance/pgm/AbstractReindexTests.java
index cad0b83..cac376f 100644
--- a/javatests/com/google/gerrit/acceptance/pgm/AbstractReindexTests.java
+++ b/javatests/com/google/gerrit/acceptance/pgm/AbstractReindexTests.java
@@ -31,14 +31,18 @@
import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.common.ChangeInput;
+import com.google.gerrit.index.IndexDefinition;
import com.google.gerrit.launcher.GerritLauncher;
import com.google.gerrit.server.index.GerritIndexStatus;
import com.google.gerrit.server.index.change.ChangeIndexCollection;
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.inject.Injector;
+import com.google.inject.Key;
import com.google.inject.Provider;
+import com.google.inject.TypeLiteral;
import java.nio.file.Files;
+import java.util.Collection;
import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.jgit.lib.Config;
@@ -48,9 +52,6 @@
@NoHttpd
public abstract class AbstractReindexTests extends StandaloneSiteTest {
- /** @param injector injector */
- public abstract void configureIndex(Injector injector) throws Exception;
-
private static final String CHANGES = ChangeSchemaDefinitions.NAME;
private Project.NameKey project;
@@ -223,10 +224,18 @@
}
}
+ protected static void createAllIndexes(Injector injector) {
+ Collection<IndexDefinition<?, ?, ?>> indexDefs =
+ injector.getInstance(Key.get(new TypeLiteral<Collection<IndexDefinition<?, ?, ?>>>() {}));
+ for (IndexDefinition<?, ?, ?> indexDef : indexDefs) {
+ indexDef.getIndexCollection().getSearchIndex().deleteAll();
+ }
+ }
+
private void setUpChange() throws Exception {
project = Project.nameKey("reindex-project-test");
try (ServerContext ctx = startServer()) {
- configureIndex(ctx.getInjector());
+ createAllIndexes(ctx.getInjector());
GerritApi gApi = ctx.getInjector().getInstance(GerritApi.class);
gApi.projects().create(project.get());
diff --git a/javatests/com/google/gerrit/acceptance/pgm/ElasticReindexIT.java b/javatests/com/google/gerrit/acceptance/pgm/ElasticReindexIT.java
index f23cc10..0632241 100644
--- a/javatests/com/google/gerrit/acceptance/pgm/ElasticReindexIT.java
+++ b/javatests/com/google/gerrit/acceptance/pgm/ElasticReindexIT.java
@@ -14,23 +14,15 @@
package com.google.gerrit.acceptance.pgm;
-import static com.google.gerrit.elasticsearch.ElasticTestUtils.createAllIndexes;
import static com.google.gerrit.elasticsearch.ElasticTestUtils.getConfig;
import com.google.gerrit.elasticsearch.ElasticVersion;
import com.google.gerrit.testing.ConfigSuite;
-import com.google.inject.Injector;
import org.eclipse.jgit.lib.Config;
public class ElasticReindexIT extends AbstractReindexTests {
-
@ConfigSuite.Default
public static Config elasticsearchV7() {
return getConfig(ElasticVersion.V7_8);
}
-
- @Override
- public void configureIndex(Injector injector) {
- createAllIndexes(injector);
- }
}
diff --git a/javatests/com/google/gerrit/acceptance/pgm/ReindexIT.java b/javatests/com/google/gerrit/acceptance/pgm/LuceneReindexIT.java
similarity index 68%
rename from javatests/com/google/gerrit/acceptance/pgm/ReindexIT.java
rename to javatests/com/google/gerrit/acceptance/pgm/LuceneReindexIT.java
index 223851e..e630bca 100644
--- a/javatests/com/google/gerrit/acceptance/pgm/ReindexIT.java
+++ b/javatests/com/google/gerrit/acceptance/pgm/LuceneReindexIT.java
@@ -14,9 +14,14 @@
package com.google.gerrit.acceptance.pgm;
-import com.google.inject.Injector;
+import com.google.gerrit.testing.ConfigSuite;
+import org.eclipse.jgit.lib.Config;
-public class ReindexIT extends AbstractReindexTests {
- @Override
- public void configureIndex(Injector injector) {}
+public class LuceneReindexIT extends AbstractReindexTests {
+ @ConfigSuite.Default
+ public static Config luceneConfig() {
+ Config cfg = new Config();
+ cfg.setString("index", null, "type", "lucene");
+ return cfg;
+ }
}
diff --git a/javatests/com/google/gerrit/acceptance/testsuite/index/DefaultIndexBindingIT.java b/javatests/com/google/gerrit/acceptance/testsuite/index/DefaultIndexBindingIT.java
new file mode 100644
index 0000000..f5e4e09
--- /dev/null
+++ b/javatests/com/google/gerrit/acceptance/testsuite/index/DefaultIndexBindingIT.java
@@ -0,0 +1,51 @@
+// Copyright (C) 2021 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.testsuite.index;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.AbstractDaemonTest;
+import com.google.gerrit.index.IndexType;
+import com.google.gerrit.index.testing.AbstractFakeIndex;
+import com.google.gerrit.server.index.change.ChangeIndexCollection;
+import javax.inject.Inject;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/** Test to check that the expected index backend was bound depending on sys/env properties. */
+public class DefaultIndexBindingIT extends AbstractDaemonTest {
+
+ @Inject private ChangeIndexCollection changeIndex;
+
+ private static String propertyBeforeTest;
+
+ @BeforeClass
+ public static void setup() {
+ propertyBeforeTest = System.getProperty(IndexType.SYS_PROP);
+ System.setProperty(IndexType.SYS_PROP, "");
+ }
+
+ @AfterClass
+ public static void teardown() {
+ System.setProperty(IndexType.SYS_PROP, propertyBeforeTest);
+ }
+
+ @Test
+ public void fakeIsBoundByDefault() throws Exception {
+ assertThat(System.getProperty(IndexType.SYS_PROP)).isEmpty();
+ assertThat(changeIndex.getSearchIndex()).isInstanceOf(AbstractFakeIndex.FakeChangeIndex.class);
+ }
+}
diff --git a/javatests/com/google/gerrit/acceptance/testsuite/index/FakeIndexBindingIT.java b/javatests/com/google/gerrit/acceptance/testsuite/index/FakeIndexBindingIT.java
new file mode 100644
index 0000000..4122426
--- /dev/null
+++ b/javatests/com/google/gerrit/acceptance/testsuite/index/FakeIndexBindingIT.java
@@ -0,0 +1,51 @@
+// Copyright (C) 2021 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.testsuite.index;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.AbstractDaemonTest;
+import com.google.gerrit.index.IndexType;
+import com.google.gerrit.index.testing.AbstractFakeIndex;
+import com.google.gerrit.server.index.change.ChangeIndexCollection;
+import javax.inject.Inject;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/** Test to check that the expected index backend was bound depending on sys/env properties. */
+public class FakeIndexBindingIT extends AbstractDaemonTest {
+
+ @Inject private ChangeIndexCollection changeIndex;
+
+ private static String propertyBeforeTest;
+
+ @BeforeClass
+ public static void setup() {
+ propertyBeforeTest = System.getProperty(IndexType.SYS_PROP);
+ System.setProperty(IndexType.SYS_PROP, "fake");
+ }
+
+ @AfterClass
+ public static void teardown() {
+ System.setProperty(IndexType.SYS_PROP, propertyBeforeTest);
+ }
+
+ @Test
+ public void fakeIsBoundWhenConfigured() throws Exception {
+ assertThat(System.getProperty(IndexType.SYS_PROP)).isEqualTo("fake");
+ assertThat(changeIndex.getSearchIndex()).isInstanceOf(AbstractFakeIndex.FakeChangeIndex.class);
+ }
+}
diff --git a/javatests/com/google/gerrit/acceptance/testsuite/index/LuceneIndexBindingIT.java b/javatests/com/google/gerrit/acceptance/testsuite/index/LuceneIndexBindingIT.java
new file mode 100644
index 0000000..31e31fd
--- /dev/null
+++ b/javatests/com/google/gerrit/acceptance/testsuite/index/LuceneIndexBindingIT.java
@@ -0,0 +1,51 @@
+// Copyright (C) 2021 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.testsuite.index;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.gerrit.acceptance.AbstractDaemonTest;
+import com.google.gerrit.index.IndexType;
+import com.google.gerrit.lucene.LuceneChangeIndex;
+import com.google.gerrit.server.index.change.ChangeIndexCollection;
+import javax.inject.Inject;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/** Test to check that the expected index backend was bound depending on sys/env properties. */
+public class LuceneIndexBindingIT extends AbstractDaemonTest {
+
+ @Inject private ChangeIndexCollection changeIndex;
+
+ private static String propertyBeforeTest;
+
+ @BeforeClass
+ public static void setup() {
+ propertyBeforeTest = System.getProperty(IndexType.SYS_PROP);
+ System.setProperty(IndexType.SYS_PROP, "lucene");
+ }
+
+ @AfterClass
+ public static void teardown() {
+ System.setProperty(IndexType.SYS_PROP, propertyBeforeTest);
+ }
+
+ @Test
+ public void luceneIsBoundWhenConfigured() throws Exception {
+ assertThat(System.getProperty(IndexType.SYS_PROP)).isEqualTo("lucene");
+ assertThat(changeIndex.getSearchIndex()).isInstanceOf(LuceneChangeIndex.class);
+ }
+}