Search in sources :

Example 11 with Vertex

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);
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Example 12 with Vertex

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());
    }
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) EntryInputImpl(com.baidu.hugegraph.computer.core.store.entry.EntryInputImpl) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) EntryInput(com.baidu.hugegraph.computer.core.store.entry.EntryInput) StreamGraphInput(com.baidu.hugegraph.computer.core.io.StreamGraphInput) Test(org.junit.Test)

Example 13 with Vertex

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());
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Test(org.junit.Test)

Example 14 with Vertex

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);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties)

Example 15 with Vertex

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);
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Aggregations

Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)46 Test (org.junit.Test)21 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)18 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)16 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)15 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)15 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)13 Id (com.baidu.hugegraph.computer.core.graph.id.Id)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)11 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)10 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)7 Value (com.baidu.hugegraph.computer.core.graph.value.Value)7 IOException (java.io.IOException)7 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)6 File (java.io.File)6 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)4 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)2