/** * Read all the errors in a log since the creation of the log. * * @param buffer containing the {@link DistinctErrorLog}. * @param consumer to be called for each exception encountered. * @return the number of entries that has been read. */ public static int read(final AtomicBuffer buffer, final ErrorConsumer consumer) { return read(buffer, consumer, 0); }
public static int saveErrorLog(final PrintStream out, final AtomicBuffer errorBuffer) { final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) -> out.format( "***%n%d observations from %s to %s for:%n %s%n", count, dateFormat.format(new Date(firstTimestamp)), dateFormat.format(new Date(lastTimestamp)), ex); final int distinctErrorCount = ErrorLogReader.read(errorBuffer, errorConsumer); out.format("%n%d distinct errors observed.%n", distinctErrorCount); return distinctErrorCount; }
public static void main(final String[] args) { final File cncFile = CommonContext.newDefaultCncFile(); System.out.println("Command `n Control file " + cncFile); final MappedByteBuffer cncByteBuffer = IoUtil.mapExistingFile(cncFile, "cnc"); final DirectBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer); final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0)); if (CNC_VERSION != cncVersion) { throw new IllegalStateException( "Aeron CnC version does not match: version=" + cncVersion + " required=" + CNC_VERSION); } final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer); final int distinctErrorCount = ErrorLogReader.read(buffer, ErrorStat::accept); System.out.format("%n%d distinct errors observed.%n", distinctErrorCount); }
@Test public void shouldReadNoExceptionsFromEmptyLog() { final ErrorConsumer consumer = mock(ErrorConsumer.class); assertThat(ErrorLogReader.read(buffer, consumer), is(0)); verifyZeroInteractions(consumer); }
@Test public void shouldReadFirstObservation() { final ErrorConsumer consumer = mock(ErrorConsumer.class); final long timestamp = 7; final RuntimeException error = new RuntimeException("Test Error"); when(clock.time()).thenReturn(timestamp); log.record(error); assertThat(ErrorLogReader.read(buffer, consumer), is(1)); verify(consumer).accept(eq(1), eq(timestamp), eq(timestamp), any(String.class)); }
formatError(out, dateFormat, count, firstTimestamp, lastTimestamp, ex); distinctErrorCount = ErrorLogReader.read(buffer, errorConsumer);
@Test public void shouldReadTwoDistinctObservations() { final ErrorConsumer consumer = mock(ErrorConsumer.class); final long timestampOne = 7; final long timestampTwo = 10; final RuntimeException errorOne = new RuntimeException("Test Error One"); final IllegalStateException errorTwo = new IllegalStateException("Test Error Two"); when(clock.time()).thenReturn(timestampOne).thenReturn(timestampTwo); log.record(errorOne); log.record(errorTwo); assertThat(ErrorLogReader.read(buffer, consumer), is(2)); final InOrder inOrder = inOrder(consumer); inOrder.verify(consumer).accept(eq(1), eq(timestampOne), eq(timestampOne), any(String.class)); inOrder.verify(consumer).accept(eq(1), eq(timestampTwo), eq(timestampTwo), any(String.class)); }
@Test public void shouldReadSummarisedObservation() { final ErrorConsumer consumer = mock(ErrorConsumer.class); final long timestampOne = 7; final long timestampTwo = 10; final RuntimeException error = new RuntimeException("Test Error"); final StringWriter stringWriter = new StringWriter(); error.printStackTrace(new PrintWriter(stringWriter)); final String errorAsString = stringWriter.toString(); when(clock.time()).thenReturn(timestampOne).thenReturn(timestampTwo); log.record(error); log.record(error); assertThat(ErrorLogReader.read(buffer, consumer), is(1)); verify(consumer).accept(eq(2), eq(timestampOne), eq(timestampTwo), eq(errorAsString)); }
@Test public void shouldReadOneObservationSinceTimestamp() { final ErrorConsumer consumer = mock(ErrorConsumer.class); final long timestampOne = 7; final long timestampTwo = 10; final RuntimeException errorOne = new RuntimeException("Test Error One"); final IllegalStateException errorTwo = new IllegalStateException("Test Error Two"); when(clock.time()).thenReturn(timestampOne).thenReturn(timestampTwo); assertFalse(ErrorLogReader.hasErrors(buffer)); log.record(errorOne); log.record(errorTwo); assertTrue(ErrorLogReader.hasErrors(buffer)); assertThat(ErrorLogReader.read(buffer, consumer, timestampTwo), is(1)); verify(consumer).accept(eq(1), eq(timestampTwo), eq(timestampTwo), any(String.class)); verifyNoMoreInteractions(consumer); } }
/** * Read all the errors in a log since the creation of the log. * * @param buffer containing the {@link DistinctErrorLog}. * @param consumer to be called for each exception encountered. * @return the number of entries that has been read. */ public static int read(final AtomicBuffer buffer, final ErrorConsumer consumer) { return read(buffer, consumer, 0); }
/** * Read all the errors in a log since the creation of the log. * * @param buffer containing the {@link DistinctErrorLog}. * @param consumer to be called for each exception encountered. * @return the number of entries that has been read. */ public static int read(final AtomicBuffer buffer, final ErrorConsumer consumer) { return read(buffer, consumer, 0); }
public int doWork() { final long timeInMs = System.currentTimeMillis(); if (timeInMs > lastSeenErrorTimeInMs) { final int errors = ErrorLogReader.read(errorBuffer, errorConsumer, lastSeenErrorTimeInMs); if (errors > 0) { lastSeenErrorTimeInMs = timeInMs; } return errors; } return 0; }
public static int saveErrorLog(final PrintStream out, final AtomicBuffer errorBuffer) { final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) -> out.format( "***%n%d observations from %s to %s for:%n %s%n", count, dateFormat.format(new Date(firstTimestamp)), dateFormat.format(new Date(lastTimestamp)), ex); final int distinctErrorCount = ErrorLogReader.read(errorBuffer, errorConsumer); out.format("%n%d distinct errors observed.%n", distinctErrorCount); return distinctErrorCount; }
public long logErrors(LoggingAdapter log, long sinceTimestamp) { // using AtomicLong because access from lambda, not because of concurrency final AtomicLong lastTimestamp = new AtomicLong(sinceTimestamp); ErrorLogReader.read( buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> { log.error( String.format( "Aeron error: %d observations from %s to %s for:%n %s", observationCount, Helpers.timestamp(firstObservationTimestamp), Helpers.timestamp(lastObservationTimestamp), encodedException)); lastTimestamp.set(Math.max(lastTimestamp.get(), lastObservationTimestamp)); }, sinceTimestamp); return lastTimestamp.get(); }
public long logErrors(LoggingAdapter log, long sinceTimestamp) { // using AtomicLong because access from lambda, not because of concurrency final AtomicLong lastTimestamp = new AtomicLong(sinceTimestamp); ErrorLogReader.read( buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> { log.error( String.format( "Aeron error: %d observations from %s to %s for:%n %s", observationCount, Helpers.timestamp(firstObservationTimestamp), Helpers.timestamp(lastObservationTimestamp), encodedException)); lastTimestamp.set(Math.max(lastTimestamp.get(), lastObservationTimestamp)); }, sinceTimestamp); return lastTimestamp.get(); }
public long logErrors(LoggingAdapter log, long sinceTimestamp) { // using AtomicLong because access from lambda, not because of concurrency final AtomicLong lastTimestamp = new AtomicLong(sinceTimestamp); ErrorLogReader.read( buffer, (observationCount, firstObservationTimestamp, lastObservationTimestamp, encodedException) -> { log.error( String.format( "Aeron error: %d observations from %s to %s for:%n %s", observationCount, Helpers.timestamp(firstObservationTimestamp), Helpers.timestamp(lastObservationTimestamp), encodedException)); lastTimestamp.set(Math.max(lastTimestamp.get(), lastObservationTimestamp)); }, sinceTimestamp); return lastTimestamp.get(); }
formatError(out, dateFormat, count, firstTimestamp, lastTimestamp, ex); distinctErrorCount = ErrorLogReader.read(buffer, errorConsumer);
formatError(out, dateFormat, count, firstTimestamp, lastTimestamp, ex); distinctErrorCount = ErrorLogReader.read(buffer, errorConsumer);