@Test
  public void
      testSynchronizationWithLegacyTableIdentifierAndLegacyTableRuntimeAndNonExistingIcebergTable() {
    ExternalCatalog externalCatalog = initExternalCatalog();
    // Simulate the anomaly scenario by only removing the table runtime in the persistent table
    // after dropping table
    createTable();
    dropTableOnly();
    List<TableRuntimeMeta> tableRuntimeMetaListForOptimizerGroup =
        persistency.getTableRuntimeMetasForOptimizerGroup(defaultResourceGroup().getName());
    persistency.deleteTableRuntime(tableRuntimeMetaListForOptimizerGroup.get(0).getTableId());

    // 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<TableRuntimeMeta> tableRuntimeMetaList = persistency.getTableRuntimeMetas();
    List<ServerTableIdentifier> serverTableIdentifierList = tableManager().listManagedTables();
    Assert.assertEquals(1, serverTableIdentifierList.size());
    Assert.assertEquals(0, tableRuntimeMetaList.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, serverTableIdentifierListAfterSync.size());
    Assert.assertEquals(0, tableRuntimeMetaListAfterSync.size());

    // Verify that recreating the table works
    createTable();
    tableRuntimeMetaListAfterSync = persistency.getTableRuntimeMetas();
    serverTableIdentifierListAfterSync = tableManager().listManagedTables();
    Assert.assertEquals(1, serverTableIdentifierListAfterSync.size());
    Assert.assertEquals(1, tableRuntimeMetaListAfterSync.size());

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