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 testCollectionEqualityByGraphIds() throws Exception { FlinkAsciiGraphLoader loader = getTestGraphLoader(); CollectionEqualityByGraphIds equality = new CollectionEqualityByGraphIds(); GraphCollection gRef1 = loader.getGraphCollectionByVariables("gRef"); GraphCollection gRef2 = loader.getGraphCollectionByVariables("gRef"); GraphCollection gClone = loader.getGraphCollectionByVariables("gClone"); GraphCollection gEmpty = getConfig().getGraphCollectionFactory() .createEmptyCollection(); // direct operator call collectAndAssertTrue(equality.execute(gRef1, gRef2)); collectAndAssertFalse(equality.execute(gRef1, gClone)); collectAndAssertFalse(equality.execute(gRef1, gEmpty)); // convenience method collectAndAssertTrue(gRef1.equalsByGraphIds(gRef2)); collectAndAssertFalse(gRef1.equalsByGraphIds(gClone)); collectAndAssertFalse(gRef1.equalsByGraphIds(gEmpty)); }
/** * 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 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 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)); }
@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)); } }