GerritServer: Support forcing local disk for all tests

Most tests are in-memory for performance reasons, which uses JGit's
InMemoryRepository. This repo implementation is fairly well tested, not
least because it's been used by Gerrit for years, but it may differ in
various ways from the FileRepository implementation. Most importantly
for the immediate NoteDb future, we want to make sure all tests continue
to work with a brand-new BatchRefUpdate implementation[1]. Running tests
against on-disk repositories is an easy way to increase coverage of the
new code.

This option is still not on by default for performance reasons, and it's
unlikely we'll enable it in CI.

[1] https://git.eclipse.org/r/100771

Change-Id: I319bdaa81a4b21e36d6615c80a04679d1bf7db07
This commit is contained in:
Dave Borowitz 2017-07-12 09:54:32 -04:00
parent dece981249
commit 96896652af
2 changed files with 32 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import static com.google.common.truth.TruthJUnit.assume;
import com.google.auto.value.AutoValue;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.config.FactoryModule;
@ -49,6 +50,7 @@ import java.net.URI;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
@ -79,7 +81,7 @@ public class GerritServer implements AutoCloseable {
return new AutoValue_GerritServer_Description(
testDesc,
configName,
!has(UseLocalDisk.class, testDesc.getTestClass()),
!has(UseLocalDisk.class, testDesc.getTestClass()) && !forceLocalDisk(),
!has(NoHttpd.class, testDesc.getTestClass()),
has(Sandboxed.class, testDesc.getTestClass()),
has(UseSsh.class, testDesc.getTestClass()),
@ -94,8 +96,9 @@ public class GerritServer implements AutoCloseable {
return new AutoValue_GerritServer_Description(
testDesc,
configName,
testDesc.getAnnotation(UseLocalDisk.class) == null
&& !has(UseLocalDisk.class, testDesc.getTestClass()),
(testDesc.getAnnotation(UseLocalDisk.class) == null
&& !has(UseLocalDisk.class, testDesc.getTestClass()))
&& !forceLocalDisk(),
testDesc.getAnnotation(NoHttpd.class) == null
&& !has(NoHttpd.class, testDesc.getTestClass()),
testDesc.getAnnotation(Sandboxed.class) != null
@ -179,6 +182,21 @@ public class GerritServer implements AutoCloseable {
}
}
private static boolean forceLocalDisk() {
String value = Strings.nullToEmpty(System.getenv("GERRIT_FORCE_LOCAL_DISK"));
if (value.isEmpty()) {
value = Strings.nullToEmpty(System.getProperty("gerrit.forceLocalDisk"));
}
switch (value.trim().toLowerCase(Locale.US)) {
case "1":
case "yes":
case "true":
return true;
default:
return false;
}
}
/**
* Initializes on-disk site but does not start server.
*

View File

@ -155,7 +155,7 @@ public class NoteDbOnlyIT extends AbstractDaemonTest {
String master = "refs/heads/master";
ObjectId initial;
try (Repository repo = repoManager.openRepository(project)) {
((InMemoryRepository) repo).setPerformsAtomicTransactions(true);
ensureAtomicTransactions(repo);
initial = repo.exactRef(master).getObjectId();
}
@ -344,4 +344,14 @@ public class NoteDbOnlyIT extends AbstractDaemonTest {
return Streams.stream(rw).map(c -> c.getShortMessage()).collect(toList());
}
}
private void ensureAtomicTransactions(Repository repo) throws Exception {
if (repo instanceof InMemoryRepository) {
((InMemoryRepository) repo).setPerformsAtomicTransactions(true);
} else {
assertThat(repo.getRefDatabase().performsAtomicTransactions())
.named("performsAtomicTransactions on %s", repo)
.isTrue();
}
}
}