use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method testWriteVertex.
@Test
public void testWriteVertex() throws IOException {
GraphFactory graphFactory = context().graphFactory();
// NOTE: need ensure the buffer size can hold follow writed bytes
WriteBuffers buffers = new WriteBuffers(context(), 100, 110);
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffers.writeVertex(vertex);
WriteBuffer buffer = Whitebox.getInternalState(buffers, "writingBuffer");
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);
buffers.writeVertex(vertex);
buffer = Whitebox.getInternalState(buffers, "writingBuffer");
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)));
buffers.writeEdges(vertex);
buffer = Whitebox.getInternalState(buffers, "writingBuffer");
long position3 = buffer.output().position();
Assert.assertGt(position2, position3);
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue 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.IntValue in project hugegraph-computer by hugegraph.
the class IntValueSumCombinerTest method testCombine.
@Test
public void testCombine() {
IntValue sum = new IntValue(0);
IntValueSumCombiner combiner = new IntValueSumCombiner();
for (int i = 1; i <= 10; i++) {
IntValue value = new IntValue(i);
combiner.combine(sum, value, sum);
}
Assert.assertEquals(55, sum.value());
}
use of com.baidu.hugegraph.computer.core.graph.value.IntValue in project hugegraph-computer by hugegraph.
the class IntValueSumCombinerTest method testCombineNull.
@Test
public void testCombineNull() {
IntValue value1 = new IntValue(1);
IntValue value2 = new IntValue(2);
IntValueSumCombiner combiner = new IntValueSumCombiner();
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.IntValue in project hugegraph-computer by hugegraph.
the class JsonStructGraphOutputTest method testWriteReadVertexWithProperties.
@Test
public void testWriteReadVertexWithProperties() throws IOException {
UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false", ComputerOptions.OUTPUT_RESULT_NAME, "rank");
ComputerContext context = context();
GraphFactory factory = context.graphFactory();
Id longId = BytesId.of(100L);
IdListList idListList = new IdListList();
IdList idList1 = new IdList();
idList1.add(BytesId.of(66L));
IdList idList2 = new IdList();
idList2.add(BytesId.of(998L));
idList2.add(BytesId.of(999L));
idListList.add(idList1);
idListList.add(idList2);
Vertex vertex = factory.createVertex(longId, idListList);
vertex.properties().put("boolean", new BooleanValue(true));
vertex.properties().put("byte", new IntValue(127));
vertex.properties().put("short", new IntValue(16383));
vertex.properties().put("int", new IntValue(1000000));
vertex.properties().put("long", new LongValue(10000000000L));
vertex.properties().put("float", new FloatValue(0.1F));
vertex.properties().put("double", new DoubleValue(-0.01D));
vertex.properties().put("idvalue", longId);
String fileName = "output.json";
File file = new File(fileName);
try {
BufferedFileOutput dos = new BufferedFileOutput(file);
StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.JSON, dos);
output.writeVertex(vertex);
dos.close();
@SuppressWarnings("deprecation") String json = FileUtils.readFileToString(file);
Assert.assertEquals("{\"id\":100,\"rank\":[[66],[998,999]]," + "\"properties\":{\"boolean\":true," + "\"byte\":127,\"double\":-0.01," + "\"short\":16383,\"idvalue\":100," + "\"float\":0.1,\"int\":1000000," + "\"long\":10000000000}}" + System.lineSeparator(), json);
} finally {
FileUtils.deleteQuietly(file);
}
}
Aggregations