org.apache.flink.graph.test.TestGraphUtils Java Examples

The following examples show how to use org.apache.flink.graph.test.TestGraphUtils. 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: GraphCreationITCase.java    From flink with Apache License 2.0 7 votes vote down vote up
@Test
public void testCreateWithMapper() throws Exception {
	/*
	 * Test create() with edge dataset and a mapper that assigns the id as value
     */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongEdgeData(env),
		new AssignIdAsValueMapper(), env);

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,1\n" +
		"2,2\n" +
		"3,3\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #2
Source File: DegreesWithExceptionITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test getDegrees() with an edge having a srcId and a trgId that does not exist in the vertex DataSet.
 */
@Test
public void testGetDegreesInvalidEdgeSrcTrgId() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(PARALLELISM);

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeInvalidSrcTrgData(env), env);

	try {
		graph.getDegrees().output(new DiscardingOutputFormat<>());
		env.execute();

		fail("graph.getDegrees() did not fail.");
	}
	catch (Exception e) {
		// We expect the job to fail with an exception
	}
}
 
Example #3
Source File: DegreesWithExceptionITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test getDegrees() with an edge having a srcId that does not exist in the vertex DataSet.
 */
@Test
public void testGetDegreesInvalidEdgeSrcId() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(PARALLELISM);

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env);

	try {
		graph.getDegrees().output(new DiscardingOutputFormat<>());
		env.execute();

		fail("graph.getDegrees() did not fail.");
	} catch (Exception e) {
		// We expect the job to fail with an exception
	}
}
 
Example #4
Source File: MapEdgesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithCustomType() throws Exception {
	/*
	 * Test mapEdges() and change the value type to a custom type
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Edge<Long, DummyCustomType>> mappedEdges = graph.mapEdges(new ToCustomTypeMapper()).getEdges();
	List<Edge<Long, DummyCustomType>> result = mappedEdges.collect();

	expectedResult = "1,2,(T,12)\n" +
		"1,3,(T,13)\n" +
		"2,3,(T,23)\n" +
		"3,4,(T,34)\n" +
		"3,5,(T,35)\n" +
		"4,5,(T,45)\n" +
		"5,1,(T,51)\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #5
Source File: GraphCreationWithMapperITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithConstantValueMapper() throws Exception {
	/*
	 * Test create() with edge dataset with String key type
	 * and a mapper that assigns a double constant as value
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<String, Double, Long> graph = Graph.fromDataSet(TestGraphUtils.getStringLongEdgeData(env),
		new AssignDoubleConstantMapper(), env);

	DataSet<Vertex<String, Double>> data = graph.getVertices();
	List<Vertex<String, Double>> result = data.collect();

	expectedResult = "1,0.1\n" +
		"2,0.1\n" +
		"3,0.1\n" +
		"4,0.1\n" +
		"5,0.1\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #6
Source File: ReduceOnEdgesMethodsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testLowestWeightInNeighbor() throws Exception {
	/*
	 * Get the lowest-weight in-neighbor
	 * for each vertex
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> verticesWithLowestOutNeighbor =
		graph.groupReduceOnEdges(new SelectMinWeightInNeighbor(), EdgeDirection.IN);
	List<Tuple2<Long, Long>> result = verticesWithLowestOutNeighbor.collect();

	expectedResult = "1,5\n" +
		"2,1\n" +
		"3,1\n" +
		"4,3\n" +
		"5,3\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #7
Source File: DegreesWithExceptionITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Test outDegrees() with an edge having a srcId that does not exist in the vertex DataSet.
 */
@Test
public void testOutDegreesInvalidEdgeSrcId() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(PARALLELISM);
	env.getConfig().disableSysoutLogging();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeInvalidSrcData(env), env);

	try {
		graph.outDegrees().output(new DiscardingOutputFormat<>());
		env.execute();

		fail("graph.outDegrees() did not fail.");
	} catch (Exception e) {
		// We expect the job to fail with an exception
	}
}
 
