org.apache.flink.api.java.io.LocalCollectionOutputFormat Java Examples

The following examples show how to use org.apache.flink.api.java.io.LocalCollectionOutputFormat. 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: SummarizationITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, String> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env);

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example #2
Source File: AutoParallelismITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testProgramWithAutoParallelism() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	env.setParallelism(ExecutionConfig.PARALLELISM_AUTO_MAX);
	env.getConfig().disableSysoutLogging();

	DataSet<Integer> result = env
			.createInput(new ParallelismDependentInputFormat())
			.rebalance()
			.mapPartition(new ParallelismDependentMapPartition());

	List<Integer> resultCollection = new ArrayList<>();
	result.output(new LocalCollectionOutputFormat<>(resultCollection));

	try {
		env.execute();
		assertEquals(PARALLELISM, resultCollection.size());
	}
	catch (Exception ex) {
		assertTrue(
			ExceptionUtils.findThrowableWithMessage(ex, ExecutionGraphBuilder.PARALLELISM_AUTO_MAX_ERROR_MESSAGE).isPresent());
	}
}
 
Example #3
Source File: SummarizationITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, String> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env);

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example #4
Source File: DeltaIterationNotDependingOnSolutionSetITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected void testProgram() throws Exception {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
		env.setParallelism(1);

		DataSet<Tuple2<Long, Long>> input = env.generateSequence(0, 9).map(new Duplicator<Long>());

		DeltaIteration<Tuple2<Long, Long>, Tuple2<Long, Long>> iteration = input.iterateDelta(input, 5, 1);

		iteration.closeWith(iteration.getWorkset(), iteration.getWorkset().map(new TestMapper()))
				.output(new LocalCollectionOutputFormat<Tuple2<Long, Long>>(result));

		env.execute();
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #5
Source File: SummarizationITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndAbsentEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, NullValue> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateEdgeValues<>(new ToNullValue<>()));

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<NullValue>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<NullValue>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_ABSENT_VALUES, summarizedEdges);
}
 
Example #6
Source File: CollectionExecutionWithBroadcastVariableTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnaryOp() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		DataSet<String> bcData = env.fromElements(SUFFIX);

		List<String> result = new ArrayList<String>();

		env.fromElements(TEST_DATA)
				.map(new SuffixAppender()).withBroadcastSet(bcData, BC_VAR_NAME)
				.output(new LocalCollectionOutputFormat<String>(result));

		env.execute();

		assertEquals(TEST_DATA.length, result.size());
		for (String s : result) {
			assertTrue(s.indexOf(SUFFIX) > 0);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #7
Source File: MultipleSolutionSetJoinsITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected void testProgram() throws Exception {

	final int numIters = 4;
	final double expectedFactor = (int) Math.pow(7, numIters);

	// this is an artificial program, it does not compute anything sensical
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	DataSet<Tuple2<Long, Double>> initialData = env.fromElements(new Tuple2<Long, Double>(1L, 1.0), new Tuple2<Long, Double>(2L, 2.0),
														new Tuple2<Long, Double>(3L, 3.0), new Tuple2<Long, Double>(4L, 4.0),
														new Tuple2<Long, Double>(5L, 5.0), new Tuple2<Long, Double>(6L, 6.0));

	DataSet<Tuple2<Long, Double>> result = MultipleJoinsWithSolutionSetCompilerTest.constructPlan(initialData, numIters);

	List<Tuple2<Long, Double>> resultCollector = new ArrayList<Tuple2<Long, Double>>();
	result.output(new LocalCollectionOutputFormat<>(resultCollector));

	env.execute();

	for (Tuple2<Long, Double> tuple : resultCollector) {
		Assert.assertEquals(expectedFactor * tuple.f0, tuple.f1.doubleValue(), 0.0);
	}
}
 
Example #8
Source File: CollectionExecutionIterationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBulkIteration() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		IterativeDataSet<Integer> iteration = env.fromElements(1).iterate(10);

		DataSet<Integer> result = iteration.closeWith(iteration.map(new AddSuperstepNumberMapper()));

		List<Integer> collected = new ArrayList<Integer>();
		result.output(new LocalCollectionOutputFormat<Integer>(collected));

		env.execute();

		assertEquals(1, collected.size());
		assertEquals(56, collected.get(0).intValue());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #9
Source File: SummarizationITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeLongValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateVertexValues<>(new StringToLong()))
		.run(new TranslateEdgeValues<>(new StringToLong()));

	List<Vertex<Long, Summarization.VertexValue<Long>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<Long>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<Long>, EdgeValue<Long>> output =
		input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example #10
