nastra commented on code in PR #16112:
URL: https://github.com/apache/iceberg/pull/16112#discussion_r3166162744
##########
gcp/src/test/java/org/apache/iceberg/gcp/gcs/TestGCSFileIOCredentialRefresh.java:
##########
@@ -226,4 +227,72 @@ void credentialRefreshWithinFiveMinuteWindow() {
});
}
}
+
+ @Test
+ void refreshedCredentialsAreKryoSerializable() throws Exception {
+ // Verify that a GCSFileIO 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(
+ "gs://bucket/path",
+ ImmutableMap.of(
+ GCPProperties.GCS_OAUTH2_TOKEN,
+ "initialToken",
+ GCPProperties.GCS_OAUTH2_TOKEN_EXPIRES_AT,
+ nearExpiryMs));
+
+ String refreshedExpiryMs =
+ Long.toString(Instant.now().plus(1, ChronoUnit.HOURS).toEpochMilli());
+ LoadCredentialsResponse refreshResponse =
+ ImmutableLoadCredentialsResponse.builder()
+ .addCredentials(
+ ImmutableCredential.builder()
+ .prefix("gs://bucket/path")
+ .config(
+ ImmutableMap.of(
+ GCPProperties.GCS_OAUTH2_TOKEN,
+ "refreshedToken",
+ GCPProperties.GCS_OAUTH2_TOKEN_EXPIRES_AT,
+ 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(
+ GCPProperties.GCS_OAUTH2_REFRESH_CREDENTIALS_ENDPOINT,
+ credentialsUri,
+ CatalogProperties.URI,
+ catalogUri);
+
+ try (GCSFileIO fileIO = new GCSFileIO()) {
+ 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:
same as above
##########
gcp/src/test/java/org/apache/iceberg/gcp/gcs/TestGCSFileIOCredentialRefresh.java:
##########
@@ -226,4 +227,72 @@ void credentialRefreshWithinFiveMinuteWindow() {
});
}
}
+
+ @Test
+ void refreshedCredentialsAreKryoSerializable() throws Exception {
+ // Verify that a GCSFileIO 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(
+ "gs://bucket/path",
+ ImmutableMap.of(
+ GCPProperties.GCS_OAUTH2_TOKEN,
+ "initialToken",
+ GCPProperties.GCS_OAUTH2_TOKEN_EXPIRES_AT,
+ nearExpiryMs));
+
+ String refreshedExpiryMs =
+ Long.toString(Instant.now().plus(1, ChronoUnit.HOURS).toEpochMilli());
+ LoadCredentialsResponse refreshResponse =
+ ImmutableLoadCredentialsResponse.builder()
+ .addCredentials(
+ ImmutableCredential.builder()
+ .prefix("gs://bucket/path")
+ .config(
+ ImmutableMap.of(
+ GCPProperties.GCS_OAUTH2_TOKEN,
+ "refreshedToken",
+ GCPProperties.GCS_OAUTH2_TOKEN_EXPIRES_AT,
+ 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(
+ GCPProperties.GCS_OAUTH2_REFRESH_CREDENTIALS_ENDPOINT,
+ credentialsUri,
+ CatalogProperties.URI,
+ catalogUri);
+
+ try (GCSFileIO fileIO = new GCSFileIO()) {
+ 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();
+ assertThat(credentials).hasSize(1);
+ assertThat(credentials.get(0).config())
+ .containsEntry(GCPProperties.GCS_OAUTH2_TOKEN,
"refreshedToken");
+ });
+
+ // Round-trip through Kryo and verify the credentials still match
+ GCSFileIO deserialized =
TestHelpers.KryoHelpers.roundTripSerialize(fileIO);
+ assertThat(deserialized.credentials()).isEqualTo(fileIO.credentials());
Review Comment:
same as above
--
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]