Skip to content

Commit

Permalink
Renamed controller name and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ajay Kumar Movva <[email protected]>
  • Loading branch information
Ajay Kumar Movva committed Feb 1, 2024
1 parent 68199a1 commit 434fb1c
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 0 additions & 17 deletions server/src/test/java/org/opensearch/index/remote/DummyTests.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void testAdmissionControllerSettings() {
AdmissionControlSettings admissionControlSettings = admissionControlService.admissionControlSettings;
List<AdmissionController> admissionControllerList = admissionControlService.getAdmissionControllers();
assertEquals(admissionControllerList.size(), 1);
CPUBasedAdmissionController cpuBasedAdmissionController = (CPUBasedAdmissionController) admissionControlService
CpuBasedAdmissionController cpuBasedAdmissionController = (CpuBasedAdmissionController) admissionControlService
.getAdmissionController(CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER);
assertEquals(
admissionControlSettings.isTransportLayerAdmissionControlEnabled(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
// }
}

0 comments on commit 434fb1c

Please sign in to comment.