Fix provisioning of ReviewDb in SystemGroupBackend.NameCheck
When the server is started, we don't have a request context which
provides an instance of ReviewDb. Therefore, we need to use the
SchemaFactory to obtain access to ReviewDb.
This issue was introduced by I52f8c66ec. Before that change, we also
used a SchemaFactory in GroupCacheImpl to access ReviewDb (probably
for exactly this reason). Unfortunately, our tests didn't catch this
issue. It only surfaces when GroupsIT#getSystemGroupByConfiguredName
is executed without any other tests of GroupsIT before it.
Change-Id: Ibdaea4bd99a7fb9aae2bdb73165a0c4e9df267c8
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/group/SystemGroupBackend.java b/gerrit-server/src/main/java/com/google/gerrit/server/group/SystemGroupBackend.java
index 151b43d..57dff1f 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/group/SystemGroupBackend.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/group/SystemGroupBackend.java
@@ -35,8 +35,8 @@
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException;
+import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
-import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
@@ -188,13 +188,13 @@
public static class NameCheck implements StartupCheck {
private final Config cfg;
private final Groups groups;
- private final Provider<ReviewDb> db;
+ private final SchemaFactory<ReviewDb> schema;
@Inject
- NameCheck(@GerritServerConfig Config cfg, Groups groups, Provider<ReviewDb> db) {
+ NameCheck(@GerritServerConfig Config cfg, Groups groups, SchemaFactory<ReviewDb> schema) {
this.cfg = cfg;
this.groups = groups;
- this.db = db;
+ this.schema = schema;
}
@Override
@@ -213,7 +213,7 @@
}
List<AccountGroup> allGroups;
try {
- allGroups = groups.getAll(db.get()).collect(toList());
+ allGroups = groups.getAll(schema.open()).collect(toList());
} catch (OrmException e) {
return;
}