Source File: CollectionExecutionIterationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testBulkIteration() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		IterativeDataSet<Integer> iteration = env.fromElements(1).iterate(10);

		DataSet<Integer> result = iteration.closeWith(iteration.map(new AddSuperstepNumberMapper()));

		List<Integer> collected = new ArrayList<Integer>();
		result.output(new LocalCollectionOutputFormat<Integer>(collected));

		env.execute();

		assertEquals(1, collected.size());
		assertEquals(56, collected.get(0).intValue());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #11
Source File: CollectionExecutionWithBroadcastVariableTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinaryOp() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		DataSet<String> bcData = env.fromElements(SUFFIX);
		DataSet<String> inData = env.fromElements(TEST_DATA);

		List<String> result = new ArrayList<String>();

		inData.cross(inData).with(new SuffixCross()).withBroadcastSet(bcData, BC_VAR_NAME)
				.output(new LocalCollectionOutputFormat<String>(result));

		env.execute();

		assertEquals(TEST_DATA.length * TEST_DATA.length, result.size());
		for (String s : result) {
			assertTrue(s.indexOf(SUFFIX) == 2);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #12
Source File: CollectionExecutionWithBroadcastVariableTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinaryOp() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		DataSet<String> bcData = env.fromElements(SUFFIX);
		DataSet<String> inData = env.fromElements(TEST_DATA);

		List<String> result = new ArrayList<String>();

		inData.cross(inData).with(new SuffixCross()).withBroadcastSet(bcData, BC_VAR_NAME)
				.output(new LocalCollectionOutputFormat<String>(result));

		env.execute();

		assertEquals(TEST_DATA.length * TEST_DATA.length, result.size());
		for (String s : result) {
			assertTrue(s.indexOf(SUFFIX) == 2);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #13
Source File: CollectionExecutionWithBroadcastVariableTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnaryOp() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		DataSet<String> bcData = env.fromElements(SUFFIX);

		List<String> result = new ArrayList<String>();

		env.fromElements(TEST_DATA)
				.map(new SuffixAppender()).withBroadcastSet(bcData, BC_VAR_NAME)
				.output(new LocalCollectionOutputFormat<String>(result));

		env.execute();

		assertEquals(TEST_DATA.length, result.size());
		for (String s : result) {
			assertTrue(s.indexOf(SUFFIX) > 0);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #14
Source File: SummarizationITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndAbsentEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, NullValue> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateEdgeValues<>(new ToNullValue<>()));

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<NullValue>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<NullValue>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_ABSENT_VALUES, summarizedEdges);
}
 
Example #15
Source File: SummarizationITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeLongValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateVertexValues<>(new StringToLong()))
		.run(new TranslateEdgeValues<>(new StringToLong()));

	List<Vertex<Long, Summarization.VertexValue<Long>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<Long>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<Long>, EdgeValue<Long>> output =
		input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example #16
Source File: DeltaIterationNotDependingOnSolutionSetITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void testProgram() throws Exception {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
		env.setParallelism(1);

		DataSet<Tuple2<Long, Long>> input = env.generateSequence(0, 9).map(new Duplicator<Long>());

		DeltaIteration<Tuple2<Long, Long>, Tuple2<Long, Long>> iteration = input.iterateDelta(input, 5, 1);

		iteration.closeWith(iteration.getWorkset(), iteration.getWorkset().map(new TestMapper()))
				.output(new LocalCollectionOutputFormat<Tuple2<Long, Long>>(result));

		env.execute();
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #17
Source File: MultipleSolutionSetJoinsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void testProgram() throws Exception {

	final int numIters = 4;
	final double expectedFactor = (int) Math.pow(7, numIters);

	// this is an artificial program, it does not compute anything sensical
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	DataSet<Tuple2<Long, Double>> initialData = env.fromElements(new Tuple2<Long, Double>(1L, 1.0), new Tuple2<Long, Double>(2L, 2.0),
														new Tuple2<Long, Double>(3L, 3.0), new Tuple2<Long, Double>(4L, 4.0),
														new Tuple2<Long, Double>(5L, 5.0), new Tuple2<Long, Double>(6L, 6.0));

	DataSet<Tuple2<Long, Double>> result = MultipleJoinsWithSolutionSetCompilerTest.constructPlan(initialData, numIters);

	List<Tuple2<Long, Double>> resultCollector = new ArrayList<Tuple2<Long, Double>>();
	result.output(new LocalCollectionOutputFormat<>(resultCollector));

	env.execute();

	for (Tuple2<Long, Double> tuple : resultCollector) {
		Assert.assertEquals(expectedFactor * tuple.f0, tuple.f1.doubleValue(), 0.0);
	}
}
 
Example #18
Source File: MultipleSolutionSetJoinsITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void testProgram() throws Exception {

	final int numIters = 4;
	final double expectedFactor = (int) Math.pow(7, numIters);

	// this is an artificial program, it does not compute anything sensical
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	DataSet<Tuple2<Long, Double>> initialData = env.fromElements(new Tuple2<Long, Double>(1L, 1.0), new Tuple2<Long, Double>(2L, 2.0),
														new Tuple2<Long, Double>(3L, 3.0), new Tuple2<Long, Double>(4L, 4.0),
														new Tuple2<Long, Double>(5L, 5.0), new Tuple2<Long, Double>(6L, 6.0));

	DataSet<Tuple2<Long, Double>> result = MultipleJoinsWithSolutionSetCompilerTest.constructPlan(initialData, numIters);

	List<Tuple2<Long, Double>> resultCollector = new ArrayList<Tuple2<Long, Double>>();
	result.output(new LocalCollectionOutputFormat<>(resultCollector));

	env.execute();

	for (Tuple2<Long, Double> tuple : resultCollector) {
		Assert.assertEquals(expectedFactor * tuple.f0, tuple.f1.doubleValue(), 0.0);
	}
}
 
Example #19
Source File: SummarizationITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeLongValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	Graph<Long, Long, Long> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateVertexValues<>(new StringToLong()))
		.run(new TranslateEdgeValues<>(new StringToLong()));

	List<Vertex<Long, Summarization.VertexValue<Long>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<Long>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<Long>, EdgeValue<Long>> output =
		input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example #20