Example #8
Source File: JoinWithVerticesITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithLessElements() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet passed as a parameter containing
	 * less elements than the vertex DataSet, but of the same type
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices().first(3)
		.map(new VertexToTuple2Map<>()), new AddValuesMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #9
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDifferenceVertices() throws Exception {
	/*Test  difference() method  by checking    the output  for getVertices()   on  the resultant   graph
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> graph2 = Graph.fromDataSet(TestGraphUtils.getLongLongVertexDataDifference(env),
		TestGraphUtils.getLongLongEdgeDataDifference(env), env);

	graph = graph.difference(graph2);

	List<Vertex<Long, Long>> result = graph.getVertices().collect();

	expectedResult = "2,2\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #10
Source File: ReduceOnEdgesMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testLowestWeightInNeighbor() throws Exception {
	/*
	 * Get the lowest-weight in-neighbor
	 * for each vertex
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> verticesWithLowestOutNeighbor =
		graph.groupReduceOnEdges(new SelectMinWeightInNeighbor(), EdgeDirection.IN);
	List<Tuple2<Long, Long>> result = verticesWithLowestOutNeighbor.collect();

	expectedResult = "1,5\n" +
		"2,1\n" +
		"3,1\n" +
		"4,3\n" +
		"5,3\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #11
Source File: JoinWithVerticesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDifferentType() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet passed as a parameter containing
	 * less elements than the vertex DataSet and of a different type(Boolean)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices().first(3)
		.map(new ProjectIdWithTrue()), new DoubleIfTrueMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #12
Source File: JoinWithVerticesITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDifferentType() throws Exception {
	/*
	 * Test joinWithVertices with the input DataSet passed as a parameter containing
	 * less elements than the vertex DataSet and of a different type(Boolean)
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	Graph<Long, Long, Long> res = graph.joinWithVertices(graph.getVertices().first(3)
		.map(new ProjectIdWithTrue()), new DoubleIfTrueMapper());

	DataSet<Vertex<Long, Long>> data = res.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,4\n" +
		"3,6\n" +
		"4,4\n" +
		"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #13
Source File: GraphCreationWithMapperITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithConstantValueMapper() throws Exception {
	/*
	 * Test create() with edge dataset with String key type
	 * and a mapper that assigns a double constant as value
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<String, Double, Long> graph = Graph.fromDataSet(TestGraphUtils.getStringLongEdgeData(env),
		new AssignDoubleConstantMapper(), env);

	DataSet<Vertex<String, Double>> data = graph.getVertices();
	List<Vertex<String, Double>> result = data.collect();

	expectedResult = "1,0.1\n" +
		"2,0.1\n" +
		"3,0.1\n" +
		"4,0.1\n" +
		"5,0.1\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #14
Source File: ReduceOnEdgesMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllInNeighborsNoValue() throws Exception {
	/*
	 * Get the all the in-neighbors for each vertex except for the vertex with id 5.
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> verticesWithAllInNeighbors =
		graph.groupReduceOnEdges(new SelectInNeighborsExceptFive(), EdgeDirection.IN);
	List<Tuple2<Long, Long>> result = verticesWithAllInNeighbors.collect();

	expectedResult = "1,5\n" +
		"2,1\n" +
		"3,1\n" +
		"3,2\n" +
		"4,3";

	compareResultAsTuples(result, expectedResult);
}
 
Example #15
Source File: ReduceOnEdgesMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllInNeighborsWithValueGreaterThanTwo() throws Exception {
	/*
	 * Get the all the in-neighbors for each vertex that have a value greater than two.
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> verticesWithAllInNeighbors =
		graph.groupReduceOnEdges(new SelectInNeighborsValueGreaterThanTwo(), EdgeDirection.IN);
	List<Tuple2<Long, Long>> result = verticesWithAllInNeighbors.collect();

	expectedResult = "3,1\n" +
		"3,2\n" +
		"4,3\n" +
		"5,3\n" +
		"5,4";

	compareResultAsTuples(result, expectedResult);
}
 
Example #16
Source File: ReduceOnNeighborsWithExceptionITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test groupReduceOnNeighbors() -NeighborsFunctionWithVertexValue-
 * with an edge having a trgId that does not exist in the vertex DataSet.
 */
@Test
public void testGroupReduceOnNeighborsWithVVInvalidEdgeTrgId() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(PARALLELISM);

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env);

	try {
		DataSet<Tuple2<Long, Long>> verticesWithSumOfOutNeighborValues =
				graph.groupReduceOnNeighbors(new SumAllNeighbors(), EdgeDirection.ALL);

		verticesWithSumOfOutNeighborValues.output(new DiscardingOutputFormat<>());
		env.execute();

		fail("Expected an exception.");
	} catch (Exception e) {
		// We expect the job to fail with an exception
	}
}
 
