Search in sources :

Example 1 with IdList

use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.

the class ComputeManagerTest method addMessages.

private static void addMessages(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        int count = RANDOM.nextInt(5);
        for (int j = 0; j < count; j++) {
            Id id = BytesId.of(i);
            IdList message = new IdList();
            message.add(id);
            ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 2 with IdList

use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.

the class ComputeMessageRecvPartitionTest method checkIdValueListMessages.

private static void checkIdValueListMessages(PeekableIterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        for (int j = 0; j < 2; j++) {
            Assert.assertTrue(it.hasNext());
            KvEntry currentEntry = it.next();
            Id currentId = ReceiverUtil.readId(currentEntry.key());
            Id expectId = BytesId.of(i);
            Assert.assertEquals(expectId, currentId);
            IdList expectMessage = new IdList();
            expectMessage.add(expectId);
            IdList currentValue = new IdList();
            ReceiverUtil.readValue(currentEntry.value(), currentValue);
            Assert.assertEquals(expectMessage, currentValue);
        }
    }
    Assert.assertFalse(it.hasNext());
}
Also used : 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) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 3 with IdList

use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.

the class ComputeMessageRecvPartitionTest method addTwentyDuplicateIdValueListMessageBuffer.

private static void addTwentyDuplicateIdValueListMessageBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        for (int j = 0; j < 2; j++) {
            Id id = BytesId.of(i);
            IdList message = new IdList();
            message.add(id);
            ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 4 with IdList

use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.

the class MessageInputTest method expectedMessages.

private static Map<Id, List<IdList>> expectedMessages() {
    Random random = new Random(1);
    Map<Id, List<IdList>> globalMessages = new HashMap<>();
    for (long i = 0L; i < 200L; i++) {
        int count = random.nextInt(5);
        for (int j = 0; j < count; j++) {
            Id id = BytesId.of(random.nextInt(200));
            IdList message = new IdList();
            message.add(id);
            List<IdList> messages = globalMessages.computeIfAbsent(id, nid -> new ArrayList<>());
            messages.add(message);
        }
    }
    return globalMessages;
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) List(java.util.List) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 5 with IdList

use of com.baidu.hugegraph.computer.core.graph.value.IdList in project hugegraph-computer by hugegraph.

the class MessageInputTest method checkMessages.

private void checkMessages(Map<Id, List<IdList>> expectedMessages, MessageInput<IdList> input) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        List<IdList> messages = expectedMessages.get(BytesId.of(i));
        Id id = BytesId.of(i);
        ReusablePointer idPointer = EdgesInputTest.idToReusablePointer(id);
        Iterator<IdList> mit = input.iterator(idPointer);
        if (messages == null) {
            Assert.assertFalse(mit.hasNext());
        } else {
            for (int j = 0; j < messages.size(); j++) {
                Assert.assertTrue(mit.hasNext());
                Assert.assertTrue(messages.contains(mit.next()));
            }
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Aggregations

IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)20 Id (com.baidu.hugegraph.computer.core.graph.id.Id)18 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)14 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)7 Test (org.junit.Test)5 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)4 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)4 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)4 File (java.io.File)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Random (java.util.Random)3 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)2 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)2 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)2 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)2 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)2 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2