use of net.morimekta.providence.mio.rolling.TimeBasedCleanupPolicy in project providence by morimekta.
the class RollingFileMessageWriterTest method testTimeBasedRolling.
@Test
public void testTimeBasedRolling() throws IOException {
FakeClock clock = FakeClock.forCurrentTimeMillis(1234567890000L).withZone(ZoneId.of("Europe/Oslo"));
RollingFileMessageWriter writer = new RollingFileMessageWriter(tmp.getRoot(), new JsonSerializer().named(), "my-log.txt", new TimeBasedRollingPolicy(5, TimeUnit.MINUTES, "my-log-%d{yyyy-MM-dd_HH-mm}.txt", clock), new TimeBasedCleanupPolicy(15, TimeUnit.MINUTES, "my-log-%d{yyyy-MM-dd_HH-mm}.txt", clock));
writer.write(generator.generate(CompactFields.kDescriptor));
for (int i = 0; i < 10; ++i) {
clock.tick(107, TimeUnit.SECONDS);
writer.write(generator.generate(CompactFields.kDescriptor));
}
String[] files = tmp.getRoot().list();
assertThat(files, is(notNullValue()));
assertThat(ImmutableSortedSet.copyOf(files), is(ImmutableSortedSet.of("my-log.txt", "my-log-2009-02-13_22-35.txt", "my-log-2009-02-13_22-40.txt", "my-log-2009-02-13_22-45.txt")));
assertThat(Files.isSymbolicLink(tmp.getRoot().toPath().resolve("my-log.txt")), is(true));
assertThat(Files.readSymbolicLink(tmp.getRoot().toPath().resolve("my-log.txt")).toFile().getName(), is("my-log-2009-02-13_22-45.txt"));
for (int i = 0; i < 10; ++i) {
clock.tick(107, TimeUnit.SECONDS);
writer.write(generator.generate(CompactFields.kDescriptor));
}
files = tmp.getRoot().list();
assertThat(files, is(notNullValue()));
assertThat(ImmutableSortedSet.copyOf(files), is(ImmutableSortedSet.of("my-log.txt", "my-log-2009-02-13_22-55.txt", "my-log-2009-02-13_23-00.txt", "my-log-2009-02-13_23-05.txt")));
assertThat(Files.isSymbolicLink(tmp.getRoot().toPath().resolve("my-log.txt")), is(true));
assertThat(Files.readSymbolicLink(tmp.getRoot().toPath().resolve("my-log.txt")).toFile().getName(), is("my-log-2009-02-13_23-05.txt"));
writer = new RollingFileMessageWriter(tmp.getRoot(), new JsonSerializer().named(), "my-log.txt", new TimeBasedRollingPolicy(TimeUnit.HOURS, "my-log-%d{yyyy-MM-dd_HH-mm}.txt", clock));
writer.write(generator.generate(CompactFields.kDescriptor));
assertThat(Files.isSymbolicLink(tmp.getRoot().toPath().resolve("my-log.txt")), is(true));
assertThat(Files.readSymbolicLink(tmp.getRoot().toPath().resolve("my-log.txt")).toFile().getName(), is("my-log-2009-02-13_23-00.txt"));
}
Aggregations