@@ -0,0 +1,3206 @@
+package net.openhft.chronicle.queue;%0A%0Aimport net.openhft.chronicle.core.time.TimeProvider;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List;%0Aimport java.util.concurrent.atomic.AtomicLong;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0A%0A@RunWith(Parameterized.class)%0Apublic class RollCyclesTest %7B%0A    private static final long NO_EPOCH_OFFSET = 0L;%0A    private static final long SOME_EPOCH_OFFSET = 17L * 37L;%0A    private static final RollCycles%5B%5D TEST_DATA = new RollCycles%5B%5D %7B%0A            RollCycles.DAILY,%0A            RollCycles.HOURLY,%0A            RollCycles.MINUTELY,%0A            RollCycles.HUGE_DAILY%0A    %7D;%0A%0A    private final RollCycles cycle;%0A    private final AtomicLong clock = new AtomicLong();%0A    private final TimeProvider timeProvider = clock::get;%0A%0A    @Parameterized.Parameters(name = %22%7B0%7D%22)%0A    public static Collection%3CObject%5B%5D%3E data() %7B%0A        final List%3CObject%5B%5D%3E data = new ArrayList%3C%3E();%0A        for (RollCycles testDatum : TEST_DATA) %7B%0A            data.add(new Object%5B%5D %7BtestDatum.name(), testDatum%7D);%0A        %7D%0A        return data;%0A    %7D%0A%0A    public RollCyclesTest(final String cycleName, final RollCycles cycle) %7B%0A        this.cycle = cycle;%0A    %7D%0A%0A    @Test%0A    public void shouldDetermineCurrentCycle() throws Exception %7B%0A        assertCycleRollTimes(NO_EPOCH_OFFSET, withDelta(timeProvider, NO_EPOCH_OFFSET));%0A    %7D%0A%0A    @Test%0A    public void shouldTakeEpochIntoAccoutWhenCalculatingCurrentCycle() throws Exception %7B%0A        assertCycleRollTimes(SOME_EPOCH_OFFSET, withDelta(timeProvider, SOME_EPOCH_OFFSET));%0A    %7D%0A%0A    private void assertCycleRollTimes(final long epochOffset, final TimeProvider timeProvider) %7B%0A        final long currentTime = System.currentTimeMillis();%0A        final long currentTimeAtStartOfCycle = currentTime - (currentTime %25 cycle.length());%0A        clock.set(currentTimeAtStartOfCycle);%0A%0A        final int startCycle = cycle.current(timeProvider, epochOffset);%0A%0A        clock.addAndGet(cycle.length());%0A%0A        assertThat(cycle.current(timeProvider, epochOffset), is(startCycle + 1));%0A        assertThat(cycle.current(plusOneMillisecond(timeProvider), epochOffset), is(startCycle + 1));%0A        assertThat(cycle.current(minusOneMillisecond(timeProvider), epochOffset), is(startCycle));%0A%0A        clock.addAndGet(cycle.length());%0A%0A        assertThat(cycle.current(timeProvider, epochOffset), is(startCycle + 2));%0A        assertThat(cycle.current(plusOneMillisecond(timeProvider), epochOffset), is(startCycle + 2));%0A        assertThat(cycle.current(minusOneMillisecond(timeProvider), epochOffset), is(startCycle + 1));%0A    %7D%0A%0A    private static TimeProvider withDelta(final TimeProvider delegate, final long deltaMillis) %7B%0A        return () -%3E delegate.currentTimeMillis() + deltaMillis;%0A    %7D%0A%0A    private static TimeProvider plusOneMillisecond(final TimeProvider delegate) %7B%0A        return () -%3E delegate.currentTimeMillis() + 1;%0A    %7D%0A%0A    private static TimeProvider minusOneMillisecond(final TimeProvider delegate) %7B%0A        return () -%3E delegate.currentTimeMillis() - 1;%0A    %7D%0A%7D

test to assert current behaviour