@Test
public void shouldRotateNonIntegralPeriod() {
// start 5 minutes before full hour
final DateTime initialTime = new DateTime(2014, 1, 1, 1, 55, 0, 0, DateTimeZone.UTC);
final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
DateTimeUtils.setCurrentMillisProvider(clock);
final Period period = Period.minutes(10);
final TimeBasedRotationStrategy tenMinRotation = new TimeBasedRotationStrategy(period);
RotationStrategy.Result result;
result = tenMinRotation.shouldRotate("ignored");
assertTrue(result.shouldRotate(), "Should rotate the first index");
// advance time to 01:55:01
clock.tick(seconds(1));
result = tenMinRotation.shouldRotate("ignored");
assertFalse(result.shouldRotate(), "Did not cross rotation period");
// advance time to 02:00:00
clock.tick(minutes(4).withSeconds(59));
result = tenMinRotation.shouldRotate("ignored");
assertTrue(result.shouldRotate(), "Crossed rotation period");
// advance time multiple rotation periods into the future
// to time 02:51:00
clock.tick(minutes(51));
result = tenMinRotation.shouldRotate("ignored");
assertTrue(result.shouldRotate(), "Crossed multiple rotation periods");
// move time to 2:52:00
// this should not cycle again, because next valid rotation time is 3:00:00
clock.tick(minutes(1));
result = tenMinRotation.shouldRotate("ignored");
assertFalse(result.shouldRotate(), "Should not cycle when we missed multiple periods");
}