@Test public void shouldReturnReturnWhenTimeIsBeforeTheLowerLimit() throws IOException { // given final TransactionTimespanThreshold threshold = new TransactionTimespanThreshold(new FrozenClock(1000l), TimeUnit.MILLISECONDS, 100); when(source.getFirstStartRecordTimestamp(version)).thenReturn(800l); // when threshold.init(); final boolean result = threshold.reached(file, version, source); // then assertTrue(result); }
@Test public void shouldReturnTrueIfTheLogHasAnOlderVersion() throws IOException { // given final TransactionTimespanThreshold threshold = new TransactionTimespanThreshold(new FrozenClock(1000l), TimeUnit.MILLISECONDS, 100); when(source.getFirstStartRecordTimestamp(version)) .thenThrow(new IllegalLogFormatException(version, 3)); // when threshold.init(); final boolean result = threshold.reached(file, version, source); // then assertTrue(result); }
@Test public void shouldThrowIfTheLogHasANewerVersion() throws IOException { // given final TransactionTimespanThreshold threshold = new TransactionTimespanThreshold(new FrozenClock(1000l), TimeUnit.MILLISECONDS, 100); final IllegalLogFormatException ex = new IllegalLogFormatException(version, 5); when(source.getFirstStartRecordTimestamp(version)).thenThrow(ex); // when threshold.init(); try { threshold.reached(file, version, source); fail("should have thrown"); } catch (RuntimeException e) { // then assertEquals(ex, e.getCause()); } }