Search in sources :

Example 16 with BytesOutput

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

the class EdgesInputTest method writeVertex.

private static byte[] writeVertex(Vertex vertex) throws IOException {
    BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
    EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
    GraphComputeOutput output = new StreamGraphOutput(context(), entryOutput);
    output.writeVertex(vertex);
    return bytesOutput.toByteArray();
}
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) StreamGraphOutput(com.baidu.hugegraph.computer.core.io.StreamGraphOutput) GraphComputeOutput(com.baidu.hugegraph.computer.core.io.GraphComputeOutput)

Example 17 with BytesOutput

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

the class EdgesInputTest method idToReusablePointer.

public static ReusablePointer idToReusablePointer(Id id) throws IOException {
    BytesOutput output = IOFactory.createBytesOutput(9);
    id.write(output);
    return new ReusablePointer(output.buffer(), (int) output.position());
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput)

Example 18 with BytesOutput

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

the class PointerCombinerTest method testMessageCombiner.

@Test
public void testMessageCombiner() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName());
    Combiner<DoubleValue> valueCombiner = config.createObject(ComputerOptions.WORKER_COMBINER_CLASS);
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(DoubleValue::new, new DoubleValueSumCombiner());
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        DoubleValue value1 = new DoubleValue(1.0D);
        DoubleValue value2 = new DoubleValue(2.0D);
        value1.write(bytesOutput1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Pointer pointer = combiner.combine(pointer1, pointer2);
        BytesInput input = IOFactory.createBytesInput(pointer.bytes());
        DoubleValue combinedValue = new DoubleValue();
        combinedValue.read(input);
        Assert.assertEquals(new DoubleValue(3.0D), combinedValue);
    }
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Test(org.junit.Test)

Example 19 with BytesOutput

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

the class UnitTestBase method assertValueEqualAfterWriteAndRead.

public static void assertValueEqualAfterWriteAndRead(Value oldValue) throws IOException {
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        oldValue.write(bao);
        bytes = bao.toByteArray();
    }
    Value newValue = graphFactory().createValue(oldValue.valueType());
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        newValue.read(bai);
        Assert.assertEquals(oldValue, newValue);
    }
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Value(com.baidu.hugegraph.computer.core.graph.value.Value)

Example 20 with BytesOutput

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

the class UnitTestBase method assertEqualAfterWriteAndRead.

public static void assertEqualAfterWriteAndRead(Writable writeObj, Readable readObj) throws IOException {
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        writeObj.write(bao);
        bytes = bao.toByteArray();
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        readObj.read(bai);
        Assert.assertEquals(writeObj, readObj);
    }
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput)

Aggregations

BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)36 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)16 Test (org.junit.Test)16 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)11 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)11 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)7 CombineKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)7 InnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher)5 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)5 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)5 ArrayList (java.util.ArrayList)5 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 Config (com.baidu.hugegraph.computer.core.config.Config)4 Id (com.baidu.hugegraph.computer.core.graph.id.Id)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 GraphComputeOutput (com.baidu.hugegraph.computer.core.io.GraphComputeOutput)4 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)4 StreamGraphOutput (com.baidu.hugegraph.computer.core.io.StreamGraphOutput)4 KvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher)4 KvEntryWriter (com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter)4