use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class FlusherTest method testKvInnerSortFlusher.
@Test
public void testKvInnerSortFlusher() throws Exception {
List<Integer> map = ImmutableList.of(2, 1, 3, 1, 2, 1, 4, 1);
BytesInput input = SorterTestUtil.inputFromKvMap(map);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
Sorter sorter = SorterTestUtil.createSorter(CONFIG);
sorter.sortBuffer(input, new KvInnerSortFlusher(output), false);
BytesInput result = EntriesUtil.inputFromOutput(output);
EntryIterator iter = new KvEntriesInput(result);
SorterTestUtil.assertKvEntry(iter.next(), 2, 1);
SorterTestUtil.assertKvEntry(iter.next(), 2, 1);
SorterTestUtil.assertKvEntry(iter.next(), 3, 1);
SorterTestUtil.assertKvEntry(iter.next(), 4, 1);
iter.close();
}
use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class FlusherTest method testOverwriteCombiner.
@Test
public void testOverwriteCombiner() throws Exception {
List<Integer> data = ImmutableList.of(1, 2, 3, 5, 1, 3, 1, 1, 3, 4);
BytesInput input = SorterTestUtil.inputFromKvMap(data);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new OverwriteCombiner<>());
InnerSortFlusher flusher = new CombineKvInnerSortFlusher(output, combiner);
Sorter sorter = SorterTestUtil.createSorter(CONFIG);
sorter.sortBuffer(input, flusher, false);
BytesInput result = EntriesUtil.inputFromOutput(output);
// Assert result
KvEntriesInput iter = new KvEntriesInput(result);
SorterTestUtil.assertKvEntry(iter.next(), 1, 1);
SorterTestUtil.assertKvEntry(iter.next(), 3, 4);
iter.close();
}
use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class SorterTestUtil method assertOutputEqualsMap.
public static void assertOutputEqualsMap(BytesOutput output, Map<Integer, List<Integer>> map) throws IOException {
byte[] buffer = output.buffer();
BytesInput input = IOFactory.createBytesInput(buffer);
for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
input.readInt();
int key = input.readInt();
Assert.assertEquals(entry.getKey().intValue(), key);
int valueLength = input.readFixedInt();
int valueCount = valueLength / Integer.BYTES;
List<Integer> values = new ArrayList<>();
for (int i = 0; i < valueCount; i++) {
values.add(input.readInt());
}
Assert.assertEquals(entry.getValue(), values);
}
}
use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.
the class EntryOutputTest method testWriteKvEntry.
@Test
public void testWriteKvEntry() throws Exception {
List<Integer> entries = ImmutableList.of(1, 5, 6, 6, 2, 1, 4, 8);
List<Id> data = intListToLongIds(entries);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
EntryOutput entryOutput = new EntryOutputImpl(output);
for (int i = 0; i < data.size(); ) {
Id id = data.get(i++);
Writable value = data.get(i++);
entryOutput.writeEntry(id, value);
}
// Assert result
BytesInput input = EntriesUtil.inputFromOutput(output);
EntryIterator iter = new KvEntriesInput(input);
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(1), BytesId.of(5));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(6), BytesId.of(6));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(2), BytesId.of(1));
SorterTestUtil.assertKvEntry(iter.next(), BytesId.of(4), BytesId.of(8));
iter.close();
}
use of com.baidu.hugegraph.computer.core.io.BytesInput 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();
}
Aggregations