Search in sources :

Example 16 with Properties

use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.

the class MergeNewPropertiesCombinerTest method testCombineNull.

@Test
public void testCombineNull() {
    Properties properties1 = graphFactory().createProperties();
    properties1.put("name", BytesId.of("marko"));
    properties1.put("city", BytesId.of("Beijing"));
    Properties properties2 = graphFactory().createProperties();
    properties2.put("name", BytesId.of("josh"));
    properties2.put("age", BytesId.of("18"));
    PropertiesCombiner combiner = new MergeNewPropertiesCombiner();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(null, properties2, properties2);
    }, e -> {
        Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(properties1, null, properties2);
    }, e -> {
        Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        combiner.combine(properties1, properties2, null);
    }, e -> {
        Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
    });
}
Also used : Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 17 with Properties

use of com.baidu.hugegraph.computer.core.graph.properties.Properties 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 18 with Properties

use of com.baidu.hugegraph.computer.core.graph.properties.Properties 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 19 with Properties

use of com.baidu.hugegraph.computer.core.graph.properties.Properties 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)

Example 20 with Properties

use of com.baidu.hugegraph.computer.core.graph.properties.Properties in project hugegraph-computer by hugegraph.

the class HugeConverterTest method testConvertProperties.

@Test
public void testConvertProperties() {
    Map<String, Object> rawProperties = new HashMap<>();
    rawProperties.put("null-value", null);
    rawProperties.put("boolean-value", true);
    rawProperties.put("int-value", 1);
    rawProperties.put("long-value", 2L);
    rawProperties.put("float-value", 0.3F);
    rawProperties.put("double-value", 0.4D);
    rawProperties.put("list-value", ImmutableList.of(1, 2));
    Properties properties = graphFactory().createProperties();
    properties.put("null-value", NullValue.get());
    properties.put("boolean-value", new BooleanValue(true));
    properties.put("int-value", new IntValue(1));
    properties.put("long-value", new LongValue(2L));
    properties.put("float-value", new FloatValue(0.3F));
    properties.put("double-value", new DoubleValue(0.4D));
    ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
    listValue.add(new IntValue(1));
    listValue.add(new IntValue(2));
    properties.put("list-value", listValue);
    Assert.assertEquals(properties, HugeConverter.convertProperties(rawProperties));
}
Also used : HashMap(java.util.HashMap) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) ListValue(com.baidu.hugegraph.computer.core.graph.value.ListValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Aggregations

Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)30 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)20 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)15 Test (org.junit.Test)12 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)11 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)9 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)7 Id (com.baidu.hugegraph.computer.core.graph.id.Id)6 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)5 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)5 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)3 Config (com.baidu.hugegraph.computer.core.config.Config)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3 IOException (java.io.IOException)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)2 EdgeFrequency (com.baidu.hugegraph.computer.core.config.EdgeFrequency)2