use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class VertexMessageRecvPartitionTest method checkTenVertexWithMergedProperties.
private static void checkTenVertexWithMergedProperties(PeekableIterator<KvEntry> it) throws IOException {
for (long i = 0L; i < 10L; i++) {
// Assert key
Assert.assertTrue(it.hasNext());
KvEntry entry = it.next();
Id id = ReceiverUtil.readId(entry.key());
Assert.assertEquals(BytesId.of(i), id);
// Assert value
Pointer value = entry.value();
RandomAccessInput input = value.input();
long position = input.position();
input.seek(value.offset());
String label = StreamGraphInput.readLabel(input);
Assert.assertEquals("", label);
Properties properties = graphFactory().createProperties();
properties.read(input);
input.seek(position);
Assert.assertEquals(2, properties.size());
LongValue v1 = properties.get("p1");
Assert.assertEquals(new LongValue(i), v1);
LongValue v2 = properties.get("p2");
Assert.assertEquals(new LongValue(2L * i), v2);
}
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class EntryOutputTest method testSubKvNeedSort.
@Test
public void testSubKvNeedSort() throws Exception {
List<Integer> entries = ImmutableList.of(5, 6, 6, 2, 1, 4, 8, 1, 2, 2, 6, 1);
BytesInput input = inputFromEntries(entries, true);
EntryIterator iter = new KvEntriesInput(input, true);
// Assert entry1
KvEntry kvEntry1 = iter.next();
Id key1 = StoreTestUtil.idFromPointer(kvEntry1.key());
Assert.assertEquals(BytesId.of(5), key1);
EntryIterator kvEntry1SubKvs = EntriesUtil.subKvIterFromEntry(kvEntry1);
KvEntry subKv1 = kvEntry1SubKvs.next();
Assert.assertEquals(0, subKv1.numSubEntries());
SorterTestUtil.assertKvEntry(subKv1, BytesId.of(2), BytesId.of(1));
KvEntry subKv2 = kvEntry1SubKvs.next();
Assert.assertEquals(0, subKv2.numSubEntries());
SorterTestUtil.assertKvEntry(subKv2, BytesId.of(4), BytesId.of(8));
KvEntry subKv3 = kvEntry1SubKvs.next();
Assert.assertEquals(0, subKv3.numSubEntries());
SorterTestUtil.assertKvEntry(subKv3, BytesId.of(6), BytesId.of(6));
// Assert entry2
KvEntry kvEntry2 = iter.next();
Id key2 = StoreTestUtil.idFromPointer(kvEntry2.key());
Assert.assertEquals(BytesId.of(1), key2);
EntryIterator kvEntry2SubKvs = EntriesUtil.subKvIterFromEntry(kvEntry2);
SorterTestUtil.assertKvEntry(kvEntry2SubKvs.next(), BytesId.of(2), BytesId.of(2));
SorterTestUtil.assertKvEntry(kvEntry2SubKvs.next(), BytesId.of(6), BytesId.of(1));
iter.close();
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method addMessages.
private static void addMessages(Consumer<NetworkBuffer> 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);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class MessageInputTest method addMessages.
private static void addMessages(Consumer<NetworkBuffer> consumer) throws IOException {
Random random = new Random(1);
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);
ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class MessageInputTest method testMessageInput.
@Test
public void testMessageInput() throws IOException {
MessageRecvManager receiveManager = this.managers.get(MessageRecvManager.NAME);
receiveManager.onStarted(this.connectionId);
// Superstep 0
receiveManager.beforeSuperstep(this.config, 0);
receiveManager.onStarted(this.connectionId);
addMessages((NetworkBuffer buffer) -> {
receiveManager.handle(MessageType.MSG, 0, buffer);
});
receiveManager.onFinished(this.connectionId);
PeekableIterator<KvEntry> it = receiveManager.messagePartitions().get(0);
MessageInput<IdList> input = new MessageInput<>(context(), it);
Map<Id, List<IdList>> expectedMessages = expectedMessages();
checkMessages(expectedMessages, input);
}
Aggregations