Example #17
Source File: DegreesITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDegreesWithDisconnectedData() throws Exception {
	/*
	 * Test getDegrees() with disconnected data
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, NullValue, Long> graph =
		Graph.fromDataSet(TestGraphUtils.getDisconnectedLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,0\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #18
Source File: GraphMutationsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddVertexExisting() throws Exception {
	/*
	 * Test addVertex() -- add an existing vertex
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeData(env), env);

	graph = graph.addVertex(new Vertex<>(1L, 1L));

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,1\n" +
			"2,2\n" +
			"3,3\n" +
			"4,4\n" +
			"5,5\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #19
Source File: GraphCreationWithMapperITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithTuple2ValueMapper() throws Exception {
	/*
	 * Test create() with edge dataset and a mapper that assigns a Tuple2 as value
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Tuple2<Long, Long>, Long> graph = Graph.fromDataSet(
		TestGraphUtils.getLongLongEdgeData(env), new AssignTuple2ValueMapper(), env);

	DataSet<Vertex<Long, Tuple2<Long, Long>>> data = graph.getVertices();
	List<Vertex<Long, Tuple2<Long, Long>>> result = data.collect();

	expectedResult = "1,(2,42)\n" +
		"2,(4,42)\n" +
		"3,(6,42)\n" +
		"4,(8,42)\n" +
		"5,(10,42)\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #20
Source File: GraphCreationWithMapperITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDCustomValueMapper() throws Exception {
	/*
	 * Test create() with edge dataset and a mapper that assigns a custom vertex value
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, DummyCustomType, Long> graph = Graph.fromDataSet(
		TestGraphUtils.getLongLongEdgeData(env), new AssignCustomValueMapper(), env);

	DataSet<Vertex<Long, DummyCustomType>> data = graph.getVertices();
	List<Vertex<Long, DummyCustomType>> result = data.collect();

	expectedResult = "1,(F,0)\n" +
		"2,(F,1)\n" +
		"3,(F,2)\n" +
		"4,(F,3)\n" +
		"5,(F,4)\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #21
Source File: DegreesITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDegreesWithDisconnectedData() throws Exception {
	/*
	 * Test getDegrees() with disconnected data
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, NullValue, Long> graph =
		Graph.fromDataSet(TestGraphUtils.getDisconnectedLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, LongValue>> data = graph.outDegrees();
	List<Tuple2<Long, LongValue>> result = data.collect();

	expectedResult = "1,2\n" +
		"2,1\n" +
		"3,0\n" +
		"4,1\n" +
		"5,0\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #22
Source File: GraphOperationsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testEdgesIds() throws Exception {
	/*
	 * Test getEdgeIds()
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> data = graph.getEdgeIds();
	List<Tuple2<Long, Long>> result = data.collect();

	expectedResult = "1,2\n" + "1,3\n" +
		"2,3\n" + "3,4\n" +
		"3,5\n" + "4,5\n" +
		"5,1\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #23
Source File: ReduceOnEdgesMethodsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllNeighborsWithValueGreaterThanFour() throws Exception {
	/*
	 * Get the all the neighbors for each vertex that have a value greater than four.
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> verticesWithAllNeighbors =
		graph.groupReduceOnEdges(new SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL);
	List<Tuple2<Long, Long>> result = verticesWithAllNeighbors.collect();

	expectedResult = "5,1\n" +
		"5,3\n" +
		"5,4";

	compareResultAsTuples(result, expectedResult);
}
 
Example #24
Source File: GraphMutationsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveInvalidEdge() throws Exception {
	/*
	 * Test removeEdge() -- invalid edge
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeData(env), env);
	graph = graph.removeEdge(new Edge<>(6L, 1L, 61L));

	DataSet<Edge<Long, Long>> data = graph.getEdges();
	List<Edge<Long, Long>> result = data.collect();

	expectedResult = "1,2,12\n" +
			"1,3,13\n" +
			"2,3,23\n" +
			"3,4,34\n" +
			"3,5,35\n" +
			"4,5,45\n" +
			"5,1,51\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #25
Source File: ReduceOnNeighborsWithExceptionITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test groupReduceOnNeighbors() -NeighborsFunction-
 * with an edge having a srcId that does not exist in the vertex DataSet.
 */
@Test
public void testGroupReduceOnNeighborsInvalidEdgeSrcId() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(PARALLELISM);

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env);

	try {
		DataSet<Tuple2<Long, Long>> verticesWithSumOfAllNeighborValues =
				graph.reduceOnNeighbors(new SumNeighbors(), EdgeDirection.ALL);

		verticesWithSumOfAllNeighborValues.output(new DiscardingOutputFormat<>());
		env.execute();
	} catch (Exception e) {
		// We expect the job to fail with an exception
	}
}
 
