use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex 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.vertex.Vertex in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method wrapForRead.
@Test
public void wrapForRead() throws IOException {
GraphFactory graphFactory = context().graphFactory();
WriteBuffers buffers = new WriteBuffers(context(), 10, 20);
Vertex vertex = graphFactory.createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffers.writeVertex(vertex);
buffers.prepareSorting();
try (RandomAccessInput input = buffers.wrapForRead()) {
EntryInput entryInput = new EntryInputImpl(input);
StreamGraphInput graphInput = new StreamGraphInput(context(), entryInput);
vertex.value(null);
Assert.assertEquals(vertex, graphInput.readVertex());
}
}
use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method testIsEmpty.
@Test
public void testIsEmpty() throws IOException {
WriteBuffers buffers = new WriteBuffers(context(), 10, 20);
Assert.assertTrue(buffers.isEmpty());
Vertex vertex = context().graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
buffers.writeVertex(vertex);
Assert.assertFalse(buffers.isEmpty());
}
use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.
the class VertexMessageRecvPartitionTest method addTwentyDuplicateVertexBuffer.
private static void addTwentyDuplicateVertexBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
vertex.properties(properties);
ReceiverUtil.consumeBuffer(writeVertex(vertex), consumer);
}
for (long i = 0L; i < 10L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
Properties properties = graphFactory().createProperties();
properties.put("p2", new LongValue(2L * i));
vertex.properties(properties);
ReceiverUtil.consumeBuffer(writeVertex(vertex), consumer);
}
}
use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex 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);
}
Aggregations