use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class SorterTest method sortedSubKvBuffer.
private BytesInput sortedSubKvBuffer(Config config) throws Exception {
List<Integer> kv1 = ImmutableList.of(3, 2, 1, 4, 1);
List<Integer> kv2 = ImmutableList.of(1, 3, 1, 5, 1);
List<Integer> kv3 = ImmutableList.of(2, 8, 1, 9, 1);
List<Integer> kv4 = ImmutableList.of(3, 2, 1, 3, 1);
List<Integer> kv5 = ImmutableList.of(2, 5, 1, 8, 1);
List<List<Integer>> data = ImmutableList.of(kv1, kv2, kv3, kv4, kv5);
BytesInput input = SorterTestUtil.inputFromSubKvMap(data);
BytesOutput output = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
PointerCombiner combiner = SorterTestUtil.createPointerCombiner(IntValue::new, new IntValueSumCombiner());
int flushThreshold = config.get(ComputerOptions.INPUT_MAX_EDGES_IN_ONE_VERTEX);
InnerSortFlusher flusher = new CombineSubKvInnerSortFlusher(output, combiner, flushThreshold);
Sorter sorter = SorterTestUtil.createSorter(config);
sorter.sortBuffer(input, flusher, true);
return EntriesUtil.inputFromOutput(output);
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class HugeConverterTest method testConvertValue.
@Test
public void testConvertValue() {
Assert.assertEquals(NullValue.get(), HugeConverter.convertValue(null));
Assert.assertEquals(new BooleanValue(true), HugeConverter.convertValue(true));
Assert.assertEquals(new IntValue(1), HugeConverter.convertValue(1));
Assert.assertEquals(new LongValue(-1L), HugeConverter.convertValue(-1L));
Assert.assertEquals(new FloatValue(0.999F), HugeConverter.convertValue(0.999F));
Assert.assertEquals(new DoubleValue(-0.001D), HugeConverter.convertValue(-0.001D));
Assert.assertEquals(new StringValue("test"), HugeConverter.convertValue("test"));
ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
listValue.add(new IntValue(1));
listValue.add(new IntValue(2));
List<Integer> list = ImmutableList.of(1, 2);
Assert.assertEquals(listValue, HugeConverter.convertValue(list));
ListValue<ListValue<LongValue>> nestListValue = new ListValue<>(ValueType.LIST_VALUE);
ListValue<LongValue> subListValue1 = new ListValue<>(ValueType.LONG);
subListValue1.add(new LongValue(1L));
subListValue1.add(new LongValue(2L));
ListValue<LongValue> subListValue2 = new ListValue<>(ValueType.LONG);
subListValue2.add(new LongValue(3L));
subListValue2.add(new LongValue(4L));
nestListValue.add(subListValue1);
nestListValue.add(subListValue2);
List<List<Long>> nestList = ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(3L, 4L));
Assert.assertEquals(nestListValue, HugeConverter.convertValue(nestList));
Assert.assertThrows(ComputerException.class, () -> HugeConverter.convertValue(new byte[0]));
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class HugeConverterTest method testConvertProperties.
@Test
public void testConvertProperties() {
Map<String, Object> rawProperties = new HashMap<>();
rawProperties.put("null-value", null);
rawProperties.put("boolean-value", true);
rawProperties.put("int-value", 1);
rawProperties.put("long-value", 2L);
rawProperties.put("float-value", 0.3F);
rawProperties.put("double-value", 0.4D);
rawProperties.put("list-value", ImmutableList.of(1, 2));
Properties properties = graphFactory().createProperties();
properties.put("null-value", NullValue.get());
properties.put("boolean-value", new BooleanValue(true));
properties.put("int-value", new IntValue(1));
properties.put("long-value", new LongValue(2L));
properties.put("float-value", new FloatValue(0.3F));
properties.put("double-value", new DoubleValue(0.4D));
ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
listValue.add(new IntValue(1));
listValue.add(new IntValue(2));
properties.put("list-value", listValue);
Assert.assertEquals(properties, HugeConverter.convertProperties(rawProperties));
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class Bsp4Worker method waitMasterResumeDone.
/**
* The master set this signal to let workers knows the first superstep to
* start with.
*/
public int waitMasterResumeDone() {
LOG.info("Worker({}) is waiting for master resume-done", this.workerInfo.id());
String path = this.constructPath(BspEvent.BSP_MASTER_RESUME_DONE);
byte[] bytes = this.bspClient().get(path, this.barrierOnMasterTimeout(), this.logInterval());
IntValue superstep = new IntValue();
SerializeUtil.fromBytes(bytes, superstep);
LOG.info("Worker({}) waited master resume-done({})", this.workerInfo.id(), superstep.value());
return superstep.value();
}
Aggregations