Search in sources :

Example 36 with DataProvider

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

the class ChannelPipelineFinalizerHandlerTest method doChannelInactive_completes_releases_resources_and_completes_tracing_if_necessary.

@DataProvider(value = { "true   |   true", "false  |   true", "true   |   false", "false  |   false" }, splitBy = "\\|")
@Test
public void doChannelInactive_completes_releases_resources_and_completes_tracing_if_necessary(boolean tracingAlreadyDone, boolean responseSendingCompleted) throws Exception {
    // given
    Span span = setupTracingForChannelInactive(tracingAlreadyDone);
    doReturn(responseSendingCompleted).when(responseInfoMock).isResponseSendingLastChunkSent();
    if (responseSendingCompleted) {
        state.setResponseWriterFinalChunkChannelFuture(mock(ChannelFuture.class));
    }
    // when
    PipelineContinuationBehavior result = handler.doChannelInactive(ctxMock);
    // then
    Assertions.assertThat(span.isCompleted()).isEqualTo(!tracingAlreadyDone);
    Assertions.assertThat(state.isTraceCompletedOrScheduled()).isTrue();
    verify(requestInfoMock).releaseAllResources();
    verify(proxyRouterStateMock).setStreamingFailed();
    verify(proxyRouterStateMock).triggerStreamingChannelErrorForChunks(any(Throwable.class));
    Assertions.assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Span(com.nike.wingtips.Span) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 37 with DataProvider

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

the class OpenChannelLimitHandlerTest method doChannelActive_marks_and_schedules_double_check_timeout_if_too_many_open_channels.

@DataProvider(value = { "0", "1" })
@Test
public void doChannelActive_marks_and_schedules_double_check_timeout_if_too_many_open_channels(int numOpenChannelsGreaterThanMax) throws Exception {
    // given
    int actualOpenChannels = maxOpenChannelsThreshold + numOpenChannelsGreaterThanMax;
    setActualOpenChannels(actualOpenChannels);
    // when
    PipelineContinuationBehavior result = handler.doChannelActive(ctxMock);
    // then
    assertThat(result).isEqualTo(CONTINUE);
    Pair<Runnable, GenericFutureListener> futureInfoPair = extractDoubleCheckRunnableAndCloseFutureListener();
    verify(tooManyOpenConnectionsAttributeMock).set(actualOpenChannels);
    verifyDoubleCheckFuture(futureInfoPair.getLeft());
    verifyCloseFutureListener(futureInfoPair.getRight());
    verify(channelGroupMock, never()).add(channelMock);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 38 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project jaeger-client-java by jaegertracing.

the class ThriftSpanConverterTest method dataProviderTracerTags.

@DataProvider
public static Object[][] dataProviderTracerTags() {
    Tracer tracer = new Tracer.Builder("x", null, null).build();
    Map<String, String> rootTags = new HashMap<>();
    rootTags.put("tracer.jaeger.version", tracer.getVersion());
    rootTags.put("tracer.hostname", ANY);
    rootTags.put("tracer.tag.str", "y");
    rootTags.put("tracer.tag.bool", "true");
    rootTags.put("tracer.tag.num", "1");
    rootTags.put("sampler.type", "const");
    rootTags.put("sampler.param", "true");
    Map<String, String> childTags = new HashMap<>();
    childTags.put("tracer.jaeger.version", UNDEF);
    childTags.put("tracer.hostname", UNDEF);
    childTags.put("tracer.tag.str", UNDEF);
    childTags.put("tracer.tag.bool", UNDEF);
    childTags.put("tracer.tag.num", UNDEF);
    childTags.put("sampler.type", UNDEF);
    childTags.put("sampler.param", UNDEF);
    Map<String, String> rpcTags = new HashMap<>();
    rpcTags.put("tracer.jaeger.version", tracer.getVersion());
    rpcTags.put("tracer.hostname", ANY);
    rpcTags.put("tracer.tag.str", "y");
    rpcTags.put("tracer.tag.bool", "true");
    rpcTags.put("tracer.tag.num", "1");
    rpcTags.put("sampler.type", UNDEF);
    rpcTags.put("sampler.param", UNDEF);
    return new Object[][] { { SpanType.ROOT, rootTags }, { SpanType.CHILD, childTags }, { SpanType.RPC_SERVER, rpcTags } };
}
Also used : HashMap(java.util.HashMap) Tracer(com.uber.jaeger.Tracer) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 39 with DataProvider

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

the class OpenChannelLimitHandlerTest method doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels.

@DataProvider(value = { "null   |   false", "-1     |   false", "0      |   true", "1      |   true" }, splitBy = "\\|")
@Test
public void doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels(Integer numOpenChannelsDiffFromMaxThreshold, boolean expectTooManyOpenChannelsException) {
    // given
    Integer numOpenChannels = (numOpenChannelsDiffFromMaxThreshold == null) ? null : maxOpenChannelsThreshold + numOpenChannelsDiffFromMaxThreshold;
    doReturn(numOpenChannels).when(tooManyOpenConnectionsAttributeMock).get();
    // when
    Throwable ex = null;
    PipelineContinuationBehavior result = null;
    try {
        result = handler.doChannelRead(ctxMock, msg);
    } catch (Throwable t) {
        ex = t;
    }
    // then
    if (expectTooManyOpenChannelsException) {
        assertThat(ex).isInstanceOf(TooManyOpenChannelsException.class);
    } else {
        assertThat(ex).isNull();
        assertThat(result).isEqualTo(CONTINUE);
    }
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 40 with DataProvider

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

the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_short_circuiting_filters_when_they_do_not_short_circuit.

@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_short_circuiting_filters_when_they_do_not_short_circuit(boolean isFirstChunk) {
    // given
    HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
    filtersList.forEach(filter -> doReturn(true).when(filter).isShortCircuitRequestFilter());
    RequestInfo<?> firstFilterResult = mock(RequestInfo.class);
    RequestInfo<?> secondFilterResult = mock(RequestInfo.class);
    // Do a mix of empty Optional vs null for the response to hit branch coverage (both indicate no short circuiting response)
    doReturn(Pair.of(firstFilterResult, Optional.empty())).when(filter1Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(any(), any());
    doReturn(Pair.of(firstFilterResult, null)).when(filter1Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(any(), any());
    doReturn(Pair.of(secondFilterResult, null)).when(filter2Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(any(), any());
    doReturn(Pair.of(secondFilterResult, Optional.empty())).when(filter2Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(any(), any());
    // when
    PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.normalFilterCall, args.shortCircuitFilterCall);
    // then
    assertThat(result).isEqualTo(CONTINUE);
    // First filter should have been passed the original request.
    if (isFirstChunk)
        verify(filter1Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
    else
        verify(filter1Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
    // Second filter should have been passed the result of the first filter.
    if (isFirstChunk)
        verify(filter2Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(firstFilterResult, ctxMock);
    else
        verify(filter2Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(firstFilterResult, ctxMock);
    // The state should have been updated with the result of the second filter.
    assertThat(state.getRequestInfo()).isSameAs(secondFilterResult);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) 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