Search in sources :

Example 31 with LongValue

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

the class MockMasterComputation2 method assertStep1Aggregators.

@Override
protected void assertStep1Aggregators(MasterComputationContext context) {
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new FloatValue(6.28f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    Assert.assertEquals(new IntValue(9), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(10L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(20.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(20.8), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 32 with LongValue

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

the class MockComputation method assertStep1Aggregators.

protected void assertStep1Aggregators(WorkerContext context) {
    Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
    Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
    Assert.assertEquals(new FloatValue(8.8f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
    Assert.assertEquals(new IntValue(888), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
    Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
    Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
    Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
    Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
    Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
    Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
    Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
    Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue)

Example 33 with LongValue

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

the class EdgeMessageRecvPartitionTest method addTenDuplicateEdgeBuffer.

private static void addTenDuplicateEdgeBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        Edges edges = graphFactory().createEdges(2);
        for (long j = i + 1; j < i + 3; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(j));
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
    }
    for (long i = 0L; i < 10L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        Edges edges = graphFactory().createEdges(2);
        for (long j = i + 1; j < i + 3; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(j));
            Properties properties = graphFactory().createProperties();
            properties.put("p2", new LongValue(2L * i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(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) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 34 with LongValue

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

the class EdgeMessageRecvPartitionTest method addTenEdgeBuffer.

public static void addTenEdgeBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        Edges edges = graphFactory().createEdges(2);
        for (long j = i + 1; j < i + 3; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(j));
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(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) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 35 with LongValue

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

the class VertexMessageRecvPartitionTest method checkTenVertexWithMergedProperties.

private static void checkTenVertexWithMergedProperties(PeekableIterator<KvEntry> it) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        // Assert key
        Assert.assertTrue(it.hasNext());
        KvEntry entry = it.next();
        Id id = ReceiverUtil.readId(entry.key());
        Assert.assertEquals(BytesId.of(i), id);
        // Assert value
        Pointer value = entry.value();
        RandomAccessInput input = value.input();
        long position = input.position();
        input.seek(value.offset());
        String label = StreamGraphInput.readLabel(input);
        Assert.assertEquals("", label);
        Properties properties = graphFactory().createProperties();
        properties.read(input);
        input.seek(position);
        Assert.assertEquals(2, properties.size());
        LongValue v1 = properties.get("p1");
        Assert.assertEquals(new LongValue(i), v1);
        LongValue v2 = properties.get("p2");
        Assert.assertEquals(new LongValue(2L * i), v2);
    }
}
Also used : RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) 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)

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