Search in sources :

Example 1 with TestInterface

use of com.palantir.tritium.test.TestInterface in project tritium by palantir.

the class InstrumentationTest method testEmptyHandlers.

@Test
void testEmptyHandlers() {
    TestInterface delegate = new TestImplementation();
    TestInterface instrumented = Instrumentation.wrap(TestInterface.class, delegate, Collections.emptyList(), InstrumentationFilters.INSTRUMENT_NONE);
    assertThat(instrumented).isEqualTo(delegate);
    assertThat(Proxy.isProxyClass(instrumented.getClass())).isFalse();
}
Also used : TestImplementation(com.palantir.tritium.test.TestImplementation) TestInterface(com.palantir.tritium.test.TestInterface) Test(org.junit.jupiter.api.Test)

Example 2 with TestInterface

use of com.palantir.tritium.test.TestInterface in project tritium by palantir.

the class InstrumentationTest method testFilterSkips.

@Test
void testFilterSkips(@Mock InvocationEventHandler<InvocationContext> mockHandler) {
    TestInterface delegate = new TestImplementation();
    TestInterface instrumented = Instrumentation.builder(TestInterface.class, delegate).withFilter(methodNameFilter("bulk")).withHandler(mockHandler).build();
    when(mockHandler.isEnabled()).thenReturn(true);
    instrumented.test();
    verify(mockHandler).isEnabled();
    verifyNoMoreInteractions(mockHandler);
}
Also used : TestImplementation(com.palantir.tritium.test.TestImplementation) TestInterface(com.palantir.tritium.test.TestInterface) Test(org.junit.jupiter.api.Test)

Example 3 with TestInterface

use of com.palantir.tritium.test.TestInterface in project tritium by palantir.

the class InstrumentationTest method testToString_delegateWithoutInstrumentation.

@Test
void testToString_delegateWithoutInstrumentation(@Mock InvocationEventHandler<InvocationContext> mockHandler) {
    TestInterface delegate = new TestImplementation();
    TestInterface instrumented = Instrumentation.builder(TestInterface.class, delegate).withHandler(mockHandler).build();
    assertThat(instrumented).asString().isEqualTo("com.palantir.tritium.test.TestImplementation");
    verifyNoMoreInteractions(mockHandler);
}
Also used : TestImplementation(com.palantir.tritium.test.TestImplementation) TestInterface(com.palantir.tritium.test.TestInterface) Test(org.junit.jupiter.api.Test)

Example 4 with TestInterface

use of com.palantir.tritium.test.TestInterface in project tritium by palantir.

the class InstrumentationTest method testEquals_sameInstance.

@Test
void testEquals_sameInstance() {
    TestInterface proxy = Instrumentation.builder(TestInterface.class, new TestImplementation()).withPerformanceTraceLogging().build();
    assertThat(proxy).isEqualTo(proxy);
}
Also used : TestImplementation(com.palantir.tritium.test.TestImplementation) TestInterface(com.palantir.tritium.test.TestInterface) Test(org.junit.jupiter.api.Test)

Example 5 with TestInterface

use of com.palantir.tritium.test.TestInterface 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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) TestImplementation(com.palantir.tritium.test.TestImplementation) TestInterface(com.palantir.tritium.test.TestInterface) Method(java.lang.reflect.Method) InvocationContext(com.palantir.tritium.event.InvocationContext) DefaultInvocationContext(com.palantir.tritium.event.DefaultInvocationContext) Test(org.junit.jupiter.api.Test)

Aggregations

TestImplementation (com.palantir.tritium.test.TestImplementation)17 TestInterface (com.palantir.tritium.test.TestInterface)17 Test (org.junit.jupiter.api.Test)16 Logger (org.slf4j.Logger)6 DefaultInvocationContext (com.palantir.tritium.event.DefaultInvocationContext)3 InvocationContext (com.palantir.tritium.event.InvocationContext)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Timer (com.codahale.metrics.Timer)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)2 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)2 Method (java.lang.reflect.Method)2 Set (java.util.Set)2 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 Metric (com.codahale.metrics.Metric)1 Slf4jReporter (com.codahale.metrics.Slf4jReporter)1 LoggingLevel (com.codahale.metrics.Slf4jReporter.LoggingLevel)1 Stopwatch (com.google.common.base.Stopwatch)1 Runnables (com.google.common.util.concurrent.Runnables)1 SafeRuntimeException (com.palantir.logsafe.exceptions.SafeRuntimeException)1