Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-8035

Add tests for generics in KStream API

    XMLWordPrintableJSON

Details

    • Test
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • streams

    Description

      During the work on KAFKA-4217, it was discovered that some combinations of Java generics block the usage of lambda expressions as parameters of the KStream API (see this discussion).

      To avoid using those blocking combinations of generics, tests shall be implemented that verify that both lambda expressions as well as classes (anonymous and declared) can be used as parameters with the KStream API. Those tests may also serve as regression tests to ensure that future changes to the generics in the KStream API may not make the API incompatible with previous versions.

      Unlike other tests, the tests required here pass if they compile. For example, to verify that the parameter mapper in

      <KR, VR> KStream<KR, VR> flatMap(final KeyValueMapper<? super K, ? super V, ? extends Iterable<? extends KeyValue<? extends KR, ? extends VR>>> mapper);
      

      accepts a KeyValueMapper specified as a lambda expression that returns an implementation of the Iterable interface, the following stream could be specified in the test:

      stream
          .flatMap((Integer key, Integer value) -> Arrays.asList(
              KeyValue.pair(key, value),
              KeyValue.pair(key, value),
              KeyValue.pair(key, value)))
          .foreach(action);
      

      If the test compiles, the test passes.

      Other tests for flatMap need to check the bounds of the generics, e.g., if the mapper accepts a KeyValueMapper specified as a lambda expression that takes a super class of K and V as inputs.

      Attachments

        Activity

          People

            Unassigned Unassigned
            cadonna Bruno Cadonna
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: