diff --git a/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlService.java b/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlService.java index 2cc409b0e4465..9dc23802c4e9f 100644 --- a/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlService.java +++ b/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlService.java @@ -13,7 +13,7 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.ratelimitting.admissioncontrol.controllers.AdmissionController; -import org.opensearch.ratelimitting.admissioncontrol.controllers.CPUBasedAdmissionController; +import org.opensearch.ratelimitting.admissioncontrol.controllers.CpuBasedAdmissionController; import org.opensearch.threadpool.ThreadPool; import java.util.ArrayList; @@ -79,7 +79,7 @@ public void registerAdmissionController(String admissionControllerName) { private AdmissionController controllerFactory(String admissionControllerName) { switch (admissionControllerName) { case CPU_BASED_ADMISSION_CONTROLLER: - return new CPUBasedAdmissionController(admissionControllerName, this.settings, this.clusterSettings); + return new CpuBasedAdmissionController(admissionControllerName, this.settings, this.clusterSettings); default: throw new IllegalArgumentException("Not Supported AdmissionController : " + admissionControllerName); } diff --git a/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionController.java b/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CpuBasedAdmissionController.java similarity index 89% rename from server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionController.java rename to server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CpuBasedAdmissionController.java index 3a8956b2cce87..5503e7f777bc5 100644 --- a/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionController.java +++ b/server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CpuBasedAdmissionController.java @@ -20,15 +20,15 @@ * Class for CPU Based Admission Controller in OpenSearch, which aims to provide CPU utilisation admission control. * It provides methods to apply admission control if configured limit has been reached */ -public class CPUBasedAdmissionController extends AdmissionController { - private static final Logger LOGGER = LogManager.getLogger(CPUBasedAdmissionController.class); +public class CpuBasedAdmissionController extends AdmissionController { + private static final Logger LOGGER = LogManager.getLogger(CpuBasedAdmissionController.class); public CPUBasedAdmissionControllerSettings settings; /** * * @param admissionControllerName State of the admission controller */ - public CPUBasedAdmissionController(String admissionControllerName, Settings settings, ClusterSettings clusterSettings) { + public CpuBasedAdmissionController(String admissionControllerName, Settings settings, ClusterSettings clusterSettings) { super(new AtomicLong(0), admissionControllerName); this.settings = new CPUBasedAdmissionControllerSettings(clusterSettings, settings); } diff --git a/server/src/test/java/org/opensearch/index/remote/DummyTests.java b/server/src/test/java/org/opensearch/index/remote/DummyTests.java deleted file mode 100644 index cecd34322838e..0000000000000 --- a/server/src/test/java/org/opensearch/index/remote/DummyTests.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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.index.remote; - -import org.opensearch.test.OpenSearchTestCase; - -public class DummyTests extends OpenSearchTestCase { - public void testDummyCase() { - assert true; - } -} diff --git a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlServiceTests.java b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlServiceTests.java index bac4eaf3fd677..baab08ad25e9f 100644 --- a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlServiceTests.java +++ b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlServiceTests.java @@ -12,7 +12,7 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.ratelimitting.admissioncontrol.controllers.AdmissionController; -import org.opensearch.ratelimitting.admissioncontrol.controllers.CPUBasedAdmissionController; +import org.opensearch.ratelimitting.admissioncontrol.controllers.CpuBasedAdmissionController; import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; import org.opensearch.ratelimitting.admissioncontrol.settings.CPUBasedAdmissionControllerSettings; import org.opensearch.test.OpenSearchTestCase; @@ -66,7 +66,7 @@ public void testAdmissionControllerSettings() { AdmissionControlSettings admissionControlSettings = admissionControlService.admissionControlSettings; List admissionControllerList = admissionControlService.getAdmissionControllers(); assertEquals(admissionControllerList.size(), 1); - CPUBasedAdmissionController cpuBasedAdmissionController = (CPUBasedAdmissionController) admissionControlService + CpuBasedAdmissionController cpuBasedAdmissionController = (CpuBasedAdmissionController) admissionControlService .getAdmissionController(CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER); assertEquals( admissionControlSettings.isTransportLayerAdmissionControlEnabled(), 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 deleted file mode 100644 index 5101be8e14a11..0000000000000 --- a/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CPUBasedAdmissionControllerTests.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.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/controllers/CpuBasedAdmissionControllerTests.java b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CpuBasedAdmissionControllerTests.java new file mode 100644 index 0000000000000..ba1bc60ef9f78 --- /dev/null +++ b/server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CpuBasedAdmissionControllerTests.java @@ -0,0 +1,109 @@ +/* + * 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.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); + // } +}