tokoko commented on code in PR #3224:
URL: https://github.com/apache/polaris/pull/3224#discussion_r2604049684


##########
polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java:
##########
@@ -135,10 +144,133 @@ public void testCacheHit() {
         true,
         Set.of("s3://bucket1/path", "s3://bucket2/path"),
         Set.of("s3://bucket3/path", "s3://bucket4/path"),
+        polarisPrincipal,
+        Optional.empty());
+    
Assertions.assertThat(storageCredentialCache.getEstimatedSize()).isEqualTo(1);
+
+    Optional<PolarisPrincipal> emptyPrincipal = Optional.empty();
+
+    storageCredentialCache.getOrGenerateSubScopeCreds(
+        storageCredentialsVendor,
+        polarisEntity,
+        true,
+        Set.of("s3://bucket1/path", "s3://bucket2/path"),
+        Set.of("s3://bucket3/path", "s3://bucket4/path"),
+        polarisPrincipal,
         Optional.empty());
     
Assertions.assertThat(storageCredentialCache.getEstimatedSize()).isEqualTo(1);
   }
 
+  @Test
+  public void testCacheMissForAnotherPrincipal() {
+
+    List<ScopedCredentialsResult> mockedScopedCreds =
+        getFakeScopedCreds(3, /* expireSoon= */ false);
+    Mockito.when(
+            storageCredentialsVendor.getSubscopedCredsForEntity(
+                Mockito.any(),
+                Mockito.anyBoolean(),
+                Mockito.anySet(),
+                Mockito.anySet(),
+                Mockito.any(),
+                Mockito.any()))
+        .thenReturn(mockedScopedCreds.get(0))
+        .thenReturn(mockedScopedCreds.get(1))
+        .thenReturn(mockedScopedCreds.get(1));
+    PolarisBaseEntity baseEntity =
+        new PolarisBaseEntity(
+            1, 2, PolarisEntityType.CATALOG, 
PolarisEntitySubType.ICEBERG_TABLE, 0, "name");
+    PolarisEntity polarisEntity = new PolarisEntity(baseEntity);
+    PolarisPrincipal polarisPrincipal = PolarisPrincipal.of("principal", 
Map.of(), Set.of());
+    PolarisPrincipal anotherPolarisPrincipal =
+        PolarisPrincipal.of("anotherPrincipal", Map.of(), Set.of());
+
+    // add an item to the cache
+    storageCredentialCache.getOrGenerateSubScopeCreds(
+        storageCredentialsVendor,
+        polarisEntity,
+        true,
+        Set.of("s3://bucket1/path", "s3://bucket2/path"),
+        Set.of("s3://bucket3/path", "s3://bucket4/path"),
+        polarisPrincipal,
+        Optional.empty());
+    
Assertions.assertThat(storageCredentialCache.getEstimatedSize()).isEqualTo(1);
+
+    // subscope for the same entity and same allowed locations, will hit the 
cache
+    storageCredentialCache.getOrGenerateSubScopeCreds(
+        storageCredentialsVendor,
+        polarisEntity,
+        true,
+        Set.of("s3://bucket1/path", "s3://bucket2/path"),
+        Set.of("s3://bucket3/path", "s3://bucket4/path"),
+        anotherPolarisPrincipal,
+        Optional.empty());
+    
Assertions.assertThat(storageCredentialCache.getEstimatedSize()).isEqualTo(1);
+  }
+
+  @Test
+  public void testCacheHitForAnotherPrincipal() {
+    Mockito.when(storageCredentialsVendor.getRealmConfig())

Review Comment:
   done



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

Reply via email to