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
Signed-off-by: zane-neo <zaniu@amazon.com>
- Loading branch information
Showing
9 changed files
with
97 additions
and
37 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
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
/* | ||
* | ||
* * Copyright OpenSearch Contributors | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.opensearch.ml.breaker; | ||
|
||
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 java.io.File; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE; | ||
|
||
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_MIN_VALUE)))); | ||
} | ||
|
||
@Test | ||
public void test_isOpen_whenDiskFreeSpaceIsHigherThanMinValue_breakerIsNotOpen() { | ||
CircuitBreaker breaker = new DiskCircuitBreaker(Settings.builder().put(ML_COMMONS_DISK_FREE_SPACE_MIN_VALUE.getKey(), 5).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_MIN_VALUE.getKey(), 5).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_MIN_VALUE.getKey(), 5).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