Skip to content

Commit

Permalink
fix intermittent unit test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjtzyy committed Sep 27, 2019
1 parent 10a5ef7 commit 68517e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public ReplicaId getNewReplica(String partitionIdStr, DataNodeId dataNodeId) {
mappedPartition =
new AmbryPartition(Long.valueOf(partitionIdStr), partitionClass, helixClusterManagerCallback);
}
// Check if data or disk is in current cluster map, if not, set newReplica to null.
// Check if data node or disk is in current cluster map, if not, set newReplica to null.
AmbryDataNode dataNode = instanceNameToAmbryDataNode.get(instanceName);
String mountPathFromHelix = replicaInfos.get(instanceName);
Set<AmbryDisk> disks = dataNode != null ? ambryDataNodeToAmbryDisks.get(dataNode) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import com.codahale.metrics.MetricRegistry;
import com.github.ambry.clustermap.TestUtils.*;
import com.github.ambry.commons.ResponseHandler;
import com.github.ambry.server.ServerErrorCode;
import com.github.ambry.config.ClusterMapConfig;
import com.github.ambry.config.VerifiableProperties;
import com.github.ambry.server.ServerErrorCode;
import com.github.ambry.utils.ByteBufferInputStream;
import com.github.ambry.utils.Pair;
import com.github.ambry.utils.Utils;
Expand Down Expand Up @@ -393,14 +393,14 @@ public void getNewReplicaTest() throws Exception {
helixClusterManager = new HelixClusterManager(clusterMapConfig, hostname,
new MockHelixManagerFactory(helixCluster, znRecordMap, null), metricRegistry);

// 2. test that no partition or no host is found in helix property store that associates with new replica
// select a partition that doesn't equal to partitionOfNewReplica dataNodeOfNewReplica
// 2. test that cases: 1) partition is not found 2) host is not found in helix property store that associates with new replica
// select a partition that doesn't equal to partitionOfNewReplica
PartitionId partitionForTest;
Random random = new Random();
List<PartitionId> partitionsInClusterManager = helixClusterManager.getAllPartitionIds(null);
do {
partitionForTest = partitionsInClusterManager.get(random.nextInt(partitionsInClusterManager.size()));
} while (partitionForTest == partitionOfNewReplica);
} while (partitionForTest.toString().equals(partitionOfNewReplica.toString()));
assertNull("New replica should be null because given partition id is not in Helix property store",
helixClusterManager.getNewReplica(partitionForTest.toPathString(), dataNodeOfNewReplica));
// select partitionOfNewReplica but a random node that doesn't equal to
Expand Down

0 comments on commit 68517e2

Please sign in to comment.