@Test public void addBlockMetaTooBig() throws Exception { final long bigBlockSize = TEST_DIR_CAPACITY + 1; BlockMeta bigBlockMeta = new BlockMeta(TEST_BLOCK_ID, bigBlockSize, mDir); String alias = bigBlockMeta.getBlockLocation().tierAlias(); mThrown.expect(WorkerOutOfSpaceException.class); mThrown.expectMessage(ExceptionMessage.NO_SPACE_FOR_BLOCK_META.getMessage(TEST_BLOCK_ID, bigBlockSize, TEST_DIR_CAPACITY, alias)); mDir.addBlockMeta(bigBlockMeta); }
public void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(blockMeta, "blockMeta"); long blockId = blockMeta.getBlockId(); long blockSize = blockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), blockMeta.getBlockLocation().tierAlias()); } if (hasBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, blockMeta .getBlockLocation().tierAlias()); } mBlockIdToBlockMap.put(blockId, blockMeta); reserveSpace(blockSize, true); }
StorageDir { public void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(blockMeta, "blockMeta"); long blockId = blockMeta.getBlockId(); long blockSize = blockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), blockMeta.getBlockLocation().tierAlias()); } if (hasBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, blockMeta .getBlockLocation().tierAlias()); } mBlockIdToBlockMap.put(blockId, blockMeta); reserveSpace(blockSize, true); } }
StorageDir { public void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(blockMeta, "blockMeta"); long blockId = blockMeta.getBlockId(); long blockSize = blockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), blockMeta.getBlockLocation().tierAlias()); } if (hasBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, blockMeta .getBlockLocation().tierAlias()); } mBlockIdToBlockMap.put(blockId, blockMeta); reserveSpace(blockSize, true); } private  StorageDir(StorageTier tier, int dirIndex, long capacityBytes, long reservedBytes,
      String dirPath, String dirMedium); }
StorageDir { public void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(blockMeta, "blockMeta"); long blockId = blockMeta.getBlockId(); long blockSize = blockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), blockMeta.getBlockLocation().tierAlias()); } if (hasBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, blockMeta .getBlockLocation().tierAlias()); } mBlockIdToBlockMap.put(blockId, blockMeta); reserveSpace(blockSize, true); } private  StorageDir(StorageTier tier, int dirIndex, long capacityBytes, long reservedBytes,
      String dirPath, String dirMedium); static StorageDir newStorageDir(StorageTier tier, int dirIndex, long capacityBytes,
      long reservedBytes, String dirPath, String dirMedium); long getCapacityBytes(); long getAvailableBytes(); long getCommittedBytes(); String getDirPath(); String getDirMedium(); StorageTier getParentTier(); int getDirIndex(); List<Long> getBlockIds(); List<BlockMeta> getBlocks(); boolean hasBlockMeta(long blockId); boolean hasTempBlockMeta(long blockId); BlockMeta getBlockMeta(long blockId); TempBlockMeta getTempBlockMeta(long blockId); void addBlockMeta(BlockMeta blockMeta); void addTempBlockMeta(TempBlockMeta tempBlockMeta); void removeBlockMeta(BlockMeta blockMeta); void removeTempBlockMeta(TempBlockMeta tempBlockMeta); void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize); void cleanupSessionTempBlocks(long sessionId, List<Long> tempBlockIds); List<TempBlockMeta> getSessionTempBlocks(long sessionId); BlockStoreLocation toBlockStoreLocation(); long getReservedBytes(); }
StorageDir { public void addBlockMeta(BlockMeta blockMeta) throws WorkerOutOfSpaceException, BlockAlreadyExistsException { Preconditions.checkNotNull(blockMeta, "blockMeta"); long blockId = blockMeta.getBlockId(); long blockSize = blockMeta.getBlockSize(); if (getAvailableBytes() + getReservedBytes() < blockSize) { throw new WorkerOutOfSpaceException(ExceptionMessage.NO_SPACE_FOR_BLOCK_META, blockId, blockSize, getAvailableBytes(), blockMeta.getBlockLocation().tierAlias()); } if (hasBlockMeta(blockId)) { throw new BlockAlreadyExistsException(ExceptionMessage.ADD_EXISTING_BLOCK, blockId, blockMeta .getBlockLocation().tierAlias()); } mBlockIdToBlockMap.put(blockId, blockMeta); reserveSpace(blockSize, true); } private  StorageDir(StorageTier tier, int dirIndex, long capacityBytes, long reservedBytes,
      String dirPath, String dirMedium); static StorageDir newStorageDir(StorageTier tier, int dirIndex, long capacityBytes,
      long reservedBytes, String dirPath, String dirMedium); long getCapacityBytes(); long getAvailableBytes(); long getCommittedBytes(); String getDirPath(); String getDirMedium(); StorageTier getParentTier(); int getDirIndex(); List<Long> getBlockIds(); List<BlockMeta> getBlocks(); boolean hasBlockMeta(long blockId); boolean hasTempBlockMeta(long blockId); BlockMeta getBlockMeta(long blockId); TempBlockMeta getTempBlockMeta(long blockId); void addBlockMeta(BlockMeta blockMeta); void addTempBlockMeta(TempBlockMeta tempBlockMeta); void removeBlockMeta(BlockMeta blockMeta); void removeTempBlockMeta(TempBlockMeta tempBlockMeta); void resizeTempBlockMeta(TempBlockMeta tempBlockMeta, long newSize); void cleanupSessionTempBlocks(long sessionId, List<Long> tempBlockIds); List<TempBlockMeta> getSessionTempBlocks(long sessionId); BlockStoreLocation toBlockStoreLocation(); long getReservedBytes();  }