diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java new file mode 100644 index 0000000000..c538b85d82 --- /dev/null +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/pgm/RebuildNotedbIT.java @@ -0,0 +1,64 @@ +// 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.Truth.assertThat; + +import com.google.common.io.Files; +import com.google.gerrit.launcher.GerritLauncher; +import com.google.gerrit.server.notedb.NotesMigration; +import com.google.gerrit.testutil.TempFileUtil; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.nio.charset.StandardCharsets; + +public class RebuildNotedbIT { + private File sitePath; + + @Before + public void createTempDirectory() throws Exception { + sitePath = TempFileUtil.createTempDirectory(); + } + + @After + public void destroySite() throws Exception { + if (sitePath != null) { + TempFileUtil.cleanup(); + } + } + + @Test + public void rebuildEmptySite() throws Exception { + initSite(); + Files.append(NotesMigration.allEnabledConfig().toText(), + new File(sitePath.toString(), "etc/gerrit.config"), + StandardCharsets.UTF_8); + runGerrit("RebuildNotedb", "-d", sitePath.toString(), + "--show-stack-trace"); + } + + 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 { + assertThat(GerritLauncher.mainImpl(args)).isEqualTo(0); + } +} diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/RebuildNotedb.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/RebuildNotedb.java index 4593aef1dd..afbb91806a 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/RebuildNotedb.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/RebuildNotedb.java @@ -25,8 +25,10 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.google.gerrit.extensions.events.GitReferenceUpdatedListener; +import com.google.gerrit.extensions.registration.DynamicSet; import com.google.gerrit.lifecycle.LifecycleManager; -import com.google.gerrit.pgm.util.BatchGitModule; +import com.google.gerrit.lucene.LuceneIndexModule; import com.google.gerrit.pgm.util.BatchProgramModule; import com.google.gerrit.pgm.util.SiteProgram; import com.google.gerrit.pgm.util.ThreadLimiter; @@ -39,14 +41,18 @@ import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.MultiProgressMonitor; import com.google.gerrit.server.git.MultiProgressMonitor.Task; import com.google.gerrit.server.git.WorkQueue; +import com.google.gerrit.server.index.IndexModule; +import com.google.gerrit.server.index.ReindexAfterUpdate; import com.google.gerrit.server.notedb.ChangeRebuilder; import com.google.gerrit.server.notedb.NoteDbModule; import com.google.gerrit.server.notedb.NotesMigration; +import com.google.gerrit.solr.SolrIndexModule; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.AbstractModule; import com.google.inject.Injector; import com.google.inject.Key; +import com.google.inject.Module; import com.google.inject.TypeLiteral; import org.eclipse.jgit.lib.BatchRefUpdate; @@ -205,8 +211,21 @@ public class RebuildNotedb extends SiteProgram { @Override public void configure() { install(dbInjector.getInstance(BatchProgramModule.class)); - install(new BatchGitModule()); install(new NoteDbModule()); + DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to( + ReindexAfterUpdate.class); + Module changeIndexModule; + switch (IndexModule.getIndexType(dbInjector)) { + case LUCENE: + changeIndexModule = new LuceneIndexModule(null, threads, null); + break; + case SOLR: + changeIndexModule = new SolrIndexModule(false, threads, null); + break; + default: + throw new IllegalStateException("unsupported index.type"); + } + install(changeIndexModule); } }); }