Skip to content

Commit

Permalink
fix failure UT
Browse files Browse the repository at this point in the history
Signed-off-by: zane-neo <[email protected]>
  • Loading branch information
zane-neo committed Jul 11, 2024
1 parent f775ee4 commit 33576c8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package org.opensearch.ml.breaker;

import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_THRESHOLD;

import java.io.File;
import java.security.AccessController;
Expand All @@ -27,8 +27,8 @@ public class DiskCircuitBreaker extends ThresholdCircuitBreaker<Integer> {
private final File diskDir;

public DiskCircuitBreaker(Settings settings, ClusterService clusterService, File diskDir) {
super(Optional.ofNullable(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE.get(settings)).orElse(DEFAULT_DISK_SHORTAGE_THRESHOLD));
clusterService.getClusterSettings().addSettingsUpdateConsumer(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE, super::setThreshold);
super(Optional.ofNullable(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.get(settings)).orElse(DEFAULT_DISK_SHORTAGE_THRESHOLD));
clusterService.getClusterSettings().addSettingsUpdateConsumer(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD, super::setThreshold);
this.diskDir = diskDir;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ public List<Setting<?>> getSettings() {
MLCommonsSettings.ML_COMMONS_MAX_DEPLOY_MODEL_TASKS_PER_NODE,
MLCommonsSettings.ML_COMMONS_TRUSTED_URL_REGEX,
MLCommonsSettings.ML_COMMONS_NATIVE_MEM_THRESHOLD,
MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE,
MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_THRESHOLD,
MLCommonsSettings.ML_COMMONS_JVM_HEAP_MEM_THRESHOLD,
MLCommonsSettings.ML_COMMONS_EXCLUDE_NODE_NAMES,
MLCommonsSettings.ML_COMMONS_ALLOW_CUSTOM_DEPLOYMENT_PLAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ private MLCommonsSettings() {}
public static final Setting<Integer> ML_COMMONS_JVM_HEAP_MEM_THRESHOLD = Setting
.intSetting("plugins.ml_commons.jvm_heap_memory_threshold", 85, 0, 100, Setting.Property.NodeScope, Setting.Property.Dynamic);

public static final Setting<Integer> ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE = Setting
public static final Setting<Integer> ML_COMMONS_DISK_FREE_SPACE_THRESHOLD = Setting
.intSetting(
"plugins.ml_commons.disk_free_space_min_value",
"plugins.ml_commons.disk_free_space_threshold",
5,
0,
Integer.MAX_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.opensearch.ml.breaker;

import static org.mockito.Mockito.when;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_THRESHOLD;

import java.io.File;
import java.util.HashSet;
Expand All @@ -34,13 +34,13 @@ public class DiskCircuitBreakerTests {
public void setup() {
MockitoAnnotations.openMocks(this);
when(clusterService.getClusterSettings())
.thenReturn(new ClusterSettings(Settings.EMPTY, new HashSet<>(List.of(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE))));
.thenReturn(new ClusterSettings(Settings.EMPTY, new HashSet<>(List.of(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD))));
}

@Test
public void test_isOpen_whenDiskFreeSpaceIsHigherThanMinValue_breakerIsNotOpen() {
CircuitBreaker breaker = new DiskCircuitBreaker(
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE.getKey(), 5).build(),
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), 5).build(),
clusterService,
file
);
Expand All @@ -51,7 +51,7 @@ public void test_isOpen_whenDiskFreeSpaceIsHigherThanMinValue_breakerIsNotOpen()
@Test
public void test_isOpen_whenDiskFreeSpaceIsLessThanMinValue_breakerIsOpen() {
CircuitBreaker breaker = new DiskCircuitBreaker(
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE.getKey(), 5).build(),
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), 5).build(),
clusterService,
file
);
Expand All @@ -62,7 +62,7 @@ public void test_isOpen_whenDiskFreeSpaceIsLessThanMinValue_breakerIsOpen() {
@Test
public void test_isOpen_whenDiskFreeSpaceConfiguredToZero_breakerIsNotOpen() {
CircuitBreaker breaker = new DiskCircuitBreaker(
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE.getKey(), 5).build(),
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), 5).build(),
clusterService,
file
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.opensearch.ml.breaker;

import static org.mockito.Mockito.when;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_THRESHOLD;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_JVM_HEAP_MEM_THRESHOLD;
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_NATIVE_MEM_THRESHOLD;

Expand Down Expand Up @@ -103,7 +104,9 @@ public void testInit() {
.build();
ClusterSettings clusterSettings = new ClusterSettings(
settings,
new HashSet<>(Arrays.asList(ML_COMMONS_NATIVE_MEM_THRESHOLD, ML_COMMONS_JVM_HEAP_MEM_THRESHOLD))
new HashSet<>(
Arrays.asList(ML_COMMONS_NATIVE_MEM_THRESHOLD, ML_COMMONS_JVM_HEAP_MEM_THRESHOLD, ML_COMMONS_DISK_FREE_SPACE_THRESHOLD)
)
);
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
mlCircuitBreakerService = new MLCircuitBreakerService(jvmService, osService, settings, clusterService);
Expand Down

0 comments on commit 33576c8

Please sign in to comment.