Search in sources :

Example 41 with LongValue

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

the class DefaultPropertiesTest method testEquals.

@Test
public void testEquals() {
    DefaultProperties props1 = new DefaultProperties(graphFactory());
    props1.put("p1", new LongValue(1L));
    props1.put("p2", new DoubleValue(2.0D));
    DefaultProperties props2 = new DefaultProperties(props1.get(), UnitTestBase.graphFactory());
    Assert.assertEquals(props1, props2);
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Example 42 with LongValue

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

the class StreamGraphOutputInputTest method testWriteReadVertex.

@Test
public void testWriteReadVertex() throws Exception {
    Id longId = BytesId.of(100L);
    LongValue longValue = new LongValue(999L);
    Vertex vertex = graphFactory().createVertex(longId, longValue);
    Properties properties = graphFactory().createProperties();
    properties.put("age", new LongValue(20L));
    vertex.properties(properties);
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        StreamGraphOutput output = newStreamGraphOutput(bao);
        output.writeVertex(vertex);
        bytes = bao.toByteArray();
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        StreamGraphInput input = newStreamGraphInput(bai);
        assertVertexEqualWithoutValue(vertex, input.readVertex());
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 43 with LongValue

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

the class StreamGraphOutputInputTest method testWriteReadEdgesWithSinglePerLabelFrequency.

@Test
public void testWriteReadEdgesWithSinglePerLabelFrequency() throws Exception {
    UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "SINGLE_PER_LABEL");
    ComputerContext context = ComputerContext.instance();
    GraphFactory graphFactory = context.graphFactory();
    Id longId = BytesId.of(100L);
    LongValue longValue = new LongValue(999L);
    Vertex vertex = graphFactory().createVertex(longId, longValue);
    vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
    vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
    vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        StreamGraphOutput output = newStreamGraphOutput(bao);
        output.writeEdges(vertex);
        bytes = bao.toByteArray();
        bytes = reweaveBytes(bytes);
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        StreamGraphInput input = newStreamGraphInput(bai);
        assertEdgesEqual(vertex, input.readEdges(), EdgeFrequency.SINGLE_PER_LABEL);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Example 44 with LongValue

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

the class StreamGraphOutputInputTest method testWriteReadEdgesWithMultipleFrequency.

@Test
public void testWriteReadEdgesWithMultipleFrequency() throws Exception {
    UnitTestBase.updateOptions(ComputerOptions.INPUT_EDGE_FREQ, "MULTIPLE");
    ComputerContext context = ComputerContext.instance();
    GraphFactory graphFactory = context.graphFactory();
    Id longId = BytesId.of(100L);
    LongValue longValue = new LongValue(999L);
    Vertex vertex = graphFactory().createVertex(longId, longValue);
    vertex.addEdge(graphFactory.createEdge(BytesId.of(2L)));
    vertex.addEdge(graphFactory.createEdge("knows", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", BytesId.of(3L)));
    vertex.addEdge(graphFactory.createEdge("watch", "1111", BytesId.of(4L)));
    vertex.addEdge(graphFactory.createEdge("watch", "2222", BytesId.of(4L)));
    byte[] bytes;
    try (BytesOutput bao = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        StreamGraphOutput output = newStreamGraphOutput(bao);
        output.writeEdges(vertex);
        bytes = bao.toByteArray();
        bytes = reweaveBytes(bytes);
    }
    try (BytesInput bai = IOFactory.createBytesInput(bytes)) {
        StreamGraphInput input = newStreamGraphInput(bai);
        assertEdgesEqual(vertex, input.readEdges(), EdgeFrequency.MULTIPLE);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Test(org.junit.Test)

Example 45 with LongValue

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

the class ComputeManagerTest method addSingleFreqEdgeBuffer.

private static void addSingleFreqEdgeBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        int count = RANDOM.nextInt(20);
        if (count == 0) {
            continue;
        }
        Edges edges = graphFactory().createEdges(count);
        for (long j = 0; j < count; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(RANDOM.nextInt(200)));
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex, EdgeFrequency.SINGLE), 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) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Aggregations

LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)48 Test (org.junit.Test)25 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)21 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)19 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)16 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)13 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)13 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)9 Id (com.baidu.hugegraph.computer.core.graph.id.Id)9 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)8 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)8 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)7 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)2 Config (com.baidu.hugegraph.computer.core.config.Config)2