This is an automated email from the ASF dual-hosted git repository.

daim pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new de2a02561b OAK-11913 : created Forwarding executir service (#2580)
de2a02561b is described below

commit de2a02561b6b43aa182a4fd606f9efa34b7cf31f
Author: Rishabh Kumar <[email protected]>
AuthorDate: Wed Oct 15 20:21:10 2025 +0530

    OAK-11913 : created Forwarding executir service (#2580)
---
 .../concurrent/ForwardingExecutorService.java      | 105 ++++++++++++++
 .../concurrent/ForwardingExecutorServiceTest.java  | 156 +++++++++++++++++++++
 2 files changed, 261 insertions(+)

diff --git 
a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/internal/concurrent/ForwardingExecutorService.java
 
b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/internal/concurrent/ForwardingExecutorService.java
new file mode 100644
index 0000000000..fb9eceb2ff
--- /dev/null
+++ 
b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/internal/concurrent/ForwardingExecutorService.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.commons.internal.concurrent;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+/**
+ * A {@link ExecutorService} that delegates all the calls to another executor
+ */
+public abstract class ForwardingExecutorService implements ExecutorService {
+
+    public abstract ExecutorService delegate();
+
+    @Override
+    public void execute(Runnable command) {
+        this.delegate().execute(command);
+    }
+
+    @Override
+    public Future<?> submit(Runnable task) {
+        return this.delegate().submit(task);
+    }
+
+    @Override
+    public <T> Future<T> submit(Runnable task, T result) {
+        return this.delegate().submit(task, result);
+    }
+
+    @Override
+    public <T> Future<T> submit(Callable<T> task) {
+        return this.delegate().submit(task);
+    }
+
+    @Override
+    public void shutdown() {
+        this.delegate().shutdown();
+    }
+
+    @Override
+    public List<Runnable> shutdownNow() {
+        return this.delegate().shutdownNow();
+    }
+
+    @Override
+    public boolean isShutdown() {
+        return this.delegate().isShutdown();
+    }
+
+    @Override
+    public boolean isTerminated() {
+        return this.delegate().isTerminated();
+    }
+
+    @Override
+    public boolean awaitTermination(long timeout, TimeUnit unit) throws 
InterruptedException {
+        return this.delegate().awaitTermination(timeout, unit);
+    }
+
+    @Override
+    public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> 
tasks)
+            throws InterruptedException {
+        return this.delegate().invokeAll(tasks);
+    }
+
+    @Override
+    public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> 
tasks, long timeout, TimeUnit unit)
+            throws InterruptedException {
+        return this.delegate().invokeAll(tasks, timeout, unit);
+    }
+
+    @Override
+    public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
+            throws InterruptedException, ExecutionException {
+        return this.delegate().invokeAny(tasks);
+    }
+
+    @Override
+    public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long 
timeout, TimeUnit unit)
+            throws InterruptedException, ExecutionException, TimeoutException {
+        return this.delegate().invokeAny(tasks, timeout, unit);
+    }
+}
diff --git 
a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/internal/concurrent/ForwardingExecutorServiceTest.java
 