Example #26
Source File: GraphMutationsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddVertex() throws Exception {
	/*
	 * Test addVertex() -- simple case
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeData(env), env);

	graph = graph.addVertex(new Vertex<>(6L, 6L));

	DataSet<Vertex<Long, Long>> data = graph.getVertices();
	List<Vertex<Long, Long>> result = data.collect();

	expectedResult = "1,1\n" +
			"2,2\n" +
			"3,3\n" +
			"4,4\n" +
			"5,5\n" +
			"6,6\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #27
Source File: DegreesWithExceptionITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Test inDegrees() with an edge having a trgId that does not exist in the vertex DataSet.
 */
@Test
public void testInDegreesInvalidEdgeTrgId() throws Exception {

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(PARALLELISM);
	env.getConfig().disableSysoutLogging();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeInvalidTrgData(env), env);

	try {
		graph.inDegrees().output(new DiscardingOutputFormat<>());
		env.execute();

		fail("graph.inDegrees() did not fail.");
	} catch (Exception e) {
		// We expect the job to fail with an exception
	}
}
 
Example #28
Source File: GraphOperationsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testUndirected() throws Exception {
	/*
	 * Test getUndirected()
	 */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Edge<Long, Long>> data = graph.getUndirected().getEdges();
	List<Edge<Long, Long>> result = data.collect();

	expectedResult = "1,2,12\n" + "2,1,12\n" +
		"1,3,13\n" + "3,1,13\n" +
		"2,3,23\n" + "3,2,23\n" +
		"3,4,34\n" + "4,3,34\n" +
		"3,5,35\n" + "5,3,35\n" +
		"4,5,45\n" + "5,4,45\n" +
		"5,1,51\n" + "1,5,51\n";

	compareResultAsTuples(result, expectedResult);
}
 
Example #29
Source File: ReduceOnEdgesMethodsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllNeighborsWithValueGreaterThanFour() throws Exception {
	/*
	 * Get the all the neighbors for each vertex that have a value greater than four.
        */
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
		TestGraphUtils.getLongLongEdgeData(env), env);

	DataSet<Tuple2<Long, Long>> verticesWithAllNeighbors =
		graph.groupReduceOnEdges(new SelectNeighborsValueGreaterThanFour(), EdgeDirection.ALL);
	List<Tuple2<Long, Long>> result = verticesWithAllNeighbors.collect();

	expectedResult = "5,1\n" +
		"5,3\n" +
		"5,4";

	compareResultAsTuples(result, expectedResult);
}
 
Example #30
Source File: GraphMutationsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveInvalidEdge() throws Exception {
	/*
	 * Test removeEdge() -- invalid edge
	 */

	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> graph = Graph.fromDataSet(TestGraphUtils.getLongLongVertexData(env),
			TestGraphUtils.getLongLongEdgeData(env), env);
	graph = graph.removeEdge(new Edge<>(6L, 1L, 61L));

	DataSet<Edge<Long, Long>> data = graph.getEdges();
	List<Edge<Long, Long>> result = data.collect();

	expectedResult = "1,2,12\n" +
			"1,3,13\n" +
			"2,3,23\n" +
			"3,4,34\n" +
			"3,5,35\n" +
			"4,5,45\n" +
			"5,1,51\n";

	compareResultAsTuples(result, expectedResult);
}