@Test public void ensureObeysLineLimit() throws IOException, ParseException { when(reader.readLine()) .thenReturn("Not a matching line") .thenReturn("2009-01-01 Part of new startup") .thenReturn(START_MARKER) .thenReturn("Not a matching line") .thenReturn("2008-01-01 Last line of old shutdown") .thenReturn(null); lastShutdownTimeService = new LastShutdownTimeServiceImpl(logManager, true); Optional<Date> result = lastShutdownTimeService.findShutdownTimeInLog(reader, START_MARKER, pattern, 4, GROUP_NAME, dateFormat); assertThat(result.isPresent(), equalTo(false)); verify(reader, times(4)).readLine(); }
@VisibleForTesting Optional<Date> findShutdownTimeInLog(final ReversedLinesFileReader logReader, final String startIndicator, final Pattern timestampPattern, final int lineScanLimit, final String groupName, final DateFormat dateFormat) throws IOException, ParseException { int linesRead = advanceReaderToShutdownLine(logReader, startIndicator, lineScanLimit); return findTimeFromPreviousInstance(logReader, timestampPattern, lineScanLimit - linesRead, groupName, dateFormat); }
LastShutdownTimeServiceImpl extends ComponentSupport implements LastShutdownTimeService { @VisibleForTesting Optional<Date> findShutdownTimeInLog(final ReversedLinesFileReader logReader, final String startIndicator, final Pattern timestampPattern, final int lineScanLimit, final String groupName, final DateFormat dateFormat) throws IOException, ParseException { int linesRead = advanceReaderToShutdownLine(logReader, startIndicator, lineScanLimit); return findTimeFromPreviousInstance(logReader, timestampPattern, lineScanLimit - linesRead, groupName, dateFormat); } }
LastShutdownTimeServiceImpl extends ComponentSupport implements LastShutdownTimeService { @VisibleForTesting Optional<Date> findShutdownTimeInLog(final ReversedLinesFileReader logReader, final String startIndicator, final Pattern timestampPattern, final int lineScanLimit, final String groupName, final DateFormat dateFormat) throws IOException, ParseException { int linesRead = advanceReaderToShutdownLine(logReader, startIndicator, lineScanLimit); return findTimeFromPreviousInstance(logReader, timestampPattern, lineScanLimit - linesRead, groupName, dateFormat); } @Inject  LastShutdownTimeServiceImpl(final LogManager logManager,
                                     @Named("${nexus.log.lastShutdownTime.enabled:-true}") final boolean enabled); }
LastShutdownTimeServiceImpl extends ComponentSupport implements LastShutdownTimeService { @VisibleForTesting Optional<Date> findShutdownTimeInLog(final ReversedLinesFileReader logReader, final String startIndicator, final Pattern timestampPattern, final int lineScanLimit, final String groupName, final DateFormat dateFormat) throws IOException, ParseException { int linesRead = advanceReaderToShutdownLine(logReader, startIndicator, lineScanLimit); return findTimeFromPreviousInstance(logReader, timestampPattern, lineScanLimit - linesRead, groupName, dateFormat); } @Inject  LastShutdownTimeServiceImpl(final LogManager logManager,
                                     @Named("${nexus.log.lastShutdownTime.enabled:-true}") final boolean enabled); @Override synchronized Optional<Date> estimateLastShutdownTime(); }
LastShutdownTimeServiceImpl extends ComponentSupport implements LastShutdownTimeService { @VisibleForTesting Optional<Date> findShutdownTimeInLog(final ReversedLinesFileReader logReader, final String startIndicator, final Pattern timestampPattern, final int lineScanLimit, final String groupName, final DateFormat dateFormat) throws IOException, ParseException { int linesRead = advanceReaderToShutdownLine(logReader, startIndicator, lineScanLimit); return findTimeFromPreviousInstance(logReader, timestampPattern, lineScanLimit - linesRead, groupName, dateFormat); } @Inject  LastShutdownTimeServiceImpl(final LogManager logManager,
                                     @Named("${nexus.log.lastShutdownTime.enabled:-true}") final boolean enabled); @Override synchronized Optional<Date> estimateLastShutdownTime();  }