@Test
  public void allocateAndFreeFailureTest() throws Exception {
    alloc = constructAllocator();
    alloc.initializePool(Collections.singletonList(new DiskSpaceRequirements(storeId0, 50, 1, 0)));
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 1));
    // test when a destination file already exists
    File f1 = new File(allocatedFileDir, "f1");
    assertTrue("Could not create file", f1.createNewFile());
    TestUtils.assertException(IOException.class, () -> alloc.allocate(f1, 50, storeId0, false), null);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 1));
    // test returning a file that does not exist
    File f2 = new File(allocatedFileDir, "f2");
    TestUtils.assertException(IOException.class, () -> alloc.free(f2, 50, storeId0, false), null);
    verifyPoolState(new ExpectedState().addStoreSeg(storeId0, 50, 1));
  }
Test situations where the allocator should throw exceptions during allocate and free calls.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/DiskSpaceAllocatorTest.java