|
58 | 58 | import java.util.function.Function;
|
59 | 59 | import java.util.function.Supplier;
|
60 | 60 |
|
| 61 | +import static org.opensearch.monitor.fs.FsProbe.adjustForHugeFilesystems; |
61 | 62 | import static org.hamcrest.CoreMatchers.equalTo;
|
62 | 63 | import static org.hamcrest.Matchers.emptyOrNullString;
|
63 | 64 | import static org.hamcrest.Matchers.greaterThan;
|
@@ -162,6 +163,46 @@ public void testFsCacheInfo() throws IOException {
|
162 | 163 | }
|
163 | 164 | }
|
164 | 165 |
|
| 166 | + public void testFsInfoWhenFileCacheOccupied() throws IOException { |
| 167 | + Settings settings = Settings.builder().putList("node.roles", "search", "data").build(); |
| 168 | + try (NodeEnvironment env = newNodeEnvironment(settings)) { |
| 169 | + // Use the total space as reserved space to simulate the situation where the cache space is occupied |
| 170 | + final long totalSpace = adjustForHugeFilesystems(env.fileCacheNodePath().fileStore.getTotalSpace()); |
| 171 | + ByteSizeValue gbByteSizeValue = new ByteSizeValue(totalSpace, ByteSizeUnit.BYTES); |
| 172 | + env.fileCacheNodePath().fileCacheReservedSize = gbByteSizeValue; |
| 173 | + FileCache fileCache = FileCacheFactory.createConcurrentLRUFileCache( |
| 174 | + gbByteSizeValue.getBytes(), |
| 175 | + 16, |
| 176 | + new NoopCircuitBreaker(CircuitBreaker.REQUEST) |
| 177 | + ); |
| 178 | + |
| 179 | + FsProbe probe = new FsProbe(env, fileCache); |
| 180 | + FsInfo stats = probe.stats(null); |
| 181 | + assertNotNull(stats); |
| 182 | + assertTrue(stats.getTimestamp() > 0L); |
| 183 | + FsInfo.Path total = stats.getTotal(); |
| 184 | + assertNotNull(total); |
| 185 | + assertTrue(total.total > 0L); |
| 186 | + assertTrue(total.free > 0L); |
| 187 | + assertTrue(total.fileCacheReserved > 0L); |
| 188 | + |
| 189 | + for (FsInfo.Path path : stats) { |
| 190 | + assertNotNull(path); |
| 191 | + assertFalse(path.getPath().isEmpty()); |
| 192 | + assertFalse(path.getMount().isEmpty()); |
| 193 | + assertFalse(path.getType().isEmpty()); |
| 194 | + assertTrue(path.total > 0L); |
| 195 | + assertTrue(path.free > 0L); |
| 196 | + |
| 197 | + if (path.fileCacheReserved > 0L) { |
| 198 | + assertEquals(0L, path.available); |
| 199 | + } else { |
| 200 | + assertTrue(path.available > 0L); |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | + |
165 | 206 | public void testFsInfoOverflow() throws Exception {
|
166 | 207 | final FsInfo.Path pathStats = new FsInfo.Path(
|
167 | 208 | "/foo/bar",
|
|
0 commit comments