### Question:
DestructiveReplica { public void dropDeletedPartitions(final List<String> sourcePartitionNames) throws TException { try (CloseableMetaStoreClient client = replicaMetaStoreClientSupplier.get()) { if (!client.tableExists(databaseName, tableName)) { return; } dropAndDeletePartitions(client, new Predicate<String>() { @Override public boolean apply(String partitionName) { return !sourcePartitionNames.contains(partitionName); } }); } 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 dropDeletedPartitions() 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); List<String> sourcePartitionNames = Lists.newArrayList(); replica.dropDeletedPartitions(sourcePartitionNames); verify(client).dropPartition(DATABASE, REPLICA_TABLE, "part1=value1", false); verify(client).dropPartition(DATABASE, REPLICA_TABLE, "part1=value2", false); verify(cleanupLocationManager).addCleanupLocation(EVENT_ID, location1); verify(cleanupLocationManager).addCleanupLocation(EVENT_ID, location2); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }
@Test public void dropDeletedPartitionsTableDoesNotExist() throws Exception { when(client.tableExists(DATABASE, REPLICA_TABLE)).thenReturn(false); replica.dropDeletedPartitions(Lists.<String> newArrayList()); verify(client, never()).dropPartition(eq(DATABASE), eq(REPLICA_TABLE), anyString(), anyBoolean()); verify(cleanupLocationManager, never()).addCleanupLocation(anyString(), any(Path.class)); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }
@Test public void dropDeletedPartitionsNothingToDrop() throws Exception { when(client.getTable(DATABASE, REPLICA_TABLE)).thenReturn(table); Partition replicaPartition = new Partition(); replicaPartition.setValues(Lists.newArrayList("value1")); List<Partition> replicaPartitions = Lists.newArrayList(replicaPartition); mockPartitionIterator(replicaPartitions); List<String> sourcePartitionNames = Lists.newArrayList("part1=value1"); replica.dropDeletedPartitions(sourcePartitionNames); verify(client, never()).dropPartition(DATABASE, REPLICA_TABLE, "part1=value1", false); verify(cleanupLocationManager, never()).addCleanupLocation(anyString(), any(Path.class)); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }
@Test public void dropDeletedPartitionsUnpartitionedTable() throws Exception { table.setPartitionKeys(null); when(client.getTable(DATABASE, REPLICA_TABLE)).thenReturn(table); List<String> sourcePartitionNames = Lists.newArrayList(); replica.dropDeletedPartitions(sourcePartitionNames); verify(client, never()).dropPartition(eq(DATABASE), eq(REPLICA_TABLE), anyString(), eq(false)); verify(cleanupLocationManager, never()).addCleanupLocation(anyString(), any(Path.class)); verify(client).close(); verify(cleanupLocationManager).scheduleLocations(); }