use of com.baidu.hugegraph.computer.core.store.buffer.SubKvEntriesInput in project hugegraph-computer by hugegraph.
the class EntriesUtilTest method testSubKvEntriesInput.
@Test
public void testSubKvEntriesInput() throws Exception {
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output);
KvEntryWriter subKvWriter = entryOutput.writeEntry(BytesId.of(100));
subKvWriter.writeSubKv(BytesId.of(20), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(10), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(50), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(40), BytesId.of(1));
subKvWriter.writeSubKv(BytesId.of(10), BytesId.of(1));
subKvWriter.writeFinish();
BytesInput input = EntriesUtil.inputFromOutput(output);
// Test inlinePointer kvEntry
KvEntry entry = EntriesUtil.kvEntryFromInput(input, true, true);
Assert.assertEquals(BytesId.of(100), StoreTestUtil.idFromPointer(entry.key()));
try (EntryIterator iter = new SubKvEntriesInput(entry, true)) {
Assert.assertEquals(BytesId.of(10), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(10), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(20), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(40), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(50), StoreTestUtil.idFromPointer(iter.next().key()));
}
input.seek(0);
// Test cachedPointer kvEntry
entry = EntriesUtil.kvEntryFromInput(input, false, true);
Assert.assertEquals(BytesId.of(100), StoreTestUtil.idFromPointer(entry.key()));
try (EntryIterator iter = new SubKvEntriesInput(entry, false)) {
Assert.assertEquals(BytesId.of(10), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(10), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(20), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(40), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertEquals(BytesId.of(50), StoreTestUtil.idFromPointer(iter.next().key()));
Assert.assertThrows(NoSuchElementException.class, iter::next);
}
}
Aggregations