Search in sources :

Example 11 with EntryOutputImpl

use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl in project hugegraph-computer by hugegraph.

the class EntriesUtilTest method testKvEntryWithFirstSubKv.

@Test
public void testKvEntryWithFirstSubKv() throws IOException {
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(output);
    KvEntryWriter subKvWriter = entryOutput.writeEntry(BytesId.of(100));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeSubKv(BytesId.of(1), BytesId.of(1));
    subKvWriter.writeFinish();
    BytesInput input = EntriesUtil.inputFromOutput(output);
    // Read entry from buffer
    KvEntry entry = EntriesUtil.kvEntryFromInput(input, true, true);
    entry = EntriesUtil.kvEntryWithFirstSubKv(entry);
    // Assert subKvEntry size
    Assert.assertEquals(4, entry.numSubEntries());
}
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) Test(org.junit.Test)

Example 12 with EntryOutputImpl

use of com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl 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

EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)12 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)12 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)11 GraphComputeOutput (com.baidu.hugegraph.computer.core.io.GraphComputeOutput)4 StreamGraphOutput (com.baidu.hugegraph.computer.core.io.StreamGraphOutput)4 KvEntryWriter (com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter)4 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)3 Id (com.baidu.hugegraph.computer.core.graph.id.Id)3 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)3 Test (org.junit.Test)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)2 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)1 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)1 Writable (com.baidu.hugegraph.computer.core.io.Writable)1 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)1 SubKvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.SubKvEntriesInput)1