Search in sources :

Example 6 with GetObjectOutput

use of com.amazonaws.s3.model.GetObjectOutput in project aws-crt-java by awslabs.

the class S3NativeClientTest method testGetObject.

@Test
public void testGetObject() {
    skipIfNetworkUnavailable();
    try (final EventLoopGroup elGroup = new EventLoopGroup(DEFAULT_NUM_THREADS);
        final HostResolver resolver = new HostResolver(elGroup, DEFAULT_MAX_HOST_ENTRIES);
        final ClientBootstrap clientBootstrap = new ClientBootstrap(elGroup, resolver);
        final CredentialsProvider provider = getTestCredentialsProvider();
        final S3NativeClient nativeClient = new S3NativeClient(REGION, clientBootstrap, provider, 64_000_000l, 100.)) {
        final long[] length = { 0 };
        nativeClient.getObject(GetObjectRequest.builder().bucket(BUCKET).key(GET_OBJECT_KEY).build(), new ResponseDataConsumer<GetObjectOutput>() {

            @Override
            public void onResponse(GetObjectOutput response) {
                assertNotNull(response);
            }

            @Override
            public void onResponseData(ByteBuffer bodyBytesIn) {
                length[0] += bodyBytesIn.remaining();
            }

            @Override
            public void onFinished() {
            }

            @Override
            public void onException(final CrtRuntimeException e) {
            }
        }).join();
    }
}
Also used : CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) GetObjectOutput(com.amazonaws.s3.model.GetObjectOutput) CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with GetObjectOutput

use of com.amazonaws.s3.model.GetObjectOutput in project aws-crt-java by awslabs.

the class S3NativeClientTest method testGetObjectExceptionCatch.

@Test
public void testGetObjectExceptionCatch() throws Throwable {
    skipIfNetworkUnavailable();
    try (final EventLoopGroup elGroup = new EventLoopGroup(DEFAULT_NUM_THREADS);
        final HostResolver resolver = new HostResolver(elGroup, DEFAULT_MAX_HOST_ENTRIES);
        final ClientBootstrap clientBootstrap = new ClientBootstrap(elGroup, resolver);
        final CredentialsProvider provider = getTestCredentialsProvider();
        final S3NativeClient nativeClient = new S3NativeClient(REGION, clientBootstrap, provider, 64_000_000l, 100.)) {
        nativeClient.getObject(GetObjectRequest.builder().bucket(BUCKET).key("_NON_EXIST_OBJECT_").build(), new ResponseDataConsumer<GetObjectOutput>() {

            @Override
            public void onResponse(GetObjectOutput response) {
            }

            @Override
            public void onResponseData(ByteBuffer bodyBytesIn) {
            }

            @Override
            public void onFinished() {
            }

            @Override
            public void onException(final CrtRuntimeException e) {
            }
        }).join();
    } catch (CompletionException e) {
        try {
            throw e.getCause();
        } catch (CrtS3RuntimeException causeException) {
            /**
             * Assert the exceptions are set correctly.
             */
            assertTrue(causeException.errorName.equals("AWS_ERROR_S3_INVALID_RESPONSE_STATUS"));
            assertTrue(causeException.getAwsErrorCode().equals("NoSuchKey"));
            assertTrue(causeException.getAwsErrorMessage().equals("The specified key does not exist."));
            assertTrue(causeException.getStatusCode() == 404);
        }
    }
}
Also used : CrtRuntimeException(software.amazon.awssdk.crt.CrtRuntimeException) CompletionException(java.util.concurrent.CompletionException) GetObjectOutput(com.amazonaws.s3.model.GetObjectOutput) CredentialsProvider(software.amazon.awssdk.crt.auth.credentials.CredentialsProvider) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

GetObjectOutput (com.amazonaws.s3.model.GetObjectOutput)7 ByteBuffer (java.nio.ByteBuffer)7 CrtRuntimeException (software.amazon.awssdk.crt.CrtRuntimeException)7 Test (org.junit.Test)6 CredentialsProvider (software.amazon.awssdk.crt.auth.credentials.CredentialsProvider)6 Duration (java.time.Duration)3 CompletionException (java.util.concurrent.CompletionException)3 DeleteObjectOutput (com.amazonaws.s3.model.DeleteObjectOutput)2 DeleteObjectRequest (com.amazonaws.s3.model.DeleteObjectRequest)2 GetObjectRequest (com.amazonaws.s3.model.GetObjectRequest)2 ListObjectsOutput (com.amazonaws.s3.model.ListObjectsOutput)2 ListObjectsRequest (com.amazonaws.s3.model.ListObjectsRequest)2 PutObjectOutput (com.amazonaws.s3.model.PutObjectOutput)2 PutObjectRequest (com.amazonaws.s3.model.PutObjectRequest)2 AwsClientTestFixture (com.amazonaws.test.AwsClientTestFixture)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CancellationException (java.util.concurrent.CancellationException)2