StandaloneSiteTest: Ignore user and system git config

Override SystemReader to return empty files for the user and system
config. This makes StandaloneNoteDbMigrationIT pass regardless of the
configuration of the system it's running on.

This has to happen in StandaloneSiteTest prior to site initialization,
since the SystemReader is queried at FileRepository creation time, and
Gerrit by design holds all created repos open in the RepositoryCache. If
we tried to override the SystemReader in a test, it would have no
effect, because the cached repos would already have the wrong config
files loaded.

Another complication is that GerritLauncher#mainImpl was creating a new
classloader for every invocation, meaning the SystemReader class used by
the wrapper code in StandaloneSiteTest was not the same class instance
seen by the tests. Fix this by explicitly passing a ClassLoader when
running.

Change-Id: I478f3f712bced530c87b8fac3422275ec93d3557
This commit is contained in:
Dave Borowitz
2018-03-20 10:41:35 -04:00
parent d2612783fc
commit d3ee31c0cf
2 changed files with 87 additions and 4 deletions

View File

@@ -63,6 +63,17 @@ public final class GerritLauncher {
System.exit(mainImpl(argv));
}
/**
* Invokes a proram.
*
* <p>Creates a new classloader to load and run the program class. To reuse a classloader across
* calls (e.g. from tests), use {@link #invokeProgram(ClassLoader, String[])}.
*
* @param argv arguments, as would be passed to {@code gerrit.war}. The first argument is the
* program name.
* @return program return code.
* @throws Exception if any error occurs.
*/
public static int mainImpl(String[] argv) throws Exception {
if (argv.length == 0) {
File me;
@@ -163,7 +174,16 @@ public final class GerritLauncher {
}
}
private static int invokeProgram(ClassLoader loader, String[] origArgv) throws Exception {
/**
* Invokes a proram in the provided {@code ClassLoader}.
*
* @param loader classloader to load program class from.
* @param origArgv arguments, as would be passed to {@code gerrit.war}. The first argument is the
* program name.
* @return program return code.
* @throws Exception if any error occurs.
*/
public static int invokeProgram(ClassLoader loader, String[] origArgv) throws Exception {
String name = origArgv[0];
final String[] argv = new String[origArgv.length - 1];
System.arraycopy(origArgv, 1, argv, 0, argv.length);