Source File: DeltaIterationNotDependingOnSolutionSetITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void testProgram() throws Exception {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
		env.setParallelism(1);

		DataSet<Tuple2<Long, Long>> input = env.generateSequence(0, 9).map(new Duplicator<Long>());

		DeltaIteration<Tuple2<Long, Long>, Tuple2<Long, Long>> iteration = input.iterateDelta(input, 5, 1);

		iteration.closeWith(iteration.getWorkset(), iteration.getWorkset().map(new TestMapper()))
				.output(new LocalCollectionOutputFormat<Tuple2<Long, Long>>(result));

		env.execute();
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #21
Source File: SummarizationITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndAbsentEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, NullValue> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env)
		.run(new TranslateEdgeValues<>(new ToNullValue<>()));

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<NullValue>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<NullValue>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_ABSENT_VALUES, summarizedEdges);
}
 
Example #22
Source File: SummarizationITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithVertexAndEdgeStringValues() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	Graph<Long, String, String> input = Graph.fromDataSet(
			SummarizationData.getVertices(env),
			SummarizationData.getEdges(env),
			env);

	List<Vertex<Long, Summarization.VertexValue<String>>> summarizedVertices = new ArrayList<>();
	List<Edge<Long, EdgeValue<String>>> summarizedEdges = new ArrayList<>();

	Graph<Long, Summarization.VertexValue<String>, EdgeValue<String>> output =
			input.run(new Summarization<>());

	output.getVertices().output(new LocalCollectionOutputFormat<>(summarizedVertices));
	output.getEdges().output(new LocalCollectionOutputFormat<>(summarizedEdges));

	env.execute();

	validateVertices(SummarizationData.EXPECTED_VERTICES, summarizedVertices);
	validateEdges(SummarizationData.EXPECTED_EDGES_WITH_VALUES, summarizedEdges);
}
 
