/** same as {@code newConfig(0, aggregateFileSize, 0, 0)} * * @param aggregateFileSize remove a file when {@code aggregateFileSize} would be exceeded. 0 to disable. * @return the retention config */ public static FileWriterRetentionConfig newAggregateFileSizeBasedConfig(long aggregateFileSize) { if (aggregateFileSize < 1) throw new IllegalArgumentException("aggregateFileSize"); return newConfig(0, aggregateFileSize, 0, 0); } /** same as {@code newConfig(0, 0, ageSe, periodMsecc)}
/** same as {@code newConfig(fileCount, 0, 0, 0)} * * @param fileCount remove a file when {@code fileCount} would be exceeded. 0 to disable. * @return the retention config */ public static FileWriterRetentionConfig newFileCountBasedConfig(int fileCount) { if (fileCount < 1) throw new IllegalArgumentException("fileCount"); return newConfig(fileCount, 0, 0, 0); } /** same as {@code newConfig(0, aggregateFileSize, 0, 0)}
/** same as {@code newConfig(0, 0, ageSe, periodMsecc)} * * @param ageSec remove a file that's older than {@code ageSec} seconds. 0 to disable. * @param periodMsec frequency for checking for ageSec based removal. 0 to disable.] * @return the retention config */ public static FileWriterRetentionConfig newAgeBasedConfig(long ageSec, long periodMsec) { if (ageSec < 1) throw new IllegalArgumentException("ageSec"); if (periodMsec < 1) throw new IllegalArgumentException("periodMsec"); return newConfig(0, 0, ageSec, periodMsec); }
@Test public void testRetentionConfig() throws Exception { FileWriterRetentionConfig cfg; cfg = FileWriterRetentionConfig.newFileCountBasedConfig(2); checkFileWriterConfig(cfg, 2, 0, 0, 0); expectIAE(() -> FileWriterRetentionConfig.newFileCountBasedConfig(0)); cfg = FileWriterRetentionConfig.newAggregateFileSizeBasedConfig(3); checkFileWriterConfig(cfg, 0, 3, 0, 0); expectIAE(() -> FileWriterRetentionConfig.newAggregateFileSizeBasedConfig(0)); cfg = FileWriterRetentionConfig.newAgeBasedConfig(10,11); checkFileWriterConfig(cfg, 0, 0, 10, 11); expectIAE(() -> FileWriterRetentionConfig.newAgeBasedConfig(0,1)); expectIAE(() -> FileWriterRetentionConfig.newAgeBasedConfig(1,0)); cfg = FileWriterRetentionConfig.newConfig(1, 2, 3, 0); checkFileWriterConfig(cfg, 1, 2, 3, 0); expectIAE(() -> FileWriterRetentionConfig.newConfig(0, 0, 0, 0)); expectIAE(() -> FileWriterRetentionConfig.newConfig(0, 0, 1, 0)); expectIAE(() -> FileWriterRetentionConfig.newConfig(0, 0, 0, 1)); expectIAE(() -> FileWriterRetentionConfig.newConfig(-1, 0, 0, 0)); expectIAE(() -> FileWriterRetentionConfig.newConfig(0, -1, 0, 0)); expectIAE(() -> FileWriterRetentionConfig.newConfig(0, 0, -1, 0)); expectIAE(() -> FileWriterRetentionConfig.newConfig(0, 0, 0, -1)); }