@Test
  public void testSynchronizationWithLegacyTableIdentifierAndNonExistingIcebergTable() {
    // Simulate the anomaly scenario by only adding the table identifier in the persistent table
    createDatabase();
    ExternalCatalog externalCatalog = initExternalCatalog();

    persistency.addTableIdentifier(
        TEST_CATALOG_NAME, TEST_DB_NAME, TEST_TABLE_NAME, TableFormat.ICEBERG);

    // Verify that the table not exists
    List<TableIDWithFormat> tableIdentifierList =
        catalogManager().getServerCatalog(TEST_CATALOG_NAME).listTables(TEST_DB_NAME);
    Assert.assertEquals(0, tableIdentifierList.size());

    // Verify that the tables do not match exactly in tableIdentifier and tableRuntime
    List<TableRuntimeMeta> tableRuntimeMetaList = persistency.getTableRuntimeMetas();
    List<ServerTableIdentifier> serverTableIdentifierList = tableManager().listManagedTables();
    Assert.assertEquals(0, tableRuntimeMetaList.size());
    Assert.assertEquals(1, serverTableIdentifierList.size());

    // Verify that the synchronization works by firing exploreExternalCatalog
    tableService().exploreExternalCatalog(externalCatalog);

    List<TableRuntimeMeta> tableRuntimeMetaListAfterSync = persistency.getTableRuntimeMetas();
    List<ServerTableIdentifier> serverTableIdentifierListAfterSync =
        tableManager().listManagedTables();
    Assert.assertEquals(0, tableRuntimeMetaListAfterSync.size());
    Assert.assertEquals(0, serverTableIdentifierListAfterSync.size());

    dropDatabase();
  }
Test synchronization in the anomaly scenario where the tableIdentifier is remained in
persistence but iceberg table does not exist.
amoro-ams/src/test/java/org/apache/amoro/server/table/TestSyncTableOfExternalCatalog.java