b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/internal/concurrent/ForwardingExecutorServiceTest.java
new file mode 100644
index 0000000000..977831fb22
--- /dev/null
+++ 
b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/internal/concurrent/ForwardingExecutorServiceTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.commons.internal.concurrent;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Unit cases for ForwardingExecutorService
+ */
+public class ForwardingExecutorServiceTest {
+
+    private ExecutorService mockDelegate;
+    private ForwardingExecutorService forwardingService;
+
+    @Before
+    public void setUp() {
+        mockDelegate = Mockito.mock(ExecutorService.class);
+        forwardingService = new ForwardingExecutorService() {
+            @Override
+            public ExecutorService delegate() {
+                return mockDelegate;
+            }
+        };
+    }
+
+    @Test
+    public void testExecuteDelegation() {
+        Runnable task = Mockito.mock(Runnable.class);
+        forwardingService.execute(task);
+        Mockito.verify(mockDelegate).execute(task);
+    }
+
+    @Test
+    public void testSubmitRunnableDelegation() {
+        Runnable task = Mockito.mock(Runnable.class);
+        Future future = Mockito.mock(Future.class);
+        Mockito.when(mockDelegate.submit(task)).thenReturn(future);
+        Assert.assertEquals(future, forwardingService.submit(task));
+        Mockito.verify(mockDelegate).submit(task);
+    }
+
+    @Test
+    public void testSubmitRunnableWithResultDelegation() {
+        Runnable task = Mockito.mock(Runnable.class);
+        Future<String> future = Mockito.mock(Future.class);
+        Mockito.when(mockDelegate.submit(task, "result")).thenReturn(future);
+        Assert.assertEquals(future, forwardingService.submit(task, "result"));
+        Mockito.verify(mockDelegate).submit(task, "result");
+    }
+
+    @Test
+    public void testSubmitCallableDelegation() {
+        Callable<String> callable = Mockito.mock(Callable.class);
+        Future<String> future = Mockito.mock(Future.class);
+        Mockito.when(mockDelegate.submit(callable)).thenReturn(future);
+        Assert.assertEquals(future, forwardingService.submit(callable));
+        Mockito.verify(mockDelegate).submit(callable);
+    }
+
+    @Test
+    public void testShutdownDelegation() {
+        forwardingService.shutdown();
+        Mockito.verify(mockDelegate).shutdown();
+    }
+
+    @Test
+    public void testShutdownNowDelegation() {
+        List<Runnable> tasks = Collections.emptyList();
+        Mockito.when(mockDelegate.shutdownNow()).thenReturn(tasks);
+        Assert.assertEquals(tasks, forwardingService.shutdownNow());
+        Mockito.verify(mockDelegate).shutdownNow();
+    }
+
+    @Test
+    public void testIsShutdownDelegation() {
+        Mockito.when(mockDelegate.isShutdown()).thenReturn(true);
+        Assert.assertTrue(forwardingService.isShutdown());
+        Mockito.verify(mockDelegate).isShutdown();
+    }
+
+    @Test
+    public void testIsTerminatedDelegation() {
+        Mockito.when(mockDelegate.isTerminated()).thenReturn(true);
+        Assert.assertTrue(forwardingService.isTerminated());
+        Mockito.verify(mockDelegate).isTerminated();
+    }
+
+    @Test
+    public void testAwaitTerminationDelegation() throws InterruptedException {
+        Mockito.when(mockDelegate.awaitTermination(1, 
TimeUnit.SECONDS)).thenReturn(true);
+        Assert.assertTrue(forwardingService.awaitTermination(1, 
TimeUnit.SECONDS));
+        Mockito.verify(mockDelegate).awaitTermination(1, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void testInvokeAllDelegation() throws InterruptedException {
+        List<Callable<String>> tasks = 
Arrays.asList(Mockito.mock(Callable.class));
+        List<Future<String>> futures = 
Arrays.asList(Mockito.mock(Future.class));
+        Mockito.when(mockDelegate.invokeAll(tasks)).thenReturn(futures);
+        Assert.assertEquals(futures, forwardingService.invokeAll(tasks));
+        Mockito.verify(mockDelegate).invokeAll(tasks);
+    }
+
+    @Test
+    public void testInvokeAllWithTimeoutDelegation() throws 
InterruptedException {
+        List<Callable<String>> tasks = 
Arrays.asList(Mockito.mock(Callable.class));
+        List<Future<String>> futures = 
Arrays.asList(Mockito.mock(Future.class));
+        Mockito.when(mockDelegate.invokeAll(tasks, 1, 
TimeUnit.SECONDS)).thenReturn(futures);
+        Assert.assertEquals(futures, forwardingService.invokeAll(tasks, 1, 
TimeUnit.SECONDS));
+        Mockito.verify(mockDelegate).invokeAll(tasks, 1, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void testInvokeAnyDelegation() throws Exception {
+        List<Callable<String>> tasks = 
Arrays.asList(Mockito.mock(Callable.class));
+        Mockito.when(mockDelegate.invokeAny(tasks)).thenReturn("result");
+        Assert.assertEquals("result", forwardingService.invokeAny(tasks));
+        Mockito.verify(mockDelegate).invokeAny(tasks);
+    }
+
+    @Test
+    public void testInvokeAnyWithTimeoutDelegation() throws Exception {
+        List<Callable<String>> tasks = 
Arrays.asList(Mockito.mock(Callable.class));
+        Mockito.when(mockDelegate.invokeAny(tasks, 1, 
TimeUnit.SECONDS)).thenReturn("result");
+        Assert.assertEquals("result", forwardingService.invokeAny(tasks, 1, 
TimeUnit.SECONDS));
+        Mockito.verify(mockDelegate).invokeAny(tasks, 1, TimeUnit.SECONDS);
+    }
+
+}
\ No newline at end of file

Reply via email to