use of io.jaegertracing.internal.senders.InMemorySender in project jaeger-client-java by jaegertracing.
the class RemoteReporterTest method testFlushIsCalledOnSender.
@Test
public void testFlushIsCalledOnSender() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
InMemorySender sender = new InMemorySender() {
@Override
public int flush() throws SenderException {
latch.countDown();
return super.flush();
}
};
RemoteReporter remoteReporter = new Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(remoteReporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
tracer.buildSpan("mySpan").start().finish();
remoteReporter.flush();
latch.await();
assertEquals("Should have called the custom sender flush", 0, latch.getCount());
assertEquals("mySpan", (sender.getReceived().get(0)).getOperationName());
}
use of io.jaegertracing.internal.senders.InMemorySender in project jaeger-client-java by jaegertracing.
the class RemoteReporterTest method testUpdateErrorMetricWhenCommandExecuteFails.
@Test
public void testUpdateErrorMetricWhenCommandExecuteFails() throws Exception {
int reporterFailures = 5;
sender = new InMemorySender() {
@Override
public int append(JaegerSpan span) throws SenderException {
throw new SenderException("", reporterFailures);
}
};
RemoteReporter reporter = new Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
reporter.report(newSpan());
reporter.close();
assertEquals(reporterFailures, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=err"));
}
use of io.jaegertracing.internal.senders.InMemorySender in project jaeger-client-java by jaegertracing.
the class RemoteReporterTest method setUp.
@Before
public void setUp() {
metricsFactory = new InMemoryMetricsFactory();
metrics = new Metrics(metricsFactory);
sender = new InMemorySender();
reporter = new RemoteReporter.Builder().withSender(sender).withFlushInterval(flushInterval).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(reporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
}
use of io.jaegertracing.internal.senders.InMemorySender in project jaeger-client-java by jaegertracing.
the class RemoteReporterTest method testFlushErrorsLoggedJustOnce.
@Test
public void testFlushErrorsLoggedJustOnce() throws InterruptedException {
Object logMonitor = new Object();
AtomicReference<String> logMsg = new AtomicReference<>(null);
mockLogger(e -> {
synchronized (logMonitor) {
logMsg.set(e.getFormattedMessage());
logMonitor.notifyAll();
}
});
class FailingSender extends InMemorySender {
private final AtomicInteger flushCounter = new AtomicInteger(0);
@Override
public int flush() throws SenderException {
int i = super.flush();
switch(flushCounter.getAndIncrement()) {
case 1:
case 2:
case 3:
throw new SenderException("test1", i);
default:
return i;
}
}
private String awaitMessage(AtomicReference<String> ref) throws InterruptedException {
synchronized (logMonitor) {
while (ref.get() == null) {
logMonitor.wait();
}
return ref.getAndSet(null);
}
}
}
FailingSender sender = new FailingSender();
RemoteReporter remoteReporter = new Builder().withSender(sender).withFlushInterval(Integer.MAX_VALUE).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(remoteReporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
assertEquals(0, sender.flushCounter.get());
tracer.buildSpan("mySpan").start().finish();
remoteReporter.flush();
// 1. SenderException is thrown (log should be produced)
await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 1);
tracer.buildSpan("mySpan").start().finish();
remoteReporter.flush();
assertEquals("FlushCommand execution failed! Repeated errors of this command will not be logged.", sender.awaitMessage(logMsg));
// 2. SenderException is thrown (log should not be produced)
await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 2);
remoteReporter.flush();
// 3. SenderException is thrown (log should not be produced)
await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 3);
remoteReporter.flush();
// No SenderException is thrown now, but 0 span is ready -> still stay in failing state
await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.flushCounter.get() == 4);
remoteReporter.flush();
// No SenderException is thrown now, but 1 span is ready -> move to working state
tracer.buildSpan("mySpan").start().finish();
remoteReporter.flush();
assertEquals("FlushCommand is working again!", sender.awaitMessage(logMsg));
await().with().pollInterval(1, TimeUnit.MILLISECONDS).until(() -> sender.getFlushed().size() == 3);
}
use of io.jaegertracing.internal.senders.InMemorySender in project jaeger-client-java by jaegertracing.
the class RemoteReporterTest method testUpdateSuccessMetricWhenAppendFlushed.
@Test
public void testUpdateSuccessMetricWhenAppendFlushed() throws InterruptedException {
int totalSpans = 3;
int flushSize = 2;
CountDownLatch latch = new CountDownLatch(1);
sender = new InMemorySender() {
@Override
public int append(JaegerSpan span) {
try {
super.append(span);
if (getAppended().size() >= flushSize) {
return flush();
}
if (getReceived().size() == totalSpans) {
latch.countDown();
}
return 0;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
reporter = new Builder().withSender(sender).withFlushInterval(Integer.MAX_VALUE).withMaxQueueSize(maxQueueSize).withMetrics(metrics).build();
tracer = new JaegerTracer.Builder("test-remote-reporter").withReporter(reporter).withSampler(new ConstSampler(true)).withMetrics(metrics).build();
for (int i = 0; i < totalSpans; i++) {
reporter.report(newSpan());
}
latch.await(1, TimeUnit.SECONDS);
assertEquals(flushSize, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=ok"));
assertEquals(0, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=err"));
assertEquals(0, metricsFactory.getCounter("jaeger_tracer_reporter_spans", "result=dropped"));
}
Aggregations