@Test
  public void testListSealedPartitions() throws Exception {
    assumeTrue(!dcStr.equals("DC1"));
    String clusterName = CLUSTER_NAME_PREFIX + CLUSTER_NAME_IN_STATIC_CLUSTER_MAP;
    ClusterMapConfig clusterMapConfig = getClusterMapConfig(clusterName, "DC1", null);
    InstanceConfigToDataNodeConfigAdapter.Converter instanceConfigConverter =
        new InstanceConfigToDataNodeConfigAdapter.Converter(clusterMapConfig);
    // Test regular bootstrap
    long expectedResourceCount =
        (testPartitionLayout.getPartitionLayout().getPartitionCount() - 1) / DEFAULT_MAX_PARTITIONS_PER_RESOURCE + 1;
    writeBootstrapOrUpgrade(expectedResourceCount, false);
    Set<String> sealedPartitions =
        HelixBootstrapUpgradeUtil.listSealedPartition(hardwareLayoutPath, partitionLayoutPath, zkLayoutPath,
            CLUSTER_NAME_PREFIX, dcStr, dataNodeConfigSourceType);
    assertEquals("Sealed partition set should be empty initially", Collections.emptySet(), sealedPartitions);
    // randomly choose 20 partitions to mark as sealed
    int[] intArray = new Random().ints(0, 100).distinct().limit(20).toArray();
    Set<String> selectedSealedPartitionSet = new HashSet<>();
    for (int id : intArray) {
      selectedSealedPartitionSet.add(String.valueOf(id));
    }
    // update the sealed lists in Helix
    for (ZkInfo zkInfo : dcsToZkInfo.values()) {
      ZKHelixAdmin admin = new ZKHelixAdmin("localhost:" + zkInfo.getPort());
      PropertyStoreToDataNodeConfigAdapter propertyStoreAdapter =
          dataNodeConfigSourceType == DataNodeConfigSourceType.INSTANCE_CONFIG ? null
              : new PropertyStoreToDataNodeConfigAdapter("localhost:" + zkInfo.getPort(), clusterMapConfig);
      for (String instanceName : admin.getInstancesInCluster(clusterName)) {
        DataNodeConfig dataNodeConfig =
            dataNodeConfigSourceType == DataNodeConfigSourceType.INSTANCE_CONFIG ? instanceConfigConverter.convert(
                admin.getInstanceConfig(clusterName, instanceName)) : propertyStoreAdapter.get(instanceName);
        Set<String> localReplicas = new HashSet<>();
        for (DataNodeConfig.DiskConfig diskConfig : dataNodeConfig.getDiskConfigs().values()) {
          localReplicas.addAll(diskConfig.getReplicaConfigs().keySet());
        }
        // derive the intersection of localReplicas set and selectedSealedPartitionSet
        localReplicas.retainAll(selectedSealedPartitionSet);
        if (dataNodeConfigSourceType == DataNodeConfigSourceType.INSTANCE_CONFIG) {
          InstanceConfig instanceConfig = admin.getInstanceConfig(clusterName, instanceName);
          instanceConfig.getRecord().setListField(SEALED_STR, new ArrayList<>(localReplicas));
          admin.setInstanceConfig(clusterName, instanceName, instanceConfig);
        } else {
          dataNodeConfig.getSealedReplicas().addAll(localReplicas);
          propertyStoreAdapter.set(dataNodeConfig);
        }
      }
    }
    // query sealed partition in Helix again
    sealedPartitions =
        HelixBootstrapUpgradeUtil.listSealedPartition(hardwareLayoutPath, partitionLayoutPath, zkLayoutPath,
            CLUSTER_NAME_PREFIX, dcStr, dataNodeConfigSourceType);
    assertEquals("Mismatch in sealed partition set", selectedSealedPartitionSet, sealedPartitions);
  }
Test listing sealed partitions in Helix cluster.
@throws Exception
ambry-tools/src/integration-test/java/com/github/ambry/clustermap/HelixBootstrapUpgradeToolTest.java