Search in sources :

Example 1 with ServiceAdapterHolder

use of io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder in project servicetalk by apple.

the class BlockingStreamingToStreamingServiceTest method invokeService.

private List<Object> invokeService(BlockingStreamingHttpService syncService, StreamingHttpRequest request) throws Exception {
    ServiceAdapterHolder holder = toStreamingHttpService(syncService, offloadNone());
    Collection<Object> responseCollection = invokeService(holder.serviceInvocationStrategy(), executorExtension.executor(), request, req -> holder.adaptor().handle(mockCtx, req, reqRespFactory).flatMapPublisher(response -> Publisher.<Object>from(response).concat(response.messageBody())), (t, e) -> failed(t)).toFuture().get();
    return new ArrayList<>(responseCollection);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PlatformDependent.throwException(io.servicetalk.utils.internal.PlatformDependent.throwException) BiFunction(java.util.function.BiFunction) SingleSource(io.servicetalk.concurrent.SingleSource) ServiceAdapterHolder(io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executor(io.servicetalk.concurrent.api.Executor) HttpExecutionStrategies.offloadNone(io.servicetalk.http.api.HttpExecutionStrategies.offloadNone) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) PayloadWriter(io.servicetalk.oio.api.PayloadWriter) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.servicetalk.buffer.api.Buffer) Function.identity(java.util.function.Function.identity) Matchers.is(org.hamcrest.Matchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) Publisher(io.servicetalk.concurrent.api.Publisher) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Cancellable(io.servicetalk.concurrent.Cancellable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Mockito.lenient(org.mockito.Mockito.lenient) Subscriber(io.servicetalk.concurrent.PublisherSource.Subscriber) ArrayList(java.util.ArrayList) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) HttpSerializers.appSerializerUtf8FixLen(io.servicetalk.http.api.HttpSerializers.appSerializerUtf8FixLen) HttpApiConversions.toStreamingHttpService(io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) Nullable(javax.annotation.Nullable) TRAILER(io.servicetalk.http.api.HttpHeaderNames.TRAILER) UTF_8(java.nio.charset.StandardCharsets.UTF_8) NO_CONTENT(io.servicetalk.http.api.HttpResponseStatus.NO_CONTENT) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) OK(io.servicetalk.http.api.HttpResponseStatus.OK) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) ExecutionException(java.util.concurrent.ExecutionException) Publisher.failed(io.servicetalk.concurrent.api.Publisher.failed) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) InputStream(java.io.InputStream) ServiceAdapterHolder(io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder) ArrayList(java.util.ArrayList)

Example 2 with ServiceAdapterHolder

use of io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder in project servicetalk by apple.

the class GrpcRouter method populateRoutes.

private static void populateRoutes(final GrpcExecutionContext executionContext, final Map<String, StreamingHttpService> allRoutes, final Map<String, RouteProvider> routes, final CompositeCloseable closeable, final Map<String, GrpcExecutionStrategy> executionStrategies) {
    for (Map.Entry<String, RouteProvider> entry : routes.entrySet()) {
        final String path = entry.getKey();
        final ServiceAdapterHolder adapterHolder = entry.getValue().buildRoute(executionContext);
        final StreamingHttpService route = closeable.append(adapterHolder.adaptor());
        final GrpcExecutionStrategy routeStrategy = executionStrategies.getOrDefault(path, null);
        final HttpExecutionStrategy missing = null == routeStrategy ? HttpExecutionStrategies.offloadNone() : executionContext.executionStrategy().missing(routeStrategy);
        verifyNoOverrides(allRoutes.put(path, null != routeStrategy && missing.isRequestResponseOffloaded() ? StreamingHttpServiceToOffloadedStreamingHttpService.offloadService(adapterHolder.serviceInvocationStrategy(), executionContext.executor(), IoThreadFactory.IoThread::currentThreadIsIoThread, route) : route), path, emptyMap());
        LOGGER.debug("route strategy for path={} : ctx={} route={} → using={}", path, executionContext.executionStrategy(), routeStrategy, missing);
    }
}
Also used : ServiceAdapterHolder(io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder) IoThreadFactory(io.servicetalk.transport.api.IoThreadFactory) BlockingStreamingHttpService(io.servicetalk.http.api.BlockingStreamingHttpService) StreamingHttpServiceToOffloadedStreamingHttpService(io.servicetalk.http.api.StreamingHttpServiceToOffloadedStreamingHttpService) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) HttpApiConversions.toStreamingHttpService(io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) Map(java.util.Map) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap)

Aggregations

ServiceAdapterHolder (io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder)2 HttpApiConversions.toStreamingHttpService (io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService)2 Buffer (io.servicetalk.buffer.api.Buffer)1 DEFAULT_ALLOCATOR (io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR)1 Cancellable (io.servicetalk.concurrent.Cancellable)1 Subscriber (io.servicetalk.concurrent.PublisherSource.Subscriber)1 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)1 SingleSource (io.servicetalk.concurrent.SingleSource)1 Executor (io.servicetalk.concurrent.api.Executor)1 ExecutorExtension (io.servicetalk.concurrent.api.ExecutorExtension)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 Publisher.failed (io.servicetalk.concurrent.api.Publisher.failed)1 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)1 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)1 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)1 BlockingStreamingHttpService (io.servicetalk.http.api.BlockingStreamingHttpService)1 HttpExecutionStrategies.offloadNone (io.servicetalk.http.api.HttpExecutionStrategies.offloadNone)1 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)1 TRAILER (io.servicetalk.http.api.HttpHeaderNames.TRAILER)1 HTTP_1_1 (io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1)1