@Test public void testIterator() throws Exception { final int blockCount = 3; RocksBlockStore blockStore = new RocksBlockStore(mFolder.newFolder().getAbsolutePath()); for (int i = 0; i < blockCount; i++) { blockStore.putBlock(i, Block.BlockMeta.newBuilder().setLength(i).build()); } Iterator<BlockStore.Block> iter = blockStore.iterator(); for (int i = 0; i < blockCount; i++) { assertTrue(iter.hasNext()); BlockStore.Block block = iter.next(); assertEquals(i, block.getId()); assertEquals(i, block.getMeta().getLength()); } assertFalse(iter.hasNext()); }
@Override public Iterator<Block> iterator() { return RocksUtils.createIterator(db().newIterator(mBlockMetaColumn.get(), mIteratorOption), (iter) -> new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value()))); }
RocksBlockStore implements BlockStore { @Override public Iterator<Block> iterator() { return RocksUtils.createIterator(db().newIterator(mBlockMetaColumn.get(), mIteratorOption), (iter) -> new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value()))); } }
RocksBlockStore implements BlockStore { @Override public Iterator<Block> iterator() { return RocksUtils.createIterator(db().newIterator(mBlockMetaColumn.get(), mIteratorOption), (iter) -> new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value()))); } RocksBlockStore(String baseDir); }
RocksBlockStore implements BlockStore { @Override public Iterator<Block> iterator() { return RocksUtils.createIterator(db().newIterator(mBlockMetaColumn.get(), mIteratorOption), (iter) -> new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value()))); } RocksBlockStore(String baseDir); @Override Optional<BlockMeta> getBlock(long id); @Override void putBlock(long id, BlockMeta meta); @Override void removeBlock(long id); @Override void clear(); @Override void close(); @Override List<BlockLocation> getLocations(long id); @Override void addLocation(long id, BlockLocation location); @Override void removeLocation(long blockId, long workerId); @Override Iterator<Block> iterator(); }
RocksBlockStore implements BlockStore { @Override public Iterator<Block> iterator() { return RocksUtils.createIterator(db().newIterator(mBlockMetaColumn.get(), mIteratorOption), (iter) -> new Block(Longs.fromByteArray(iter.key()), BlockMeta.parseFrom(iter.value()))); } RocksBlockStore(String baseDir); @Override Optional<BlockMeta> getBlock(long id); @Override void putBlock(long id, BlockMeta meta); @Override void removeBlock(long id); @Override void clear(); @Override void close(); @Override List<BlockLocation> getLocations(long id); @Override void addLocation(long id, BlockLocation location); @Override void removeLocation(long blockId, long workerId); @Override Iterator<Block> iterator();  }