use of com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher in project hugegraph-computer by hugegraph.
the class SortManager method createSortFlusher.
private InnerSortFlusher createSortFlusher(MessageType type, RandomAccessOutput output, int flushThreshold) {
PointerCombiner combiner;
boolean needSortSubKv;
switch(type) {
case VERTEX:
combiner = new VertexValueCombiner(this.context);
needSortSubKv = false;
break;
case EDGE:
combiner = new EdgeValueCombiner(this.context);
needSortSubKv = true;
break;
case MSG:
combiner = this.createMessageCombiner();
needSortSubKv = false;
break;
default:
throw new ComputerException("Unsupported combine message " + "type for %s", type);
}
InnerSortFlusher flusher;
if (combiner == null) {
flusher = new KvInnerSortFlusher(output);
} else {
if (needSortSubKv) {
flusher = new CombineSubKvInnerSortFlusher(output, combiner, flushThreshold);
} else {
flusher = new CombineKvInnerSortFlusher(output, combiner);
}
}
return flusher;
}
use of com.baidu.hugegraph.computer.core.sort.flusher.KvInnerSortFlusher 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.sort.flusher.KvInnerSortFlusher in project hugegraph-computer by hugegraph.
the class FlusherTest method testExceptionCaseForFlusher.
@Test
public void testExceptionCaseForFlusher() {
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
InnerSortFlusher flusher = new KvInnerSortFlusher(output);
List<KvEntry> entries = new ArrayList<>();
Assert.assertThrows(IllegalArgumentException.class, () -> {
flusher.flush(entries.iterator());
}, e -> {
String errorMsg = "Parameter entries can't be empty";
Assert.assertContains(errorMsg, e.getMessage());
});
}
Aggregations