use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class TracingInvocationEventHandlerTest method testSuccess.
@Test
public void testSuccess() {
InvocationContext context = handler.preInvocation(instance, method, args);
assertThat(Tracer.hasTraceId()).isTrue();
handler.onSuccess(context, null);
ArgumentCaptor<Span> spanCaptor = ArgumentCaptor.forClass(Span.class);
verify(mockSpanObserver, times(1)).consume(spanCaptor.capture());
Span span = spanCaptor.getValue();
assertThat(span.getDurationNanoSeconds()).isGreaterThan(0L);
assertThat(Tracer.hasTraceId()).isFalse();
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class TracingInvocationEventHandler method preInvocation.
@Override
public InvocationContext preInvocation(@Nonnull Object instance, @Nonnull Method method, @Nonnull Object[] args) {
InvocationContext context = DefaultInvocationContext.of(instance, method, args);
String operationName = getOperationName(method);
Tracer.fastStartSpan(operationName);
return context;
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class InstrumentationTest method testReturnNull_failure_compositeHandler.
@Test
@SuppressWarnings("unchecked")
void testReturnNull_failure_compositeHandler() {
InvocationEventHandler<InvocationContext> handler = Mockito.mock(InvocationEventHandler.class);
when(handler.isEnabled()).thenReturn(true);
when(handler.preInvocation(any(), any(), any())).thenReturn(null);
Runnable wrapped = Instrumentation.builder(Runnable.class, () -> {
throw new SafeRuntimeException("expected");
}).withHandler(handler).withTaggedMetrics(new DefaultTaggedMetricRegistry()).build();
assertThatCode(wrapped::run).isExactlyInstanceOf(SafeRuntimeException.class).hasMessage("expected");
verify(handler).isEnabled();
verify(handler).preInvocation(any(), any(), any());
verify(handler).onFailure(isNull(), any());
verifyNoMoreInteractions(handler);
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class InstrumentationTest method testThrowingHandler_success_composite.
@Test
@SuppressWarnings("unchecked")
void testThrowingHandler_success_composite() {
InvocationEventHandler<InvocationContext> handler = Mockito.mock(InvocationEventHandler.class);
when(handler.isEnabled()).thenReturn(true);
when(handler.preInvocation(any(), any(), any())).thenThrow(new RuntimeException());
Runnable wrapped = Instrumentation.builder(Runnable.class, Runnables.doNothing()).withHandler(handler).withTaggedMetrics(new DefaultTaggedMetricRegistry()).build();
assertThatCode(wrapped::run).doesNotThrowAnyException();
verify(handler).isEnabled();
verify(handler).preInvocation(any(), any(), any());
verify(handler).onSuccess(isNull(), any());
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class InstrumentationTest method testFilterMatches.
@Test
void testFilterMatches(@Mock InvocationEventHandler<InvocationContext> mockHandler) throws Exception {
TestInterface delegate = new TestImplementation();
TestInterface instrumented = Instrumentation.builder(TestInterface.class, delegate).withFilter(methodNameFilter("bulk")).withHandler(mockHandler).build();
InvocationContext mockContext = mock(InvocationContext.class);
when(mockHandler.isEnabled()).thenReturn(true);
when(mockHandler.preInvocation(any(), any(Method.class), any(Object[].class))).thenReturn(mockContext);
ImmutableSet<String> testSet = ImmutableSet.of("test");
instrumented.bulk(testSet);
verify(mockHandler).isEnabled();
verify(mockHandler).preInvocation(instrumented, TestInterface.class.getDeclaredMethod("bulk", Set.class), new Object[] { testSet });
verify(mockHandler).onSuccess(mockContext, null);
verifyNoMoreInteractions(mockHandler);
}
Aggregations