use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBufferTest method testWriteVertex.
@Test
public void testWriteVertex() throws IOException {
GraphFactory graphFactory = context.graphFactory();
// NOTE: need ensure the buffer size can hold follow writed bytes
WriteBuffer buffer = new WriteBuffer(context, 100, 110);
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffer.writeVertex(vertex);
long position1 = buffer.output().position();
Assert.assertGt(0L, position1);
vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
Properties properties = graphFactory.createProperties();
properties.put("name", BytesId.of("marko"));
properties.put("age", new IntValue(18));
properties.put("city", new ListValue<>(ValueType.ID, ImmutableList.of(BytesId.of("wuhan"), BytesId.of("xian"))));
vertex.properties(properties);
buffer.writeVertex(vertex);
long position2 = buffer.output().position();
Assert.assertGt(position1, position2);
vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
buffer.writeEdges(vertex);
long position3 = buffer.output().position();
Assert.assertGt(position2, position3);
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class WriteBufferTest method testIsEmpty.
@Test
public void testIsEmpty() throws IOException {
WriteBuffer buffer = new WriteBuffer(context, 10, 20);
Assert.assertTrue(buffer.isEmpty());
Vertex vertex = context.graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffer.writeVertex(vertex);
Assert.assertFalse(buffer.isEmpty());
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class DoubleValueSumCombinerTest method testCombineNull.
@Test
public void testCombineNull() {
DoubleValue value1 = new DoubleValue(0.0D);
DoubleValue value2 = new DoubleValue(0.0D);
DoubleValueSumCombiner combiner = new DoubleValueSumCombiner();
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(null, value2, value2);
}, e -> {
Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, null, value2);
}, e -> {
Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, value2, null);
}, e -> {
Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class PointerCombinerTest method testMessageCombiner.
@Test
public void testMessageCombiner() throws IOException {
Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName());
Combiner<DoubleValue> valueCombiner = config.createObject(ComputerOptions.WORKER_COMBINER_CLASS);
PointerCombiner combiner = SorterTestUtil.createPointerCombiner(DoubleValue::new, new DoubleValueSumCombiner());
try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
DoubleValue value1 = new DoubleValue(1.0D);
DoubleValue value2 = new DoubleValue(2.0D);
value1.write(bytesOutput1);
value2.write(bytesOutput2);
Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
Pointer pointer = combiner.combine(pointer1, pointer2);
BytesInput input = IOFactory.createBytesInput(pointer.bytes());
DoubleValue combinedValue = new DoubleValue();
combinedValue.read(input);
Assert.assertEquals(new DoubleValue(3.0D), combinedValue);
}
}
use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.
the class DefaultPropertiesTest method testConstructor.
@Test
public void testConstructor() {
DefaultProperties properties = new DefaultProperties(graphFactory());
Assert.assertEquals(0, properties.get().size());
properties.put("p1", new LongValue(1L));
properties.put("p2", new DoubleValue(2.0D));
Map<String, Value> props = properties.get();
Assert.assertEquals(2, props.size());
Assert.assertEquals(new LongValue(1L), props.get("p1"));
Assert.assertEquals(new DoubleValue(2.0D), props.get("p2"));
}
Aggregations