use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.
the class BuildIdPropertyValuePairsTest method testFunction.
/**
* Test if the function selects the correct labels and properties.
*
* @throws Exception when the execution in Flink fails.
*/
@Test
public void testFunction() throws Exception {
VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
EPGMVertex v1 = vertexFactory.createVertex("a");
EPGMVertex v2 = vertexFactory.createVertex("a");
v2.setProperty("k1", 1L);
v2.setProperty("k2", 1L);
EPGMVertex v3 = vertexFactory.createVertex("b");
v3.setProperty("k1", 1L);
v3.setProperty("k2", 1L);
EPGMVertex v4 = vertexFactory.createVertex();
List<Tuple2<GradoopId, PropertyValue>> result = getExecutionEnvironment().fromElements(v1, v2, v3, v4).flatMap(new BuildIdPropertyValuePairs<>("a", "k1")).collect();
assertEquals(1, result.size());
assertEquals(Tuple2.of(v2.getId(), PropertyValue.create(1L)), result.get(0));
}
use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.
the class CreateCartesianNeighborhoodEdgesTest method testWithEmptyNeighborhood.
/**
* Test the function using an empty neighborhood. Should produce no edges.
*
* @throws Exception when the execution in Flink fails.
*/
@Test
public void testWithEmptyNeighborhood() throws Exception {
EPGMVertex someVertex = vertexFactory.createVertex();
Tuple2<EPGMVertex, List<NeighborhoodVertex>> inputEmpty = new Tuple2<>(someVertex, Collections.emptyList());
List<EPGMEdge> result = getExecutionEnvironment().fromElements(inputEmpty).flatMap(toTest).collect();
assertEquals(0, result.size());
}
use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.
the class CreateEdgesFromTripleTest method testFunction.
/**
* Test the function by applying it to some tuples.
*
* @throws Exception when the execution in Flink fails.
*/
@Test
public void testFunction() throws Exception {
CreateEdgesFromTriple<EPGMVertex, EPGMEdge> function = new CreateEdgesFromTriple<>(getConfig().getLogicalGraphFactory().getEdgeFactory(), "source", "target");
VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
EPGMVertex testVertex1 = vertexFactory.createVertex();
EPGMVertex testVertex2 = vertexFactory.createVertex();
GradoopId source1 = GradoopId.get();
GradoopId source2 = GradoopId.get();
GradoopId target1 = GradoopId.get();
GradoopId target2 = GradoopId.get();
Tuple3<EPGMVertex, GradoopId, GradoopId> tuple1 = new Tuple3<>(testVertex1, source1, target1);
Tuple3<EPGMVertex, GradoopId, GradoopId> tuple2 = new Tuple3<>(testVertex2, source2, target2);
List<EPGMEdge> result = getExecutionEnvironment().fromElements(tuple1, tuple2).flatMap(function).collect();
// Check if the correct number of edges were created and if they are distinct.
assertEquals(4, result.size());
// By id.
assertEquals(4, result.stream().map(EPGMElement::getId).count());
// By source and target id.
assertEquals(4, result.stream().map(e -> Tuple2.of(e.getSourceId(), e.getTargetId())).distinct().count());
// Finally check the data of the edges.
for (EPGMEdge resultEdge : result) {
if (resultEdge.getLabel().equals("source")) {
if (resultEdge.getSourceId().equals(source1)) {
assertEquals(testVertex1.getId(), resultEdge.getTargetId());
} else if (resultEdge.getSourceId().equals(source2)) {
assertEquals(testVertex2.getId(), resultEdge.getTargetId());
} else {
fail("EPGMEdge with invalid source ID created.");
}
} else if (resultEdge.getLabel().equals("target")) {
if (resultEdge.getSourceId().equals(testVertex1.getId())) {
assertEquals(target1, resultEdge.getTargetId());
} else if (resultEdge.getSourceId().equals(testVertex2.getId())) {
assertEquals(target2, resultEdge.getTargetId());
} else {
fail("EPGMEdge with invalid source ID created.");
}
} else {
fail("EPGMEdge with invalid label created.");
}
}
}
use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.
the class CreateMappingFromMarkedDuplicatesTest method testFlatMapFunction.
/**
* Test the flat map function.
*
* @throws Exception when the execution in Flink fails.
*/
@Test
public void testFlatMapFunction() throws Exception {
VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
GradoopId duplicateId = GradoopId.get();
EPGMVertex vertexWithProp = vertexFactory.createVertex();
vertexWithProp.setProperty(MarkDuplicatesInGroup.PROPERTY_KEY, PropertyValue.create(duplicateId));
EPGMVertex vertexWithProp2 = vertexFactory.createVertex();
vertexWithProp2.setProperty(MarkDuplicatesInGroup.PROPERTY_KEY, PropertyValue.create(duplicateId));
EPGMVertex vertexWithoutProp = vertexFactory.createVertex();
List<EPGMVertex> vertices = Arrays.asList(vertexWithoutProp, vertexWithProp, vertexWithProp2);
vertices.sort(Comparator.comparing(EPGMElement::getId));
List<Tuple2<GradoopId, GradoopId>> mapping = getExecutionEnvironment().fromCollection(vertices).flatMap(new CreateMappingFromMarkedDuplicates<>()).collect();
assertEquals(2, mapping.size());
assertNotEquals(mapping.get(0).f0, mapping.get(1).f0);
assertEquals(duplicateId, mapping.get(0).f1);
assertEquals(duplicateId, mapping.get(1).f1);
assertNotEquals(vertexWithoutProp.getId(), mapping.get(0).f0);
assertNotEquals(vertexWithoutProp.getId(), mapping.get(1).f0);
}
use of org.gradoop.common.model.impl.pojo.EPGMVertex in project gradoop by dbs-leipzig.
the class MarkDuplicatesInGroupTest method testReduce.
/**
* Test the reduce functionality.
*
* @throws Exception when the execution in Flink fails.
*/
@Test
public void testReduce() throws Exception {
VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
List<EPGMVertex> testVertices = IntStream.range(0, 10).mapToObj(i -> vertexFactory.createVertex()).collect(Collectors.toList());
for (EPGMVertex testVertex : testVertices) {
testVertex.setLabel("Test");
testVertex.setProperty("a", PropertyValue.NULL_VALUE);
}
List<EPGMVertex> reduced = getExecutionEnvironment().fromCollection(testVertices).groupBy(new GetPropertiesAsList<>(Collections.singletonList("a"))).reduceGroup(new MarkDuplicatesInGroup<>()).collect();
assertEquals(testVertices.size(), reduced.size());
int numberOfMarkedElements = 0;
GradoopId duplicateId = null;
for (EPGMVertex vertex : reduced) {
if (vertex.hasProperty(MarkDuplicatesInGroup.PROPERTY_KEY)) {
numberOfMarkedElements++;
} else {
assertNull("Duplicate ID was already found", duplicateId);
duplicateId = vertex.getId();
}
}
assertEquals(testVertices.size() - 1, numberOfMarkedElements);
for (EPGMVertex vertex : reduced) {
if (vertex.hasProperty(MarkDuplicatesInGroup.PROPERTY_KEY)) {
PropertyValue propertyValue = vertex.getPropertyValue(MarkDuplicatesInGroup.PROPERTY_KEY);
assertTrue(propertyValue.isGradoopId());
assertEquals(duplicateId, propertyValue.getGradoopId());
}
}
}
Aggregations