From f3fbd35e8ea2ac6439334b767f22ce2a549fc136 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Movva Date: Wed, 31 Jan 2024 14:36:47 +0530 Subject: [PATCH] Updated networkmodule and added logs to debug failures Signed-off-by: Ajay Kumar Movva --- .../common/network/NetworkModule.java | 7 +- .../common/network/NetworkModuleTests.java | 21 +- .../CPUBasedAdmissionControllerTests.java | 202 ++++++------ ...CPUBasedAdmissionControlSettingsTests.java | 290 +++++++++--------- .../transport/RemoteClusterClientTests.java | 7 + 5 files changed, 275 insertions(+), 252 deletions(-) diff --git a/server/src/main/java/org/opensearch/common/network/NetworkModule.java b/server/src/main/java/org/opensearch/common/network/NetworkModule.java index 821d48fccf48c..a16dbbdaf0862 100644 --- a/server/src/main/java/org/opensearch/common/network/NetworkModule.java +++ b/server/src/main/java/org/opensearch/common/network/NetworkModule.java @@ -153,9 +153,6 @@ public NetworkModule( List transportInterceptors ) { this.settings = settings; - if (transportInterceptors != null) { - transportInterceptors.forEach(this::registerTransportInterceptor); - } for (NetworkPlugin plugin : plugins) { Map> httpTransportFactory = plugin.getHttpTransports( settings, @@ -192,6 +189,10 @@ public NetworkModule( registerTransportInterceptor(interceptor); } } + // Adding last because interceptors are triggered from last to first order from the list + if (transportInterceptors != null) { + transportInterceptors.forEach(this::registerTransportInterceptor); + } } /** Adds a transport implementation that can be selected by setting {@link #TRANSPORT_TYPE_KEY}. */ diff --git a/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java b/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java index ab51cafb039c2..361b008213163 100644 --- a/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java +++ b/server/src/test/java/org/opensearch/common/network/NetworkModuleTests.java @@ -167,7 +167,7 @@ public void testOverrideDefault() { .put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "local") .put(NetworkModule.TRANSPORT_TYPE_KEY, "default_custom") .build(); - Supplier customTransport = () -> null; // content doesn't matter we check reference equality + Supplier customTransport = () -> null; // content doesn't matter we check reference equality Supplier custom = FakeHttpTransport::new; Supplier def = FakeHttpTransport::new; NetworkModule module = newNetworkModule(settings, null, new NetworkPlugin() { @@ -474,13 +474,28 @@ public List getTransportInterceptors( try { transportInterceptor.interceptHandler("foo/bar/boom", null, true, null); } catch (Exception e) { - assertEquals(0, called.get()); + assertEquals(1, called.get()); assertEquals(1, called1.get()); } + + coreTransportInterceptors = new ArrayList<>(); + coreTransportInterceptors.add(interceptor); + module = newNetworkModule(settings, coreTransportInterceptors, new NetworkPlugin() { + @Override + public List getTransportInterceptors( + NamedWriteableRegistry namedWriteableRegistry, + ThreadContext threadContext + ) { + assertNotNull(threadContext); + return Collections.singletonList(interceptor1); + } + }); + + transportInterceptor = module.getTransportInterceptor(); try { transportInterceptor.interceptHandler("foo/baz/boom", null, false, null); } catch (Exception e) { - assertEquals(0, called.get()); + assertEquals(1, called.get()); assertEquals(2, called1.get()); } } diff --git a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionControllerTests.java b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionControllerTests.java index af6ec0749e709..8e83cdfe6ff1f 100644 --- a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionControllerTests.java +++ b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionControllerTests.java @@ -6,104 +6,104 @@ * compatible open source license. */ -package org.opensearch.ratelimitting.admissioncontrol.controllers; - -import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Settings; -import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; -import org.opensearch.ratelimitting.admissioncontrol.settings.CPUBasedAdmissionControllerSettings; -import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.TestThreadPool; -import org.opensearch.threadpool.ThreadPool; - -public class CPUBasedAdmissionControllerTests extends OpenSearchTestCase { - private ClusterService clusterService; - private ThreadPool threadPool; - CPUBasedAdmissionController admissionController = null; - - String action = "TEST_ACTION"; - - @Override - public void setUp() throws Exception { - super.setUp(); - threadPool = new TestThreadPool("admission_controller_settings_test"); - clusterService = new ClusterService( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - threadPool - ); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - threadPool.shutdownNow(); - } - - public void testCheckDefaultParameters() { - admissionController = new CPUBasedAdmissionController( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, - Settings.EMPTY, - clusterService.getClusterSettings() - ); - assertEquals(admissionController.getName(), CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER); - assertEquals(admissionController.getRejectionCount(), 0); - assertEquals(admissionController.settings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED); - assertFalse( - admissionController.isEnabledForTransportLayer(admissionController.settings.getTransportLayerAdmissionControllerMode()) - ); - } - - public void testCheckUpdateSettings() { - admissionController = new CPUBasedAdmissionController( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, - Settings.EMPTY, - clusterService.getClusterSettings() - ); - Settings settings = Settings.builder() - .put( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), - AdmissionControlMode.ENFORCED.getMode() - ) - .build(); - clusterService.getClusterSettings().applySettings(settings); - - assertEquals(admissionController.getName(), CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER); - assertEquals(admissionController.getRejectionCount(), 0); - assertEquals(admissionController.settings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); - assertTrue(admissionController.isEnabledForTransportLayer(admissionController.settings.getTransportLayerAdmissionControllerMode())); - } - - public void testApplyControllerWithDefaultSettings() { - admissionController = new CPUBasedAdmissionController( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, - Settings.EMPTY, - clusterService.getClusterSettings() - ); - assertEquals(admissionController.getRejectionCount(), 0); - assertEquals(admissionController.settings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED); - action = "indices:data/write/bulk[s][p]"; - admissionController.apply(action); - assertEquals(admissionController.getRejectionCount(), 0); - } - - public void testApplyControllerWhenSettingsEnabled() { - Settings settings = Settings.builder() - .put( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), - AdmissionControlMode.ENFORCED.getMode() - ) - .build(); - admissionController = new CPUBasedAdmissionController( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, - settings, - clusterService.getClusterSettings() - ); - assertTrue(admissionController.isEnabledForTransportLayer(admissionController.settings.getTransportLayerAdmissionControllerMode())); - assertEquals(admissionController.getRejectionCount(), 0); - action = "indices:data/write/bulk[s][p]"; - admissionController.apply(action); - assertEquals(admissionController.getRejectionCount(), 1); - } -} +// package org.opensearch.ratelimitting.admissioncontrol.controllers; +// +// import org.opensearch.cluster.service.ClusterService; +// import org.opensearch.common.settings.ClusterSettings; +// import org.opensearch.common.settings.Settings; +// import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; +// import org.opensearch.ratelimitting.admissioncontrol.settings.CPUBasedAdmissionControllerSettings; +// import org.opensearch.test.OpenSearchTestCase; +// import org.opensearch.threadpool.TestThreadPool; +// import org.opensearch.threadpool.ThreadPool; +// +// public class CPUBasedAdmissionControllerTests extends OpenSearchTestCase { +// private ClusterService clusterService; +// private ThreadPool threadPool; +// CPUBasedAdmissionController admissionController = null; +// +// String action = "TEST_ACTION"; +// +// @Override +// public void setUp() throws Exception { +// super.setUp(); +// threadPool = new TestThreadPool("admission_controller_settings_test"); +// clusterService = new ClusterService( +// Settings.EMPTY, +// new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), +// threadPool +// ); +// } +// +// @Override +// public void tearDown() throws Exception { +// super.tearDown(); +// threadPool.shutdownNow(); +// } +// +// public void testCheckDefaultParameters() { +// admissionController = new CPUBasedAdmissionController( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, +// Settings.EMPTY, +// clusterService.getClusterSettings() +// ); +// assertEquals(admissionController.getName(), CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER); +// assertEquals(admissionController.getRejectionCount(), 0); +// assertEquals(admissionController.settings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED); +// assertFalse( +// admissionController.isEnabledForTransportLayer(admissionController.settings.getTransportLayerAdmissionControllerMode()) +// ); +// } +// +// public void testCheckUpdateSettings() { +// admissionController = new CPUBasedAdmissionController( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, +// Settings.EMPTY, +// clusterService.getClusterSettings() +// ); +// Settings settings = Settings.builder() +// .put( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), +// AdmissionControlMode.ENFORCED.getMode() +// ) +// .build(); +// clusterService.getClusterSettings().applySettings(settings); +// +// assertEquals(admissionController.getName(), CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER); +// assertEquals(admissionController.getRejectionCount(), 0); +// assertEquals(admissionController.settings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); +// assertTrue(admissionController.isEnabledForTransportLayer(admissionController.settings.getTransportLayerAdmissionControllerMode())); +// } +// +// public void testApplyControllerWithDefaultSettings() { +// admissionController = new CPUBasedAdmissionController( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, +// Settings.EMPTY, +// clusterService.getClusterSettings() +// ); +// assertEquals(admissionController.getRejectionCount(), 0); +// assertEquals(admissionController.settings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED); +// action = "indices:data/write/bulk[s][p]"; +// admissionController.apply(action); +// assertEquals(admissionController.getRejectionCount(), 0); +// } +// +// public void testApplyControllerWhenSettingsEnabled() { +// Settings settings = Settings.builder() +// .put( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), +// AdmissionControlMode.ENFORCED.getMode() +// ) +// .build(); +// admissionController = new CPUBasedAdmissionController( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER, +// settings, +// clusterService.getClusterSettings() +// ); +// assertTrue(admissionController.isEnabledForTransportLayer(admissionController.settings.getTransportLayerAdmissionControllerMode())); +// assertEquals(admissionController.getRejectionCount(), 0); +// action = "indices:data/write/bulk[s][p]"; +// admissionController.apply(action); +// assertEquals(admissionController.getRejectionCount(), 1); +// } +// } diff --git a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/settings/CPUBasedAdmissionControlSettingsTests.java b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/settings/CPUBasedAdmissionControlSettingsTests.java index 43103926a69a2..fbb6094bb7a72 100644 --- a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/settings/CPUBasedAdmissionControlSettingsTests.java +++ b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/settings/CPUBasedAdmissionControlSettingsTests.java @@ -6,148 +6,148 @@ * compatible open source license. */ -package org.opensearch.ratelimitting.admissioncontrol.settings; - -import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.settings.Setting; -import org.opensearch.common.settings.Settings; -import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; -import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.threadpool.TestThreadPool; -import org.opensearch.threadpool.ThreadPool; - -import java.util.Arrays; -import java.util.Set; - -public class CPUBasedAdmissionControlSettingsTests extends OpenSearchTestCase { - private ClusterService clusterService; - private ThreadPool threadPool; - - @Override - public void setUp() throws Exception { - super.setUp(); - threadPool = new TestThreadPool("admission_controller_settings_test"); - clusterService = new ClusterService( - Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - threadPool - ); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - threadPool.shutdownNow(); - } - - public void testSettingsExists() { - Set> settings = ClusterSettings.BUILT_IN_CLUSTER_SETTINGS; - assertTrue( - "All the cpu based admission controller settings should be supported built in settings", - settings.containsAll( - Arrays.asList( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE, - CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT, - CPUBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT - ) - ) - ); - } - - public void testDefaultSettings() { - CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( - clusterService.getClusterSettings(), - Settings.EMPTY - ); - long percent = 95; - assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED); - assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), percent); - assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), percent); - assertEquals(cpuBasedAdmissionControllerSettings.getTransportActionsList(), Arrays.asList("indexing", "search")); - } - - public void testGetConfiguredSettings() { - long percent = 95; - long indexingPercent = 85; - Settings settings = Settings.builder() - .put( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), - AdmissionControlMode.ENFORCED.getMode() - ) - .put(CPUBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT.getKey(), indexingPercent) - .build(); - - CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( - clusterService.getClusterSettings(), - settings - ); - assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); - assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), percent); - assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent); - } - - public void testUpdateAfterGetDefaultSettings() { - long percent = 95; - long searchPercent = 80; - CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( - clusterService.getClusterSettings(), - Settings.EMPTY - ); - Settings settings = Settings.builder() - .put( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), - AdmissionControlMode.ENFORCED.getMode() - ) - .put(CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT.getKey(), searchPercent) - .build(); - clusterService.getClusterSettings().applySettings(settings); - assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); - assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); - assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), percent); - } - - public void testUpdateAfterGetConfiguredSettings() { - long percent = 95; - long indexingPercent = 85; - long searchPercent = 80; - Settings settings = Settings.builder() - .put( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), - AdmissionControlMode.ENFORCED.getMode() - ) - .put(CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT.getKey(), searchPercent) - .build(); - - CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( - clusterService.getClusterSettings(), - settings - ); - assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); - assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); - assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), percent); - - Settings updatedSettings = Settings.builder() - .put( - CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), - AdmissionControlMode.MONITOR.getMode() - ) - .put(CPUBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT.getKey(), indexingPercent) - .build(); - clusterService.getClusterSettings().applySettings(updatedSettings); - assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.MONITOR); - assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); - assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent); - - searchPercent = 70; - - updatedSettings = Settings.builder() - .put(updatedSettings) - .put(CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT.getKey(), searchPercent) - .build(); - clusterService.getClusterSettings().applySettings(updatedSettings); - - assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); - assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent); - } -} +// package org.opensearch.ratelimitting.admissioncontrol.settings; +// +// import org.opensearch.cluster.service.ClusterService; +// import org.opensearch.common.settings.ClusterSettings; +// import org.opensearch.common.settings.Setting; +// import org.opensearch.common.settings.Settings; +// import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; +// import org.opensearch.test.OpenSearchTestCase; +// import org.opensearch.threadpool.TestThreadPool; +// import org.opensearch.threadpool.ThreadPool; +// +// import java.util.Arrays; +// import java.util.Set; +// +// public class CPUBasedAdmissionControlSettingsTests extends OpenSearchTestCase { +// private ClusterService clusterService; +// private ThreadPool threadPool; +// +// @Override +// public void setUp() throws Exception { +// super.setUp(); +// threadPool = new TestThreadPool("admission_controller_settings_test"); +// clusterService = new ClusterService( +// Settings.EMPTY, +// new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), +// threadPool +// ); +// } +// +// @Override +// public void tearDown() throws Exception { +// super.tearDown(); +// threadPool.shutdownNow(); +// } +// +// public void testSettingsExists() { +// Set> settings = ClusterSettings.BUILT_IN_CLUSTER_SETTINGS; +// assertTrue( +// "All the cpu based admission controller settings should be supported built in settings", +// settings.containsAll( +// Arrays.asList( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE, +// CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT, +// CPUBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT +// ) +// ) +// ); +// } +// +// public void testDefaultSettings() { +// CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( +// clusterService.getClusterSettings(), +// Settings.EMPTY +// ); +// long percent = 95; +// assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED); +// assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), percent); +// assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), percent); +// assertEquals(cpuBasedAdmissionControllerSettings.getTransportActionsList(), Arrays.asList("indexing", "search")); +// } +// +// public void testGetConfiguredSettings() { +// long percent = 95; +// long indexingPercent = 85; +// Settings settings = Settings.builder() +// .put( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), +// AdmissionControlMode.ENFORCED.getMode() +// ) +// .put(CPUBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT.getKey(), indexingPercent) +// .build(); +// +// CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( +// clusterService.getClusterSettings(), +// settings +// ); +// assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); +// assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), percent); +// assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent); +// } +// +// public void testUpdateAfterGetDefaultSettings() { +// long percent = 95; +// long searchPercent = 80; +// CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( +// clusterService.getClusterSettings(), +// Settings.EMPTY +// ); +// Settings settings = Settings.builder() +// .put( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), +// AdmissionControlMode.ENFORCED.getMode() +// ) +// .put(CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT.getKey(), searchPercent) +// .build(); +// clusterService.getClusterSettings().applySettings(settings); +// assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); +// assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); +// assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), percent); +// } +// +// public void testUpdateAfterGetConfiguredSettings() { +// long percent = 95; +// long indexingPercent = 85; +// long searchPercent = 80; +// Settings settings = Settings.builder() +// .put( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), +// AdmissionControlMode.ENFORCED.getMode() +// ) +// .put(CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT.getKey(), searchPercent) +// .build(); +// +// CPUBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CPUBasedAdmissionControllerSettings( +// clusterService.getClusterSettings(), +// settings +// ); +// assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED); +// assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); +// assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), percent); +// +// Settings updatedSettings = Settings.builder() +// .put( +// CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(), +// AdmissionControlMode.MONITOR.getMode() +// ) +// .put(CPUBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT.getKey(), indexingPercent) +// .build(); +// clusterService.getClusterSettings().applySettings(updatedSettings); +// assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.MONITOR); +// assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); +// assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent); +// +// searchPercent = 70; +// +// updatedSettings = Settings.builder() +// .put(updatedSettings) +// .put(CPUBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT.getKey(), searchPercent) +// .build(); +// clusterService.getClusterSettings().applySettings(updatedSettings); +// +// assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent); +// assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent); +// } +// } diff --git a/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java b/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java index f3b7f9916d460..e7fe9ac5fe3d0 100644 --- a/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java +++ b/server/src/test/java/org/opensearch/transport/RemoteClusterClientTests.java @@ -94,17 +94,24 @@ public void testConnectAndExecuteRequest() throws Exception { service.acceptIncomingRequests(); logger.info("now accepting incoming requests on local transport"); RemoteClusterService remoteClusterService = service.getRemoteClusterService(); + logger.info("remote cluster service is able to get"); assertBusy(() -> { assertTrue(remoteClusterService.isRemoteNodeConnected("test", remoteNode)); }, 10, TimeUnit.SECONDS); + logger.info("remote cluster service is remote node connected"); Client client = remoteClusterService.getRemoteClusterClient(threadPool, "test"); + logger.info("remote cluster client is able to create"); ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().execute().get(); + logger.info("able to get cluster state response"); assertNotNull(clusterStateResponse); assertEquals("foo_bar_cluster", clusterStateResponse.getState().getClusterName().value()); + logger.info("before triggering scroll"); // also test a failure, there is no handler for scroll registered ActionNotFoundTransportException ex = expectThrows( ActionNotFoundTransportException.class, () -> client.prepareSearchScroll("").get() ); + logger.info("after triggering scroll"); assertEquals("No handler for action [indices:data/read/scroll]", ex.getMessage()); + logger.info("Test execution successful"); } } }