Repository: flink Updated Branches: refs/heads/master aaa231bc0 -> 5308ac832
[FLINK-1677][gelly] Suppresed Sysout Printing for the Degrees with exception test suite This closes #475 Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/b891ff5f Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/b891ff5f Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/b891ff5f Branch: refs/heads/master Commit: b891ff5f5cf034704de76f7d96b253d797b810dc Parents: aaa231b Author: andralungu <lungu.an...@gmail.com> Authored: Tue Mar 10 22:06:04 2015 +0100 Committer: Stephan Ewen <se...@apache.org> Committed: Sun Mar 15 16:03:33 2015 +0100 ---------------------------------------------------------------------- .../graph/test/DegreesWithExceptionITCase.java | 138 -------------- .../apache/flink/graph/test/TestGraphUtils.java | 14 ++ .../operations/DegreesWithExceptionITCase.java | 187 +++++++++++++++++++ 3 files changed, 201 insertions(+), 138 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/b891ff5f/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/DegreesWithExceptionITCase.java ---------------------------------------------------------------------- diff --git a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/DegreesWithExceptionITCase.java b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/DegreesWithExceptionITCase.java deleted file mode 100644 index 564b99b..0000000 --- a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/DegreesWithExceptionITCase.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.flink.graph.test; - -import org.apache.flink.api.java.ExecutionEnvironment; -import org.apache.flink.api.java.io.DiscardingOutputFormat; -import org.apache.flink.api.java.tuple.Tuple2; -import org.apache.flink.graph.Graph; -import org.junit.Assert; -import org.junit.Test; - -import java.util.NoSuchElementException; - -import static org.junit.Assert.fail; - -public class DegreesWithExceptionITCase { - - @Test - public void testOutDegreesInvalidEdgeSrcId() throws Exception { - /* - * Test outDegrees() with an edge having a srcId that does not exist in the vertex DataSet - */ - final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); - - Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), - TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env); - - try { - graph.outDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); - env.execute(); - - fail("graph.outDegrees() did not throw NoSuchElementException"); - } catch (Exception e) { - Assert.assertEquals("The edge src/trg id could not be found within the vertexIds", e.getCause().getMessage()); - Assert.assertTrue(e.getCause() instanceof NoSuchElementException); - } - } - - @Test - public void testInDegreesInvalidEdgeTrgId() throws Exception { - /* - * Test inDegrees() with an edge having a trgId that does not exist in the vertex DataSet - */ - final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); - - Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), - TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env); - - try { - graph.inDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); - env.execute(); - - fail("graph.inDegrees() did not throw NoSuchElementException"); - } catch (Exception e) { - Assert.assertEquals("The edge src/trg id could not be found within the vertexIds", e.getCause().getMessage()); - Assert.assertTrue(e.getCause() instanceof NoSuchElementException); - } - } - - @Test - public void testGetDegreesInvalidEdgeTrgId() throws Exception { - /* - * Test getDegrees() with an edge having a trgId that does not exist in the vertex DataSet - */ - final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); - - Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), - TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env); - - try { - graph.getDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); - env.execute(); - - fail("graph.getDegrees() did not throw NoSuchElementException"); - } catch (Exception e) { - Assert.assertEquals("The edge src/trg id could not be found within the vertexIds", e.getCause().getMessage()); - Assert.assertTrue(e.getCause() instanceof NoSuchElementException); - } - } - - @Test - public void testGetDegreesInvalidEdgeSrcId() throws Exception { - /* - * Test getDegrees() with an edge having a srcId that does not exist in the vertex DataSet - */ - final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); - - Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), - TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env); - - try { - graph.getDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); - env.execute(); - - fail("graph.getDegrees() did not throw NoSuchElementException"); - } catch (Exception e) { - Assert.assertEquals("The edge src/trg id could not be found within the vertexIds", e.getCause().getMessage()); - Assert.assertTrue(e.getCause() instanceof NoSuchElementException); - } - } - - @Test - public void testGetDegreesInvalidEdgeSrcTrgId() throws Exception { - /* - * Test getDegrees() with an edge having a srcId and a trgId that does not exist in the vertex DataSet - */ - final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); - - Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), - TestGraphUtils.getLongLongEdgeInvalidSrcTrgData(env), env); - - try { - graph.getDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); - env.execute(); - - fail("graph.getDegrees() did not throw NoSuchElementException"); - } catch (Exception e) { - Assert.assertEquals("The edge src/trg id could not be found within the vertexIds", e.getCause().getMessage()); - Assert.assertTrue(e.getCause() instanceof NoSuchElementException); - } - } -} http://git-wip-us.apache.org/repos/asf/flink/blob/b891ff5f/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/TestGraphUtils.java ---------------------------------------------------------------------- diff --git a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/TestGraphUtils.java b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/TestGraphUtils.java index e38932d..ad4e935 100644 --- a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/TestGraphUtils.java +++ b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/TestGraphUtils.java @@ -18,6 +18,7 @@ package org.apache.flink.graph.test; +import java.io.PrintStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -346,4 +347,17 @@ public class TestGraphUtils { return "(" + tField.toString() + "," + intField + ")"; } } + + /** + * Method useful for suppressing sysout printing + */ + public static void pipeSystemOutToNull() { + System.setOut(new PrintStream(new BlackholeOutputSteam())); + System.setErr(new PrintStream(new BlackholeOutputSteam())); + } + + private static final class BlackholeOutputSteam extends java.io.OutputStream { + @Override + public void write(int b){} + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flink/blob/b891ff5f/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/DegreesWithExceptionITCase.java ---------------------------------------------------------------------- diff --git a/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/DegreesWithExceptionITCase.java b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/DegreesWithExceptionITCase.java new file mode 100644 index 0000000..47f2920 --- /dev/null +++ b/flink-staging/flink-gelly/src/test/java/org/apache/flink/graph/test/operations/DegreesWithExceptionITCase.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.graph.test.operations; + +import org.apache.flink.api.java.ExecutionEnvironment; +import org.apache.flink.api.java.io.DiscardingOutputFormat; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.configuration.ConfigConstants; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.graph.Graph; +import org.apache.flink.graph.test.TestGraphUtils; +import org.apache.flink.test.util.ForkableFlinkMiniCluster; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.fail; + +@SuppressWarnings("serial") +public class DegreesWithExceptionITCase { + + private static ForkableFlinkMiniCluster cluster; + + @BeforeClass + public static void suppressOutput() { + TestGraphUtils.pipeSystemOutToNull(); + } + + @BeforeClass + public static void setupCluster() { + Configuration config = new Configuration(); + config.setInteger(ConfigConstants.LOCAL_INSTANCE_MANAGER_NUMBER_TASK_MANAGER, 2); + config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, 2); + config.setString(ConfigConstants.AKKA_WATCH_HEARTBEAT_PAUSE, "2 s"); + + cluster = new ForkableFlinkMiniCluster(config, false); + } + + @AfterClass + public static void tearDownCluster() { + try { + cluster.stop(); + } + catch (Throwable t) { + System.err.println("Error stopping cluster on shutdown"); + t.printStackTrace(); + fail("Cluster shutdown caused an exception: " + t.getMessage()); + } + } + + @Test + public void testOutDegreesInvalidEdgeSrcId() throws Exception { + /* + * Test outDegrees() with an edge having a srcId that does not exist in the vertex DataSet + */ + + final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment( + "localhost", cluster.getJobManagerRPCPort()); + + env.setDegreeOfParallelism(4); + env.setNumberOfExecutionRetries(0); + + Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), + TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env); + + try { + graph.outDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); + env.execute(); + + fail("graph.outDegrees() did not throw NoSuchElementException"); + } catch (Exception e) { + // expected + } + } + + @Test + public void testInDegreesInvalidEdgeTrgId() throws Exception { + /* + * Test inDegrees() with an edge having a trgId that does not exist in the vertex DataSet + */ + final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment( + "localhost", cluster.getJobManagerRPCPort()); + + env.setDegreeOfParallelism(4); + env.setNumberOfExecutionRetries(0); + + Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), + TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env); + + try { + graph.inDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); + env.execute(); + + fail("graph.inDegrees() did not throw NoSuchElementException"); + } catch (Exception e) { + // expected + } + } + + @Test + public void testGetDegreesInvalidEdgeTrgId() throws Exception { + /* + * Test getDegrees() with an edge having a trgId that does not exist in the vertex DataSet + */ + final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment( + "localhost", cluster.getJobManagerRPCPort()); + + env.setDegreeOfParallelism(4); + env.setNumberOfExecutionRetries(0); + + Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), + TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env); + + try { + graph.getDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); + env.execute(); + + fail("graph.getDegrees() did not throw NoSuchElementException"); + } catch (Exception e) { + // expected + } + } + + @Test + public void testGetDegreesInvalidEdgeSrcId() throws Exception { + /* + * Test getDegrees() with an edge having a srcId that does not exist in the vertex DataSet + */ + final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment( + "localhost", cluster.getJobManagerRPCPort()); + + env.setDegreeOfParallelism(4); + env.setNumberOfExecutionRetries(0); + + Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), + TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env); + + try { + graph.getDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); + env.execute(); + + fail("graph.getDegrees() did not throw NoSuchElementException"); + } catch (Exception e) { + // expected + } + } + + @Test + public void testGetDegreesInvalidEdgeSrcTrgId() throws Exception { + /* + * Test getDegrees() with an edge having a srcId and a trgId that does not exist in the vertex DataSet + */ + final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment( + "localhost", cluster.getJobManagerRPCPort()); + + env.setDegreeOfParallelism(4); + env.setNumberOfExecutionRetries(0); + + Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env), + TestGraphUtils.getLongLongEdgeInvalidSrcTrgData(env), env); + + try { + graph.getDegrees().output(new DiscardingOutputFormat<Tuple2<Long, Long>>()); + env.execute(); + + fail("graph.getDegrees() did not throw NoSuchElementException"); + } catch (Exception e) { + // expected + } + } +}