Source:
<code>public void cloudReplicaAdditionTest() throws Exception { StorageManager storageManager = new StorageManager(storeConfig, new DiskManagerConfig(verifiableProperties), Utils.newScheduler(1, true), clusterMap.getMetricRegistry(), null, clusterMap, currentNode, null, mockHelixParticipant, new MockTime(), null); CloudToStoreReplicationManager cloudToStoreReplicationManager = new CloudToStoreReplicationManager(replicationConfig, clusterMapConfig, storeConfig, storageManager, storeKeyFactory, clusterMap, mockScheduler, currentNode, null, clusterMap.getMetricRegistry(), null, storeKeyConverterFactory, serverConfig.serverMessageTransformer, mockClusterSpectator, mockHelixParticipant); storageManager.start(); cloudToStoreReplicationManager.start(); mockClusterSpectator.spectate(); mockHelixParticipant.onPartitionBecomeLeaderFromStandby(NEW_PARTITION_NAME); assertNull("Thread pool for DC1 should be null", <START> cloudToStoreReplicationManager.getReplicaThreadPoolByDc().get("DC1")); <END> PartitionId newPartition = new MockPartitionId(Long.parseLong(NEW_PARTITION_NAME), MockClusterMap.DEFAULT_PARTITION_CLASS, clusterMap.getDataNodes(), 0); ReplicaId replicaToAdd = newPartition.getReplicaIds().get(0); assertTrue("Adding new store should succeed", storageManager.addBlobStore(replicaToAdd)); storageManager.shutdownBlobStore(newPartition); mockHelixParticipant.onPartitionBecomeLeaderFromStandby(NEW_PARTITION_NAME); assertNull("Thread pool for DC1 should be null", cloudToStoreReplicationManager.getReplicaThreadPoolByDc().get("DC1")); storageManager.startBlobStore(newPartition); mockHelixParticipant.onPartitionBecomeLeaderFromStandby(NEW_PARTITION_NAME); assertNotNull("There should be a thread for DC1", cloudToStoreReplicationManager.getReplicaThreadPoolByDc().get("DC1")); cloudToStoreReplicationManager.shutdown(); storageManager.shutdown(); }</code><technical_language>I expose internal thread pool for test check if operation succeeded. expose a more specific method hasStoreForDatacenter() in ReplicationEngine base class</technical_language>

Target:
public void cloudReplicaAdditionTest() throws Exception { StorageManager storageManager = new StorageManager(storeConfig, new DiskManagerConfig(verifiableProperties), Utils.newScheduler(1, true), clusterMap.getMetricRegistry(), null, clusterMap, currentNode, null, mockHelixParticipant, new MockTime(), null); CloudToStoreReplicationManager cloudToStoreReplicationManager = new CloudToStoreReplicationManager(replicationConfig, clusterMapConfig, storeConfig, storageManager, storeKeyFactory, clusterMap, mockScheduler, currentNode, null, clusterMap.getMetricRegistry(), null, storeKeyConverterFactory, serverConfig.serverMessageTransformer, mockClusterSpectator, mockHelixParticipant); storageManager.start(); cloudToStoreReplicationManager.start(); mockClusterSpectator.spectate(); mockHelixParticipant.onPartitionBecomeLeaderFromStandby(NEW_PARTITION_NAME); assertNull("Cloud replica thread should not be created", TestUtils.getThreadByThisName(VCR_REPLICA_THREAD_PREFIX)); PartitionId newPartition = new MockPartitionId(Long.parseLong(NEW_PARTITION_NAME), MockClusterMap.DEFAULT_PARTITION_CLASS, clusterMap.getDataNodes(), 0); ReplicaId replicaToAdd = newPartition.getReplicaIds().get(0); assertTrue("Adding new store should succeed", storageManager.addBlobStore(replicaToAdd)); storageManager.shutdownBlobStore(newPartition); mockHelixParticipant.onPartitionBecomeLeaderFromStandby(NEW_PARTITION_NAME); assertNull("Cloud replica thread should not be created", TestUtils.getThreadByThisName(VCR_REPLICA_THREAD_PREFIX)); storageManager.startBlobStore(newPartition); mockHelixParticipant.onPartitionBecomeLeaderFromStandby(NEW_PARTITION_NAME); assertNotNull("Cloud replica thread should be created for DC1", TestUtils.getThreadByThisName(VCR_REPLICA_THREAD_PREFIX)); cloudToStoreReplicationManager.shutdown(); storageManager.shutdown(); }