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();
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations