Skip to content

Commit

Permalink
Added test for AWS CRT based client
Browse files Browse the repository at this point in the history
Signed-off-by: Shubhendu Ram Tripathi <shubhendu@minio.io>
  • Loading branch information
shtripat committed May 6, 2024
1 parent f1cfe44 commit 12592f4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
1 change: 1 addition & 0 deletions build/aws-sdk-java-v2/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation(platform("software.amazon.awssdk:bom:2.25.31"))
implementation("software.amazon.awssdk:s3")
implementation("software.amazon.awssdk:netty-nio-client")
implementation("software.amazon.awssdk:aws-crt-client")

// jackson dependency
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.+")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package io.minio.awssdk.v2.tests;

import software.amazon.awssdk.auth.credentials.*;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.core.internal.http.loader.DefaultSdkHttpClientBuilder;
import software.amazon.awssdk.core.waiters.WaiterResponse;
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
Expand All @@ -34,6 +36,7 @@
import java.io.IOException;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
Expand Down Expand Up @@ -62,6 +65,7 @@ public class FunctionalTests {

private static S3Client s3Client;
private static S3AsyncClient s3AsyncClient;
private static S3AsyncClient s3CrtAsyncClient;
private static S3TestUtils s3TestUtils;

public static String getRandomName() {
Expand Down Expand Up @@ -118,6 +122,7 @@ public static void runTests() throws Exception {
uploadMultiPart_test();
uploadMultiPartAsync_test();
uploadObjectVersions_test();
crtClientDownload_test();
// uploadSnowballObjects_test();
}

Expand Down Expand Up @@ -321,6 +326,45 @@ public static void uploadObjectVersions_test() throws Exception {
}
}

public static void crtClientDownload_test() throws Exception {
if (!mintEnv) {
System.out.println("Test: Async S3CrtClient.getObject");
}
if (!enableHTTPS) {
return;
}

String bucket = getRandomName();
long startTime = System.currentTimeMillis();
String objectName = "testobject";
try {
s3Client.createBucket(CreateBucketRequest
.builder()
.bucket(bucket)
.build());
s3Client.waiter().waitUntilBucketExists(HeadBucketRequest
.builder()
.bucket(bucket)
.build());
s3CrtAsyncClient.putObject(
r -> r.bucket(bucket).key(objectName), AsyncRequestBody.empty()
).join();
s3CrtAsyncClient.getObject(
r -> r.bucket(bucket).key(objectName), Path.of("/tmp/test")
).join();
mintSuccessLog("Async S3CrtClient.getObject versions",
"bucket: " + bucket + ", object: " + objectName,
startTime);
} catch (Exception ex) {
mintFailedLog("Async S3CrtClient.getObject",
"bucket: " + bucket + ", object: " + objectName,
startTime,
null,
ex.toString() + " >>> " + Arrays.toString(ex.getStackTrace()));
throw ex;
}
}

public static void teardown() throws IOException {
ListBucketsResponse response = s3Client.listBuckets(ListBucketsRequest
.builder()
Expand Down Expand Up @@ -406,6 +450,20 @@ public static void main(String[] args) throws Exception, IOException, NoSuchAlgo
.region(region)
.httpClient(sdkAsyncHttpClient)
.build();
SdkAsyncHttpClient crtAsyncHttpClient = AwsCrtAsyncHttpClient
.builder()
.buildWithDefaults(AttributeMap
.builder()
.put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, true)
.build());
s3CrtAsyncClient = S3AsyncClient
.builder()
.endpointOverride(URI.create(endpoint))
.forcePathStyle(true)
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.region(region)
.httpClient(crtAsyncHttpClient)
.build();
} else {
s3Client = S3Client
.builder()
Expand All @@ -425,9 +483,17 @@ public static void main(String[] args) throws Exception, IOException, NoSuchAlgo
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.region(region)
.build();
s3CrtAsyncClient = S3AsyncClient
.crtBuilder()
.checksumValidationEnabled(false)
.endpointOverride(URI.create(endpoint))
.forcePathStyle(true)
.credentialsProvider(StaticCredentialsProvider.create(credentials))
.region(region)
.build();
}

s3TestUtils = new S3TestUtils(s3Client, s3AsyncClient);
s3TestUtils = new S3TestUtils(s3Client, s3AsyncClient, s3CrtAsyncClient);

try {
initTests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
public class S3TestUtils {
private final S3Client s3Client;
private final S3AsyncClient s3AsyncClient;
private final S3AsyncClient s3CrtAsyncClient;

S3TestUtils(S3Client s3Client, S3AsyncClient s3AsyncClient) {
this.s3Client = s3Client;
this.s3AsyncClient = s3AsyncClient;
S3TestUtils(S3Client s3Client, S3AsyncClient s3AsyncClient, S3AsyncClient s3CrtAsyncClient) {
this.s3Client = s3Client;
this.s3AsyncClient = s3AsyncClient;
this.s3CrtAsyncClient = s3CrtAsyncClient;
}

void uploadMultipartObject(String bucketName, String keyName) throws IOException {
Expand Down

0 comments on commit 12592f4

Please # to comment.