Search in sources :

Example 41 with Id

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);
}
Also used : BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 42 with Id

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);
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 43 with Id

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);
    }
}
Also used : BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Id(com.baidu.hugegraph.computer.core.graph.id.Id)

Example 44 with Id

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();
}
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) KvEntryWriter(com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 45 with Id

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);
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId)

Aggregations

Id (com.baidu.hugegraph.computer.core.graph.id.Id)74 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)51 Test (org.junit.Test)29 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)18 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)12 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)12 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)12 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)9 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)8 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)6 File (java.io.File)6 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)5 Config (com.baidu.hugegraph.computer.core.config.Config)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4