Search in sources :

Example 1 with SubKvEntriesInput

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);
    }
}
Also used : EntryOutput(com.baidu.hugegraph.computer.core.store.entry.EntryOutput) EntryOutputImpl(com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) SubKvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.SubKvEntriesInput) Test(org.junit.Test)

Aggregations

BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)1 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)1 SubKvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.SubKvEntriesInput)1 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)1 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)1 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)1 KvEntryWriter (com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter)1 Test (org.junit.Test)1