@Test
  public void testSynchronizationWithLegacyTableRuntimeAndNonExistingIcebergTable() {
    ExternalCatalog externalCatalog = initExternalCatalog();
    // Simulate the anomaly scenario by only removing the table runtime in the persistent table
    // after dropping table
    createTable();
    dropTableOnly();
    persistency.deleteTableIdentifier(
        serverTableIdentifier().getIdentifier().buildTableIdentifier());

    // Verify that the table is dropped
    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<ServerTableIdentifier> serverTableIdentifierList = tableManager().listManagedTables();
    List<TableRuntimeMeta> tableRuntimeMetaListForOptimizerGroup =
        persistency.getTableRuntimeMetasForOptimizerGroup(defaultResourceGroup().getName());
    Assert.assertEquals(0, serverTableIdentifierList.size());
    Assert.assertEquals(1, tableRuntimeMetaListForOptimizerGroup.size());

    // Verify that the synchronization does not work by firing exploreExternalCatalog
    tableService().exploreExternalCatalog(externalCatalog);

    List<ServerTableIdentifier> serverTableIdentifierListAfterSync =
        tableManager().listManagedTables();
    List<TableRuntimeMeta> tableRuntimeMetaListForOptimizerGroupAfterSync =
        persistency.getTableRuntimeMetasForOptimizerGroup(defaultResourceGroup().getName());
    Assert.assertEquals(0, serverTableIdentifierListAfterSync.size());
    Assert.assertEquals(1, tableRuntimeMetaListForOptimizerGroupAfterSync.size());

    // The existed tableRuntime will prevent the table from being added again
    Assert.assertThrows(IndexOutOfBoundsException.class, this::createTable);

    MetricRegistry globalRegistry = MetricManager.getInstance().getGlobalRegistry();
    globalRegistry.getMetrics().keySet().forEach(globalRegistry::unregister);
    persistency.deleteTableRuntime(serverTableIdentifier().getId());
    dropTable();
    dropDatabase();
  }
Test synchronization in the anomaly scenario where the tableRuntime is remained but iceberg
table does not exist.

<p>NOTE: exploreExternalCatalog does not work.
amoro-ams/src/test/java/org/apache/amoro/server/table/TestSyncTableOfExternalCatalog.java