@Test
  public void concurrencyTest() throws Exception {
    alloc = constructAllocator();
    List<DiskSpaceRequirements> requirementsList = new ArrayList<>();
    requirementsList.add(new DiskSpaceRequirements(storeId0, 10, 500, 1));
    requirementsList.add(new DiskSpaceRequirements(storeId1, 5, 251, 0));
    alloc.initializePool(requirementsList);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 10, 500).addStoreSeg(storeId1, 5, 251));
    exec = Executors.newCachedThreadPool();
    // allocate all files in pool
    runConcurrencyTest(requirementsList, true, false);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 10, 0).addStoreSeg(storeId1, 5, 0));
    // free all files from last run
    runConcurrencyTest(requirementsList, false, true);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 10, 500).addStoreSeg(storeId1, 5, 251));
    // allocate and free all files
    runConcurrencyTest(requirementsList, true, true);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 10, 500).addStoreSeg(storeId1, 5, 251));
    // allocate all files
    runConcurrencyTest(requirementsList, true, false);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 10, 0).addStoreSeg(storeId1, 5, 0));
  }
Test a large number of concurrent alloc/free operations
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/DiskSpaceAllocatorTest.java