@Test
  public void swapSegmentRequirementTest() throws Exception {
    requiredSwapSegmentsPerSize = 4;
    alloc = constructAllocator();
    List<DiskSpaceRequirements> requirementsList = new ArrayList<>();
    requirementsList.add(new DiskSpaceRequirements(storeId0, 3, 7, 0));
    requirementsList.add(new DiskSpaceRequirements(storeId1, 5, 4, 2));
    // This should result in 0 swap segments b/c 0 > 4 - 10
    requirementsList.add(new DiskSpaceRequirements(storeId2, 7, 3, 10));
    Collections.shuffle(requirementsList);
    alloc.initializePool(requirementsList);
    verifyPoolState(
        new ExpectedState().addStoreSeg(storeId0, 3, 7).addStoreSeg(storeId1, 5, 4).addStoreSeg(storeId2, 7, 3).
            addSwapSeg(3, 4).addSwapSeg(5, 2));

    // test reinitialization with different requirements, and num swap used for each size
    requiredSwapSegmentsPerSize = 3;
    alloc = constructAllocator();
    requirementsList.clear();
    requirementsList.add(new DiskSpaceRequirements(storeId0, 3, 2, 0));
    requirementsList.add(new DiskSpaceRequirements(storeId1, 5, 4, 2));
    requirementsList.add(new DiskSpaceRequirements(storeId2, 7, 3, 1));
    Collections.shuffle(requirementsList);
    alloc.initializePool(requirementsList);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 3, 2)
        .addStoreSeg(storeId1, 5, 4)
        .addStoreSeg(storeId2, 7, 3)
        .addSwapSeg(3, 3)
        .addSwapSeg(5, 1)
        .addSwapSeg(7, 2));
  }
Test various swap segment usage combinations
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/DiskSpaceAllocatorTest.java