use of software.amazon.awssdk.crt.http.HttpClientConnection in project aws-crt-java by awslabs.
the class HttpClientConnectionManagerTest method testPendingAcquisitionsDuringShutdown.
@Test
public void testPendingAcquisitionsDuringShutdown() throws Exception {
skipIfNetworkUnavailable();
HttpClientConnection firstConnection = null;
CompletableFuture<HttpClientConnection> firstAcquisition;
CompletableFuture<HttpClientConnection> secondAcquisition;
try (HttpClientConnectionManager connectionPool = createConnectionManager(new URI(endpoint), 1, 1)) {
firstAcquisition = connectionPool.acquireConnection();
secondAcquisition = connectionPool.acquireConnection();
firstConnection = firstAcquisition.get();
}
firstConnection.close();
}
use of software.amazon.awssdk.crt.http.HttpClientConnection in project aws-crt-java by awslabs.
the class HttpClientConnectionManagerTest method testCancelAcquire.
@Test
public void testCancelAcquire() throws Exception {
// related: https://github.com/awslabs/aws-sdk-kotlin/issues/511
skipIfNetworkUnavailable();
try (HttpClientConnectionManager connectionPool = createConnectionManager(new URI(endpoint), 1, 1)) {
CompletableFuture<HttpClientConnection> firstAcquisition = connectionPool.acquireConnection();
CompletableFuture<HttpClientConnection> secondAcquisition = connectionPool.acquireConnection();
CompletableFuture<HttpClientConnection> thirdAcquisition = connectionPool.acquireConnection();
HttpClientConnection firstConnection = firstAcquisition.get();
// cancel acquisition and abandon it
secondAcquisition.cancel(false);
// return the first conn to the pool, future acquisitions should succeed
firstConnection.close();
// should succeed, will timeout if the second acquisition doesn't return the unused/abandoned conn to the pool
HttpClientConnection conn = thirdAcquisition.get(500, TimeUnit.MILLISECONDS);
conn.close();
}
}
use of software.amazon.awssdk.crt.http.HttpClientConnection in project aws-sdk-java-v2 by aws.
the class AwsCrtResponseBodyPublisherReactiveStreamCompatTest method createPublisher.
@Override
public Publisher<ByteBuffer> createPublisher(long elements) {
HttpClientConnection connection = mock(HttpClientConnection.class);
HttpStream stream = mock(HttpStream.class);
AwsCrtResponseBodyPublisher bodyPublisher = new AwsCrtResponseBodyPublisher(connection, stream, new CompletableFuture<>(), Integer.MAX_VALUE);
for (long i = 0; i < elements; i++) {
bodyPublisher.queueBuffer(UUID.randomUUID().toString().getBytes());
}
bodyPublisher.setQueueComplete();
return bodyPublisher;
}
use of software.amazon.awssdk.crt.http.HttpClientConnection in project aws-sdk-java-v2 by aws.
the class CrtRequestExecutorTest method makeRequest_success.
@Test
public void makeRequest_success() {
SdkHttpFullRequest request = createRequest(URI.create("http://localhost"));
CrtRequestContext context = CrtRequestContext.builder().readBufferSize(2000).crtConnPool(connectionManager).request(AsyncExecuteRequest.builder().request(request).requestContentPublisher(createProvider("")).responseHandler(responseHandler).build()).build();
CompletableFuture<HttpClientConnection> completableFuture = new CompletableFuture<>();
Mockito.when(connectionManager.acquireConnection()).thenReturn(completableFuture);
completableFuture.complete(httpClientConnection);
CompletableFuture<Void> executeFuture = requestExecutor.execute(context);
Mockito.verifyNoMoreInteractions(responseHandler);
}
use of software.amazon.awssdk.crt.http.HttpClientConnection in project aws-sdk-java-v2 by aws.
the class CrtRequestExecutorTest method cancelRequest_shouldInvokeOnError.
@Test
public void cancelRequest_shouldInvokeOnError() {
CrtRequestContext context = CrtRequestContext.builder().crtConnPool(connectionManager).request(AsyncExecuteRequest.builder().responseHandler(responseHandler).build()).build();
CompletableFuture<HttpClientConnection> completableFuture = new CompletableFuture<>();
Mockito.when(connectionManager.acquireConnection()).thenReturn(completableFuture);
CompletableFuture<Void> executeFuture = requestExecutor.execute(context);
executeFuture.cancel(true);
ArgumentCaptor<Exception> argumentCaptor = ArgumentCaptor.forClass(Exception.class);
Mockito.verify(responseHandler).onError(argumentCaptor.capture());
Exception actualException = argumentCaptor.getValue();
assertThat(actualException).hasMessageContaining("The request was cancelled");
assertThat(actualException).isInstanceOf(SdkCancellationException.class);
}
Aggregations