@Test public void getBlockIdByIndex() throws Exception { MutableInodeFile inodeFile = createInodeFile(1); List<Long> blockIds = new ArrayList<>(); final int NUM_BLOCKS = 3; for (int i = 0; i < NUM_BLOCKS; i++) { blockIds.add(inodeFile.getNewBlockId()); } for (int i = 0; i < NUM_BLOCKS; i++) { assertEquals(blockIds.get(i), (Long) inodeFile.getBlockIdByIndex(i)); } try { inodeFile.getBlockIdByIndex(-1); Assert.fail(); } catch (BlockInfoException e) { assertEquals(String.format("blockIndex -1 is out of range. File blocks: %d", NUM_BLOCKS), e.getMessage()); } try { inodeFile.getBlockIdByIndex(NUM_BLOCKS); Assert.fail(); } catch (BlockInfoException e) { assertEquals(String.format("blockIndex %d is out of range. File blocks: %d", NUM_BLOCKS, NUM_BLOCKS), e.getMessage()); } }
@Override public long getBlockIdByIndex(int blockIndex) throws BlockInfoException { if (blockIndex < 0 || blockIndex >= mBlocks.size()) { throw new BlockInfoException( "blockIndex " + blockIndex + " is out of range. File blocks: " + mBlocks.size()); } return mBlocks.get(blockIndex); }
MutableInodeFile extends MutableInode<MutableInodeFile> implements InodeFileView { @Override public long getBlockIdByIndex(int blockIndex) throws BlockInfoException { if (blockIndex < 0 || blockIndex >= mBlocks.size()) { throw new BlockInfoException( "blockIndex " + blockIndex + " is out of range. File blocks: " + mBlocks.size()); } return mBlocks.get(blockIndex); } }
MutableInodeFile extends MutableInode<MutableInodeFile> implements InodeFileView { @Override public long getBlockIdByIndex(int blockIndex) throws BlockInfoException { if (blockIndex < 0 || blockIndex >= mBlocks.size()) { throw new BlockInfoException( "blockIndex " + blockIndex + " is out of range. File blocks: " + mBlocks.size()); } return mBlocks.get(blockIndex); } private  MutableInodeFile(long blockContainerId); }
MutableInodeFile extends MutableInode<MutableInodeFile> implements InodeFileView { @Override public long getBlockIdByIndex(int blockIndex) throws BlockInfoException { if (blockIndex < 0 || blockIndex >= mBlocks.size()) { throw new BlockInfoException( "blockIndex " + blockIndex + " is out of range. File blocks: " + mBlocks.size()); } return mBlocks.get(blockIndex); } private  MutableInodeFile(long blockContainerId); @Override FileInfo generateClientFileInfo(String path); void reset(); @Override DefaultAccessControlList getDefaultACL(); @Override MutableInodeFile setDefaultACL(DefaultAccessControlList acl); @Override List<Long> getBlockIds(); @Override long getBlockSizeBytes(); @Override long getLength(); @Override long getBlockContainerId(); @Override long getBlockIdByIndex(int blockIndex); @Override long getPersistJobId(); @Override long getShouldPersistTime(); @Override int getReplicationDurable(); @Override int getReplicationMax(); @Override int getReplicationMin(); @Override String getTempUfsPath(); @Override boolean isCacheable(); @Override boolean isCompleted(); long getNewBlockId(); MutableInodeFile setBlockSizeBytes(long blockSizeBytes); MutableInodeFile setBlockIds(List<Long> blockIds); MutableInodeFile setCacheable(boolean cacheable); MutableInodeFile setCompleted(boolean completed); MutableInodeFile setLength(long length); MutableInodeFile setPersistJobId(long persistJobId); MutableInodeFile setShouldPersistTime(long shouldPersistTime); MutableInodeFile setReplicationDurable(int replicationDurable); MutableInodeFile setReplicationMax(int replicationMax); MutableInodeFile setReplicationMin(int replicationMin); MutableInodeFile setTempUfsPath(String tempUfsPath); void updateFromEntry(UpdateInodeFileEntry entry); @Override String toString(); static MutableInodeFile fromJournalEntry(InodeFileEntry entry); static MutableInodeFile create(long blockContainerId, long parentId, String name,
      long creationTimeMs, CreateFileContext context); @Override JournalEntry toJournalEntry(); @Override JournalEntry toJournalEntry(String path); @Override InodeMeta.Inode toProto(); static MutableInodeFile fromProto(InodeOrBuilder inode); }
MutableInodeFile extends MutableInode<MutableInodeFile> implements InodeFileView { @Override public long getBlockIdByIndex(int blockIndex) throws BlockInfoException { if (blockIndex < 0 || blockIndex >= mBlocks.size()) { throw new BlockInfoException( "blockIndex " + blockIndex + " is out of range. File blocks: " + mBlocks.size()); } return mBlocks.get(blockIndex); } private  MutableInodeFile(long blockContainerId); @Override FileInfo generateClientFileInfo(String path); void reset(); @Override DefaultAccessControlList getDefaultACL(); @Override MutableInodeFile setDefaultACL(DefaultAccessControlList acl); @Override List<Long> getBlockIds(); @Override long getBlockSizeBytes(); @Override long getLength(); @Override long getBlockContainerId(); @Override long getBlockIdByIndex(int blockIndex); @Override long getPersistJobId(); @Override long getShouldPersistTime(); @Override int getReplicationDurable(); @Override int getReplicationMax(); @Override int getReplicationMin(); @Override String getTempUfsPath(); @Override boolean isCacheable(); @Override boolean isCompleted(); long getNewBlockId(); MutableInodeFile setBlockSizeBytes(long blockSizeBytes); MutableInodeFile setBlockIds(List<Long> blockIds); MutableInodeFile setCacheable(boolean cacheable); MutableInodeFile setCompleted(boolean completed); MutableInodeFile setLength(long length); MutableInodeFile setPersistJobId(long persistJobId); MutableInodeFile setShouldPersistTime(long shouldPersistTime); MutableInodeFile setReplicationDurable(int replicationDurable); MutableInodeFile setReplicationMax(int replicationMax); MutableInodeFile setReplicationMin(int replicationMin); MutableInodeFile setTempUfsPath(String tempUfsPath); void updateFromEntry(UpdateInodeFileEntry entry); @Override String toString(); static MutableInodeFile fromJournalEntry(InodeFileEntry entry); static MutableInodeFile create(long blockContainerId, long parentId, String name,
      long creationTimeMs, CreateFileContext context); @Override JournalEntry toJournalEntry(); @Override JournalEntry toJournalEntry(String path); @Override InodeMeta.Inode toProto(); static MutableInodeFile fromProto(InodeOrBuilder inode);  }