forked from opensearch-project/ml-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change disk circuit breaker to cluster settings (opensearch-project#2634
) * change disk circuit breaker to cluster settings Signed-off-by: zane-neo <[email protected]> * Fix IT failure Signed-off-by: zane-neo <[email protected]> * format code Signed-off-by: zane-neo <[email protected]> * fix failure UT Signed-off-by: zane-neo <[email protected]> * fix failure IT Signed-off-by: zane-neo <[email protected]> * Address comments Signed-off-by: zane-neo <[email protected]> --------- Signed-off-by: zane-neo <[email protected]>
- Loading branch information
Showing
10 changed files
with
138 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
plugin/src/test/java/org/opensearch/ml/breaker/DiskCircuitBreakerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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 java.io.File; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.core.common.unit.ByteSizeUnit; | ||
import org.opensearch.core.common.unit.ByteSizeValue; | ||
|
||
public class DiskCircuitBreakerTests { | ||
@Mock | ||
ClusterService clusterService; | ||
|
||
@Mock | ||
File file; | ||
|
||
@Before | ||
public void setup() { | ||
MockitoAnnotations.openMocks(this); | ||
when(clusterService.getClusterSettings()) | ||
.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_THRESHOLD.getKey(), new ByteSizeValue(4L, ByteSizeUnit.GB)).build(), | ||
clusterService, | ||
file | ||
); | ||
when(file.getFreeSpace()).thenReturn(5 * 1024 * 1024 * 1024L); | ||
Assert.assertFalse(breaker.isOpen()); | ||
} | ||
|
||
@Test | ||
public void test_isOpen_whenDiskFreeSpaceIsLessThanMinValue_breakerIsOpen() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker( | ||
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), new ByteSizeValue(5L, ByteSizeUnit.GB)).build(), | ||
clusterService, | ||
file | ||
); | ||
when(file.getFreeSpace()).thenReturn(4 * 1024 * 1024 * 1024L); | ||
Assert.assertTrue(breaker.isOpen()); | ||
} | ||
|
||
@Test | ||
public void test_isOpen_whenDiskFreeSpaceConfiguredToZero_breakerIsNotOpen() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker( | ||
Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_THRESHOLD.getKey(), new ByteSizeValue(0L, ByteSizeUnit.KB)).build(), | ||
clusterService, | ||
file | ||
); | ||
when(file.getFreeSpace()).thenReturn((long) (Math.random() * 1024 * 1024 * 1024 * 1024L)); | ||
Assert.assertFalse(breaker.isOpen()); | ||
} | ||
|
||
@Test | ||
public void test_getName() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker(Settings.EMPTY, clusterService, file); | ||
Assert.assertEquals("Disk Circuit Breaker", breaker.getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters