private synchronized void applyRetention() { long aggregateFileSize = 0; // compute when enabled if (retentionConfig.getAggregateFileSize() > 0) { for (Path path : retainedPaths) { File file = path.toFile(); aggregateFileSize += file.length(); // 0 if doesn't exist } } if (retentionConfig.evaluate(retainedPaths.size(), aggregateFileSize)) { Path oldestPath = retainedPaths.remove(0); File file = oldestPath.toFile(); trace.info("deleting file {}", file); file.delete(); } }
private static <T> void checkFileWriterConfig(FileWriterRetentionConfig cfg, int fileCnt, long aggSize, long ageSec, long periodMsec) { assertEquals(fileCnt, cfg.getFileCount()); assertEquals(aggSize, cfg.getAggregateFileSize()); assertEquals(ageSec, cfg.getAgeSec()); assertEquals(periodMsec, cfg.getPeriodMsec()); cfg.toString(); int falseFileCnt = fileCnt-1; int trueFileCnt = fileCnt+1; long falseAggSize = aggSize-1; long trueAggSize = aggSize+1; assertFalse("fileCnt:"+fileCnt+" aggSize:"+aggSize, cfg.evaluate(falseFileCnt, falseAggSize)); if (fileCnt!=0) assertTrue("fileCnt:"+fileCnt+" aggSize:"+aggSize, cfg.evaluate(trueFileCnt, falseAggSize)); if (aggSize!=0) assertTrue("fileCnt:"+fileCnt+" aggSize:"+aggSize, cfg.evaluate(falseFileCnt, trueAggSize)); }