use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class CsvStructGraphOutputTest method testWriteReadVertexWithProperties.
@Test
public void testWriteReadVertexWithProperties() throws IOException {
UnitTestBase.updateOptions(ComputerOptions.OUTPUT_WITH_ADJACENT_EDGES, "false", ComputerOptions.OUTPUT_WITH_VERTEX_PROPERTIES, "true", ComputerOptions.OUTPUT_WITH_EDGE_PROPERTIES, "false");
ComputerContext context = context();
GraphFactory factory = context.graphFactory();
Id longId = BytesId.of(100L);
IdListList idListList = new IdListList();
IdList idList1 = new IdList();
idList1.add(BytesId.of(66L));
IdList idList2 = new IdList();
idList2.add(BytesId.of(998L));
idList2.add(BytesId.of(999L));
idListList.add(idList1);
idListList.add(idList2);
Vertex vertex = factory.createVertex(longId, idListList);
vertex.properties().put("boolean", new BooleanValue(true));
vertex.properties().put("byte", new IntValue(127));
vertex.properties().put("short", new IntValue(16383));
vertex.properties().put("int", new IntValue(1000000));
vertex.properties().put("long", new LongValue(10000000000L));
vertex.properties().put("float", new FloatValue(0.1F));
vertex.properties().put("double", new DoubleValue(-0.01D));
vertex.properties().put("idvalue", longId);
String fileName = "output3.csv";
File file = new File(fileName);
try {
BufferedFileOutput dos = new BufferedFileOutput(file);
StructGraphOutput output = (StructGraphOutput) IOFactory.createGraphOutput(context, OutputFormat.CSV, dos);
output.writeVertex(vertex);
dos.close();
@SuppressWarnings("deprecation") String text = FileUtils.readFileToString(file);
Assert.assertEquals("100,[[66],[998,999]],{true,127,-0.01,16383," + "100,0.1,1000000,10000000000}" + System.lineSeparator(), text);
} finally {
FileUtils.deleteQuietly(file);
}
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class OverwriteCombinerTest method testCombineNull.
@Test
public void testCombineNull() {
LongValue value1 = new LongValue(1L);
LongValue value2 = new LongValue(2L);
OverwriteCombiner<LongValue> combiner = new OverwriteCombiner<>();
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(null, value2, value2);
}, e -> {
Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, null, value2);
}, e -> {
Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, value2, null);
}, e -> {
Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue 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.value.LongValue 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.value.LongValue in project hugegraph-computer by hugegraph.
the class ValueMaxCombinerTest method testCombineNull.
@Test
public void testCombineNull() {
LongValue value1 = new LongValue(1L);
LongValue value2 = new LongValue(2L);
ValueMaxCombiner<LongValue> combiner = new ValueMaxCombiner<>();
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(null, value2, value2);
}, e -> {
Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, null, value2);
}, e -> {
Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, value2, null);
}, e -> {
Assert.assertEquals("The combine parameter result can't be null", e.getMessage());
});
}
Aggregations