use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.
the class ExpectContinueTest method expectationFailedAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectationFailedAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol);
StreamingHttpClient client = createClient(serverContext, protocol);
HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
BufferAllocator allocator = connection.executionContext().bufferAllocator();
Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, true, PAYLOAD + PAYLOAD, allocator)).toFuture();
requestReceived.await();
sendContinue.countDown();
returnResponse.countDown();
HttpResponse response = responseFuture.get();
assertThat(response.status(), is(EXPECTATION_FAILED));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, OK);
}
}
use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.
the class ExpectContinueTest method serverRespondsWithSuccessAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverRespondsWithSuccessAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
requestReceived.countDown();
returnResponse.await();
response.status(ACCEPTED);
try (HttpPayloadWriter<Buffer> writer = response.sendMetaData()) {
for (Buffer chunk : request.payloadBody()) {
writer.write(chunk);
}
}
});
StreamingHttpClient client = createClient(serverContext, protocol);
HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
BufferAllocator allocator = connection.executionContext().bufferAllocator();
returnResponse.countDown();
HttpResponse response = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture().get();
assertThat(response.status(), is(ACCEPTED));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, ACCEPTED);
}
}
use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.
the class ExpectContinueTest method expectContinueAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol);
StreamingHttpClient client = createClient(serverContext, protocol);
HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
BufferAllocator allocator = connection.executionContext().bufferAllocator();
Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture();
requestReceived.await();
sendContinue.countDown();
returnResponse.countDown();
HttpResponse response = responseFuture.get();
assertThat(response.status(), is(OK));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, OK);
}
}
use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.
the class StreamObserverTest method maxActiveStreamsViolationError.
@Disabled("https://github.com/apple/servicetalk/issues/1264")
@Test
void maxActiveStreamsViolationError() throws Exception {
CountDownLatch maxConcurrentStreamsValueSetToOne = new CountDownLatch(1);
try (HttpConnection connection = client.reserveConnection(client.get("/")).map(conn -> {
conn.transportEventStream(MAX_CONCURRENCY).forEach(event -> {
if (event.event() == 1) {
maxConcurrentStreamsValueSetToOne.countDown();
}
});
return conn;
}).toFuture().get()) {
verify(clientTransportObserver).onNewConnection(any(), any());
verify(clientConnectionObserver).multiplexedConnectionEstablished(any(ConnectionInfo.class));
connection.request(connection.get("/first")).subscribe(__ -> {
/* no response expected */
});
requestReceived.await();
maxConcurrentStreamsValueSetToOne.await();
ExecutionException e = assertThrows(ExecutionException.class, () -> connection.request(connection.get("/second")).toFuture().get());
assertThat(e.getCause(), instanceOf(Http2Exception.class));
assertThat(e.getCause(), instanceOf(RetryableException.class));
assertThat(e.getCause().getCause(), instanceOf(StreamException.class));
verify(clientMultiplexedObserver, times(2)).onNewStream();
verify(clientStreamObserver, times(2)).streamEstablished();
verify(clientDataObserver, times(2)).onNewRead();
verify(clientDataObserver, times(2)).onNewWrite();
verify(clientReadObserver).readFailed(any(ClosedChannelException.class));
verify(clientWriteObserver).writeFailed(e.getCause());
verify(clientStreamObserver, await()).streamClosed(e.getCause());
}
verify(clientStreamObserver, await()).streamClosed();
verify(clientConnectionObserver).connectionClosed();
verifyNoMoreInteractions(clientTransportObserver, clientMultiplexedObserver, clientStreamObserver, clientDataObserver);
}
use of io.servicetalk.http.api.HttpConnection in project servicetalk by apple.
the class ExpectContinueTest method serverErrorAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverErrorAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
requestReceived.countDown();
returnResponse.await();
if (request.headers().contains(EXPECT, CONTINUE)) {
response.status(INTERNAL_SERVER_ERROR);
}
response.sendMetaData().close();
});
StreamingHttpClient client = createClient(serverContext, protocol);
HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
BufferAllocator allocator = connection.executionContext().bufferAllocator();
Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture();
requestReceived.await();
returnResponse.countDown();
HttpResponse response = responseFuture.get();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
// send a follow-up request on the same connection:
response = connection.request(connection.get("/")).toFuture().get();
assertThat(response.status(), is(OK));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
}
}
Aggregations