Use WorkQueue to create thread pool for JGroupsForwarder Change-Id: I9f97fcd26bdd35c97049a6e14a4464adf753d01d
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/FailsafeExecutorProvider.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/FailsafeExecutorProvider.java index 2867028..d2dafe9 100644 --- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/FailsafeExecutorProvider.java +++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/FailsafeExecutorProvider.java
@@ -15,20 +15,22 @@ package com.ericsson.gerrit.plugins.highavailability.forwarder.jgroups; import com.ericsson.gerrit.plugins.highavailability.Configuration; +import com.google.gerrit.server.git.WorkQueue; import com.google.inject.Inject; import com.google.inject.Provider; import dev.failsafe.Failsafe; import dev.failsafe.FailsafeExecutor; import dev.failsafe.RetryPolicy; -import java.util.concurrent.Executors; public class FailsafeExecutorProvider implements Provider<FailsafeExecutor<Boolean>> { private final Configuration cfg; + private final WorkQueue workQueue; @Inject - FailsafeExecutorProvider(Configuration cfg) { + FailsafeExecutorProvider(Configuration cfg, WorkQueue workQueue) { this.cfg = cfg; + this.workQueue = workQueue; } @Override @@ -40,6 +42,6 @@ .handleResult(false) .build(); return Failsafe.with(retryPolicy) - .with(Executors.newScheduledThreadPool(cfg.jgroups().threadPoolSize())); + .with(workQueue.createQueue(cfg.jgroups().threadPoolSize(), "JGroupsForwarder")); } }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/JGroupsForwarderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/JGroupsForwarderTest.java index 1bce488..082b5d1 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/JGroupsForwarderTest.java +++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/jgroups/JGroupsForwarderTest.java
@@ -24,11 +24,13 @@ import com.ericsson.gerrit.plugins.highavailability.Configuration; import com.google.gerrit.server.events.EventGsonProvider; +import com.google.gerrit.server.git.WorkQueue; import com.google.gson.Gson; import java.time.Duration; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; import org.jgroups.Address; import org.jgroups.blocks.MessageDispatcher; import org.jgroups.util.Rsp; @@ -40,6 +42,7 @@ public class JGroupsForwarderTest { private static final int MAX_TRIES = 3; + private static final int THREAD_POOLS_SIZE = 4; private static final Address A1 = new UUID(1, 1); private static final Address A2 = new UUID(2, 2); @@ -56,13 +59,18 @@ Configuration cfg = mock(Configuration.class, RETURNS_DEEP_STUBS); when(cfg.jgroups().maxTries()).thenReturn(MAX_TRIES); when(cfg.jgroups().retryInterval()).thenReturn(Duration.ofMillis(1)); + when(cfg.jgroups().threadPoolSize()).thenReturn(THREAD_POOLS_SIZE); dispatcher = mock(MessageDispatcher.class, RETURNS_DEEP_STUBS); when(dispatcher.getChannel().getView().size()).thenReturn(2); when(dispatcher.getChannel().getView().getMembers()).thenReturn(List.of(A1, A2)); + WorkQueue workQueue = mock(WorkQueue.class); + when(workQueue.createQueue(THREAD_POOLS_SIZE, "JGroupsForwarder")) + .thenReturn(Executors.newScheduledThreadPool(THREAD_POOLS_SIZE)); forwarder = - new JGroupsForwarder(dispatcher, cfg, gson, new FailsafeExecutorProvider(cfg).get()); + new JGroupsForwarder( + dispatcher, cfg, gson, new FailsafeExecutorProvider(cfg, workQueue).get()); } @Test