brucearctor commented on code in PR #13891:
URL: https://github.com/apache/gravitino/pull/13891#discussion_r4588592215
##########
clients/filesystem-hadoop3/src/test/java/org/apache/gravitino/filesystem/hadoop/TestFilesetMetadataCache.java:
##########
@@ -118,4 +123,41 @@ public void testNonFilesetCatalogIsNotCached() throws
IOException {
// The failed load is not cached, so the second call loads the catalog
again.
verify(client, times(2)).loadCatalog("catalog");
}
+
+ @Test
+ public void testCacheReusesCatalogSchemaAndFileset() throws IOException {
+ GravitinoClient client = mock(GravitinoClient.class);
+ Catalog catalog = mock(Catalog.class);
+ FilesetCatalog filesetCatalog = mock(FilesetCatalog.class);
+ SupportsSchemas schemas = mock(SupportsSchemas.class);
+ Schema schema = mock(Schema.class);
+ Fileset fileset = mock(Fileset.class);
+
+ when(client.loadCatalog("catalog")).thenReturn(catalog);
+ when(catalog.asFilesetCatalog()).thenReturn(filesetCatalog);
+ when(catalog.asSchemas()).thenReturn(schemas);
+ when(schemas.loadSchema("schema")).thenReturn(schema);
+ when(filesetCatalog.loadFileset(NameIdentifier.of("schema",
"fs"))).thenReturn(fileset);
+
+ NameIdentifier catalogIdent = NameIdentifier.of("ml", "catalog");
+ NameIdentifier schemaIdent = NameIdentifier.of("ml", "catalog", "schema");
+ NameIdentifier filesetIdent = NameIdentifier.of("ml", "catalog", "schema",
"fs");
+
+ try (FilesetMetadataCache cache = new FilesetMetadataCache(client)) {
+ assertSame(catalog, cache.getCatalog(catalogIdent));
+ assertSame(filesetCatalog, cache.getFilesetCatalog(catalogIdent));
+ assertSame(schema, cache.getSchema(schemaIdent));
+ assertSame(fileset, cache.getFileset(filesetIdent));
+
+ // Second round should all hit caches.
+ assertSame(catalog, cache.getCatalog(catalogIdent));
+ assertSame(filesetCatalog, cache.getFilesetCatalog(catalogIdent));
+ assertSame(schema, cache.getSchema(schemaIdent));
+ assertSame(fileset, cache.getFileset(filesetIdent));
Review Comment:
Addressed in 2c4ace1c6 — added `clearInvocations(catalog)` immediately
before the second `cache.getFileset(filesetIdent)` and verified
`verify(catalog, never()).asFilesetCatalog()`.
--
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]