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);
}
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());
});
}
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"));
}
}
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());
});
}
}
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);
}
Aggregations