@Test public void testEmptyFromGraphsMethod() throws Exception { GraphCollection expected = factory.createEmptyCollection(); GraphCollection result = factory.fromGraphs(); collectAndAssertTrue(result.equalsByGraphElementData(expected)); }
@Test public void testSameCollection() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); int limit = 2; GraphCollection input = loader.getGraphCollectionByVariables("g0", "g1"); collectAndAssertTrue(input.equalsByGraphElementData(input.limit(limit))); }
@Test public void testDistinctGraphs() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString("(v1) (v2) g1[(v1)] g2[(v1) (v2)]"); int limit = 2; GraphCollection inputCollection = loader.getGraphCollectionByVariables("g1", "g2"); collectAndAssertTrue(inputCollection.equalsByGraphElementData(inputCollection.limit(limit))); } }
@Test public void testSingleFromGraphsMethod() throws Exception { GraphCollection expected = loader.getGraphCollectionByVariables("g0"); GraphCollection result = factory.fromGraphs(loader.getLogicalGraphByVariable("g0")); collectAndAssertTrue(result.equalsByGraphElementData(expected)); }
@Test public void testFromGraphMethod() throws Exception { GraphCollection expected = loader.getGraphCollectionByVariables("g0"); GraphCollection result = factory.fromGraph(loader.getLogicalGraphByVariable("g0")); collectAndAssertTrue(expected.equalsByGraphElementData(result)); }
@Test public void testFromGraphsMethod() throws Exception { LogicalGraph graph1 = loader.getLogicalGraphByVariable("g1"); LogicalGraph graph2 = loader.getLogicalGraphByVariable("g2"); GraphCollection expected = loader.getGraphCollectionByVariables("g1", "g2"); GraphCollection result = factory.fromGraphs(graph1, graph2); collectAndAssertTrue(result.equalsByGraphElementData(expected)); } }
@Test public void testGraphElementEquality() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString(asciiGraphs); GraphCollection searchSpace = loader.getGraphCollectionByVariables(searchSpaceVariables); GraphCollection expectation = loader.getGraphCollectionByVariables(expectedResultVariables); GraphCollection result = getImplementation().execute(searchSpace); collectAndAssertTrue(result.equalsByGraphElementData(expectation)); } }
@Test public void testWrite() throws Exception { FlinkAsciiGraphLoader testLoader = getSocialNetworkLoader(); GraphCollection expectedCollection = testLoader.getGraphCollectionByVariables("g0", "g1", "g2", "g3"); String path = temporaryFolder.getRoot().getPath() + "/graph.gdl"; DataSink gdlsink = new GDLDataSink(path); gdlsink.write(expectedCollection, true); getExecutionEnvironment().execute(); FlinkAsciiGraphLoader sinkLoader = getLoaderFromFile(path); GraphCollection sinkCollection = sinkLoader .getGraphCollectionByVariables("g0", "g1", "g2", "g3"); collectAndAssertTrue(sinkCollection.equalsByGraphElementData(expectedCollection)); } }
@Test public void testGraphElementEquality() 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, true).execute(db); GraphCollection expected = loader.getGraphCollectionByVariables(expectedGraphVariables); collectAndAssertTrue(result.equalsByGraphElementData(expected)); } }
@Test public void testRead() throws Exception { String csvPath = getFilePath("/data/csv/input_graph_collection"); String gdlPath = getFilePath("/data/csv/expected/expected_graph_collection.gdl"); DataSource dataSource = new CSVDataSource(csvPath, getConfig()); GraphCollection input = dataSource.getGraphCollection(); GraphCollection expected = getLoaderFromFile(gdlPath) .getGraphCollectionByVariables("expected1", "expected2"); collectAndAssertTrue(input.equalsByGraphElementData(expected)); }
@Test public void testExecute() throws Exception { FlinkAsciiGraphLoader loader = new FlinkAsciiGraphLoader(getConfig()); loader.initDatabaseFromFile(getFilePath("/data/gdl/iig_btgs.gdl")); LogicalGraph iig = loader.getLogicalGraphByVariable("iig"); GraphCollection expectation = loader .getGraphCollectionByVariables("btg1", "btg2", "btg3", "btg4"); GraphCollection result = iig .callForCollection(new BusinessTransactionGraphs()); collectAndAssertTrue(expectation.equalsByGraphElementData(result)); } }
/** * Test reading an indexed csv graph collection. * * @throws Exception on failure */ @Test public void testRead() throws Exception { String csvPath = getFilePath("/data/csv/input_indexed"); String gdlPath = getFilePath("/data/csv/expected/expected_graph_collection.gdl"); DataSource dataSource = new IndexedCSVDataSource(csvPath, getConfig()); GraphCollection input = dataSource.getGraphCollection(); GraphCollection expected = getLoaderFromFile(gdlPath) .getGraphCollectionByVariables("expected1", "expected2"); collectAndAssertTrue(input.equalsByGraphElementData(expected)); }
/** * Test writing and reading the given graph to and from CSV * * @param tmpPath path to write csv * @param input graph collection * @throws Exception if the execution or IO fails. */ private void checkCSVWrite(String tmpPath, GraphCollection input) throws Exception { DataSink csvDataSink = new CSVDataSink(tmpPath, getConfig()); csvDataSink.write(input, true); getExecutionEnvironment().execute(); DataSource csvDataSource = new CSVDataSource(tmpPath, getConfig()); GraphCollection output = csvDataSource.getGraphCollection(); collectAndAssertTrue(input.equalsByGraphElementData(output)); } }
@Test public void testWrite() throws Exception { String tmpDir = temporaryFolder.getRoot().toString(); final String vertexFile = tmpDir + "/nodes.json"; final String edgeFile = tmpDir + "/edges.json"; final String graphFile = tmpDir + "/graphs.json"; GraphCollection input = getSocialNetworkLoader().getGraphCollection(); // write to JSON input.writeTo(new JSONDataSink(graphFile, vertexFile, edgeFile, getConfig())); getExecutionEnvironment().execute(); // read from JSON GraphCollection output = new JSONDataSource( graphFile, vertexFile, edgeFile, getConfig()).getGraphCollection(); collectAndAssertTrue(output.equalsByGraphElementData(input)); } }
/** * Test writing and reading the given graph to and from CSV * * @param tmpPath path to write csv * @param input graph collection * @throws Exception if the execution or IO fails. */ private void checkIndexedCSVWrite(String tmpPath, GraphCollection input) throws Exception { DataSink indexedCSVDataSink = new IndexedCSVDataSink(tmpPath, getConfig()); indexedCSVDataSink.write(input, true); getExecutionEnvironment().execute(); DataSource indexedCSVDataSource = new IndexedCSVDataSource(tmpPath, getConfig()); GraphCollection output = indexedCSVDataSource.getGraphCollection(); collectAndAssertTrue(input.equalsByGraphElementData(output)); } }
/** * Test reading a indexed csv graph collection without edges. * * @throws Exception on failure */ @Test public void testEmptyEdgeRead() throws Exception { String csvPath = getFilePath("/data/csv/input_indexed_no_edges"); String gdlPath = getFilePath("/data/csv/expected/expected_no_edges.gdl"); DataSource dataSource = new IndexedCSVDataSource(csvPath, getConfig()); GraphCollection input = dataSource.getGraphCollection(); GraphCollection expected = getLoaderFromFile(gdlPath) .getGraphCollectionByVariables("expected1", "expected2"); collectAndAssertTrue(input.equalsByGraphElementData(expected)); } }
@Test public void testWriteWithoutEdges() throws Exception { String tmpPath = temporaryFolder.getRoot().getPath(); String tlfFileImport = getFilePath("/data/tlf/io_test_string_without_edges.tlf"); String tlfFileExport = tmpPath + "/data/tlf/io_test_output"; // read from inputfile DataSource dataSource = new TLFDataSource(tlfFileImport, getConfig()); // write to ouput path DataSink dataSink = new TLFDataSink(tlfFileExport, getConfig()); dataSink.write(dataSource.getGraphCollection(), true); // read from output path DataSource dataSource2 = new TLFDataSource(tlfFileExport, getConfig()); getExecutionEnvironment().execute(); // compare original graph and written one collectAndAssertTrue(dataSource.getGraphCollection() .equalsByGraphElementData(dataSource2.getGraphCollection())); }
/** * Test reading from a directory containing multiple parts. * * @throws Exception when the execution in Flink fails. */ @Test public void testReadDir() throws Exception { DataSource dataImport = new MinimalJSONImporter(dirPath, getConfig()); LogicalGraph read = dataImport.getLogicalGraph(); LogicalGraph expected = loader.getLogicalGraph(); GraphCollection expectedCollection = getConfig().getGraphCollectionFactory().fromGraph(expected); collectAndAssertTrue(expected.equalsByElementData(read)); collectAndAssertTrue(dataImport.getGraphCollection() .equalsByGraphElementData(expectedCollection)); }
/** * Test reading a single file. * * @throws Exception when the execution in Flink fails. */ @Test public void testReadFile() throws Exception { DataSource dataImport = new MinimalJSONImporter(filePath, getConfig()); LogicalGraph read = dataImport.getLogicalGraph(); LogicalGraph expected = loader.getLogicalGraphByVariable("expected2"); GraphCollection expectedCollection = getConfig().getGraphCollectionFactory().fromGraph(expected); collectAndAssertTrue(expected.equalsByElementData(read)); collectAndAssertTrue(dataImport.getGraphCollection() .equalsByGraphElementData(expectedCollection)); } }
@Test public void testWrite() throws Exception { String tlfFileImport = getFilePath("/data/tlf/io_test.tlf"); String tlfFileExport = getFilePath("/data/tlf") + "/io_test_output"; // read from inputfile DataSource dataSource = new TLFDataSource(tlfFileImport, getConfig()); // write to ouput path DataSink dataSink = new TLFDataSink(tlfFileExport, getConfig()); dataSink.write(dataSource.getGraphCollection(), true); // read from output path DataSource dataSource2 = new TLFDataSource(tlfFileExport, getConfig()); getExecutionEnvironment().execute(); // compare original graph and written one collectAndAssertTrue(dataSource.getGraphCollection() .equalsByGraphElementData(dataSource2.getGraphCollection())); }