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();
}
}
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);
}
}
}
Aggregations