From cc815d4e7620022c7849a1ea1787f11e3b250c9d Mon Sep 17 00:00:00 2001 From: Shivansh Arora Date: Tue, 3 Sep 2024 20:04:25 +0530 Subject: [PATCH 1/2] Release latch listeners in case of no-op RoutingTableService Signed-off-by: Shivansh Arora --- .../routing/remote/NoopRemoteRoutingTableService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableService.java b/server/src/main/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableService.java index 17687199c39d6..4eb641bf3a0d7 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableService.java +++ b/server/src/main/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableService.java @@ -43,7 +43,7 @@ public void getAsyncIndexRoutingWriteAction( IndexRoutingTable indexRouting, LatchedActionListener latchedActionListener ) { - // noop + latchedActionListener.onResponse(null); } @Override @@ -54,7 +54,7 @@ public void getAsyncIndexRoutingDiffWriteAction( StringKeyDiffProvider routingTableDiff, LatchedActionListener latchedActionListener ) { - // noop + latchedActionListener.onResponse(null); } @Override @@ -73,7 +73,7 @@ public void getAsyncIndexRoutingReadAction( String uploadedFilename, LatchedActionListener latchedActionListener ) { - // noop + latchedActionListener.onResponse(null); } @Override @@ -82,7 +82,7 @@ public void getAsyncIndexRoutingTableDiffReadAction( String uploadedFilename, LatchedActionListener> latchedActionListener ) { - // noop + latchedActionListener.onResponse(null); } @Override From 937e34f7b82e6987f3922bf09c05f627e67dfe27 Mon Sep 17 00:00:00 2001 From: Shivansh Arora Date: Thu, 5 Sep 2024 23:57:05 +0530 Subject: [PATCH 2/2] Add UT Signed-off-by: Shivansh Arora --- .../NoopRemoteRoutingTableServiceTests.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 server/src/test/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableServiceTests.java diff --git a/server/src/test/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableServiceTests.java b/server/src/test/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableServiceTests.java new file mode 100644 index 0000000000000..dbabb872bd0c7 --- /dev/null +++ b/server/src/test/java/org/opensearch/cluster/routing/remote/NoopRemoteRoutingTableServiceTests.java @@ -0,0 +1,66 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.cluster.routing.remote; + +import org.opensearch.action.LatchedActionListener; +import org.opensearch.cluster.Diff; +import org.opensearch.cluster.routing.IndexRoutingTable; +import org.opensearch.cluster.routing.RoutingTable; +import org.opensearch.common.util.TestCapturingListener; +import org.opensearch.gateway.remote.ClusterMetadataManifest; +import org.opensearch.test.OpenSearchTestCase; +import org.junit.Before; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +public class NoopRemoteRoutingTableServiceTests extends OpenSearchTestCase { + private NoopRemoteRoutingTableService service; + + @Before + public void setup() { + service = new NoopRemoteRoutingTableService(); + } + + public void testGetAsyncIndexRoutingWriteAction() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + TestCapturingListener capturingListener = new TestCapturingListener<>(); + LatchedActionListener listener = new LatchedActionListener<>(capturingListener, latch); + service.getAsyncIndexRoutingWriteAction("clusterUUID", 1, 1, null, listener); + latch.await(100, TimeUnit.MILLISECONDS); + assertNull(capturingListener.getResult()); + } + + public void testGetAsyncIndexRoutingReadAction() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + TestCapturingListener capturingListener = new TestCapturingListener<>(); + LatchedActionListener listener = new LatchedActionListener<>(capturingListener, latch); + service.getAsyncIndexRoutingReadAction("clusterUUID", "filename", listener); + latch.await(100, TimeUnit.MILLISECONDS); + assertNull(capturingListener.getResult()); + } + + public void testGetAsyncIndexRoutingDiffWriteAction() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + TestCapturingListener capturingListener = new TestCapturingListener<>(); + LatchedActionListener listener = new LatchedActionListener<>(capturingListener, latch); + service.getAsyncIndexRoutingDiffWriteAction("clusterUUID", 1, 1, null, listener); + latch.await(100, TimeUnit.MILLISECONDS); + assertNull(capturingListener.getResult()); + } + + public void testGetAsyncIndexRoutingDiffReadAction() throws InterruptedException { + CountDownLatch latch = new CountDownLatch(1); + TestCapturingListener> capturingListener = new TestCapturingListener<>(); + LatchedActionListener> listener = new LatchedActionListener<>(capturingListener, latch); + service.getAsyncIndexRoutingTableDiffReadAction("clusterUUID", "filename", listener); + latch.await(100, TimeUnit.MILLISECONDS); + assertNull(capturingListener.getResult()); + } +}