Search in sources :

Example 1 with INTERNAL_SERVER_ERROR

use of io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project servicetalk by apple.

the class HttpSerializerErrorTest method serializationMapThrowsPropagatesToClient.

@ParameterizedTest
@MethodSource("executors")
void serializationMapThrowsPropagatesToClient(HttpTestExecutionStrategy serverStrategy) throws Exception {
    serverExecutionStrategy = serverStrategy.executorSupplier.get();
    TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
    };
    HttpStreamingSerializerDeserializer<Map<String, Object>> streamingSerializer = jsonStreamingSerializer(JACKSON.streamingSerializerDeserializer(mapType));
    HttpSerializerDeserializer<Map<String, Object>> serializer = HttpSerializers.jsonSerializer(JACKSON.serializerDeserializer(mapType));
    try (ServerContext srv = HttpServers.forAddress(localAddress(0)).executionStrategy(serverExecutionStrategy).listenAndAwait((ctx, request, responseFactory) -> responseFactory.ok().toStreamingResponse().payloadBody(request.toStreamingRequest().payloadBody(streamingSerializer).map(result -> {
        throw DELIBERATE_EXCEPTION;
    }), streamingSerializer).toResponse());
        BlockingHttpClient clt = HttpClients.forSingleAddress(serverHostAndPort(srv)).buildBlocking()) {
        HttpResponse resp = clt.request(clt.post("/foo").payloadBody(emptyMap(), serializer));
        assertEquals(INTERNAL_SERVER_ERROR, resp.status());
    }
}
Also used : HttpSerializers.jsonStreamingSerializer(io.servicetalk.http.api.HttpSerializers.jsonStreamingSerializer) SerializationException(io.servicetalk.serializer.api.SerializationException) BAD_REQUEST(io.servicetalk.http.api.HttpResponseStatus.BAD_REQUEST) HttpPayloadWriter(io.servicetalk.http.api.HttpPayloadWriter) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) MethodSource(org.junit.jupiter.params.provider.MethodSource) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) INTERNAL_SERVER_ERROR(io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Collections.emptyMap(java.util.Collections.emptyMap) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) JACKSON(io.servicetalk.data.jackson.JacksonSerializerFactory.JACKSON) DEFAULT(io.servicetalk.http.netty.HttpTestExecutionStrategy.DEFAULT) Collection(java.util.Collection) HttpResponse(io.servicetalk.http.api.HttpResponse) BlockingIterable(io.servicetalk.concurrent.BlockingIterable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HttpStreamingSerializerDeserializer(io.servicetalk.http.api.HttpStreamingSerializerDeserializer) NO_OFFLOAD(io.servicetalk.http.netty.HttpTestExecutionStrategy.NO_OFFLOAD) HttpSerializers(io.servicetalk.http.api.HttpSerializers) HttpSerializerDeserializer(io.servicetalk.http.api.HttpSerializerDeserializer) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with INTERNAL_SERVER_ERROR

use of io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project servicetalk by apple.

the class HttpSerializationErrorTest method serializationMapThrowsPropagatesToClient.

@ParameterizedTest
@MethodSource("executors")
void serializationMapThrowsPropagatesToClient(HttpTestExecutionStrategy serverStrategy) throws Exception {
    serverExecutionStrategy = serverStrategy.executorSupplier.get();
    TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {
    };
    HttpSerializerDeserializer<Map<String, Object>> httpSerializer = jsonSerializer(JACKSON.serializerDeserializer(mapType));
    HttpStreamingSerializerDeserializer<Map<String, Object>> httpStreamingSerializer = jsonStreamingSerializer(JACKSON.streamingSerializerDeserializer(mapType));
    try (ServerContext srv = HttpServers.forAddress(localAddress(0)).executionStrategy(serverExecutionStrategy).listenAndAwait((ctx, request, responseFactory) -> responseFactory.ok().toStreamingResponse().payloadBody(request.toStreamingRequest().payloadBody(httpStreamingSerializer).map(result -> {
        throw DELIBERATE_EXCEPTION;
    }), httpStreamingSerializer).toResponse());
        BlockingHttpClient clt = HttpClients.forSingleAddress(serverHostAndPort(srv)).buildBlocking()) {
        HttpResponse resp = clt.request(clt.post("/foo").payloadBody(emptyMap(), httpSerializer));
        assertEquals(INTERNAL_SERVER_ERROR, resp.status());
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) INTERNAL_SERVER_ERROR(io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) Collections.emptyMap(java.util.Collections.emptyMap) HttpSerializers.jsonStreamingSerializer(io.servicetalk.http.api.HttpSerializers.jsonStreamingSerializer) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ServerContext(io.servicetalk.transport.api.ServerContext) JACKSON(io.servicetalk.data.jackson.JacksonSerializerFactory.JACKSON) DEFAULT(io.servicetalk.http.netty.HttpTestExecutionStrategy.DEFAULT) Collection(java.util.Collection) HttpResponse(io.servicetalk.http.api.HttpResponse) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) HttpStreamingSerializerDeserializer(io.servicetalk.http.api.HttpStreamingSerializerDeserializer) NO_OFFLOAD(io.servicetalk.http.netty.HttpTestExecutionStrategy.NO_OFFLOAD) HttpSerializers.jsonSerializer(io.servicetalk.http.api.HttpSerializers.jsonSerializer) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HttpSerializerDeserializer(io.servicetalk.http.api.HttpSerializerDeserializer) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) MethodSource(org.junit.jupiter.params.provider.MethodSource) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Collections.emptyMap(java.util.Collections.emptyMap) Map(java.util.Map) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with INTERNAL_SERVER_ERROR

use of io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR in project servicetalk by apple.

the class TracingHttpServiceFilterTest method tracerThrowsReturnsErrorResponse.

