@Test
  public void addAndDeleteSegmentsTest() throws Exception {
    alloc = constructAllocator();
    alloc.initializePool(Collections.singletonList(new DiskSpaceRequirements(storeId0, 50, 1, 0)));
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 1));
    // add requirements for new store (storeId1)
    DiskSpaceRequirements requirements1 = new DiskSpaceRequirements(storeId1, 20L, 3L, 1L);
    alloc.addRequiredSegments(alloc.getOverallRequirements(Collections.singletonList(requirements1)), false);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 1).addStoreSeg(storeId1, 20, 3));
    // verify that swapSegmentNumBySize map has two entries and there is one segment for size 20L
    assertTrue("The number of swap segments in map is not expected",
        alloc.getSwapSegmentBySizeMap().size() == 2 && alloc.getSwapSegmentBySizeMap().get(20L) == 1L);
    // test that segments associated with storeId0 can be correctly deleted
    alloc.deleteAllSegmentsForStoreIds(Collections.singletonList(storeId0));
    verifyPoolState(new ExpectedState().addStoreSeg(storeId1, 20, 3));
    // verify in-mem store reserve file map doesn't contain storeId0
    Map<String, DiskSpaceAllocator.ReserveFileMap> storeFileMap = alloc.getStoreReserveFileMap();
    assertFalse("Store reserve file map should not contain entry associated with storeId0",
        storeFileMap.containsKey(storeId0));
  }
Test that disk allocator is able to dynamically add/delete segments for certain store.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/DiskSpaceAllocatorTest.java