### Question:
SnapshotFileReader extends LocalDirReader { @Override public int readFile(final ByteBufferCollector metaBufferCollector, final String fileName, final long offset, final long maxCount) throws IOException, RetryAgainException { if (fileName.equals(Snapshot.JRAFT_SNAPSHOT_META_FILE)) { final ByteBuffer metaBuf = this.metaTable.saveToByteBufferAsRemote(); metaBuf.position(metaBuf.limit()); metaBufferCollector.setBuffer(metaBuf); return EOF; } final LocalFileMeta fileMeta = this.metaTable.getFileMeta(fileName); if (fileMeta == null) { throw new FileNotFoundException("LocalFileMeta not found for " + fileName); } long newMaxCount = maxCount; if (this.snapshotThrottle != null) { newMaxCount = this.snapshotThrottle.throttledByThroughput(maxCount); if (newMaxCount < maxCount) { if (newMaxCount == 0) { throw new RetryAgainException("readFile throttled by throughput"); } } } return readFileWithMeta(metaBufferCollector, fileName, fileMeta, offset, newMaxCount); } SnapshotFileReader(String path, SnapshotThrottle snapshotThrottle); LocalSnapshotMetaTable getMetaTable(); void setMetaTable(LocalSnapshotMetaTable metaTable); boolean open(); @Override int readFile(final ByteBufferCollector metaBufferCollector, final String fileName, final long offset,
                        final long maxCount);  }### Answer:
@Test public void testReadMetaFile() throws Exception { final ByteBufferCollector bufRef = ByteBufferCollector.allocate(1024); final LocalFileMetaOutter.LocalFileMeta meta = addDataMeta(); assertEquals(-1, this.reader.readFile(bufRef, Snapshot.JRAFT_SNAPSHOT_META_FILE, 0, Integer.MAX_VALUE)); final ByteBuffer buf = bufRef.getBuffer(); buf.flip(); final LocalSnapshotMetaTable newTable = new LocalSnapshotMetaTable(new RaftOptions()); newTable.loadFromIoBufferAsRemote(buf); Assert.assertEquals(meta, newTable.getFileMeta("data")); }
@Test public void testReadFile() throws Exception { final ByteBufferCollector bufRef = ByteBufferCollector.allocate(); try { this.reader.readFile(bufRef, "unfound", 0, 1024); fail(); } catch (final FileNotFoundException e) { } final String data = writeData(); addDataMeta(); final int read = this.reader.readFile(bufRef, "data", 0, 1024); assertEquals(-1, read); final ByteBuffer buf = bufRef.getBuffer(); buf.flip(); assertEquals(data.length(), buf.remaining()); final byte[] bs = new byte[data.length()]; buf.get(bs); assertEquals(data, new String(bs)); }