nastra commented on code in PR #16112:
URL: https://github.com/apache/iceberg/pull/16112#discussion_r3166159055
##########
aws/src/test/java/org/apache/iceberg/aws/s3/TestS3FileIOCredentialRefresh.java:
##########
@@ -265,4 +266,85 @@ public void credentialRefreshWithinFiveMinuteWindow() {
});
}
}
+
+ @Test
+ public void refreshedCredentialsAreKryoSerializable() throws Exception {
+ // Verify that an S3FileIO whose credentials have been refreshed at
runtime can still be
+ // round-tripped through Kryo. The internal storageCredentials list must
be backed by a
+ // collection that Kryo can serialize and deserialize.
+ String nearExpiryMs = Long.toString(Instant.now().plus(3,
ChronoUnit.MINUTES).toEpochMilli());
+
+ StorageCredential initialCredential =
+ StorageCredential.create(
+ "s3://bucket/path",
+ ImmutableMap.of(
+ S3FileIOProperties.ACCESS_KEY_ID,
+ "initialAccessKey",
+ S3FileIOProperties.SECRET_ACCESS_KEY,
+ "initialSecretKey",
+ S3FileIOProperties.SESSION_TOKEN,
+ "initialToken",
+ S3FileIOProperties.SESSION_TOKEN_EXPIRES_AT_MS,
+ nearExpiryMs));
+
+ String refreshedExpiryMs =
+ Long.toString(Instant.now().plus(1, ChronoUnit.HOURS).toEpochMilli());
+ LoadCredentialsResponse refreshResponse =
+ ImmutableLoadCredentialsResponse.builder()
+ .addCredentials(
+ ImmutableCredential.builder()
+ .prefix("s3://bucket/path")
+ .config(
+ ImmutableMap.of(
+ S3FileIOProperties.ACCESS_KEY_ID,
+ "refreshedAccessKey",
+ S3FileIOProperties.SECRET_ACCESS_KEY,
+ "refreshedSecretKey",
+ S3FileIOProperties.SESSION_TOKEN,
+ "refreshedToken",
+ S3FileIOProperties.SESSION_TOKEN_EXPIRES_AT_MS,
+ refreshedExpiryMs))
+ .build())
+ .build();
+
+ HttpRequest mockRequest =
request("/v1/credentials").withMethod(HttpMethod.GET.name());
+ mockServer
+ .when(mockRequest)
+ .respond(
+
response(LoadCredentialsResponseParser.toJson(refreshResponse)).withStatusCode(200));
+
+ Map<String, String> properties =
+ ImmutableMap.of(
+ AwsProperties.CLIENT_FACTORY,
+ StaticClientFactory.class.getName(),
+ VendedCredentialsProvider.URI,
+ CREDENTIALS_URI,
+ CatalogProperties.URI,
+ CATALOG_URI,
+ "init-creation-stacktrace",
+ "false");
+
+ StaticClientFactory.client = null;
+ try (S3FileIO fileIO = new S3FileIO()) {
+ fileIO.initialize(properties);
+ fileIO.setCredentials(List.of(initialCredential));
+
+ fileIO.client();
+
+ // Wait for the refresh to update the in-memory credentials
+ Awaitility.await()
+ .atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(
+ () -> {
+ List<StorageCredential> credentials = fileIO.credentials();
Review Comment:
can be simplified to
```
Awaitility.await()
.atMost(10, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertThat(fileIO.credentials().get(0).config())
.containsEntry(S3FileIOProperties.ACCESS_KEY_ID,
"refreshedAccessKey"));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]