@Test
  public void allocateBeforeInitializeTest() throws Exception {
    // For general testing purpose, following tests assume store may have different segment sizes.
    alloc = constructAllocator();
    File f1 = allocateAndVerify(storeId1, "file1", 50, false);
    File f2 = allocateAndVerify(storeId1, "file2", 20, false);
    File f3 = allocateAndVerify(storeId1, "file3", 20, false);
    // free one file before initializing pool
    freeAndVerify(storeId1, f3, 20, false);
    // expect the pool to still be empty
    verifyPoolState(new ExpectedState());

    alloc.initializePool(
        Arrays.asList(new DiskSpaceRequirements(storeId0, 50, 2, 0), new DiskSpaceRequirements(storeId1, 21, 1, 0)));
    // return files that were allocated before initialization to the pool
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 2).addStoreSeg(storeId1, 21, 1));
    freeAndVerify(storeId1, f1, 50, false);
    verifyPoolState(
        new ExpectedState().addStoreSeg(storeId0, 50, 2).addStoreSeg(storeId1, 21, 1).addStoreSeg(storeId1, 50, 1));
    freeAndVerify(storeId1, f2, 20, false);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 2)
        .addStoreSeg(storeId1, 20, 1)
        .addStoreSeg(storeId1, 21, 1)
        .addStoreSeg(storeId1, 50, 1));
    // allocate and free file from initialized pool
    File f4 = allocateAndVerify(storeId1, "file4", 50, false);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 2)
        .addStoreSeg(storeId1, 20, 1)
        .addStoreSeg(storeId1, 21, 1)
        .addStoreSeg(storeId1, 50, 0));
    freeAndVerify(storeId1, f4, 50, false);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 2)
        .addStoreSeg(storeId1, 20, 1)
        .addStoreSeg(storeId1, 21, 1)
        .addStoreSeg(storeId1, 50, 1));
  }
Test behavior when segments are allocated before the pool is fully initialized.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/DiskSpaceAllocatorTest.java