Support sending review comment emails synchronously

A directExecutor is not a WorkQueue.Executor so the bound type needs
to change, but this is fine, as callers are only using submit.

Turn this on by default for tests. Don't even bother reading the
config in InMemoryModule, but still set the config option as it may
be required in the non-in-memory test path.

Change-Id: Ib48792b585971206452543173f8194a08b46875b
This commit is contained in:
Dave Borowitz
2015-05-01 11:03:52 -07:00
parent b0ef2cd435
commit e75830ed9c
3 changed files with 13 additions and 11 deletions

View File

@@ -24,7 +24,6 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.git.EmailReviewCommentsExecutor;
import com.google.gerrit.server.git.WorkQueue.Executor;
import com.google.gerrit.server.mail.CommentSender;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.util.RequestContext;
@@ -43,6 +42,7 @@ import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ExecutorService;
public class EmailReviewComments implements Runnable, RequestContext {
private static final Logger log = LoggerFactory.getLogger(EmailReviewComments.class);
@@ -57,7 +57,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
List<PatchLineComment> comments);
}
private final Executor sendEmailsExecutor;
private final ExecutorService sendEmailsExecutor;
private final PatchSetInfoFactory patchSetInfoFactory;
private final CommentSender.Factory commentSenderFactory;
private final SchemaFactory<ReviewDb> schemaFactory;
@@ -73,7 +73,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
@Inject
EmailReviewComments (
@EmailReviewCommentsExecutor final Executor executor,
@EmailReviewCommentsExecutor ExecutorService executor,
PatchSetInfoFactory patchSetInfoFactory,
CommentSender.Factory commentSenderFactory,
SchemaFactory<ReviewDb> schemaFactory,
@@ -103,8 +103,8 @@ public class EmailReviewComments implements Runnable, RequestContext {
@Override
public void run() {
RequestContext old = requestContext.setContext(this);
try {
requestContext.setContext(this);
comments = Lists.newArrayList(comments);
Collections.sort(comments, new Comparator<PatchLineComment>() {
@@ -138,7 +138,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
} catch (Exception e) {
log.error("Cannot email comments for " + patchSet.getId(), e);
} finally {
requestContext.setContext(null);
requestContext.setContext(old);
if (db != null) {
db.close();
db = null;

View File

@@ -25,6 +25,7 @@ import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -48,9 +49,12 @@ public class ReceiveCommitsExecutorModule extends AbstractModule {
@Provides
@Singleton
@EmailReviewCommentsExecutor
public WorkQueue.Executor createEmailReviewCommentsExecutor(
public ExecutorService createEmailReviewCommentsExecutor(
@GerritServerConfig Config config, WorkQueue queues) {
int poolSize = config.getInt("sendemail", null, "threadPoolSize", 1);
if (poolSize == 0) {
return MoreExecutors.newDirectExecutorService();
}
return queues.createQueue(poolSize, "EmailReviewComments");
}

View File

@@ -44,7 +44,6 @@ import com.google.gerrit.server.git.EmailReviewCommentsExecutor;
import com.google.gerrit.server.git.GarbageCollection;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.PerThreadRequestScope;
import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.index.ChangeSchemas;
import com.google.gerrit.server.index.IndexModule.IndexType;
import com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier;
@@ -94,6 +93,7 @@ public class InMemoryModule extends FactoryModule {
cfg.setBoolean("index", "lucene", "testInmemory", true);
cfg.setInt("index", "lucene", "testVersion",
ChangeSchemas.getLatest().getVersion());
cfg.setInt("sendemail", null, "threadPoolSize", 0);
}
private final Config cfg;
@@ -205,10 +205,8 @@ public class InMemoryModule extends FactoryModule {
@Provides
@Singleton
@EmailReviewCommentsExecutor
public WorkQueue.Executor createEmailReviewCommentsExecutor(
@GerritServerConfig Config config, WorkQueue queues) {
int poolSize = config.getInt("sendemail", null, "threadPoolSize", 1);
return queues.createQueue(poolSize, "EmailReviewComments");
public ExecutorService createEmailReviewCommentsExecutor() {
return MoreExecutors.newDirectExecutorService();
}
@Provides