klion26 commented on code in PR #3534:
URL: https://github.com/apache/amoro/pull/3534#discussion_r2062773713
##########
amoro-ams/src/test/java/org/apache/amoro/server/table/TestSyncTableOfExternalCatalog.java:
##########
@@ -239,6 +257,194 @@ public void
testSynchronizationWithLegacyTableRuntimeAndNonExistingIcebergTable(
dropDatabase();
}
+ @Mock private ExternalCatalog externalCatalog;
+
+ @Test
+ public void exploreExternalCatalog_ListDatabasesException() {
+ createTable();
+ ServerCatalog originalCatalog =
catalogManager().getServerCatalog(TEST_CATALOG_NAME);
+
+ // test list tables
+ List<TableRuntimeMeta> tableRuntimeMetaListAfterAddTable =
persistency.getTableRuntimeMetas();
+ Assert.assertEquals(1, tableRuntimeMetaListAfterAddTable.size());
+
+ MockitoAnnotations.openMocks(this);
+ when(externalCatalog.name()).thenReturn(TEST_CATALOG_NAME);
+ when(externalCatalog.toString()).thenReturn(originalCatalog.toString());
+
when(externalCatalog.getMetadata()).thenReturn(originalCatalog.getMetadata());
+ when(externalCatalog.listDatabases()).thenThrow(new RuntimeException("List
databases error"));
+
+ // This should throw an exception
+ Assert.assertThrows(
+ "List databases error",
+ RuntimeException.class,
+ () -> tableService().exploreExternalCatalog(externalCatalog));
+
+ verify(externalCatalog, times(1)).listDatabases();
+
+ // test tableRuntime not removed
+ List<TableRuntimeMeta> tableRuntimeMetaListAfterExploreCatalog =
+ persistency.getTableRuntimeMetas();
+ Assert.assertEquals(1, tableRuntimeMetaListAfterExploreCatalog.size());
+
+ dropTable();
+ dropDatabase();
+ }
+
+ @Test
+ public void exploreExternalCatalog_ListTablesException() {
+ createTable();
+ ServerCatalog originalCatalog =
catalogManager().getServerCatalog(TEST_CATALOG_NAME);
+
+ // test list tables
+ List<TableRuntimeMeta> tableRuntimeMetaListAfterAddTable =
persistency.getTableRuntimeMetas();
+ Assert.assertEquals(1, tableRuntimeMetaListAfterAddTable.size());
+
+ MockitoAnnotations.openMocks(this);
Review Comment:
Currently, there are many `mock`s in the tests; we can avoid `mock`s as much
as possible because using mocks may prevent the test from sensing actual
changes and thus fail to initiate corresponding actions.
But this does not need to be done in this PR, we can do it later.
--
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]