@Test
void tracerThrowsReturnsErrorResponse() throws Exception {
    when(mockTracer.buildSpan(any())).thenThrow(DELIBERATE_EXCEPTION);
    try (ServerContext context = HttpServers.forAddress(localAddress(0)).appendServiceFilter(new TracingHttpServiceFilter(mockTracer, "testServer")).listenStreamingAndAwait(((ctx, request, responseFactory) -> succeeded(responseFactory.forbidden())))) {
        try (HttpClient client = forSingleAddress(serverHostAndPort(context)).build()) {
            HttpRequest request = client.get("/");
            HttpResponse response = client.request(request).toFuture().get();
            assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
        }
    }
}
Also used : AsyncContextHttpFilterVerifier.verifyServerFilterAsyncContextVisibility(io.servicetalk.http.netty.AsyncContextHttpFilterVerifier.verifyServerFilterAsyncContextVisibility) BeforeEach(org.junit.jupiter.api.BeforeEach) TestUtils.randomHexId(io.servicetalk.opentracing.http.TestUtils.randomHexId) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) Matchers.not(org.hamcrest.Matchers.not) TimeoutException(java.util.concurrent.TimeoutException) StreamingHttpServiceFilterFactory(io.servicetalk.http.api.StreamingHttpServiceFilterFactory) CountingInMemorySpanEventListener(io.servicetalk.opentracing.http.TestUtils.CountingInMemorySpanEventListener) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) HttpRequest(io.servicetalk.http.api.HttpRequest) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) PublisherSource(io.servicetalk.concurrent.PublisherSource) HttpClients.forSingleAddress(io.servicetalk.http.netty.HttpClients.forSingleAddress) HttpResponse(io.servicetalk.http.api.HttpResponse) LoggerStringWriter(io.servicetalk.log4j2.mdc.utils.LoggerStringWriter) SamplingStrategies(io.servicetalk.opentracing.inmemory.SamplingStrategies) Test(org.junit.jupiter.api.Test) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) DefaultInMemoryTracer(io.servicetalk.opentracing.inmemory.DefaultInMemoryTracer) SAMPLED(io.servicetalk.opentracing.internal.ZipkinHeaderNames.SAMPLED) Matchers.is(org.hamcrest.Matchers.is) TRUE(java.lang.Boolean.TRUE) TRACING_TEST_LOG_LINE_PREFIX(io.servicetalk.opentracing.http.TestUtils.TRACING_TEST_LOG_LINE_PREFIX) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Mock(org.mockito.Mock) SPAN_STATE_SERIALIZER(io.servicetalk.opentracing.http.TestUtils.SPAN_STATE_SERIALIZER) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) InMemorySpan(io.servicetalk.opentracing.inmemory.api.InMemorySpan) PARENT_SPAN_ID(io.servicetalk.opentracing.internal.ZipkinHeaderNames.PARENT_SPAN_ID) StreamingHttpServiceFilter(io.servicetalk.http.api.StreamingHttpServiceFilter) HttpServiceContext(io.servicetalk.http.api.HttpServiceContext) TestUtils.verifyTraceIdPresentInLogs(io.servicetalk.opentracing.http.TestUtils.verifyTraceIdPresentInLogs) ERROR(io.opentracing.tag.Tags.ERROR) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpSerializers.textSerializerUtf8(io.servicetalk.http.api.HttpSerializers.textSerializerUtf8) TRACE_ID(io.servicetalk.opentracing.internal.ZipkinHeaderNames.TRACE_ID) HttpClient(io.servicetalk.http.api.HttpClient) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Nullable(javax.annotation.Nullable) INTERNAL_SERVER_ERROR(io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) Logger(org.slf4j.Logger) ServerContext(io.servicetalk.transport.api.ServerContext) Tracer(io.opentracing.Tracer) Single(io.servicetalk.concurrent.api.Single) LoggerStringWriter.stableAccumulated(io.servicetalk.log4j2.mdc.utils.LoggerStringWriter.stableAccumulated) SCOPE_MANAGER(io.servicetalk.opentracing.asynccontext.AsyncContextInMemoryScopeManager.SCOPE_MANAGER) Mockito.when(org.mockito.Mockito.when) Matchers.equalToIgnoringCase(org.hamcrest.Matchers.equalToIgnoringCase) SPAN_ID(io.servicetalk.opentracing.internal.ZipkinHeaderNames.SPAN_ID) AfterEach(org.junit.jupiter.api.AfterEach) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) HttpServers(io.servicetalk.http.netty.HttpServers) HttpRequest(io.servicetalk.http.api.HttpRequest) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ServerContext(io.servicetalk.transport.api.ServerContext) HttpClient(io.servicetalk.http.api.HttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)3 HttpResponse (io.servicetalk.http.api.HttpResponse)3 INTERNAL_SERVER_ERROR (io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)3 ServerContext (io.servicetalk.transport.api.ServerContext)3 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)3 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)2 JACKSON (io.servicetalk.data.jackson.JacksonSerializerFactory.JACKSON)2 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)2 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)2 HttpSerializerDeserializer (io.servicetalk.http.api.HttpSerializerDeserializer)2 HttpSerializers.jsonStreamingSerializer (io.servicetalk.http.api.HttpSerializers.jsonStreamingSerializer)2 HttpStreamingSerializerDeserializer (io.servicetalk.http.api.HttpStreamingSerializerDeserializer)2 DEFAULT (io.servicetalk.http.netty.HttpTestExecutionStrategy.DEFAULT)2 NO_OFFLOAD (io.servicetalk.http.netty.HttpTestExecutionStrategy.NO_OFFLOAD)2 Arrays.asList (java.util.Arrays.asList)2 Collection (java.util.Collection)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Map (java.util.Map)2