1717
1818package org .apache .hadoop .ozone .local ;
1919
20+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2021import static org .junit .jupiter .api .Assertions .assertTrue ;
2122
2223import java .net .HttpURLConnection ;
24+ import java .net .URI ;
2325import java .net .URL ;
2426import java .nio .file .Path ;
2527import java .time .Duration ;
28+ import java .util .UUID ;
2629import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
2730import org .junit .jupiter .api .Test ;
2831import org .junit .jupiter .api .io .TempDir ;
32+ import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
33+ import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
34+ import software .amazon .awssdk .core .ResponseBytes ;
35+ import software .amazon .awssdk .core .sync .RequestBody ;
36+ import software .amazon .awssdk .regions .Region ;
37+ import software .amazon .awssdk .services .s3 .S3Client ;
38+ import software .amazon .awssdk .services .s3 .model .GetObjectResponse ;
39+ import software .amazon .awssdk .services .s3 .model .ListBucketsResponse ;
2940
3041/**
3142 * Integration tests for the S3 Gateway of the {@code ozone local} runtime.
@@ -50,6 +61,46 @@ void s3GatewayServesRequests() throws Exception {
5061 }
5162 }
5263
64+ @ Test
65+ void awsSdkCanCreateListPutAndGetAgainstLocalRuntime () throws Exception {
66+ // Non-default credentials prove the launcher provisions whatever key pair is configured.
67+ LocalOzoneClusterConfig config = LocalOzoneClusterConfig .builder (
68+ tempDir .resolve ("local-ozone-s3-sdk" ))
69+ .setS3AccessKey ("localuser" )
70+ .setS3SecretKey ("localsecret" )
71+ .setStartupTimeout (Duration .ofMinutes (3 ))
72+ .build ();
73+
74+ String bucketName = "local-" + UUID .randomUUID ().toString ().replace ("-" , "" );
75+ String keyName = "key-" + UUID .randomUUID ().toString ().replace ("-" , "" );
76+ String payload = "local-ozone-s3" ;
77+
78+ try (LocalOzoneCluster cluster = new LocalOzoneCluster (config , new OzoneConfiguration ())) {
79+ cluster .start ();
80+
81+ try (S3Client client = S3Client .builder ()
82+ .region (Region .of (config .getS3Region ()))
83+ .endpointOverride (URI .create (cluster .getS3Endpoint ()))
84+ .credentialsProvider (StaticCredentialsProvider .create (
85+ AwsBasicCredentials .create (config .getS3AccessKey (), config .getS3SecretKey ())))
86+ .forcePathStyle (true )
87+ .build ()) {
88+ client .createBucket (builder -> builder .bucket (bucketName ));
89+
90+ ListBucketsResponse buckets = client .listBuckets ();
91+ assertTrue (buckets .buckets ().stream ()
92+ .anyMatch (bucket -> bucketName .equals (bucket .name ())));
93+
94+ client .putObject (builder -> builder .bucket (bucketName ).key (keyName ),
95+ RequestBody .fromString (payload ));
96+
97+ ResponseBytes <GetObjectResponse > response = client .getObjectAsBytes (
98+ builder -> builder .bucket (bucketName ).key (keyName ));
99+ assertEquals (payload , response .asUtf8String ());
100+ }
101+ }
102+ }
103+
53104 private static void assertS3EndpointResponds (String endpoint ) throws Exception {
54105 HttpURLConnection connection = (HttpURLConnection ) new URL (endpoint ).openConnection ();
55106 try {
0 commit comments