Search in sources :

Example 11 with Properties

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

the class MergeOldPropertiesCombinerTest method testCombine.

@Test
public void testCombine() {
    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"));
    Properties expect = graphFactory().createProperties();
    expect.put("name", BytesId.of("josh"));
    expect.put("age", BytesId.of("18"));
    expect.put("city", BytesId.of("Beijing"));
    Properties properties = graphFactory().createProperties();
    PropertiesCombiner combiner = new MergeOldPropertiesCombiner();
    combiner.combine(properties1, properties2, properties);
    Assert.assertEquals(expect, properties);
}
Also used : Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 12 with Properties

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

the class MergeOldPropertiesCombinerTest method testCombineNullValue.

@Test
public void testCombineNullValue() {
    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 MergeOldPropertiesCombiner();
    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 13 with Properties

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

the class PointerCombinerTest method testVertexPropertiesCombiner.

@Test
public void testVertexPropertiesCombiner() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_VERTEX_PROPERTIES_COMBINER_CLASS, MergeOldPropertiesCombiner.class.getName());
    Combiner<Properties> valueCombiner = config.createObject(ComputerOptions.WORKER_VERTEX_PROPERTIES_COMBINER_CLASS);
    GraphFactory graphFactory = graphFactory();
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(graphFactory::createProperties, valueCombiner);
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        Properties value1 = graphFactory.createProperties();
        value1.put("p1", new LongValue(1L));
        Properties value2 = graphFactory.createProperties();
        value2.put("p2", new LongValue(2L));
        value1.write(bytesOutput1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Pointer pointer = combiner.combine(pointer1, pointer2);
        BytesInput input = IOFactory.createBytesInput(pointer.bytes());
        Properties combinedValue = graphFactory.createProperties();
        combinedValue.read(input);
        Map<String, Value> map = combinedValue.get();
        Assert.assertEquals(2, map.size());
        Assert.assertEquals(new LongValue(1L), map.get("p1"));
        Assert.assertEquals(new LongValue(2L), map.get("p2"));
    }
}
Also used : GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Value(com.baidu.hugegraph.computer.core.graph.value.Value) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Example 14 with Properties

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

the class PointerCombinerTest method testCombineEdgePropertiesFail.

@Test
public void testCombineEdgePropertiesFail() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_EDGE_PROPERTIES_COMBINER_CLASS, MergeOldPropertiesCombiner.class.getName());
    Combiner<Properties> valueCombiner = config.createObject(ComputerOptions.WORKER_EDGE_PROPERTIES_COMBINER_CLASS);
    GraphFactory graphFactory = graphFactory();
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(graphFactory::createProperties, valueCombiner);
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        Properties value1 = graphFactory.createProperties();
        value1.put("p1", new LongValue(1L));
        Properties value2 = graphFactory.createProperties();
        value2.put("p2", new LongValue(2L));
        // Only write count.
        bytesOutput1.writeInt(1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Assert.assertThrows(ComputerException.class, () -> {
            combiner.combine(pointer1, pointer2);
        }, e -> {
            Assert.assertContains("Failed to combine pointer", e.getMessage());
        });
    }
}
Also used : GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 15 with Properties

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

the class MergeNewPropertiesCombinerTest method testCombine.

@Test
public void testCombine() {
    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"));
    Properties expect = graphFactory().createProperties();
    expect.put("name", BytesId.of("marko"));
    expect.put("age", BytesId.of("18"));
    expect.put("city", BytesId.of("Beijing"));
    Properties properties = graphFactory().createProperties();
    PropertiesCombiner combiner = new MergeNewPropertiesCombiner();
    combiner.combine(properties1, properties2, properties);
    Assert.assertEquals(expect, properties);
}
Also used : Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) 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