### Question:
Log implements Write { File allocate(String filename, long size, boolean requestSwapSegment) throws StoreException { File segmentFile = new File(dataDir, filename); if (!segmentFile.exists()) { try { diskSpaceAllocator.allocate(segmentFile, size, storeId, requestSwapSegment); } catch (IOException e) { StoreErrorCodes errorCode = StoreException.resolveErrorCode(e); throw new StoreException(errorCode.toString() + " while allocating the file", e, errorCode); } } return segmentFile; } Log(String dataDir, long totalCapacityInBytes, DiskSpaceAllocator diskSpaceAllocator, StoreConfig config,
      StoreMetrics metrics);   Log(String dataDir, long totalCapacityInBytes, DiskSpaceAllocator diskSpaceAllocator, StoreConfig config,
      StoreMetrics metrics, boolean isLogSegmented, List<LogSegment> segmentsToLoad,
      Iterator<Pair<String, String>> segmentNameAndFileNameIterator); @Override int appendFrom(ByteBuffer buffer); @Override void appendFrom(ReadableByteChannel channel, long size);  }### Answer:
@Test public void constructionFailureTest() throws IOException, StoreException { List<Pair<Long, Long>> logAndSegmentSizes = new ArrayList<>(); 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)); 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); fail("Construction should have failed"); } catch (IllegalArgumentException e) { } } File file = create(LogSegmentNameHelper.nameToFilename(LogSegmentNameHelper.generateFirstSegmentName(false))); try { new Log(file.getAbsolutePath(), 1, StoreTestUtils.DEFAULT_DISK_SPACE_ALLOCATOR, createStoreConfig(1, setFilePermissionEnabled), metrics); fail("Construction should have failed"); } catch (StoreException e) { } 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()); fail("Should have failed to when constructing log"); } catch (StoreException e) { assertEquals("Mismatch in error code", StoreErrorCodes.IOError, e.getErrorCode()); } }