@Test
  public void testDisposeTableRuntimeFailure() {
    createTable();
    ServerTableIdentifier tableIdentifier = serverTableIdentifier();

    // test list tables
    List<TableRuntimeMeta> tableRuntimeMetaListAfterAddTable = persistency.getTableRuntimeMetas();
    List<TableRuntimeMeta> tableRuntimeMetaListForOptimizerGroupAfterAddTable =
        persistency.getTableRuntimeMetasForOptimizerGroup(defaultResourceGroup().getName());
    Assert.assertEquals(1, tableRuntimeMetaListForOptimizerGroupAfterAddTable.size());
    Assert.assertEquals(1, tableRuntimeMetaListAfterAddTable.size());

    DefaultTableRuntime tableRuntime = tableService().getRuntime(tableIdentifier.getId());
    // create a tableIdentifier that throw exceptions when calling the getTableName() method, which
    // can lead to exceptions when deleting tableIdentifier in disposeTable().
    try (AutoCloseable ignored = MockitoAnnotations.openMocks(this)) {
      when(tableRuntimeWithException.getTableIdentifier())
          .thenReturn(tableRuntime.getTableIdentifier());

      tableService().setRuntime(tableRuntimeWithException);
      when(tableRuntimeWithException.getFormat())
          .thenThrow(new RuntimeException("get table format error"));
      Assert.assertThrows(
          "get table format error",
          RuntimeException.class,
          () -> tableService().disposeTable(tableIdentifier));

      // test list tables after disposing table
      // Because the doAsTransaction() method is used, when a tableIdentifier deletion exception
      // occurs, the tableRuntime and tableIdentifier will remain consistent and neither will
      // actually be deleted.
      List<TableRuntimeMeta> tableRuntimeMetaListAfterDropTable =
          persistency.getTableRuntimeMetas();
      List<TableRuntimeMeta> tableRuntimeMetaListForOptimizerGroupAfterDropTable =
          persistency.getTableRuntimeMetasForOptimizerGroup(defaultResourceGroup().getName());
      Assert.assertEquals(1, tableRuntimeMetaListForOptimizerGroupAfterDropTable.size());
      Assert.assertEquals(1, tableRuntimeMetaListAfterDropTable.size());

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    tableService().setRuntime(tableRuntime);
    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