Example #23
Source File: CollectionExecutionWithBroadcastVariableTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinaryOp() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		DataSet<String> bcData = env.fromElements(SUFFIX);
		DataSet<String> inData = env.fromElements(TEST_DATA);

		List<String> result = new ArrayList<String>();

		inData.cross(inData).with(new SuffixCross()).withBroadcastSet(bcData, BC_VAR_NAME)
				.output(new LocalCollectionOutputFormat<String>(result));

		env.execute();

		assertEquals(TEST_DATA.length * TEST_DATA.length, result.size());
		for (String s : result) {
			assertTrue(s.indexOf(SUFFIX) == 2);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #24
Source File: CollectionExecutionWithBroadcastVariableTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnaryOp() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		DataSet<String> bcData = env.fromElements(SUFFIX);

		List<String> result = new ArrayList<String>();

		env.fromElements(TEST_DATA)
				.map(new SuffixAppender()).withBroadcastSet(bcData, BC_VAR_NAME)
				.output(new LocalCollectionOutputFormat<String>(result));

		env.execute();

		assertEquals(TEST_DATA.length, result.size());
		for (String s : result) {
			assertTrue(s.indexOf(SUFFIX) > 0);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #25
Source File: CollectionExecutionIterationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBulkIteration() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		IterativeDataSet<Integer> iteration = env.fromElements(1).iterate(10);

		DataSet<Integer> result = iteration.closeWith(iteration.map(new AddSuperstepNumberMapper()));

		List<Integer> collected = new ArrayList<Integer>();
		result.output(new LocalCollectionOutputFormat<Integer>(collected));

		env.execute();

		assertEquals(1, collected.size());
		assertEquals(56, collected.get(0).intValue());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #26
Source File: SimpleRecoveryITCaseBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestartMultipleTimes() {
	try {
		List<Long> resultCollection = new ArrayList<Long>();

		ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

		env.setParallelism(4);
		env.setRestartStrategy(RestartStrategies.fixedDelayRestart(5, 100));

		env.generateSequence(1, 10)
				.rebalance()
				.map(new FailingMapper3<Long>())
				.reduce(new ReduceFunction<Long>() {
					@Override
					public Long reduce(Long value1, Long value2) {
						return value1 + value2;
					}
				})
				.output(new LocalCollectionOutputFormat<Long>(resultCollection));

		executeAndRunAssertions(env);

		long sum = 0;
		for (long l : resultCollection) {
			sum += l;
		}
		assertEquals(55, sum);
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	} finally {
		FailingMapper3.failuresBeforeSuccess = 3;
	}
}
 
Example #27
Source File: IdentityIterationITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void testProgram() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	IterativeDataSet<Long> iteration = env.generateSequence(1, 10).iterate(100);
	iteration.closeWith(iteration)
		.output(new LocalCollectionOutputFormat<Long>(result));

	env.execute();
}
 
Example #28
Source File: CollectionExecutionIterationTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testBulkIterationWithTerminationCriterion() {
	try {
		ExecutionEnvironment env = ExecutionEnvironment.createCollectionsEnvironment();

		IterativeDataSet<Integer> iteration = env.fromElements(1).iterate(100);

		DataSet<Integer> iterationResult = iteration.map(new AddSuperstepNumberMapper());

		DataSet<Integer> terminationCriterion = iterationResult.filter(new FilterFunction<Integer>() {
			public boolean filter(Integer value) {
				return value < 50;
			}
		});

		List<Integer> collected = new ArrayList<Integer>();

		iteration.closeWith(iterationResult, terminationCriterion)
				.output(new LocalCollectionOutputFormat<Integer>(collected));

		env.execute();

		assertEquals(1, collected.size());
		assertEquals(56, collected.get(0).intValue());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #29
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public final void testIntersect() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges1 = new ArrayList<>();
	edges1.add(new Edge<>(1L, 3L, 12L));
	edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output
	edges1.add(new Edge<>(1L, 3L, 14L));

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges2 = new ArrayList<>();
	edges2.add(new Edge<>(1L, 3L, 13L));

	Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env);
	Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env);

	Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true);

	List<Vertex<Long, NullValue>> vertices = new ArrayList<>();
	List<Edge<Long, Long>> edges = new ArrayList<>();

	intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices));
	intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges));

	env.execute();

	String expectedVertices = "1,(null)\n" + "3,(null)\n";

	String expectedEdges = "1,3,13\n";

	compareResultAsTuples(vertices, expectedVertices);
	compareResultAsTuples(edges, expectedEdges);
}
 
Example #30
Source File: GraphOperationsITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public final void testIntersect() throws Exception {
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges1 = new ArrayList<>();
	edges1.add(new Edge<>(1L, 3L, 12L));
	edges1.add(new Edge<>(1L, 3L, 13L)); // needs to be in the output
	edges1.add(new Edge<>(1L, 3L, 14L));

	@SuppressWarnings("unchecked")
	List<Edge<Long, Long>> edges2 = new ArrayList<>();
	edges2.add(new Edge<>(1L, 3L, 13L));

	Graph<Long, NullValue, Long> graph1 = Graph.fromCollection(edges1, env);
	Graph<Long, NullValue, Long> graph2 = Graph.fromCollection(edges2, env);

	Graph<Long, NullValue, Long> intersect = graph1.intersect(graph2, true);

	List<Vertex<Long, NullValue>> vertices = new ArrayList<>();
	List<Edge<Long, Long>> edges = new ArrayList<>();

	intersect.getVertices().output(new LocalCollectionOutputFormat<>(vertices));
	intersect.getEdges().output(new LocalCollectionOutputFormat<>(edges));

	env.execute();

	String expectedVertices = "1,(null)\n" + "3,(null)\n";

	String expectedEdges = "1,3,13\n";

	compareResultAsTuples(vertices, expectedVertices);
	compareResultAsTuples(edges, expectedEdges);
}