use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class MockComputation2 method assertStep1Aggregators.
@Override
protected void assertStep1Aggregators(WorkerContext context) {
Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
Assert.assertEquals(new LongValue(10L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
Assert.assertEquals(new FloatValue(20.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
Assert.assertEquals(new DoubleValue(20.8), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation method updateStep0Aggregators.
protected void updateStep0Aggregators(MasterComputationContext context) {
// Update UNSTABLE aggregator
context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE, new FloatValue(8.8f));
Assert.assertEquals(new FloatValue(8.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE, new IntValue(888));
Assert.assertEquals(new IntValue(888), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
// Update aggregator with error
this.assertAggregatedValueWithError(context);
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation method registerAggregatorWithError.
private void registerAggregatorWithError(MasterContext context) {
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.registerAggregator("", MockIntAggregator.class);
}, e -> {
Assert.assertContains("registered aggregator name can't be empty", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.registerAggregator(null, MockIntAggregator.class);
}, e -> {
Assert.assertContains("registered aggregator name can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.registerAggregator("", ValueType.INT, IntValueSumCombiner.class);
}, e -> {
Assert.assertContains("registered aggregator name can't be empty", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.registerAggregator(null, ValueType.INT, IntValueSumCombiner.class);
}, e -> {
Assert.assertContains("registered aggregator name can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.registerAggregator(AGGR_INT_UNSTABLE, ValueType.INT, null);
}, e -> {
Assert.assertContains("combiner of aggregator can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
ValueType type = null;
context.registerAggregator(AGGR_INT_UNSTABLE, type, IntValueSumCombiner.class);
}, e -> {
Assert.assertContains("value type of aggregator can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
IntValue value = null;
context.registerAggregator(AGGR_INT_UNSTABLE, value, IntValueSumCombiner.class);
}, e -> {
Assert.assertContains("The aggregator default value can't be null", e.getMessage());
});
// Not applied now, can get it through aggregatedValue() after inited()
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.aggregatedValue(AGGR_INT_UNSTABLE, new IntValue(Integer.MAX_VALUE));
}, e -> {
Assert.assertContains("Can't get aggregator 'aggr_int_unstable", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class SortLargeDataTest method mergeFiles.
private static void mergeFiles(Sorter sorter, List<String> files, List<String> outputs) throws Exception {
PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
OuterSortFlusher flusher = new CombineKvOuterSortFlusher(combiner);
sorter.mergeInputs(files, flusher, outputs, false);
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class SortLargeDataTest method sortBuffer.
private static RandomAccessInput sortBuffer(Sorter sorter, RandomAccessInput input) throws Exception {
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
InnerSortFlusher flusher = new CombineKvInnerSortFlusher(output, combiner);
sorter.sortBuffer(input, flusher, false);
return EntriesUtil.inputFromOutput(output);
}
Aggregations