use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.
the class EdgeMessageRecvPartitionTest method checkTenEdges.
public static void checkTenEdges(PeekableIterator<KvEntry> it) throws IOException {
for (long i = 0L; i < 10L; i++) {
Assert.assertTrue(it.hasNext());
KvEntry entry = it.next();
Id id = ReceiverUtil.readId(entry.key());
Assert.assertEquals(BytesId.of(i), id);
EntryIterator subKvIt = EntriesUtil.subKvIterFromEntry(entry);
for (long j = i + 1; j < i + 3; j++) {
Assert.assertTrue(subKvIt.hasNext());
KvEntry subKv = subKvIt.next();
Id targetId = ReceiverUtil.readId(subKv.key());
Assert.assertEquals(BytesId.of(j), targetId);
Properties properties = graphFactory().createProperties();
ReceiverUtil.readValue(subKv.value(), properties);
Assert.assertEquals(1, properties.size());
LongValue v1 = properties.get("p1");
Assert.assertEquals(new LongValue(i), v1);
}
}
Assert.assertFalse(it.hasNext());
}
use of com.baidu.hugegraph.computer.core.store.entry.KvEntry 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());
}
use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.
the class VertexMessageRecvPartitionTest method checkPartitionIterator.
public static void checkPartitionIterator(PeekableIterator<KvEntry> it) throws IOException {
for (long i = 0L; i < 10L; i++) {
Assert.assertTrue(it.hasNext());
KvEntry entry = it.next();
Id id = ReceiverUtil.readId(entry.key());
Assert.assertEquals(BytesId.of(i), id);
}
}
use of com.baidu.hugegraph.computer.core.store.entry.KvEntry in project hugegraph-computer by hugegraph.
the class EntryOutputTest method testSubKvNotNeedSort.
@Test
public void testSubKvNotNeedSort() throws Exception {
List<Integer> entries = ImmutableList.of(5, 6, 6, 2, 1, 4, 8, 1, 2, 2, 6, 1);
BytesInput input = inputFromEntries(entries, false);
EntryIterator iter = new KvEntriesInput(input, true);
// Assert entry1
KvEntry kvEntry1 = iter.next();
Assert.assertEquals(3, kvEntry1.numSubEntries());
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(6), BytesId.of(6));
SorterTestUtil.assertKvEntry(kvEntry1SubKvs.next(), BytesId.of(2), BytesId.of(1));
SorterTestUtil.assertKvEntry(kvEntry1SubKvs.next(), BytesId.of(4), BytesId.of(8));
// 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.store.entry.KvEntry 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