From e764207fc14aaf0e2cce786db8f4e234df54f2d0 Mon Sep 17 00:00:00 2001 From: panguixin Date: Fri, 15 Dec 2023 20:00:28 +0800 Subject: [PATCH] fix test Signed-off-by: panguixin --- .../org/opensearch/monitor/fs/FsProbeTests.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/server/src/test/java/org/opensearch/monitor/fs/FsProbeTests.java b/server/src/test/java/org/opensearch/monitor/fs/FsProbeTests.java index 26e5f60e9c91e..95664f63c3c90 100644 --- a/server/src/test/java/org/opensearch/monitor/fs/FsProbeTests.java +++ b/server/src/test/java/org/opensearch/monitor/fs/FsProbeTests.java @@ -169,8 +169,9 @@ 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(), @@ -178,13 +179,6 @@ public void testFsInfoWhenFileCacheOccupied() throws IOException { 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); @@ -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);