use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class ConnectionAcceptingNettyHttpServerTest method assertConnectionRequestSucceeds.
private void assertConnectionRequestSucceeds(final StreamingHttpRequest request) throws Exception {
final StreamingHttpResponse response = awaitIndefinitely(streamingHttpClient().reserveConnection(request).flatMap(conn -> conn.request(request)));
assert response != null;
assertResponse(response, HTTP_1_1, OK, "");
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class ConnectionAcceptingNettyHttpServerTest method testIdleTimeout.
@Test
void testIdleTimeout() throws Exception {
setUp(CACHED, CACHED);
final StreamingHttpRequest request = streamingHttpClient().newRequest(GET, SVC_ECHO);
assertConnectionRequestSucceeds(request);
serverContext().acceptConnections(false);
// Netty will evaluate the auto-read on the next round, so the next connection will go through.
assertConnectionRequestSucceeds(request);
// Connection will establish but remain in the accept-queue
// (i.e., NOT accepted by the server => occupying 1 backlog entry)
assertConnectionRequestReceiveTimesOut(request);
try (StreamingHttpClient client = newClientWithConnectTimeout()) {
// Since we control the backlog size, this connection won't establish (i.e., NO syn-ack)
// timeout operator can be used to kill it or socket connection-timeout
final Single<StreamingHttpResponse> response = client.reserveConnection(request).flatMap(conn -> conn.request(request));
final ExecutionException executionException = assertThrows(ExecutionException.class, () -> awaitIndefinitely(response));
assertThat(executionException.getCause(), instanceOf(ConnectTimeoutException.class));
}
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class ConnectionAcceptingNettyHttpServerTest method testStopAcceptingAndResume.
@Test
void testStopAcceptingAndResume() throws Exception {
setUp(CACHED, CACHED);
final StreamingHttpRequest request = streamingHttpClient().newRequest(GET, SVC_ECHO);
assertConnectionRequestSucceeds(request);
serverContext().acceptConnections(false);
// Netty will evaluate the auto-read on the next round, so the next connection will go through.
assertConnectionRequestSucceeds(request);
// This connection should get established but not accepted.
assertConnectionRequestReceiveTimesOut(request);
// Restoring auto-read will resume accepting.
serverContext().acceptConnections(true);
assertConnectionRequestSucceeds(request);
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class HttpLifecycleObserverTest method makeRequestAndAssertResponse.
private void makeRequestAndAssertResponse(String path, HttpProtocol protocol, HttpResponseStatus status, int contentLength) throws Exception {
StreamingHttpClient client = streamingHttpClient();
StreamingHttpRequest request = contentLength == 0 ? client.get(path) : client.post(path).payloadBody(Publisher.from(CONTENT.duplicate())).transform(// adds empty trailers
new StatelessTrailersTransformer<>());
StreamingHttpResponse response = client.request(request).toFuture().get();
assertResponse(response, protocol.version, status, contentLength);
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class HttpLifecycleObserverTest method testClientCancelsRequestAfterResponse.
@ParameterizedTest(name = "{displayName} [{index}] protocol={0}")
@EnumSource(HttpProtocol.class)
void testClientCancelsRequestAfterResponse(HttpProtocol protocol) throws Exception {
TestPublisher<Buffer> serverResponsePayload = new TestPublisher<>();
serviceFilterFactory(service -> new StreamingHttpServiceFilter(service) {
@Override
public Single<StreamingHttpResponse> handle(HttpServiceContext ctx, StreamingHttpRequest request, StreamingHttpResponseFactory responseFactory) {
return request.payloadBody().ignoreElements().concat(succeeded(responseFactory.ok().payloadBody(serverResponsePayload)));
}
});
setUp(protocol);
StreamingHttpConnection connection = streamingHttpConnection();
StreamingHttpRequest request = connection.post("/").payloadBody(Publisher.from(CONTENT.duplicate())).transform(// adds empty trailers
new StatelessTrailersTransformer<>());
StreamingHttpResponse response = connection.request(request).toFuture().get();
assertResponse(response, protocol.version, OK);
Future<Collection<Buffer>> payload = response.payloadBody().toFuture();
payload.cancel(true);
if (protocol == HttpProtocol.HTTP_1) {
// wait for cancellation to close the connection:
connection.onClose().toFuture().get();
}
// try to write server content to trigger write failure and close the server-side connection:
serverResponsePayload.onNext(CONTENT.duplicate());
bothTerminate.await();
clientInOrder.verify(clientLifecycleObserver).onNewExchange();
clientInOrder.verify(clientExchangeObserver).onConnectionSelected(any(ConnectionInfo.class));
clientInOrder.verify(clientExchangeObserver).onRequest(any(StreamingHttpRequest.class));
clientInOrder.verify(clientExchangeObserver).onResponse(any(StreamingHttpResponse.class));
clientInOrder.verify(clientResponseObserver).onResponseCancel();
clientRequestInOrder.verify(clientRequestObserver).onRequestData(any(Buffer.class));
clientRequestInOrder.verify(clientRequestObserver).onRequestTrailers(any(HttpHeaders.class));
clientRequestInOrder.verify(clientRequestObserver).onRequestComplete();
clientInOrder.verify(clientExchangeObserver).onExchangeFinally();
verifyNoMoreInteractions(clientLifecycleObserver, clientExchangeObserver, clientRequestObserver, clientResponseObserver);
serverInOrder.verify(serverLifecycleObserver).onNewExchange();
serverInOrder.verify(serverExchangeObserver).onConnectionSelected(any(ConnectionInfo.class));
serverInOrder.verify(serverExchangeObserver).onRequest(any(StreamingHttpRequest.class));
serverInOrder.verify(serverExchangeObserver).onResponse(any(StreamingHttpResponse.class));
verify(serverResponseObserver, atMostOnce()).onResponseData(any(Buffer.class));
serverInOrder.verify(serverResponseObserver).onResponseCancel();
serverRequestInOrder.verify(serverRequestObserver).onRequestData(any(Buffer.class));
serverRequestInOrder.verify(serverRequestObserver).onRequestComplete();
serverInOrder.verify(serverExchangeObserver).onExchangeFinally();
verifyNoMoreInteractions(serverLifecycleObserver, serverExchangeObserver, serverRequestObserver, serverResponseObserver);
}
Aggregations