AbstractQueryAccountsTest: Do account creation in request context
Otherwise getting the database injected into the account index
fails. This is no problem for the account index which is based on
Lucene as it doesn't need the database, but other implementations of
the account index may need it (e.g. the account index at Google).
Change-Id: I0ca904407aa9b5579ad67af9e7e717f4e7638383
diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java
index 5686dc3..1ff5aac 100644
--- a/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java
+++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/account/AbstractQueryAccountsTest.java
@@ -36,6 +36,8 @@
import com.google.gerrit.server.account.AuthRequest;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.schema.SchemaCreator;
+import com.google.gerrit.server.util.ManualRequestContext;
+import com.google.gerrit.server.util.OneOffRequestContext;
import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.gerrit.testutil.ConfigSuite;
@@ -97,6 +99,9 @@
@Inject
protected ThreadLocalRequestContext requestContext;
+ @Inject
+ protected OneOffRequestContext oneOffRequestContext;
+
protected LifecycleManager lifecycle;
protected ReviewDb db;
protected AccountInfo currentUserInfo;
@@ -405,18 +410,20 @@
private Account.Id createAccount(String username, String fullName,
String email, boolean active) throws Exception {
- Account.Id id =
- accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
- if (email != null) {
- accountManager.link(id, AuthRequest.forEmail(email));
+ try (ManualRequestContext ctx = oneOffRequestContext.open()) {
+ Account.Id id =
+ accountManager.authenticate(AuthRequest.forUser(username)).getAccountId();
+ if (email != null) {
+ accountManager.link(id, AuthRequest.forEmail(email));
+ }
+ Account a = db.accounts().get(id);
+ a.setFullName(fullName);
+ a.setPreferredEmail(email);
+ a.setActive(active);
+ db.accounts().update(ImmutableList.of(a));
+ accountCache.evict(id);
+ return id;
}
- Account a = db.accounts().get(id);
- a.setFullName(fullName);
- a.setPreferredEmail(email);
- a.setActive(active);
- db.accounts().update(ImmutableList.of(a));
- accountCache.evict(id);
- return id;
}
private void addEmails(AccountInfo account, String... emails)