コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }
コード例 #3
0
  @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());
    }
  }