@Override public void run() { // if the ring buffer is full this waits until a slot becomes available // as this happens on a different thread, // the reporting does not block and thus there is no danger of deadlocks logger.debug("Request flush because the request timeout occurred"); flush = reporter.flush(); }
private void waitForFlush() { try { flush().get(); } catch (Exception e) { throw new RuntimeException(e); } }
@Test void testReportSpan() throws ExecutionException, InterruptedException { reporter.report(new Span(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }
@Test void testReportErrorCapture() throws ExecutionException, InterruptedException { reporter.report(new ErrorCapture(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }
@Test void testReportTransaction() throws ExecutionException, InterruptedException { reporter.report(new Transaction(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }
@Test void testTransactionProcessor() throws Exception { reporter.report(new Transaction(mock(ElasticApmTracer.class))); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); verify(reportingEventHandler).onEvent(notNull(ReportingEvent::getTransaction), anyLong(), anyBoolean()); }
@Test void testErrorProcessor() throws Exception { reporter.report(new ErrorCapture(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); verify(reportingEventHandler).onEvent(notNull(ReportingEvent::getError), anyLong(), anyBoolean()); }
@Test void testSecretToken() throws ExecutionException, InterruptedException { when(reporterConfiguration.getSecretToken()).thenReturn("token"); handler = exchange -> { assertThat(exchange.getRequestHeaders().get("Authorization").getFirst()).isEqualTo("Bearer token"); receivedHttpRequests.incrementAndGet(); exchange.setStatusCode(200).endExchange(); }; reporter.report(new Transaction(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }