@Test
  public void constructionFailureTest() throws IOException, StoreException {
    List<Pair<Long, Long>> logAndSegmentSizes = new ArrayList<>();
    // <=0 values for capacities
    logAndSegmentSizes.add(new Pair<>(-1L, SEGMENT_CAPACITY));
    logAndSegmentSizes.add(new Pair<>(LOG_CAPACITY, -1L));
    logAndSegmentSizes.add(new Pair<>(0L, SEGMENT_CAPACITY));
    logAndSegmentSizes.add(new Pair<>(LOG_CAPACITY, 0L));
    // log capacity is not perfectly divisible by segment capacity
    logAndSegmentSizes.add(new Pair<>(LOG_CAPACITY, LOG_CAPACITY - 1));

    for (Pair<Long, Long> logAndSegmentSize : logAndSegmentSizes) {
      try {
        new Log(tempDir.getAbsolutePath(), logAndSegmentSize.getFirst(), StoreTestUtils.DEFAULT_DISK_SPACE_ALLOCATOR,
            createStoreConfig(logAndSegmentSize.getSecond(), setFilePermissionEnabled), metrics, null);
        fail("Construction should have failed");
      } catch (IllegalArgumentException e) {
        // expected. Nothing to do.
      }
    }

    // file which is not a directory
    File file = create(LogSegmentName.generateFirstSegmentName(false).toFilename());
    try {
      new Log(file.getAbsolutePath(), 1, StoreTestUtils.DEFAULT_DISK_SPACE_ALLOCATOR,
          createStoreConfig(1, setFilePermissionEnabled), metrics, null);
      fail("Construction should have failed");
    } catch (StoreException e) {
      // expected. Nothing to do.
    }

    // Store exception occurred during construction
    DiskSpaceAllocator mockDiskAllocator = Mockito.mock(DiskSpaceAllocator.class);
    doThrow(new IOException(StoreException.IO_ERROR_STR)).when(mockDiskAllocator)
        .allocate(any(File.class), anyLong(), anyString(), anyBoolean());
    List<LogSegment> segmentsToLoad = Collections.emptyList();
    try {
      new Log(tempDir.getAbsolutePath(), LOG_CAPACITY, mockDiskAllocator,
          createStoreConfig(SEGMENT_CAPACITY, setFilePermissionEnabled), metrics, true, segmentsToLoad,
          Collections.EMPTY_LIST.iterator(), null);
      fail("Should have failed to when constructing log");
    } catch (StoreException e) {
      assertEquals("Mismatch in error code", StoreErrorCodes.IOError, e.getErrorCode());
    }
  }
Tests cases where construction of {@link Log} failed either because of bad arguments or because of store exception.
@throws IOException
ambry-store/src/test/java/com/github/ambry/store/LogTest.java