@Test
  public void testReplPolicyToPartitionClassMapping() throws Exception {
    Account refAccount = accountService.createAndAddRandomAccount(QuotaResourceType.SERVICE);
    Map<Container, String> containerToPartClass = new HashMap<>();
    Iterator<Container> allContainers = refAccount.getAllContainers().iterator();
    Container container = allContainers.next();
    // container with null replication policy
    container = accountService.addReplicationPolicyToContainer(container, null);
    containerToPartClass.put(container, MockClusterMap.DEFAULT_PARTITION_CLASS);
    container = allContainers.next();
    // container with configured default replication policy
    container = accountService.addReplicationPolicyToContainer(container, MockClusterMap.DEFAULT_PARTITION_CLASS);
    containerToPartClass.put(container, MockClusterMap.DEFAULT_PARTITION_CLASS);
    container = allContainers.next();
    // container with a special replication policy
    container = accountService.addReplicationPolicyToContainer(container, MockClusterMap.SPECIAL_PARTITION_CLASS);
    containerToPartClass.put(container, MockClusterMap.SPECIAL_PARTITION_CLASS);
    // adding this to test the random account and container case (does not actually happen if coming from the frontend)
    containerToPartClass.put(null, MockClusterMap.DEFAULT_PARTITION_CLASS);

    Map<Integer, Integer> sizeToChunkCount = new HashMap<>();
    // simple
    sizeToChunkCount.put(random.nextInt(chunkSize) + 1, 1);
    int count = random.nextInt(8) + 3;
    // composite
    sizeToChunkCount.put(chunkSize * count, count + 1);
    for (Map.Entry<Integer, Integer> sizeAndChunkCount : sizeToChunkCount.entrySet()) {
      for (Map.Entry<Container, String> containerAndPartClass : containerToPartClass.entrySet()) {
        requestAndResultsList.clear();
        requestAndResultsList.add(
            new RequestAndResult(sizeAndChunkCount.getKey(), containerAndPartClass.getKey(), PutBlobOptions.DEFAULT,
                null));
        mockClusterMap.clearLastNRequestedPartitionClasses();
        submitPutsAndAssertSuccess(true);
        // since the puts are processed one at a time, it is fair to check the last partition class set
        checkLastRequestPartitionClasses(sizeAndChunkCount.getValue(), containerAndPartClass.getValue(), false);
      }
    }

    // if there is no partition class that conforms to the replication policy, the default should be used.
    String nonExistentClass = TestUtils.getRandomString(3);
    accountService.addReplicationPolicyToContainer(container, nonExistentClass);
    requestAndResultsList.clear();
    requestAndResultsList.add(new RequestAndResult(chunkSize, container, PutBlobOptions.DEFAULT, null));
    mockClusterMap.clearLastNRequestedPartitionClasses();
    submitPutsAndAssertSuccess(true);
    // because of how the non-encrypted flow is, prepareForSending() may be called twice. So not checking for count
    checkLastRequestPartitionClasses(-1, nonExistentClass, false);
  }
Tests that the replication policy in the container is respected
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/PutManagerTest.java