Search in sources :

Example 61 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class SignalFxEndpointMetricsHandlerTest method RollingWindowTimerBuilder_isInstance_works_as_expected.

@DataProvider(value = { "true   |   true", "false  |   false" }, splitBy = "\\|")
@Test
public void RollingWindowTimerBuilder_isInstance_works_as_expected(boolean useTimer, boolean expectedResult) {
    // given
    Metric metric = (useTimer) ? mock(Timer.class) : mock(Gauge.class);
    RollingWindowTimerBuilder rwtb = new RollingWindowTimerBuilder(42, TimeUnit.DAYS);
    // when
    boolean result = rwtb.isInstance(metric);
    // then
    assertThat(result).isEqualTo(expectedResult);
}
Also used : Timer(com.codahale.metrics.Timer) Metric(com.codahale.metrics.Metric) RollingWindowTimerBuilder(com.nike.riposte.metrics.codahale.impl.SignalFxEndpointMetricsHandler.RollingWindowTimerBuilder) Gauge(com.codahale.metrics.Gauge) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 62 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class RunnableWithTracingAndMdcSupportTest method run_handles_tracing_and_mdc_info_as_expected.

@DataProvider(value = { "true", "false" })
@Test
public void run_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
    // given
    throwExceptionDuringCall = throwException;
    Tracer.getInstance().startRequestWithRootSpan("foo");
    Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
    Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
    RunnableWithTracingAndMdcSupport instance = new RunnableWithTracingAndMdcSupport(runnableMock, spanStack, mdcInfo);
    resetTracingAndMdc();
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
    // when
    Throwable ex = catchThrowable(() -> instance.run());
    // then
    verify(runnableMock).run();
    if (throwException)
        assertThat(ex).isNotNull();
    else
        assertThat(ex).isNull();
    assertThat(currentSpanStackWhenRunnableWasCalled.get(0)).isEqualTo(spanStack);
    assertThat(currentMdcInfoWhenRunnableWasCalled.get(0)).isEqualTo(mdcInfo);
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 63 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class SupplierWithTracingAndMdcSupportTest method apply_handles_tracing_and_mdc_info_as_expected.

@DataProvider(value = { "true", "false" })
@Test
public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
    // given
    throwExceptionDuringCall = throwException;
    Tracer.getInstance().startRequestWithRootSpan("foo");
    Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
    Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
    SupplierWithTracingAndMdcSupport instance = new SupplierWithTracingAndMdcSupport(supplierMock, spanStack, mdcInfo);
    resetTracingAndMdc();
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
    // when
    Throwable ex = null;
    Object result = null;
    try {
        result = instance.get();
    } catch (Throwable t) {
        ex = t;
    }
    // then
    verify(supplierMock).get();
    if (throwException) {
        assertThat(ex).isNotNull();
        assertThat(result).isNull();
    } else {
        assertThat(ex).isNull();
        assertThat(result).isSameAs(outObj);
    }
    assertThat(currentSpanStackWhenSupplierWasCalled.get(0)).isEqualTo(spanStack);
    assertThat(currentMdcInfoWhenSupplierWasCalled.get(0)).isEqualTo(mdcInfo);
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 64 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class BiConsumerWithTracingAndMdcSupportTest method apply_handles_tracing_and_mdc_info_as_expected.

@DataProvider(value = { "true", "false" })
@Test
public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
    // given
    throwExceptionDuringCall = throwException;
    Tracer.getInstance().startRequestWithRootSpan("foo");
    Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
    Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
    BiConsumerWithTracingAndMdcSupport instance = new BiConsumerWithTracingAndMdcSupport(consumerMock, spanStack, mdcInfo);
    resetTracingAndMdc();
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
    // when
    Throwable ex = catchThrowable(() -> instance.accept(inObj1, inObj2));
    // then
    verify(consumerMock).accept(inObj1, inObj2);
    if (throwException) {
        assertThat(ex).isNotNull();
    } else {
        assertThat(ex).isNull();
    }
    assertThat(currentSpanStackWhenBiConsumerWasCalled.get(0)).isEqualTo(spanStack);
    assertThat(currentMdcInfoWhenBiConsumerWasCalled.get(0)).isEqualTo(mdcInfo);
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 65 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class BiFunctionWithTracingAndMdcSupportTest method apply_handles_tracing_and_mdc_info_as_expected.

@DataProvider(value = { "true", "false" })
@Test
public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
    // given
    throwExceptionDuringCall = throwException;
    Tracer.getInstance().startRequestWithRootSpan("foo");
    Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
    Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
    BiFunctionWithTracingAndMdcSupport instance = new BiFunctionWithTracingAndMdcSupport(biFunctionMock, spanStack, mdcInfo);
    resetTracingAndMdc();
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
    // when
    Throwable ex = null;
    Object result = null;
    try {
        result = instance.apply(inObj1, inObj2);
    } catch (Throwable t) {
        ex = t;
    }
    // then
    verify(biFunctionMock).apply(inObj1, inObj2);
    if (throwException) {
        assertThat(ex).isNotNull();
        assertThat(result).isNull();
    } else {
        assertThat(ex).isNull();
        assertThat(result).isSameAs(outObj);
    }
    assertThat(currentSpanStackWhenFunctionWasCalled.get(0)).isEqualTo(spanStack);
    assertThat(currentMdcInfoWhenFunctionWasCalled.get(0)).isEqualTo(mdcInfo);
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)88 Test (org.junit.Test)85 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)20 Span (com.nike.wingtips.Span)19 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)19 Matchers.anyString (org.mockito.Matchers.anyString)11 HttpMethod (io.netty.handler.codec.http.HttpMethod)9 Endpoint (com.nike.riposte.server.http.Endpoint)8 Timer (com.codahale.metrics.Timer)7 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 RequestInfo (com.nike.riposte.server.http.RequestInfo)5 Charset (java.nio.charset.Charset)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Meter (com.codahale.metrics.Meter)4 Response (com.ning.http.client.Response)4 ExtractableResponse (io.restassured.response.ExtractableResponse)4 Deque (java.util.Deque)4 Optional (java.util.Optional)4