Package org.apache.flink.streaming.api.environment

Examples of org.apache.flink.streaming.api.environment.LocalStreamEnvironment


  private static ArrayList<Tuple2<Tuple2<Integer, String>, Integer>> crossResults = new ArrayList<Tuple2<Tuple2<Integer, String>, Integer>>();
  private static ArrayList<Tuple2<Tuple2<Integer, String>, Integer>> crossExpectedResults = new ArrayList<Tuple2<Tuple2<Integer, String>, Integer>>();

  @Test
  public void test() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);
    env.setBufferTimeout(1);

    ArrayList<Tuple2<Integer, String>> in1 = new ArrayList<Tuple2<Integer, String>>();
    ArrayList<Integer> in2 = new ArrayList<Integer>();

    in1.add(new Tuple2<Integer, String>(10, "a"));
    in1.add(new Tuple2<Integer, String>(20, "b"));
    in1.add(new Tuple2<Integer, String>(20, "x"));
    in1.add(new Tuple2<Integer, String>(0, "y"));

    in2.add(0);
    in2.add(5);
    in2.add(20);

    joinExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "b"), 20));
    joinExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "x"), 20));
    joinExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(0, "y"), 0));

    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(10, "a"), 0));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(10, "a"), 5));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(10, "a"), 20));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "b"), 0));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "b"), 5));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "b"), 20));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "x"), 0));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "x"), 5));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(20, "x"), 20));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(0, "y"), 0));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(0, "y"), 5));
    crossExpectedResults.add(new Tuple2<Tuple2<Integer, String>, Integer>(
        new Tuple2<Integer, String>(0, "y"), 20));

    DataStream<Tuple2<Integer, String>> inStream1 = env.fromCollection(in1);
    DataStream<Integer> inStream2 = env.fromCollection(in2);

    inStream1.windowJoin(inStream2, 1000, 1000, new MyTimestamp1(), new MyTimestamp2(), 0, 0)
        .addSink(new JoinResultSink());

    inStream1.windowCross(inStream2, 1000, 1000, new MyTimestamp1(), new MyTimestamp2())
      .addSink(new CrossResultSink());

    env.executeTest(MEMORYSIZE);
   
    assertEquals(joinExpectedResults, joinResults);
    assertEquals(crossExpectedResults, crossResults);
  }
View Full Code Here


  private static final int SOURCE_PARALELISM = 1;
  private static final long MEMORYSIZE = 32;

  @Test
  public void wrongJobGraph() {
    LocalStreamEnvironment env = StreamExecutionEnvironment
        .createLocalEnvironment(SOURCE_PARALELISM);


    try {
      env.fromCollection(null);
      fail();
    } catch (NullPointerException e) {
    }

    try {
      env.fromElements();
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      env.generateSequence(-10, -30);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      env.setBufferTimeout(-10);
      fail();
    } catch (IllegalArgumentException e) {
    }

    try {
      env.setExecutionParallelism(-10);
      fail();
    } catch (IllegalArgumentException e) {
    }
    try {
      env.generateSequence(1, 10).project(2);
      fail();
    } catch (RuntimeException e) {
    }

    try {
      env.readTextFile("random/path/that/is/not/valid");
      fail();
    } catch (IllegalArgumentException e) {
    }
  }
View Full Code Here

    Runtime.getRuntime().addShutdownHook(new Thread(r));
  }

  @Test
  public void test() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);
   
    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream1 = env.addSource(new MySource1(), 1).writeAsText(PREFIX + "test1.txt");

    fillExpected1();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream2 = env.addSource(new MySource1(), 1).writeAsText(PREFIX + "test2.txt", 5);

    fillExpected2();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream3 = env.addSource(new MySource1(), 1).writeAsText(PREFIX + "test3.txt", 10);

    fillExpected3();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream4 = env.addSource(new MySource1(), 1).writeAsText(PREFIX + "test4.txt", 10, new Tuple1<Integer>(26));

    fillExpected4();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream5 = env.addSource(new MySource1(), 1).writeAsText(PREFIX + "test5.txt", 10, new Tuple1<Integer>(14));

    fillExpected5();

    env.executeTest(MEMORYSIZE);

    readFile(PREFIX + "test1.txt", result1);
    readFile(PREFIX + "test2.txt", result2);
    readFile(PREFIX + "test3.txt", result3);
    readFile(PREFIX + "test4.txt", result4);
