protected void checkAssertions(GraphCollection expectation, GraphCollection result, String attribute) throws Exception { assertTrue( "wrong graph ids for " + attribute + " overlapping collections", result.equalsByGraphIds(expectation).collect().get(0)); assertTrue( "wrong graph element ids for" + attribute + " overlapping collections", result.equalsByGraphElementIds(expectation).collect().get(0)); } }
@Test public void testNonDistinctCollection() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection inputCollection = loader .getGraphCollectionByVariables("g0", "g0", "g1"); GraphCollection expectedCollection = loader .getGraphCollectionByVariables("g0", "g1"); GraphCollection outputCollection = inputCollection.distinctById(); collectAndAssertTrue(outputCollection .equalsByGraphElementIds(expectedCollection)); }
@Test public void testDistinctCollection() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection inputCollection = loader .getGraphCollectionByVariables("g0", "g1"); GraphCollection expectedCollection = loader .getGraphCollectionByVariables("g0", "g1"); GraphCollection outputCollection = inputCollection.distinctById(); collectAndAssertTrue(outputCollection .equalsByGraphElementIds(expectedCollection)); } }
/** * Test getting a graph collection from the loader * * @throws Exception on failure */ @Test public void testGetGraphCollection() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection collectionFromLoader = loader.getGraphCollectionByVariables("g0", "g1", "g2", "g3"); GraphCollection collectionFromDb = loader.getGraphCollection(); // heads <> heads collectAndAssertTrue(collectionFromLoader.equalsByGraphIds(collectionFromDb)); // elements <> elements collectAndAssertTrue(collectionFromLoader.equalsByGraphElementIds(collectionFromDb)); }
@Test public void testGraphElementIdEquality() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString(dataGraph); // initialize with data graph LogicalGraph db = loader.getLogicalGraphByVariable(TestData.DATA_GRAPH_VARIABLE); // append the expected result loader.appendToDatabaseFromString(expectedCollection); // execute and validate GraphCollection result = getImplementation(queryGraph, false).execute(db); GraphCollection expected = loader.getGraphCollectionByVariables(expectedGraphVariables); collectAndAssertTrue(result.equalsByGraphElementIds(expected)); }
/** * Test getting a graph collection by variables from the loader * * @throws Exception on failure */ @Test public void testGetGraphCollectionByVariables() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); String[] graphVariables = new String[]{"g0", "g1", "g2"}; List<GradoopId> graphIds = Lists.newArrayList(); for (String graphVariable : graphVariables) { graphIds.add(loader.getGraphHeadByVariable(graphVariable).getId()); } GradoopIdSet graphIdSet = GradoopIdSet.fromExisting(graphIds); GraphCollection collectionFromLoader = loader.getGraphCollectionByVariables(graphVariables); GraphCollection collectionFromDbViaSet = loader.getGraphCollection().getGraphs(graphIdSet); // heads <> heads collectAndAssertTrue(collectionFromLoader.equalsByGraphIds(collectionFromDbViaSet)); // elements <> elements collectAndAssertTrue(collectionFromLoader.equalsByGraphElementIds(collectionFromDbViaSet)); } }
@Test public void testByElementIds() throws Exception { String graph = "input[" + // First component "(v0 {id:0, component:1})" + // Second component "(v1 {id:1, component:2})-[e0]->(v2 {id:2, component:2})" + "(v1)-[e1]->(v3 {id:3, component:2})" + "(v2)-[e2]->(v3)" + "(v3)-[e3]->(v4 {id:4, component:2})" + "(v4)-[e4]->(v5 {id:5, component:2})" + "]"; FlinkAsciiGraphLoader loader = getLoaderFromString(graph); LogicalGraph input = loader.getLogicalGraphByVariable("input"); GraphCollection result = input .callForCollection(new WeaklyConnectedComponentsAsCollection(propertyKey, 10)); GraphCollection components = input.splitBy("component"); collectAndAssertTrue(result.equalsByGraphElementIds(components)); } }
@Test public void testSelectionWithResult() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection inputCollection = loader.getGraphCollectionByVariables("g0", "g1", "g2"); GraphCollection expectedOutputCollection = loader.getGraphCollectionByVariables("g0", "g1"); FilterFunction<GraphHead> predicateFunc = (FilterFunction<GraphHead>) entity -> entity.hasProperty("vertexCount") && entity.getPropertyValue("vertexCount").getInt() == 3; GraphCollection outputCollection = inputCollection.select(predicateFunc); collectAndAssertTrue( expectedOutputCollection.equalsByGraphElementIds(outputCollection)); }
@Test public void testSplit() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString( "input[" + "(v0 {key1 : 0})" + "(v1 {key1 : 1})" + "(v2 {key1 : 1})" + "(v3 {key1 : 0})" + "(v1)-[e1]->(v2)" + "(v3)-[e2]->(v0)" + "(v2)-[e3]->(v0)" + "]" + "graph1[" + "(v1)-[e1]->(v2)" + "]" + "graph2[" + "(v3)-[e2]->(v0)" + "]" ); LogicalGraph input = loader.getLogicalGraphByVariable("input"); GraphCollection result = input.callForCollection(new Split(SplitTest::getSplitValues)); collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables("graph1", "graph2"))); }
@Test public void testSplitWithMultipleKeys() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString("" + "input[" + "(v0 {key1 : 0})" + "(v1 {key1 : 1})" + "(v2 {key1 : 1, key2 : 0})" + "(v3 {key1 : 0})" + "(v1)-[e1]->(v2)" + "(v3)-[e2]->(v0)" + "(v2)-[e3]->(v0)" + "]" + "graph1[" + "(v1)-[e1]->(v2)" + "]" + "graph2[" + "(v2)-[e3]->(v0)" + "(v3)-[e2]->(v0)" + "]" ); LogicalGraph input = loader.getLogicalGraphByVariable("input"); GraphCollection result = input .callForCollection(new Split(SplitTest::getSplitValues)); collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables("graph1", "graph2"))); }
@Test public void testCollectionEqualityByGraphElementIds() throws Exception { FlinkAsciiGraphLoader loader = getTestGraphLoader(); CollectionEquality equality = new CollectionEquality( new GraphHeadToEmptyString(), new VertexToIdString(), new EdgeToIdString(), true); GraphCollection gRef = loader .getGraphCollectionByVariables("gRef", "gClone", "gEmpty"); GraphCollection gClone = loader .getGraphCollectionByVariables("gClone", "gRef", "gEmpty"); GraphCollection gSmall = loader .getGraphCollectionByVariables("gRef", "gRef"); GraphCollection gDiffId = loader .getGraphCollectionByVariables("gRef", "gDiffId", "gEmpty"); GraphCollection gEmpty = getConfig().getGraphCollectionFactory() .createEmptyCollection(); // direct operator call collectAndAssertTrue(equality.execute(gRef, gClone)); collectAndAssertFalse(equality.execute(gRef, gDiffId)); collectAndAssertFalse(equality.execute(gRef, gSmall)); collectAndAssertFalse(equality.execute(gRef, gEmpty)); // convenience method collectAndAssertTrue(gRef.equalsByGraphElementIds(gClone)); collectAndAssertFalse(gRef.equalsByGraphElementIds(gDiffId)); collectAndAssertFalse(gRef.equalsByGraphElementIds(gSmall)); collectAndAssertFalse(gRef.equalsByGraphElementIds(gEmpty)); }
"graph1", "graph2", "graph3"); collectAndAssertTrue(result.equalsByGraphElementIds(expectation));
@Test public void testTransformation() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection originalCollection = loader.getGraphCollection(); DataSet<GraphTransaction> transactions = originalCollection.getGraphTransactions(); GraphCollection restoredCollection = getConfig().getGraphCollectionFactory() .fromTransactions(transactions); collectAndAssertTrue( originalCollection.equalsByGraphIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphElementIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphData(restoredCollection)); }
collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables("g2"))); collectAndAssertTrue(result.equalsByGraphElementData(
@Test public void testTransformationWithCustomReducer() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection originalCollection = loader.getGraphCollection(); DataSet<GraphTransaction> transactions = originalCollection.getGraphTransactions(); GraphCollection restoredCollection = getConfig().getGraphCollectionFactory() .fromTransactions(transactions, new First<>(), new First<>()); collectAndAssertTrue( originalCollection.equalsByGraphIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphElementIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphData(restoredCollection)); }
@Test public void testWithSubsetGraphContainment() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); loader.appendToDatabaseFromString("g1[(eve)]"); GraphCollection originalCollection = loader.getGraphCollectionByVariables("g1"); DataSet<GraphTransaction> transactions = originalCollection.getGraphTransactions(); GraphCollection restoredCollection = getConfig().getGraphCollectionFactory() .fromTransactions(transactions, new First<>(), new First<>()); collectAndAssertTrue( originalCollection.equalsByGraphIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphElementIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphData(restoredCollection)); } }
.apply(new ApplySubgraph(vertexFilterFunction, null)); collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected4")));
.apply(new ApplySubgraph(vertexFilterFunction, edgeFilterFunction)); collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected4")));
@Test public void testCollectionEdgeInducedSubgraph() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); loader.appendToDatabaseFromString( "expected0[" + "(eve)-[ekb]->(bob)" + "]" ); loader.appendToDatabaseFromString( "expected1[" + "(frank)-[fkc]->(carol)" + "(frank)-[fkd]->(dave)" + "]" ); loader.appendToDatabaseFromString( "expected2[]" ); GraphCollection input = loader.getGraphCollectionByVariables("g0", "g1", "g2"); GraphCollection result = input .apply(new ApplySubgraph(null, e -> e.getPropertyValue("since").getInt() == 2015)); collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected2"))); collectAndAssertTrue(result.equalsByGraphData( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected2"))); }