Add simple tests to launch Reindex

We currently have no tests for the Reindex injector stack, and it is
not uncommon for changes to break Reindex as contributors do not
always know or remember to run it.

Add tests that run the Reindex program directly via GerritLauncher,
using a real injector stack on a newly created site.

Eventually we may want to reindex a site with changes in it, wiring up
GerritServer, which is beyond the scope of this test.

Change-Id: Ic6f32ee4d24395be74b3ea60b9084c79531c6a4a
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/BUCK b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/BUCK
new file mode 100644
index 0000000..217af2f
--- /dev/null
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/BUCK
@@ -0,0 +1,9 @@
+include_defs('//gerrit-acceptance-tests/tests.defs')
+
+acceptance_tests(
+  srcs = glob(['*IT.java']),
+  deps = [
+    '//gerrit-acceptance-tests:lib',
+  ],
+  source_under_test = ['//gerrit-pgm:pgm'],
+)
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java
new file mode 100644
index 0000000..5778b19
--- /dev/null
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/ReindexIT.java
@@ -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 org.junit.Assert.assertEquals;
+
+import com.google.gerrit.acceptance.TempFileUtil;
+import com.google.gerrit.launcher.GerritLauncher;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+public class ReindexIT {
+  private File sitePath;
+
+  @Before
+  public void createTempDirectory() throws Exception {
+    sitePath = TempFileUtil.createTempDirectory();
+  }
+
+  @After
+  public void destroySite() throws Exception {
+    if (sitePath != null) {
+      TempFileUtil.recursivelyDelete(sitePath);
+    }
+  }
+
+  @Test
+  public void reindexEmptySite() throws Exception {
+    initSite();
+    runGerrit("reindex", "-d", sitePath.getPath(),
+        "--show-stack-trace");
+  }
+
+  @Test
+  public void reindexEmptySiteWithRecheckMergeable() throws Exception {
+    initSite();
+    runGerrit("reindex", "-d", sitePath.getPath(),
+        "--show-stack-trace",
+        "--recheck-mergeable");
+  }
+
+  private void initSite() throws Exception {
+    runGerrit("init", "-d", sitePath.getPath(),
+        "--batch", "--no-auto-start", "--skip-plugins", "--show-stack-trace");
+  }
+
+  private static void runGerrit(String... args) throws Exception {
+    assertEquals(0, GerritLauncher.mainImpl(args));
+  }
+}
diff --git a/gerrit-acceptance-tests/tests.defs b/gerrit-acceptance-tests/tests.defs
index 3c8b4d5..6c5a087 100644
--- a/gerrit-acceptance-tests/tests.defs
+++ b/gerrit-acceptance-tests/tests.defs
@@ -1,6 +1,7 @@
 def acceptance_tests(
     srcs,
     deps = [],
+    source_under_test = [],
     vm_args = ['-Xmx256m']):
   for j in srcs:
     java_test(
@@ -11,7 +12,7 @@
         '//gerrit-httpd:httpd',
         '//gerrit-sshd:sshd',
         '//gerrit-server:server',
-      ],
+      ] + source_under_test,
       labels = [
         'acceptance',
         'slow',
diff --git a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java
index 33a3534..6c39743 100644
--- a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java
+++ b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java
@@ -50,7 +50,7 @@
     System.exit(mainImpl(argv));
   }
 
-  private static int mainImpl(final String argv[]) throws Exception {
+  public static int mainImpl(final String argv[]) throws Exception {
     if (argv.length == 0) {
       File me;
       try {