Merge "Cache refs/... resolutions" into stable-3.3
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/LibModule.java b/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/LibModule.java
index 8e9eb71..73593be 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/LibModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cachedrefdb/LibModule.java
@@ -19,12 +19,19 @@
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.lifecycle.LifecycleModule;
+import com.google.gerrit.server.git.GitRepositoryManager;
+import com.google.gerrit.server.git.LocalDiskRepositoryManager;
+import com.google.inject.name.Names;
public class LibModule extends LifecycleModule {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Override
protected void configure() {
+ bind(GitRepositoryManager.class)
+ .annotatedWith(Names.named(LocalDiskRepositoryManager.class.getSimpleName()))
+ .to(CachedGitRepositoryManager.class);
+
DynamicItem.itemOf(binder(), RefByNameCache.class);
DynamicItem.bind(binder(), RefByNameCache.class).to(NoOpRefByNameCache.class).in(SINGLETON);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDbIT.java b/src/test/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDbIT.java
index 23fb9ac..ff00b26 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDbIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/cachedrefdb/CachedRefDbIT.java
@@ -24,11 +24,16 @@
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
import com.google.gerrit.server.git.MultiBaseLocalDiskRepositoryManager;
import com.google.inject.Inject;
+import com.google.inject.name.Named;
import org.junit.Test;
@UseLocalDisk
@NoHttpd
public class CachedRefDbIT extends AbstractDaemonTest {
+ @Inject(optional = true)
+ @Named("LocalDiskRepositoryManager")
+ private GitRepositoryManager localGitRepositoryManager;
+
@Inject private GitRepositoryManager gitRepoManager;
@Inject private RefByNameCacheWrapper refByNameCacheWrapper;
@@ -61,4 +66,16 @@
.isInstanceOf(MultiBaseLocalDiskRepositoryManager.class);
assertThat(refByNameCacheWrapper.cache()).isInstanceOf(RefByNameCacheImpl.class);
}
+
+ @Test
+ @GerritConfig(
+ name = "gerrit.installDbModule",
+ value = "com.googlesource.gerrit.plugins.cachedrefdb.LibModule")
+ @GerritConfig(
+ name = "gerrit.installModule",
+ value = "com.googlesource.gerrit.plugins.cachedrefdb.LibSysModule")
+ public void shouldBeAbleToInstallCachedGitRepoManagerAsNamedBinding() {
+ assertThat(localGitRepositoryManager).isNotNull();
+ assertThat(localGitRepositoryManager).isInstanceOf(CachedGitRepositoryManager.class);
+ }
}