Java Code Examples for org.apache.flink.test.util.TestBaseUtils#compareResultAsText()
The following examples show how to use
org.apache.flink.test.util.TestBaseUtils#compareResultAsText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertexInDegreeTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithUndirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, LongValue>> inDegree = undirectedSimpleGraph .run(new VertexInDegree<IntValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,2)\n" + "(1,3)\n" + "(2,3)\n" + "(3,4)\n" + "(4,1)\n" + "(5,1)"; TestBaseUtils.compareResultAsText(inDegree.collect(), expectedResult); }
Example 2
Source File: JaccardIndexTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraphWithMaximumScore() throws Exception { DataSet<Result<IntValue>> ji = undirectedSimpleGraph .run(new JaccardIndex<IntValue, NullValue, NullValue>() .setMaximumScore(1, 2)); String expectedResult = "(0,1,1,4)\n" + "(0,2,1,4)\n" + "(0,3,2,4)\n" + "(1,2,2,4)\n" + "(1,3,1,6)\n" + "(1,4,1,3)\n" + "(1,5,1,3)\n" + "(2,3,1,6)\n" + "(2,4,1,3)\n" + "(2,5,1,3)\n"; TestBaseUtils.compareResultAsText(ji.collect(), expectedResult); }
Example 3
Source File: VertexOutDegreeTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithUndirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, LongValue>> outDegree = undirectedSimpleGraph .run(new VertexOutDegree<IntValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,2)\n" + "(1,3)\n" + "(2,3)\n" + "(3,4)\n" + "(4,1)\n" + "(5,1)"; TestBaseUtils.compareResultAsText(outDegree.collect(), expectedResult); }
Example 4
Source File: VertexInDegreeTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Vertex<LongValue, LongValue>> inDegreeWithoutZeroDegreeVertices = emptyGraphWithVertices .run(new VertexInDegree<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(false)); assertEquals(0, inDegreeWithoutZeroDegreeVertices.collect().size()); DataSet<Vertex<LongValue, LongValue>> inDegreeWithZeroDegreeVertices = emptyGraphWithVertices .run(new VertexInDegree<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,0)\n" + "(1,0)\n" + "(2,0)"; TestBaseUtils.compareResultAsText(inDegreeWithZeroDegreeVertices.collect(), expectedResult); }
Example 5
Source File: VertexInDegreeTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithDirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, LongValue>> inDegree = directedSimpleGraph .run(new VertexInDegree<IntValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,0)\n" + "(1,3)\n" + "(2,1)\n" + "(3,2)\n" + "(4,1)\n" + "(5,0)"; TestBaseUtils.compareResultAsText(inDegree.collect(), expectedResult); }
Example 6
Source File: CommunityDetectionTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSingletonEdgeGraph() throws Exception { Graph<LongValue, Long, Double> result = new SingletonEdgeGraph(env, 1) .generate() .mapVertices(v -> v.getId().getValue(), new TypeHint<Vertex<LongValue, Long>>(){}.getTypeInfo()) .mapEdges(e -> 1.0, new TypeHint<Edge<LongValue, Double>>(){}.getTypeInfo()) .run(new CommunityDetection<>(10, 0.5)); String expectedResult = "(0,0)\n" + "(1,1)\n"; TestBaseUtils.compareResultAsText(result.getVertices().collect(), expectedResult); }
Example 7
Source File: VertexDegreeTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testWithSimpleGraph() throws Exception { String expectedResult = "(0,2)\n" + "(1,3)\n" + "(2,3)\n" + "(3,4)\n" + "(4,1)\n" + "(5,1)"; DataSet<Vertex<IntValue, LongValue>> degreeOnSourceId = undirectedSimpleGraph .run(new VertexDegree<IntValue, NullValue, NullValue>() .setReduceOnTargetId(false)); TestBaseUtils.compareResultAsText(degreeOnSourceId.collect(), expectedResult); DataSet<Vertex<IntValue, LongValue>> degreeOnTargetId = undirectedSimpleGraph .run(new VertexDegree<IntValue, NullValue, NullValue>() .setReduceOnTargetId(true)); TestBaseUtils.compareResultAsText(degreeOnTargetId.collect(), expectedResult); }
Example 8
Source File: VertexDegreeTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testWithEmptyGraphWithVertices() throws Exception { DataSet<Vertex<LongValue, LongValue>> degree; degree = emptyGraphWithVertices .run(new VertexDegree<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(false)); assertEquals(0, degree.collect().size()); degree = emptyGraphWithVertices .run(new VertexDegree<LongValue, NullValue, NullValue>() .setIncludeZeroDegreeVertices(true)); String expectedResult = "(0,0)\n" + "(1,0)\n" + "(2,0)"; TestBaseUtils.compareResultAsText(degree.collect(), expectedResult); }
Example 9
Source File: VertexDegreesTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testWithUndirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, Degrees>> degrees = undirectedSimpleGraph .run(new VertexDegrees<>()); String expectedResult = "(0,(2,2,2))\n" + "(1,(3,3,3))\n" + "(2,(3,3,3))\n" + "(3,(4,4,4))\n" + "(4,(1,1,1))\n" + "(5,(1,1,1))"; TestBaseUtils.compareResultAsText(degrees.collect(), expectedResult); }
Example 10
Source File: AvroTypesITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testAvroObjectAccess() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tEnv = BatchTableEnvironment.create(env, config()); Table t = tEnv.fromDataSet(testData(env)); Table result = t .filter("type_nested.isNotNull") .select("type_nested.flatten()").as("city, num, state, street, zip"); List<Address> results = tEnv.toDataSet(result, Types.POJO(Address.class)).collect(); String expected = USER_1.getTypeNested().toString(); TestBaseUtils.compareResultAsText(results, expected); }
Example 11
Source File: SimplifyTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void test() throws Exception { String expectedResult = "(0,1,(null))\n" + "(0,2,(null))\n" + "(1,0,(null))"; Graph<IntValue, NullValue, NullValue> simpleGraph = graph .run(new Simplify<>()); TestBaseUtils.compareResultAsText(simpleGraph.getEdges().collect(), expectedResult); }
Example 12
Source File: VertexDegreesTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testWithDirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, Degrees>> degrees = directedSimpleGraph .run(new VertexDegrees<>()); String expectedResult = "(0,(2,2,0))\n" + "(1,(3,0,3))\n" + "(2,(3,2,1))\n" + "(3,(4,2,2))\n" + "(4,(1,0,1))\n" + "(5,(1,1,0))"; TestBaseUtils.compareResultAsText(degrees.collect(), expectedResult); }
Example 13
Source File: TestUtils.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private static <K, VV, EV> void compareEdges(Graph<K, VV, EV> graph, String expectedEdges) throws Exception { if (expectedEdges != null) { List<Edge<K, EV>> edges = graph.getEdges().collect(); List<String> resultEdges = new ArrayList<>(edges.size()); for (Edge<K, EV> edge : edges) { resultEdges.add(edge.f0.toString() + "," + edge.f1.toString()); } TestBaseUtils.compareResultAsText(resultEdges, expectedEdges.replaceAll("\\s", "").replace(";", "\n")); } }
Example 14
Source File: SimplifyTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithClipAndFlip() throws Exception { String expectedResult = "(0,1,(null))\n" + "(1,0,(null))"; Graph<IntValue, NullValue, NullValue> simpleGraph = graph .run(new Simplify<>(true)); TestBaseUtils.compareResultAsText(simpleGraph.getEdges().collect(), expectedResult); }
Example 15
Source File: IPv6HostnamesITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testClusterWithIPv6host() { try { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(4); env.getConfig().disableSysoutLogging(); // get input data DataSet<String> text = env.fromElements(WordCountData.TEXT.split("\n")); DataSet<Tuple2<String, Integer>> counts = text .flatMap(new FlatMapFunction<String, Tuple2<String, Integer>>() { @Override public void flatMap(String value, Collector<Tuple2<String, Integer>> out) throws Exception { for (String token : value.toLowerCase().split("\\W+")) { if (token.length() > 0) { out.collect(new Tuple2<String, Integer>(token, 1)); } } } }) .groupBy(0).sum(1); List<Tuple2<String, Integer>> result = counts.collect(); TestBaseUtils.compareResultAsText(result, WordCountData.COUNTS_AS_TUPLES); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 16
Source File: BipartiteGraphTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testFullBottomProjection() throws Exception { BipartiteGraph<Integer, Integer, String, String, String> bipartiteGraph = createBipartiteGraph(); Graph<Integer, String, Projection<Integer, String, String, String>> graph = bipartiteGraph.projectionBottomFull(); compareGraph(graph, "1; 2; 3", "1,2; 2,1; 2,3; 3,2"); String expected = "(3,2,(6,top6,bottom3,bottom2,6-3,6-2))\n" + "(2,3,(6,top6,bottom2,bottom3,6-2,6-3))\n" + "(2,1,(5,top5,bottom2,bottom1,5-2,5-1))\n" + "(1,2,(5,top5,bottom1,bottom2,5-1,5-2))"; TestBaseUtils.compareResultAsText(graph.getEdges().collect(), expected); }
Example 17
Source File: AvroTypesITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testAvroObjectAccess() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tEnv = BatchTableEnvironment.create(env, config()); Table t = tEnv.fromDataSet(testData(env)); Table result = t .filter($("type_nested").isNotNull()) .select($("type_nested").flatten()) .as("city", "num", "state", "street", "zip"); List<Address> results = tEnv.toDataSet(result, Types.POJO(Address.class)).collect(); String expected = USER_1.getTypeNested().toString(); TestBaseUtils.compareResultAsText(results, expected); }
Example 18
Source File: TestUtils.java From flink with Apache License 2.0 | 5 votes |
private static <K, VV, EV> void compareEdges(Graph<K, VV, EV> graph, String expectedEdges) throws Exception { if (expectedEdges != null) { List<Edge<K, EV>> edges = graph.getEdges().collect(); List<String> resultEdges = new ArrayList<>(edges.size()); for (Edge<K, EV> edge : edges) { resultEdges.add(edge.f0.toString() + "," + edge.f1.toString()); } TestBaseUtils.compareResultAsText(resultEdges, expectedEdges.replaceAll("\\s", "").replace(";", "\n")); } }
Example 19
Source File: VertexDegreesTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testWithDirectedSimpleGraph() throws Exception { DataSet<Vertex<IntValue, Degrees>> degrees = directedSimpleGraph .run(new VertexDegrees<>()); String expectedResult = "(0,(2,2,0))\n" + "(1,(3,0,3))\n" + "(2,(3,2,1))\n" + "(3,(4,2,2))\n" + "(4,(1,0,1))\n" + "(5,(1,1,0))"; TestBaseUtils.compareResultAsText(degrees.collect(), expectedResult); }
Example 20
Source File: LocalClusteringCoefficientTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSimpleGraph() throws Exception { String expectedResult = "(0,2,1)\n" + "(1,3,2)\n" + "(2,3,2)\n" + "(3,4,1)\n" + "(4,1,0)\n" + "(5,1,0)"; DataSet<Result<IntValue>> cc = directedSimpleGraph .run(new LocalClusteringCoefficient<>()); TestBaseUtils.compareResultAsText(cc.collect(), expectedResult); }