Search in sources :

Example 1 with Writable

use of com.baidu.hugegraph.computer.core.io.Writable in project hugegraph-computer by hugegraph.

the class EntryOutputTest method testWriteKvEntry.

@Test
public void testWriteKvEntry() throws Exception {
    List<Integer> entries = ImmutableList.of(1, 5, 6, 6, 2, 1, 4, 8);
    List<Id> data = intListToLongIds(entries);
    BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(output);
    for (int i = 0; i < data.size(); ) {
        Id id = data.get(i++);
        Writable value = data.get(i++);
        entryOutput.writeEntry(id, value);
    }
    // Assert result
    BytesInput input = EntriesUtil.inputFromOutput(output);
    EntryIterator iter = new KvEntriesInput(input);
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(1), BytesId.of(5));
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(6), BytesId.of(6));
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(2), BytesId.of(1));
    SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(4), BytesId.of(8));
    iter.close();
}
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) Writable(com.baidu.hugegraph.computer.core.io.Writable) KvEntriesInput(com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Aggregations

BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)1 Id (com.baidu.hugegraph.computer.core.graph.id.Id)1 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)1 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)1 Writable (com.baidu.hugegraph.computer.core.io.Writable)1 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)1 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)1 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)1 Test (org.junit.Test)1