Search in sources :

Example 6 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class WriteBuffersTest method testReachThreshold.

@Test
public void testReachThreshold() throws IOException {
    WriteBuffers buffers = new WriteBuffers(context(), 20, 50);
    Assert.assertFalse(buffers.reachThreshold());
    Vertex vertex = context().graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
    // After write, the position is 11
    buffers.writeVertex(vertex);
    Assert.assertFalse(buffers.reachThreshold());
    // After write, the position is 22
    buffers.writeVertex(vertex);
    Assert.assertTrue(buffers.reachThreshold());
    // After write, the position is 33
    buffers.writeVertex(vertex);
    Assert.assertTrue(buffers.reachThreshold());
}
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 7 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue 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 8 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue 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 9 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue 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 10 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue in project hugegraph-computer by hugegraph.

the class ComputeMessageRecvPartitionTest method addTwentyCombineMessageBuffer.

public static void addTwentyCombineMessageBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        for (int j = 0; j < 2; j++) {
            Id id = BytesId.of(i);
            DoubleValue message = new DoubleValue(i);
            ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
        }
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId)

Aggregations

DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)49 Test (org.junit.Test)28 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)21 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)14 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)13 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)12 Id (com.baidu.hugegraph.computer.core.graph.id.Id)10 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)8 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)6 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 DefaultEdge (com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge)2 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)2 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 File (java.io.File)2