use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class InstrumentationTest method testEquals_separateInstanceWithSameArgs.
@Test
void testEquals_separateInstanceWithSameArgs() {
TestImplementation delegate = new TestImplementation();
InvocationEventHandler<InvocationContext> handler = TracingInvocationEventHandler.create("test");
TestInterface proxy0 = Instrumentation.builder(TestInterface.class, delegate).withHandler(handler).build();
TestInterface proxy1 = Instrumentation.builder(TestInterface.class, delegate).withHandler(handler).build();
assertThat(proxy0).isNotEqualTo(proxy1);
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class InstrumentationTest method testThrowingHandler_success_single.
@Test
@SuppressWarnings("unchecked")
void testThrowingHandler_success_single() {
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).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 testThrowingHandler_failure_composite.
@Test
@SuppressWarnings("unchecked")
void testThrowingHandler_failure_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, () -> {
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());
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class InvocationEventProxyTest method testInstrumentOnSuccessThrows.
@Test
@SuppressWarnings("checkstyle:illegalthrows")
public void testInstrumentOnSuccessThrows() throws Throwable {
InvocationEventHandler<InvocationContext> testHandler = new SimpleHandler() {
@Override
public void onSuccess(@Nullable InvocationContext _context, @Nullable Object _result) {
throw new IllegalStateException("expected");
}
};
InvocationEventProxy proxy = createTestProxy(testHandler);
Object result = proxy.invoke(this, getStringLengthMethod(), EMPTY_ARGS);
assertThat(result).isEqualTo("test".length());
InvocationContext context = DefaultInvocationContext.of(this, getStringLengthMethod(), null);
proxy.handleOnSuccess(context, result);
}
use of com.palantir.tritium.event.InvocationContext in project tritium by palantir.
the class MetricsInvocationEventHandlerTest method testFailure.
@Test
// SortedMap is part of Metrics API
@SuppressWarnings("JdkObsolete")
void testFailure() throws Exception {
MetricRegistry metricRegistry = new MetricRegistry();
MetricsInvocationEventHandler handler = new MetricsInvocationEventHandler(metricRegistry, "test");
InvocationContext context = mock(InvocationContext.class);
when(context.getMethod()).thenReturn(String.class.getDeclaredMethod("length"));
assertThat(metricRegistry.getMeters()).doesNotContainKey("failures");
handler.onFailure(context, new RuntimeException("unexpected"));
assertThat(metricRegistry.getMeters()).containsKey("failures");
assertThat(metricRegistry.getMeters().get("failures").getCount()).isOne();
}
Aggregations