View Full Code Here

    }
  }

  @Test
  public void coTest() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment
        .createLocalEnvironment(SOURCE_PARALELISM);

    DataStream<String> fromStringElements = env.fromElements("aa", "bb", "cc");
    DataStream<Long> generatedSequence = env.generateSequence(0, 3);

    fromStringElements.connect(generatedSequence).map(new CoMap()).addSink(new SetSink());

    resultSet = new HashSet<String>();
    env.executeTest(MEMORYSIZE);

    HashSet<String> expectedSet = new HashSet<String>(Arrays.asList("aa", "bb", "cc", "0", "1",
        "2", "3"));
    assertEquals(expectedSet, resultSet);
  }
View Full Code Here

    assertEquals(expectedSet, resultSet);
  }

  @Test
  public void runStream() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment
        .createLocalEnvironment(SOURCE_PARALELISM);

    env.addSource(new MySource(), SOURCE_PARALELISM).map(new MyTask()).addSink(new MySink());

    env.executeTest(MEMORYSIZE);
    assertEquals(10, data.keySet().size());

    for (Integer k : data.keySet()) {
      assertEquals((Integer) (k + 1), data.get(k));
    }
View Full Code Here

    }
  }
 
  @Test
  public void test() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);
    env.generateSequence(1, 10).map(new IdentityMap()).filter(new FilterAll()).print();
    env.executeTest(MEMORYSIZE);
   
  }
View Full Code Here

  }

  @Test
  public void test() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);

    env.setBufferTimeout(10);

    DataStream<Boolean> source = env.fromElements(false, false, false);

    IterativeDataStream<Boolean> iteration = source.iterate().setMaxWaitTime(3000);

    DataStream<Boolean> increment = iteration.flatMap(new IterationHead()).flatMap(
        new IterationTail());

    iteration.closeWith(increment).addSink(new MySink());

    env.executeTest(MEMORYSIZE);

    assertTrue(iterated);

  }
View Full Code Here

    Runtime.getRuntime().addShutdownHook(new Thread(r));
  }
 
  @Test
  public void test() throws Exception {
    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream1 = env.addSource(new MySource1(), 1).writeAsCsv(PREFIX + "test1.txt");

    fillExpected1();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream2 = env.addSource(new MySource1(), 1).writeAsCsv(PREFIX + "test2.txt", 5);

    fillExpected2();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream3 = env.addSource(new MySource1(), 1).writeAsCsv(PREFIX + "test3.txt", 10);

    fillExpected3();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream4 = env.addSource(new MySource1(), 1).writeAsCsv(PREFIX + "test4.txt", 10, new Tuple1<Integer>(26));

    fillExpected4();

    @SuppressWarnings("unused")
    DataStream<Tuple1<Integer>> dataStream5 = env.addSource(new MySource1(), 1).writeAsCsv(PREFIX + "test5.txt", 10, new Tuple1<Integer>(14));

    fillExpected5();

    env.executeTest(MEMORYSIZE);

    readFile(PREFIX + "test1.txt", result1);
    readFile(PREFIX + "test2.txt", result2);
    readFile(PREFIX + "test3.txt", result3);
    readFile(PREFIX + "test4.txt", result4);
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Test
  public void multipleInputTest() {
    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);

    DataStream<Integer> ds1 = env.fromElements(1, 3, 5);
    DataStream<Integer> ds2 = env.fromElements(2, 4).merge(ds1);
   
    try {
      ds1.forward().merge(ds2);
      fail();
    } catch (RuntimeException e) {
View Full Code Here

 
  @Test
  public void outputSelectorTest() throws Exception {
   

    LocalStreamEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1);
   
    SplitDataStream<Long> source = env.generateSequence(1, 11).split(new MyOutputSelector());
    source.select(EVEN).addSink(new ListSink(EVEN));
    source.select(ODD, TEN).addSink(new ListSink(ODD_AND_TEN));
    source.select(EVEN, ODD).addSink(new ListSink(EVEN_AND_ODD));
    source.selectAll().addSink(new ListSink(ALL));
   
    env.executeTest(128);
    assertEquals(Arrays.asList(2L, 4L, 6L, 8L, 10L), outputs.get(EVEN));
    assertEquals(Arrays.asList(1L, 3L, 5L, 7L, 9L, 10L, 11L), outputs.get(ODD_AND_TEN));
    assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), outputs.get(EVEN_AND_ODD));
    assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L), outputs.get(ALL));
  }
View Full Code Here

TOP

Related Classes of org.apache.flink.streaming.api.environment.LocalStreamEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.