### Question:
PartitionedTableMetadataMirrorReplication implements Replication { @Override public void replicate() throws CircusTrainException { try { TableAndStatistics sourceTableAndStatistics = source.getTableAndStatistics(database, table); Table sourceTable = sourceTableAndStatistics.getTable(); PartitionsAndStatistics sourcePartitionsAndStatistics = source .getPartitions(sourceTable, partitionPredicate.getPartitionPredicate(), partitionPredicate.getPartitionPredicateLimit()); List<Partition> sourcePartitions = sourcePartitionsAndStatistics.getPartitions(); replica.validateReplicaTable(replicaDatabaseName, replicaTableName); SourceLocationManager sourceLocationManager = source .getLocationManager(sourceTable, sourcePartitions, eventId, Collections.<String, Object>emptyMap()); ReplicaLocationManager replicaLocationManager = new MetadataMirrorReplicaLocationManager(sourceLocationManager, TableType.PARTITIONED); sourceLocationManager.cleanUpLocations(); if (sourcePartitions.isEmpty()) { LOG.debug("Update table {}.{} metadata only", database, table); replica .updateMetadata(eventId, sourceTableAndStatistics, replicaDatabaseName, replicaTableName, replicaLocationManager); LOG .info( "No matching partitions found on table {}.{} with predicate {}. Table metadata updated, no partitions were updated.", database, table, partitionPredicate); } else { replica .updateMetadata(eventId, sourceTableAndStatistics, sourcePartitionsAndStatistics, replicaDatabaseName, replicaTableName, replicaLocationManager); int partitionsCopied = sourcePartitions.size(); LOG .info("Metadata mirrored for {} partitions of table {}.{} (no data copied).", partitionsCopied, database, table); } } catch (Throwable t) { throw new CircusTrainException("Unable to replicate", t); } } PartitionedTableMetadataMirrorReplication(
      String database,
      String table,
      PartitionPredicate partitionPredicate,
      Source source,
      Replica replica,
      EventIdFactory eventIdFactory,
      String replicaDatabaseName,
      String replicaTableName); @Override void replicate(); @Override String name(); @Override String getEventId();  }### Answer:
@Test public void typical() throws Exception { when(source.getPartitions(sourceTable, PARTITION_PREDICATE, MAX_PARTITIONS)).thenReturn(partitionsAndStatistics); PartitionedTableMetadataMirrorReplication replication = new PartitionedTableMetadataMirrorReplication(DATABASE, TABLE, partitionPredicate, source, replica, eventIdFactory, DATABASE, TABLE); replication.replicate(); InOrder replicationOrder = inOrder(sourceLocationManager, replica); replicationOrder.verify(replica).validateReplicaTable(DATABASE, TABLE); replicationOrder.verify(sourceLocationManager).cleanUpLocations(); replicationOrder .verify(replica) .updateMetadata(eq(EVENT_ID), eq(sourceTableAndStatistics), eq(partitionsAndStatistics), eq(DATABASE), eq(TABLE), any(ReplicaLocationManager.class)); }
@Test public void noMatchingPartitions() throws Exception { PartitionsAndStatistics emptyPartitionsAndStats = new PartitionsAndStatistics(sourceTable.getPartitionKeys(), Collections.<Partition>emptyList(), Collections.<String, List<ColumnStatisticsObj>>emptyMap()); when(source.getPartitions(sourceTable, PARTITION_PREDICATE, MAX_PARTITIONS)).thenReturn(emptyPartitionsAndStats); when(source.getLocationManager(sourceTable, Collections.<Partition>emptyList(), EVENT_ID, copierOptions)) .thenReturn(sourceLocationManager); PartitionedTableMetadataMirrorReplication replication = new PartitionedTableMetadataMirrorReplication(DATABASE, TABLE, partitionPredicate, source, replica, eventIdFactory, DATABASE, TABLE); replication.replicate(); verify(replica).validateReplicaTable(DATABASE, TABLE); verify(replica) .updateMetadata(eq(EVENT_ID), eq(sourceTableAndStatistics), eq(DATABASE), eq(TABLE), any(ReplicaLocationManager.class)); }