@Test public void logsOnAcceptError() { IllegalStateException acceptException = new IllegalStateException("failed"); AsyncSpanConsumer consumer = mock(AsyncSpanConsumer.class); when(storage.asyncSpanConsumer()).thenReturn(consumer); doAnswer(answer(c -> { throw acceptException; })).when(consumer).accept(eq(TestObjects.TRACE), any(Callback.class)); storageConsumer.accept(TestObjects.TRACE); assertThat(logger.lines()).hasSize(1); assertThat(logger.lines().iterator().next().toString()) .startsWith("LogMessage(,WARN,Dropped 3 spans: failed"); }
@Override public final void accept(Iterable<Span> spansSharingId) { List<Span> list = asList(spansSharingId); if (list.isEmpty()) { log().debug("Input was empty"); return; } CallbackCaptor<Void> blockingCallback = new CallbackCaptor<>(); try { get().asyncSpanConsumer().accept(list, blockingCallback); blockingCallback.get(); log().debug("Wrote {} spans", list.size()); } catch (RuntimeException e) { Throwable toLog = e.getClass().equals(RuntimeException.class) && e.getCause() != null ? e.getCause() : e; String message = "Dropped " + list.size() + " spans: " + toLog.getMessage(); if (log().isWarnEnabled()) { log().warn(message, toLog); } else { log().warn(message); } } }
StorageConsumer implements Consumer, Component { @Override public final void accept(Iterable<Span> spansSharingId) { List<Span> list = asList(spansSharingId); if (list.isEmpty()) { log().debug("Input was empty"); return; } CallbackCaptor<Void> blockingCallback = new CallbackCaptor<>(); try { get().asyncSpanConsumer().accept(list, blockingCallback); blockingCallback.get(); log().debug("Wrote {} spans", list.size()); } catch (RuntimeException e) { Throwable toLog = e.getClass().equals(RuntimeException.class) && e.getCause() != null ? e.getCause() : e; String message = "Dropped " + list.size() + " spans: " + toLog.getMessage(); if (log().isWarnEnabled()) { log().warn(message, toLog); } else { log().warn(message); } } } }
StorageConsumer implements Consumer, Component { @Override public final void accept(Iterable<Span> spansSharingId) { List<Span> list = asList(spansSharingId); if (list.isEmpty()) { log().debug("Input was empty"); return; } CallbackCaptor<Void> blockingCallback = new CallbackCaptor<>(); try { get().asyncSpanConsumer().accept(list, blockingCallback); blockingCallback.get(); log().debug("Wrote {} spans", list.size()); } catch (RuntimeException e) { Throwable toLog = e.getClass().equals(RuntimeException.class) && e.getCause() != null ? e.getCause() : e; String message = "Dropped " + list.size() + " spans: " + toLog.getMessage(); if (log().isWarnEnabled()) { log().warn(message, toLog); } else { log().warn(message); } } }  }
StorageConsumer implements Consumer, Component { @Override public final void accept(Iterable<Span> spansSharingId) { List<Span> list = asList(spansSharingId); if (list.isEmpty()) { log().debug("Input was empty"); return; } CallbackCaptor<Void> blockingCallback = new CallbackCaptor<>(); try { get().asyncSpanConsumer().accept(list, blockingCallback); blockingCallback.get(); log().debug("Wrote {} spans", list.size()); } catch (RuntimeException e) { Throwable toLog = e.getClass().equals(RuntimeException.class) && e.getCause() != null ? e.getCause() : e; String message = "Dropped " + list.size() + " spans: " + toLog.getMessage(); if (log().isWarnEnabled()) { log().warn(message, toLog); } else { log().warn(message); } } }  @Override final void accept(Iterable<Span> spansSharingId); @Override CheckResult check(); @Override final void close(); }
StorageConsumer implements Consumer, Component { @Override public final void accept(Iterable<Span> spansSharingId) { List<Span> list = asList(spansSharingId); if (list.isEmpty()) { log().debug("Input was empty"); return; } CallbackCaptor<Void> blockingCallback = new CallbackCaptor<>(); try { get().asyncSpanConsumer().accept(list, blockingCallback); blockingCallback.get(); log().debug("Wrote {} spans", list.size()); } catch (RuntimeException e) { Throwable toLog = e.getClass().equals(RuntimeException.class) && e.getCause() != null ? e.getCause() : e; String message = "Dropped " + list.size() + " spans: " + toLog.getMessage(); if (log().isWarnEnabled()) { log().warn(message, toLog); } else { log().warn(message); } } }  @Override final void accept(Iterable<Span> spansSharingId); @Override CheckResult check(); @Override final void close();  }