Search in sources :

Example 1 with HttpClientConnection

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();
}
Also used : HttpClientConnection(software.amazon.awssdk.crt.http.HttpClientConnection) HttpClientConnectionManager(software.amazon.awssdk.crt.http.HttpClientConnectionManager) URI(java.net.URI) Test(org.junit.Test)

Example 2 with HttpClientConnection

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();
    }
}
Also used : HttpClientConnection(software.amazon.awssdk.crt.http.HttpClientConnection) HttpClientConnectionManager(software.amazon.awssdk.crt.http.HttpClientConnectionManager) URI(java.net.URI) Test(org.junit.Test)

Example 3 with HttpClientConnection

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;
}
Also used : AwsCrtResponseBodyPublisher(software.amazon.awssdk.http.crt.internal.AwsCrtResponseBodyPublisher) HttpClientConnection(software.amazon.awssdk.crt.http.HttpClientConnection) HttpStream(software.amazon.awssdk.crt.http.HttpStream)

Example 4 with HttpClientConnection

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) HttpClientConnection(software.amazon.awssdk.crt.http.HttpClientConnection) Test(org.junit.Test)

Example 5 with HttpClientConnection

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HttpClientConnection(software.amazon.awssdk.crt.http.HttpClientConnection) IOException(java.io.IOException) CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) SdkCancellationException(software.amazon.awssdk.http.SdkCancellationException) Test(org.junit.Test)

Aggregations

HttpClientConnection (software.amazon.awssdk.crt.http.HttpClientConnection)12 Test (org.junit.Test)8 HttpClientConnectionManager (software.amazon.awssdk.crt.http.HttpClientConnectionManager)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 IOException (java.io.IOException)4 URI (java.net.URI)4 CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)4 HttpRequest (software.amazon.awssdk.crt.http.HttpRequest)3 HttpStream (software.amazon.awssdk.crt.http.HttpStream)3 SdkCancellationException (software.amazon.awssdk.http.SdkCancellationException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HttpClientConnectionManagerOptions (software.amazon.awssdk.crt.http.HttpClientConnectionManagerOptions)2 HttpStreamResponseHandler (software.amazon.awssdk.crt.http.HttpStreamResponseHandler)2 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)2 HttpHeader (software.amazon.awssdk.crt.http.HttpHeader)1 ClientBootstrap (software.amazon.awssdk.crt.io.ClientBootstrap)1 SocketOptions (software.amazon.awssdk.crt.io.SocketOptions)1 TlsContext (software.amazon.awssdk.crt.io.TlsContext)1 TlsContextOptions (software.amazon.awssdk.crt.io.TlsContextOptions)1 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)1