danielcweeks commented on code in PR #18817:
URL: https://github.com/apache/iceberg/pull/18817#discussion_r4668076206


##########
core/src/test/java/org/apache/iceberg/io/TestResolvingIO.java:
##########
@@ -182,4 +182,92 @@ public void 
resolvingFileIOWithStorageCredentialsSerialization(
         .isEqualTo(storageCredentials)
         .isEqualTo(resolvingFileIO.credentials());
   }
+
+  @Test
+  void delegateKeepsItsRefreshedCredentials() {
+    List<StorageCredential> initial =
+        ImmutableList.of(StorageCredential.create("prefix", Map.of("key", 
"initial")));
+    List<StorageCredential> refreshed =
+        ImmutableList.of(StorageCredential.create("prefix", Map.of("key", 
"refreshed")));
+    ResolvingFileIO resolvingFileIO = resolvingFileIOWithCredentialsDelegate();
+    resolvingFileIO.setCredentials(initial);
+
+    FileIOWithCredentials delegate = (FileIOWithCredentials) 
resolvingFileIO.io("delegate://file");
+    assertThat(delegate.credentials()).isEqualTo(initial);
+
+    // the delegate refreshes its credentials without going through 
ResolvingFileIO
+    delegate.refreshCredentials(refreshed);
+    resolvingFileIO.newInputFile("delegate://file");
+
+    assertThat(resolvingFileIO.io("delegate://file")).isSameAs(delegate);
+    assertThat(delegate.credentials()).isEqualTo(refreshed);
+  }

Review Comment:
   The description says a FileIO serialized after a reset carries the old 
credentials, but we don't test that. 
`resolvingFileIOWithStorageCredentialsSerialization` only round-trips 
`ResolvingFileIO.credentials()`, and that still returns the table-load 
credentials. `ioInstances` is serialized along with the delegates, so can we 
add a parameterized case using `TestHelpers#serializers` that checks the 
refreshed delegate credentials survive the round trip? The spy won't survive 
serialization, so you'll need to stub `implFromLocation` again on the 
deserialized instance.
   
   <!-- lenses: nastra-test-review, russell-review -->



##########
core/src/test/java/org/apache/iceberg/io/TestResolvingIO.java:
##########
@@ -182,4 +182,92 @@ public void 
resolvingFileIOWithStorageCredentialsSerialization(
         .isEqualTo(storageCredentials)
         .isEqualTo(resolvingFileIO.credentials());
   }
+
+  @Test
+  void delegateKeepsItsRefreshedCredentials() {
+    List<StorageCredential> initial =
+        ImmutableList.of(StorageCredential.create("prefix", Map.of("key", 
"initial")));
+    List<StorageCredential> refreshed =
+        ImmutableList.of(StorageCredential.create("prefix", Map.of("key", 
"refreshed")));
+    ResolvingFileIO resolvingFileIO = resolvingFileIOWithCredentialsDelegate();
+    resolvingFileIO.setCredentials(initial);
+
+    FileIOWithCredentials delegate = (FileIOWithCredentials) 
resolvingFileIO.io("delegate://file");
+    assertThat(delegate.credentials()).isEqualTo(initial);
+
+    // the delegate refreshes its credentials without going through 
ResolvingFileIO
+    delegate.refreshCredentials(refreshed);
+    resolvingFileIO.newInputFile("delegate://file");
+
+    assertThat(resolvingFileIO.io("delegate://file")).isSameAs(delegate);
+    assertThat(delegate.credentials()).isEqualTo(refreshed);
+  }
+
+  @Test
+  void setCredentialsUpdatesExistingDelegates() {
+    List<StorageCredential> initial =
+        ImmutableList.of(StorageCredential.create("prefix", Map.of("key", 
"initial")));
+    List<StorageCredential> updated =
+        ImmutableList.of(StorageCredential.create("prefix", Map.of("key", 
"updated")));
+    ResolvingFileIO resolvingFileIO = resolvingFileIOWithCredentialsDelegate();
+    resolvingFileIO.setCredentials(initial);
+    FileIOWithCredentials delegate = (FileIOWithCredentials) 
resolvingFileIO.io("delegate://file");
+
+    resolvingFileIO.setCredentials(updated);
+
+    assertThat(delegate.credentials()).isEqualTo(updated);
+    assertThat(resolvingFileIO.credentials()).isEqualTo(updated);
+  }
+
+  private static ResolvingFileIO resolvingFileIOWithCredentialsDelegate() {
+    ResolvingFileIO resolvingFileIO = spy(new ResolvingFileIO());
+    resolvingFileIO.setConf(new Configuration());
+    resolvingFileIO.initialize(ImmutableMap.of());
+    
doReturn(FileIOWithCredentials.class.getName()).when(resolvingFileIO).implFromLocation(any());
+    return resolvingFileIO;
+  }
+
+  public static class FileIOWithCredentials implements DelegateFileIO, 
SupportsStorageCredentials {
+    private List<StorageCredential> storageCredentials = ImmutableList.of();
+
+    public FileIOWithCredentials() {}

Review Comment:
   nit: we don't need the explicit no-arg constructor here. The implicit 
default constructor is already public, so `CatalogUtil.loadFileIO` can still 
instantiate it. Can we remove it?
   
   <!-- lenses: weeks-review, nastra-test-review -->



##########
core/src/main/java/org/apache/iceberg/io/ResolvingFileIO.java:
##########
@@ -284,6 +279,11 @@ public void setCredentials(List<StorageCredential> 
credentials) {
     Preconditions.checkArgument(credentials != null, "Invalid storage 
credentials: null");
     // copy credentials into a modifiable collection for Kryo serde
     this.storageCredentials = Lists.newArrayList(credentials);
+    for (DelegateFileIO io : ioInstances.values()) {
+      if (io instanceof SupportsStorageCredentials ioWithCredentials) {

Review Comment:
   nit: no test covers a delegate in `ioInstances` that doesn't implement 
`SupportsStorageCredentials`. Could we load a `HadoopFileIO` delegate first, 
then call `setCredentials(updated)` and check that `credentials()` is updated 
and the delegate is the same instance?
   
   <!-- lenses: nastra-test-review -->



-- 
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]

Reply via email to