use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class SerializeUtilTest method testConvertBytesAndListObject.
@Test
public void testConvertBytesAndListObject() {
Id id1 = BytesId.of(1L);
Id id2 = BytesId.of(2L);
List<Id> list1 = new ArrayList<>(2);
list1.add(id1);
list1.add(id2);
byte[] bytes = SerializeUtil.toBytes(list1);
List<Id> list2 = SerializeUtil.fromBytes(bytes, () -> new BytesId());
Assert.assertEquals(list1, list2);
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class SerializeUtilTest method testConvertBytesAndObject.
@Test
public void testConvertBytesAndObject() {
Id id1 = BytesId.of(1L);
byte[] bytes = SerializeUtil.toBytes(id1);
Id id2 = BytesId.of(2L);
SerializeUtil.fromBytes(bytes, id2);
Assert.assertEquals(id1, id2);
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class UnitTestBase method assertIdEqualAfterWriteAndRead.
public static void assertIdEqualAfterWriteAndRead(Id oldId) throws IOException {
byte[] bytes;
try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
oldId.write(bao);
bytes = bao.toByteArray();
}
Id newId = IdFactory.createId(oldId.idType());
try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
newId.read(bai);
Assert.assertEquals(oldId, newId);
}
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class EdgeMessageRecvPartitionTest method writeEdges.
private static byte[] writeEdges(Vertex vertex) throws IOException {
BytesOutput bytesOutput = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(bytesOutput);
Id id = vertex.id();
KvEntryWriter subKvWriter = entryOutput.writeEntry(out -> {
id.write(out);
});
for (Edge edge : vertex.edges()) {
Id targetId = edge.targetId();
subKvWriter.writeSubKv(out -> {
targetId.write(out);
}, out -> {
edge.properties().write(out);
});
}
subKvWriter.writeFinish();
return bytesOutput.toByteArray();
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class ComputeMessageRecvPartitionTest method checkTenCombineMessages.
public static void checkTenCombineMessages(PeekableIterator<KvEntry> it) throws IOException {
Assert.assertTrue(it.hasNext());
KvEntry lastEntry = it.next();
Id lastId = ReceiverUtil.readId(lastEntry.key());
DoubleValue lastSumValue = new DoubleValue();
ReceiverUtil.readValue(lastEntry.value(), lastSumValue);
while (it.hasNext()) {
KvEntry currentEntry = it.next();
Id currentId = ReceiverUtil.readId(currentEntry.key());
DoubleValue currentValue = new DoubleValue();
ReceiverUtil.readValue(lastEntry.value(), currentValue);
if (lastId.equals(currentId)) {
lastSumValue.value(lastSumValue.value() + currentValue.value());
} else {
Assert.assertEquals((Long) lastId.asObject() * 2.0D, lastSumValue.value(), 0.0D);
}
}
Assert.assertEquals((Long) lastId.asObject() * 2.0D, lastSumValue.value(), 0.0D);
}
Aggregations