Search in sources :

Example 66 with DataProvider

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

the class ConsumerWithTracingAndMdcSupportTest 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();
    ConsumerWithTracingAndMdcSupport instance = new ConsumerWithTracingAndMdcSupport(consumerMock, spanStack, mdcInfo);
    resetTracingAndMdc();
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
    assertThat(MDC.getCopyOfContextMap()).isEmpty();
    // when
    Throwable ex = catchThrowable(() -> instance.accept(inObj));
    // then
    verify(consumerMock).accept(inObj);
    if (throwException) {
        assertThat(ex).isNotNull();
    } else {
        assertThat(ex).isNull();
    }
    assertThat(currentSpanStackWhenConsumerWasCalled.get(0)).isEqualTo(spanStack);
    assertThat(currentMdcInfoWhenConsumerWasCalled.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 67 with DataProvider

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

the class SignalFxEndpointMetricsHandlerTest method kitchen_sink_constructor_fails_with_IllegalArgumentException_if_certain_args_are_null.

@DataProvider(value = { "true   |   false   |   false   |   signalFxReporterMetricMetadata cannot be null", "false  |   true    |   false   |   metricRegistry cannot be null", "false  |   false   |   true    |   requestTimerBuilder cannot be null" }, splitBy = "\\|")
@Test
public void kitchen_sink_constructor_fails_with_IllegalArgumentException_if_certain_args_are_null(boolean metadataIsNull, boolean registryIsNull, boolean timerBuilderIsNull, String expectedMessage) {
    // given
    MetricMetadata metricMetadata = (metadataIsNull) ? null : metricMetadataMock;
    MetricRegistry registry = (registryIsNull) ? null : metricRegistryMock;
    MetricBuilder<Timer> timerBuilder = (timerBuilderIsNull) ? null : requestTimerBuilderMock;
    // when
    Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(metricMetadata, registry, timerBuilder, null));
    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage(expectedMessage);
}
Also used : MetricMetadata(com.signalfx.codahale.reporter.MetricMetadata) Timer(com.codahale.metrics.Timer) MetricRegistry(com.codahale.metrics.MetricRegistry) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 68 with DataProvider

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

the class StreamingAsyncHttpClientTest method StreamingChannel_doCloseChannelDueToUnrecoverableError_works_as_expected.

@DataProvider(value = { "true", "false" })
@Test
public void StreamingChannel_doCloseChannelDueToUnrecoverableError_works_as_expected(boolean callActive) {
    // given
    streamingChannelSpy.callActiveHolder.heldObject = callActive;
    Throwable unrecoverableError = new RuntimeException("kaboom");
    // when
    streamingChannelSpy.doCloseChannelDueToUnrecoverableError(unrecoverableError);
    // then
    if (callActive) {
        verify(channelIsBrokenAttrMock).set(true);
        verifyChannelReleasedBackToPool(streamingChannelSpy.callActiveHolder, channelPoolMock, channelMock);
        verify(channelMock).close();
    } else {
        verify(channelIsBrokenAttrMock, never()).set(anyBoolean());
        verify(channelMock, never()).close();
    }
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 69 with DataProvider

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

the class StreamingAsyncHttpClientTest method StreamingChannel_closeChannelDueToUnrecoverableError_sets_field_to_true_but_otherwise_does_nothing_if_already_closed_or_call_inactive.

@DataProvider(value = { "true   |   true", "false  |   false", "true   |   false" }, splitBy = "\\|")
@Test
public void StreamingChannel_closeChannelDueToUnrecoverableError_sets_field_to_true_but_otherwise_does_nothing_if_already_closed_or_call_inactive(boolean alreadyClosed, boolean callActive) {
    // given
    Throwable unrecoverableError = new RuntimeException("kaboom");
    streamingChannelSpy.channelClosedDueToUnrecoverableError = alreadyClosed;
    streamingChannelSpy.callActiveHolder.heldObject = callActive;
    // when
    streamingChannelSpy.closeChannelDueToUnrecoverableError(unrecoverableError);
    // then
    assertThat(streamingChannelSpy.channelClosedDueToUnrecoverableError).isTrue();
    verifyZeroInteractions(channelMock);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 70 with DataProvider

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

the class StreamingAsyncHttpClientTest method StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_does_not_match_requirements.

@DataProvider(value = { "false  |   0", "true   |   42" }, splitBy = "\\|")
@Test
public void StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_does_not_match_requirements(boolean chunkIsLastChunk, int readableBytes) {
    // given
    streamingChannelSpy.downstreamLastChunkSentHolder.heldObject = true;
    streamingChannelSpy.callActiveHolder.heldObject = true;
    streamingChannelSpy.channelClosedDueToUnrecoverableError = false;
    HttpContent contentChunkMock = (chunkIsLastChunk) ? mock(LastHttpContent.class) : mock(HttpContent.class);
    ByteBuf contentByteBufMock = mock(ByteBuf.class);
    doReturn(contentByteBufMock).when(contentChunkMock).content();
    doReturn(readableBytes).when(contentByteBufMock).readableBytes();
    doReturn(writeAndFlushChannelFutureMock).when(channelMock).writeAndFlush(contentChunkMock);
    // when
    ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock);
    // then
    verify(channelMock).writeAndFlush(contentChunkMock);
    assertThat(result).isSameAs(writeAndFlushChannelFutureMock);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) 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