Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-14335

ExampleIntegrationTest in testing docs is incorrect

    XMLWordPrintableJSON

Details

    Description

      The java version of the ExampleIntegrationTest is incorrect since it assumes elements to arrive in the sink in order, but this isn't guaranteed since there are 2 sink subtasks mutating a shared collection.

      The scala example was modified correctly; it checks that elements are contained without verifying the order.

      public class ExampleIntegrationTest {
              ...
      
              // configure your test environment
              env.setParallelism(2);
      
              ...
      
              // create a stream of custom elements and apply transformations
              env.fromElements(1L, 21L, 22L)
                      .map(new IncrementMapFunction())
                      .addSink(new CollectSink());
      
              // execute
              env.execute();
      
              // verify your results
              assertEquals(Lists.newArrayList(2L, 42L, 44L), CollectSink.values);
          }
      
          // create a testing sink
          private static class CollectSink implements SinkFunction<Long> {
      
              // must be static
              public static final List<Long> values = new ArrayList<>();
      
              @Override
              public synchronized void invoke(Long value) throws Exception {
                  values.add(value);
              }
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              guoyangze Yangze Guo
              chesnay Chesnay Schepler
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m