@Test
  public void getNewReplicaInFullAutoRaceConditionTest() throws Exception {
    assumeTrue(!useComposite && fullAutoCompatible);
    metricRegistry = new MetricRegistry();

    // 1. Set up for test
    // 1.1 Set the node to FullAuto
    List<String> resourceNames = helixCluster.getResources(localDc);
    String resourceName = resourceNames.get(0);
    String tag = "TAG_100000";
    IdealState idealState = helixCluster.getResourceIdealState(resourceName, localDc);
    idealState.setRebalanceMode(IdealState.RebalanceMode.FULL_AUTO);
    idealState.setInstanceGroupTag(tag);
    helixCluster.refreshIdealState();
    for (DataNode dataNode : testHardwareLayout.getAllDataNodesFromDc(localDc)) {
      String instanceName = ClusterMapUtils.getInstanceName(dataNode.getHostname(), dataNode.getPort());
      InstanceConfig instanceConfig =
          helixCluster.getHelixAdminFromDc(localDc).getInstanceConfig(helixCluster.getClusterName(), instanceName);
      instanceConfig.addTag(tag);
    }
    // 1.2 Create Helix cluster manager
    HelixClusterManager helixClusterManager = new HelixClusterManager(clusterMapConfig, selfInstanceName,
        new MockHelixManagerFactory(helixCluster, null, null, useAggregatedView), metricRegistry);
    // 1.3 Get list of disks present on the node
    HelixClusterManager.HelixClusterManagerQueryHelper clusterManagerCallback =
        helixClusterManager.getManagerQueryHelper();
    AmbryDataNode ambryDataNode = helixClusterManager.getDataNodeId(currentNode.getHostname(), currentNode.getPort());
    List<AmbryDisk> disks = new ArrayList<>(clusterManagerCallback.getDisks(ambryDataNode));
    // 1.4 Select partition for getting the bootstrap replicas
    PartitionId partition = helixClusterManager.getAllPartitionIds(null).get(0);
    long replicaCapacity = partition.getReplicaIds().get(0).getCapacityInBytes();
    // 1.5 Let only 2 disks be available
    for (int i = 0; i < disks.size(); i++) {
      AmbryDisk disk = disks.get(i);
      if (i == 0 || i == 1) {
        disk.setDiskAvailableSpace(replicaCapacity);
      } else {
        disk.setDiskAvailableSpace(0);
      }
    }

    // 2. Bootstrap 2 replicas in separate threads
    final ReplicaId[] bootstrapReplica1 = new ReplicaId[1];
    final ReplicaId[] bootstrapReplica2 = new ReplicaId[1];
    Thread t1 = new Thread(
        () -> bootstrapReplica1[0] = helixClusterManager.getBootstrapReplica(partition.toPathString(), ambryDataNode));
    Thread t2 = new Thread(
        () -> bootstrapReplica2[0] = helixClusterManager.getBootstrapReplica(partition.toPathString(), ambryDataNode));
    t1.start();
    t2.start();
    t1.join();
    t2.join();

    // 3. Verify that both bootstrapping of both replicas are successful
    assertNotNull("Bootstrapping of replica must be successful", bootstrapReplica1[0]);
    assertNotNull("Bootstrapping of replica must be successful", bootstrapReplica2[0]);
    // 4. Verify disks for both replicas are different
    assertNotEquals("Both disks must be different", bootstrapReplica1[0].getDiskId(), bootstrapReplica2[0].getDiskId());

    helixClusterManager.close();
  }
Test correct disk is used while getting new replica in full auto.
ambry-clustermap/src/test/java/com/github/ambry/clustermap/HelixClusterManagerTest.java