Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: panguixin <panguixin@bytedance.com>
  • Loading branch information
bugmakerrrrrr committed Jun 20, 2024
1 parent 9615cbc commit 3d6db0f
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions server/src/test/java/org/opensearch/monitor/fs/FsProbeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,16 @@ public void testFsCacheInfo() throws IOException {
public void testFsInfoWhenFileCacheOccupied() throws IOException {
Settings settings = Settings.builder().putList("node.roles", "search", "data").build();
try (NodeEnvironment env = newNodeEnvironment(settings)) {
final long usableSpace = adjustForHugeFilesystems(env.fileCacheNodePath().fileStore.getUsableSpace());
ByteSizeValue gbByteSizeValue = new ByteSizeValue(usableSpace - 10, ByteSizeUnit.BYTES);
// Use the total space as reserved space to simulate the situation where the cache space is occupied
final long totalSpace = adjustForHugeFilesystems(env.fileCacheNodePath().fileStore.getTotalSpace());
ByteSizeValue gbByteSizeValue = new ByteSizeValue(totalSpace, ByteSizeUnit.BYTES);
env.fileCacheNodePath().fileCacheReservedSize = gbByteSizeValue;
FileCache fileCache = FileCacheFactory.createConcurrentLRUFileCache(
gbByteSizeValue.getBytes(),
16,
new NoopCircuitBreaker(CircuitBreaker.REQUEST)
);

// write a temp file to occupy some file cache space
Path tempFile = createTempFile();
try (BufferedWriter bufferedWriter = Files.newBufferedWriter(tempFile, StandardOpenOption.APPEND)) {
bufferedWriter.write(randomAlphaOfLength(100));
bufferedWriter.flush();
}

FsProbe probe = new FsProbe(env, fileCache);
FsInfo stats = probe.stats(null);
assertNotNull(stats);
Expand All @@ -194,11 +188,6 @@ public void testFsInfoWhenFileCacheOccupied() throws IOException {
assertTrue(total.total > 0L);
assertTrue(total.free > 0L);
assertTrue(total.fileCacheReserved > 0L);
if (env.nodePaths().length > 1) {
assertTrue(total.available > 0L);
} else {
assertEquals(0L, total.available);
}

for (FsInfo.Path path : stats) {
assertNotNull(path);
Expand Down

0 comments on commit 3d6db0f

Please sign in to comment.