use of org.apache.accumulo.core.file.rfile.MultiLevelIndex.BufferedWriter in project accumulo by apache.
the class MultiLevelIndexTest method runTest.
private void runTest(int maxBlockSize, int num) throws IOException {
AccumuloConfiguration aconf = DefaultConfiguration.getInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FSDataOutputStream dos = new FSDataOutputStream(baos, new FileSystem.Statistics("a"));
BCFile.Writer _cbw = new BCFile.Writer(dos, null, "gz", hadoopConf, CryptoServiceFactory.newInstance(aconf, JAVA));
BufferedWriter mliw = new BufferedWriter(new Writer(_cbw, maxBlockSize));
for (int i = 0; i < num; i++) mliw.add(new Key(String.format("%05d000", i)), i, 0, 0, 0);
mliw.addLast(new Key(String.format("%05d000", num)), num, 0, 0, 0);
BCFile.Writer.BlockAppender root = _cbw.prepareMetaBlock("root");
mliw.close(root);
root.close();
_cbw.close();
dos.close();
baos.close();
byte[] data = baos.toByteArray();
SeekableByteArrayInputStream bais = new SeekableByteArrayInputStream(data);
FSDataInputStream in = new FSDataInputStream(bais);
CachableBuilder cb = new CachableBuilder().input(in, "source-1").length(data.length).conf(hadoopConf).cryptoService(CryptoServiceFactory.newInstance(aconf, JAVA));
CachableBlockFile.Reader _cbr = new CachableBlockFile.Reader(cb);
Reader reader = new Reader(_cbr, RFile.RINDEX_VER_8);
CachableBlockFile.CachedBlockRead rootIn = _cbr.getMetaBlock("root");
reader.readFields(rootIn);
rootIn.close();
IndexIterator liter = reader.lookup(new Key("000000"));
int count = 0;
while (liter.hasNext()) {
assertEquals(count, liter.nextIndex());
assertEquals(count, liter.peek().getNumEntries());
assertEquals(count, liter.next().getNumEntries());
count++;
}
assertEquals(num + 1, count);
while (liter.hasPrevious()) {
count--;
assertEquals(count, liter.previousIndex());
assertEquals(count, liter.peekPrevious().getNumEntries());
assertEquals(count, liter.previous().getNumEntries());
}
assertEquals(0, count);
// go past the end
liter = reader.lookup(new Key(String.format("%05d000", num + 1)));
assertFalse(liter.hasNext());
random.ints(100, 0, num * 1_000).forEach(k -> {
int expected;
if (k % 1000 == 0)
// end key is inclusive
expected = k / 1000;
else
expected = k / 1000 + 1;
try {
IndexEntry ie = reader.lookup(new Key(String.format("%08d", k))).next();
assertEquals(expected, ie.getNumEntries());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
Aggregations