This is an automated email from the ASF dual-hosted git repository. daim pushed a commit to branch OAK-11907 in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit ce736d3cd12774ef5610cee87add26406f33cee2 Author: rishabhdaim <rishabhdaim1...@gmail.com> AuthorDate: Thu Sep 11 20:29:58 2025 +0530 OAK-11907 : removed Guava's DirectExecutor with oak-commons implementation --- .../plugins/blob/AbstractDataStoreCacheTest.java | 4 +- .../internal/concurrent/DirectExecutor.java | 37 ++++++++++++++++++ .../internal/concurrent/DirectExecutorTest.java | 45 ++++++++++++++++++++++ .../oak/commons/jmx/ManagementOperationTest.java | 4 +- 4 files changed, 86 insertions(+), 4 deletions(-) diff --git a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractDataStoreCacheTest.java b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractDataStoreCacheTest.java index 51abc90295..c753819f4d 100644 --- a/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractDataStoreCacheTest.java +++ b/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractDataStoreCacheTest.java @@ -55,8 +55,8 @@ import org.apache.jackrabbit.guava.common.util.concurrent.AbstractListeningExecu import org.apache.jackrabbit.guava.common.util.concurrent.FutureCallback; import org.apache.jackrabbit.guava.common.util.concurrent.Futures; import org.apache.jackrabbit.guava.common.util.concurrent.ListenableFuture; -import org.apache.jackrabbit.guava.common.util.concurrent.MoreExecutors; import org.apache.jackrabbit.oak.commons.FileIOUtils; +import org.apache.jackrabbit.oak.commons.internal.concurrent.DirectExecutor; import org.apache.jackrabbit.oak.spi.blob.AbstractDataRecord; import org.apache.jackrabbit.oak.spi.blob.AbstractSharedBackend; import org.jetbrains.annotations.NotNull; @@ -241,7 +241,7 @@ public class AbstractDataStoreCacheTest { LOG.trace("After submitting to super...."); futures.add(submit); - Futures.addCallback(submit, new TestFutureCallback<Integer>(afterLatch), MoreExecutors.directExecutor()); + Futures.addCallback(submit, new TestFutureCallback<Integer>(afterLatch), DirectExecutor.INSTANCE); LOG.trace("Added callback"); return submit; diff --git a/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/internal/concurrent/DirectExecutor.java b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/internal/concurrent/DirectExecutor.java new file mode 100644 index 0000000000..bc60e3d33b --- /dev/null +++ b/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/internal/concurrent/DirectExecutor.java @@ -0,0 +1,37 @@ +/* + * 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.concurrent.Executor; + +/** + * An @{@link Executor} that runs the task in calling thread + */ +public enum DirectExecutor implements Executor { + INSTANCE; + + public void execute(Runnable command) { + command.run(); + } + + @Override + public String toString() { + return "DirectExecutor"; + } +} diff --git a/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/internal/concurrent/DirectExecutorTest.java b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/internal/concurrent/DirectExecutorTest.java new file mode 100644 index 0000000000..cbb3f6d89a --- /dev/null +++ b/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/internal/concurrent/DirectExecutorTest.java @@ -0,0 +1,45 @@ +/* + * 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.Test; + +/** + * Unit case for {@link DirectExecutor} + */ +public class DirectExecutorTest { + + @Test + public void testExecuteRunsInCallingThread() { + final String callingThread = Thread.currentThread().getName(); + final String[] executedThread = new String[1]; + + DirectExecutor.INSTANCE.execute(() -> executedThread[0] = Thread.currentThread().getName()); + + Assert.assertEquals(callingThread, executedThread[0]); + } + + @Test + public void testExecuteRunsImmediately() { + final boolean[] ran = {false}; + DirectExecutor.INSTANCE.execute(() -> ran[0] = true); + Assert.assertTrue(ran[0]); + } +} \ No newline at end of file diff --git a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/commons/jmx/ManagementOperationTest.java b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/commons/jmx/ManagementOperationTest.java index 2f3ec9b809..6ca84c2ce4 100644 --- a/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/commons/jmx/ManagementOperationTest.java +++ b/oak-core-spi/src/test/java/org/apache/jackrabbit/oak/commons/jmx/ManagementOperationTest.java @@ -23,7 +23,6 @@ import static java.lang.Thread.currentThread; import static java.lang.Thread.sleep; import static java.util.concurrent.Executors.newCachedThreadPool; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.jackrabbit.guava.common.util.concurrent.MoreExecutors.directExecutor; import static org.apache.jackrabbit.guava.common.util.concurrent.MoreExecutors.listeningDecorator; import static org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean.StatusCode.FAILED; import static org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean.StatusCode.RUNNING; @@ -41,6 +40,7 @@ import java.util.concurrent.TimeoutException; import javax.management.openmbean.CompositeData; import org.apache.jackrabbit.guava.common.util.concurrent.ListeningExecutorService; +import org.apache.jackrabbit.oak.commons.internal.concurrent.DirectExecutor; import org.apache.jackrabbit.oak.commons.jmx.ManagementOperation.Status; import org.junit.After; import org.junit.Before; @@ -64,7 +64,7 @@ public class ManagementOperationTest { ManagementOperation<Integer> op = ManagementOperation.done("test", 42); assertTrue(op.isDone()); assertEquals(42, (int) op.get()); - directExecutor().execute(op); + DirectExecutor.INSTANCE.execute(op); } @Test