@VisibleForTesting
  static void validatePartitionedReplicaGroupInstance(TableConfig tableConfig) {
    if (tableConfig.getValidationConfig().getReplicaGroupStrategyConfig() == null || MapUtils.isEmpty(
        tableConfig.getInstanceAssignmentConfigMap())) {
      return;
    }
    for (Map.Entry<String, InstanceAssignmentConfig> entry : tableConfig.getInstanceAssignmentConfigMap().entrySet()) {
      boolean isNullReplicaGroupPartitionConfig = entry.getValue().getReplicaGroupPartitionConfig() == null;
      Preconditions.checkState(isNullReplicaGroupPartitionConfig,
          "Both replicaGroupStrategyConfig and replicaGroupPartitionConfig is provided");
    }
  }
@Test
  public void testValidatePartitionedReplicaGroupInstance() {
    String partitionColumn = "testPartitionCol";
    ReplicaGroupStrategyConfig replicaGroupStrategyConfig = new ReplicaGroupStrategyConfig(partitionColumn, 2);

    TableConfig tableConfigWithoutReplicaGroupStrategyConfig =
        new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME).build();
    // Call validate with a table-config without replicaGroupStrategyConfig or replicaGroupPartitionConfig.
    TableConfigUtils.validatePartitionedReplicaGroupInstance(tableConfigWithoutReplicaGroupStrategyConfig);

    TableConfig tableConfigWithReplicaGroupStrategyConfig =
        new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME).build();
    tableConfigWithReplicaGroupStrategyConfig.getValidationConfig()
        .setReplicaGroupStrategyConfig(replicaGroupStrategyConfig);

    // Call validate with a table-config with replicaGroupStrategyConfig and without replicaGroupPartitionConfig.
    TableConfigUtils.validatePartitionedReplicaGroupInstance(tableConfigWithReplicaGroupStrategyConfig);

    InstanceAssignmentConfig instanceAssignmentConfig = Mockito.mock(InstanceAssignmentConfig.class);
    InstanceReplicaGroupPartitionConfig instanceReplicaGroupPartitionConfig =
        new InstanceReplicaGroupPartitionConfig(true, 0, 0, 0, 2, 0, false, partitionColumn);
    Mockito.doReturn(instanceReplicaGroupPartitionConfig).when(instanceAssignmentConfig)
        .getReplicaGroupPartitionConfig();

    TableConfig invalidTableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)
        .setInstanceAssignmentConfigMap(ImmutableMap.of(TableType.OFFLINE.toString(), instanceAssignmentConfig))
        .build();
    invalidTableConfig.getValidationConfig().setReplicaGroupStrategyConfig(replicaGroupStrategyConfig);

    try {
      // Call validate with a table-config with replicaGroupStrategyConfig and replicaGroupPartitionConfig.
      TableConfigUtils.validatePartitionedReplicaGroupInstance(invalidTableConfig);
      Assert.fail("Validation should have failed since both replicaGroupStrategyConfig "
          + "and replicaGroupPartitionConfig are set");
    } catch (IllegalStateException ignored) {
    }
  }