### Question:
DestructiveReplica { public void dropTable() throws TException { try { try (CloseableMetaStoreClient client = replicaMetaStoreClientSupplier.get()) { if (!client.tableExists(databaseName, tableName)) { return; } dropAndDeletePartitions(client, Predicates.<String> alwaysTrue()); Table table = client.getTable(databaseName, tableName); log.info("Dropping replica table: " + databaseName + "." + tableName); client.dropTable(databaseName, tableName, DELETE_DATA, IGNORE_UNKNOWN); Path oldLocation = locationAsPath(table); String oldEventId = table.getParameters().get(REPLICATION_EVENT.parameterName()); cleanupLocationManager.addCleanupLocation(oldEventId, oldLocation); } } finally { cleanupLocationManager.scheduleLocations(); } } DestructiveReplica(
      Supplier<CloseableMetaStoreClient> replicaMetaStoreClientSupplier,
      CleanupLocationManager cleanupLocationManager,
      TableReplication tableReplication); boolean tableIsUnderCircusTrainControl(); void dropDeletedPartitions(final List<String> sourcePartitionNames); void dropTable();  }### Answer:
@Test public void dropTablePartitioned() throws Exception { when(client.tableExists(DATABASE, REPLICA_TABLE)).thenReturn(true); when(client.getTable(DATABASE, REPLICA_TABLE)).thenReturn(table); Path location1 = new Path("loc1"); Partition replicaPartition1 = newPartition("value1", location1); Path location2 = new Path("loc2"); Partition replicaPartition2 = newPartition("value2", location2); List<Partition> replicaPartitions = Lists.newArrayList(replicaPartition1, replicaPartition2); mockPartitionIterator(replicaPartitions); replica.dropTable(); verify(client).dropPartition(DATABASE, REPLICA_TABLE, "part1=value1", false); verify(client).dropPartition(DATABASE, REPLICA_TABLE, "part1=value2", false); verify(client).dropTable(DATABASE, REPLICA_TABLE, false, true); verify(cleanupLocationManager).addCleanupLocation(EVENT_ID, location1); verify(cleanupLocationManager).addCleanupLocation(EVENT_ID, location2); verify(cleanupLocationManager).addCleanupLocation(EVENT_ID, tableLocation); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }
@Test public void dropTableButTableDoesNotExist() throws Exception { when(client.tableExists(DATABASE, REPLICA_TABLE)).thenReturn(false); List<Partition> replicaPartitions = Lists.newArrayList(); mockPartitionIterator(replicaPartitions); replica.dropTable(); verify(client, never()).dropPartition(eq(DATABASE), eq(REPLICA_TABLE), anyString(), anyBoolean()); verify(client, never()).dropTable(eq(DATABASE), eq(REPLICA_TABLE), anyBoolean(), anyBoolean()); verify(cleanupLocationManager, never()).addCleanupLocation(anyString(), any(Path.class)); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }
@Test public void dropTableUnpartitioned() throws Exception { when(client.tableExists(DATABASE, REPLICA_TABLE)).thenReturn(true); table.setPartitionKeys(null); when(client.getTable(DATABASE, REPLICA_TABLE)).thenReturn(table); replica.dropTable(); verify(client).dropTable(DATABASE, REPLICA_TABLE, false, true); verify(cleanupLocationManager).addCleanupLocation(EVENT_ID, tableLocation); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }