Java Code Examples for org.apache.flink.streaming.api.functions.source.FromElementsFunction#run()
The following examples show how to use
org.apache.flink.streaming.api.functions.source.FromElementsFunction#run() .
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: FromElementsFunctionTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testStrings() { try { String[] data = { "Oh", "boy", "what", "a", "show", "!"}; FromElementsFunction<String> source = new FromElementsFunction<String>( BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), data); List<String> result = new ArrayList<String>(); source.run(new ListSourceContext<String>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 2
Source File: FromElementsFunctionTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testNonJavaSerializableType() { try { MyPojo[] data = { new MyPojo(1, 2), new MyPojo(3, 4), new MyPojo(5, 6) }; FromElementsFunction<MyPojo> source = new FromElementsFunction<MyPojo>( TypeExtractor.getForClass(MyPojo.class).createSerializer(new ExecutionConfig()), data); List<MyPojo> result = new ArrayList<MyPojo>(); source.run(new ListSourceContext<MyPojo>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 3
Source File: FromElementsFunctionTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testStrings() { try { String[] data = { "Oh", "boy", "what", "a", "show", "!"}; FromElementsFunction<String> source = new FromElementsFunction<String>( BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), data); List<String> result = new ArrayList<String>(); source.run(new ListSourceContext<String>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 4
Source File: FromElementsFunctionTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testNonJavaSerializableType() { try { MyPojo[] data = { new MyPojo(1, 2), new MyPojo(3, 4), new MyPojo(5, 6) }; FromElementsFunction<MyPojo> source = new FromElementsFunction<MyPojo>( TypeExtractor.getForClass(MyPojo.class).createSerializer(new ExecutionConfig()), data); List<MyPojo> result = new ArrayList<MyPojo>(); source.run(new ListSourceContext<MyPojo>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 5
Source File: FromElementsFunctionTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testStrings() { try { String[] data = { "Oh", "boy", "what", "a", "show", "!"}; FromElementsFunction<String> source = new FromElementsFunction<String>( BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), data); List<String> result = new ArrayList<String>(); source.run(new ListSourceContext<String>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 6
Source File: FromElementsFunctionTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testNonJavaSerializableType() { try { MyPojo[] data = { new MyPojo(1, 2), new MyPojo(3, 4), new MyPojo(5, 6) }; FromElementsFunction<MyPojo> source = new FromElementsFunction<MyPojo>( TypeExtractor.getForClass(MyPojo.class).createSerializer(new ExecutionConfig()), data); List<MyPojo> result = new ArrayList<MyPojo>(); source.run(new ListSourceContext<MyPojo>(result)); assertEquals(Arrays.asList(data), result); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 7
Source File: FromElementsFunctionTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testCheckpointAndRestore() { try { final int numElements = 10000; List<Integer> data = new ArrayList<Integer>(numElements); List<Integer> result = new ArrayList<Integer>(numElements); for (int i = 0; i < numElements; i++) { data.add(i); } final FromElementsFunction<Integer> source = new FromElementsFunction<>(IntSerializer.INSTANCE, data); StreamSource<Integer, FromElementsFunction<Integer>> src = new StreamSource<>(source); AbstractStreamOperatorTestHarness<Integer> testHarness = new AbstractStreamOperatorTestHarness<>(src, 1, 1, 0); testHarness.open(); final SourceFunction.SourceContext<Integer> ctx = new ListSourceContext<Integer>(result, 2L); final Throwable[] error = new Throwable[1]; // run the source asynchronously Thread runner = new Thread() { @Override public void run() { try { source.run(ctx); } catch (Throwable t) { error[0] = t; } } }; runner.start(); // wait for a bit Thread.sleep(1000); // make a checkpoint List<Integer> checkpointData = new ArrayList<>(numElements); OperatorSubtaskState handles = null; synchronized (ctx.getCheckpointLock()) { handles = testHarness.snapshot(566, System.currentTimeMillis()); checkpointData.addAll(result); } // cancel the source source.cancel(); runner.join(); // check for errors if (error[0] != null) { System.err.println("Error in asynchronous source runner"); error[0].printStackTrace(); fail("Error in asynchronous source runner"); } final FromElementsFunction<Integer> sourceCopy = new FromElementsFunction<>(IntSerializer.INSTANCE, data); StreamSource<Integer, FromElementsFunction<Integer>> srcCopy = new StreamSource<>(sourceCopy); AbstractStreamOperatorTestHarness<Integer> testHarnessCopy = new AbstractStreamOperatorTestHarness<>(srcCopy, 1, 1, 0); testHarnessCopy.setup(); testHarnessCopy.initializeState(handles); testHarnessCopy.open(); // recovery run SourceFunction.SourceContext<Integer> newCtx = new ListSourceContext<>(checkpointData); sourceCopy.run(newCtx); assertEquals(data, checkpointData); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 8
Source File: FromElementsFunctionTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCheckpointAndRestore() { try { final int numElements = 10000; List<Integer> data = new ArrayList<Integer>(numElements); List<Integer> result = new ArrayList<Integer>(numElements); for (int i = 0; i < numElements; i++) { data.add(i); } final FromElementsFunction<Integer> source = new FromElementsFunction<>(IntSerializer.INSTANCE, data); StreamSource<Integer, FromElementsFunction<Integer>> src = new StreamSource<>(source); AbstractStreamOperatorTestHarness<Integer> testHarness = new AbstractStreamOperatorTestHarness<>(src, 1, 1, 0); testHarness.open(); final SourceFunction.SourceContext<Integer> ctx = new ListSourceContext<Integer>(result, 2L); final Throwable[] error = new Throwable[1]; // run the source asynchronously Thread runner = new Thread() { @Override public void run() { try { source.run(ctx); } catch (Throwable t) { error[0] = t; } } }; runner.start(); // wait for a bit Thread.sleep(1000); // make a checkpoint List<Integer> checkpointData = new ArrayList<>(numElements); OperatorSubtaskState handles = null; synchronized (ctx.getCheckpointLock()) { handles = testHarness.snapshot(566, System.currentTimeMillis()); checkpointData.addAll(result); } // cancel the source source.cancel(); runner.join(); // check for errors if (error[0] != null) { System.err.println("Error in asynchronous source runner"); error[0].printStackTrace(); fail("Error in asynchronous source runner"); } final FromElementsFunction<Integer> sourceCopy = new FromElementsFunction<>(IntSerializer.INSTANCE, data); StreamSource<Integer, FromElementsFunction<Integer>> srcCopy = new StreamSource<>(sourceCopy); AbstractStreamOperatorTestHarness<Integer> testHarnessCopy = new AbstractStreamOperatorTestHarness<>(srcCopy, 1, 1, 0); testHarnessCopy.setup(); testHarnessCopy.initializeState(handles); testHarnessCopy.open(); // recovery run SourceFunction.SourceContext<Integer> newCtx = new ListSourceContext<>(checkpointData); sourceCopy.run(newCtx); assertEquals(data, checkpointData); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 9
Source File: FromElementsFunctionTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testCheckpointAndRestore() { try { final int numElements = 10000; List<Integer> data = new ArrayList<Integer>(numElements); List<Integer> result = new ArrayList<Integer>(numElements); for (int i = 0; i < numElements; i++) { data.add(i); } final FromElementsFunction<Integer> source = new FromElementsFunction<>(IntSerializer.INSTANCE, data); StreamSource<Integer, FromElementsFunction<Integer>> src = new StreamSource<>(source); AbstractStreamOperatorTestHarness<Integer> testHarness = new AbstractStreamOperatorTestHarness<>(src, 1, 1, 0); testHarness.open(); final SourceFunction.SourceContext<Integer> ctx = new ListSourceContext<Integer>(result, 2L); final Throwable[] error = new Throwable[1]; // run the source asynchronously Thread runner = new Thread() { @Override public void run() { try { source.run(ctx); } catch (Throwable t) { error[0] = t; } } }; runner.start(); // wait for a bit Thread.sleep(1000); // make a checkpoint List<Integer> checkpointData = new ArrayList<>(numElements); OperatorSubtaskState handles = null; synchronized (ctx.getCheckpointLock()) { handles = testHarness.snapshot(566, System.currentTimeMillis()); checkpointData.addAll(result); } // cancel the source source.cancel(); runner.join(); // check for errors if (error[0] != null) { System.err.println("Error in asynchronous source runner"); error[0].printStackTrace(); fail("Error in asynchronous source runner"); } final FromElementsFunction<Integer> sourceCopy = new FromElementsFunction<>(IntSerializer.INSTANCE, data); StreamSource<Integer, FromElementsFunction<Integer>> srcCopy = new StreamSource<>(sourceCopy); AbstractStreamOperatorTestHarness<Integer> testHarnessCopy = new AbstractStreamOperatorTestHarness<>(srcCopy, 1, 1, 0); testHarnessCopy.setup(); testHarnessCopy.initializeState(handles); testHarnessCopy.open(); // recovery run SourceFunction.SourceContext<Integer> newCtx = new ListSourceContext<>(checkpointData); sourceCopy.run(newCtx); assertEquals(data, checkpointData); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }