[ 
https://issues.apache.org/jira/browse/KAFKA-8035?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Bruno Cadonna updated KAFKA-8035:
---------------------------------
    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|https://github.com/apache/kafka/pull/5273#discussion_r216810275]).

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
{code:java}
<KR, VR> KStream<KR, VR> flatMap(final KeyValueMapper<? super K, ? super V, ? 
extends Iterable<? extends KeyValue<? extends KR, ? extends VR>>> mapper);
{code}
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:
{code:java}
stream
    .flatMap((Integer key, Integer value) -> Arrays.asList(
        KeyValue.pair(key, value),
        KeyValue.pair(key, value),
        KeyValue.pair(key, value)))
    .foreach(action);
{code}
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.

  was:
During the work on KAFKA-4217, it was discovered that some combinations of Java 
generics block the usage of lambda functions ([see this 
discussion|https://github.com/apache/kafka/pull/5273#discussion_r216810275]).

To avoid using those blocking combinations of generics, tests shall be 
implemented that verify that lambda functions can be used 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 block lambda functions and 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
{code:java}
<KR, VR> KStream<KR, VR> flatMap(final KeyValueMapper<? super K, ? super V, ? 
extends Iterable<? extends KeyValue<? extends KR, ? extends VR>>> mapper);
{code}
accepts a {{KeyValueMapper}} specified as a lambda function that returns an 
implementation of the {{Iterable}} interface, the following stream could be 
specified in the test:
{code:java}
stream
    .flatMap((Integer key, Integer value) -> Arrays.asList(
        KeyValue.pair(key, value),
        KeyValue.pair(key, value),
        KeyValue.pair(key, value)))
    .foreach(action);
{code}
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 function that 
takes a super class of K and V as inputs.


> Add tests for generics in KStream API 
> --------------------------------------
>
>                 Key: KAFKA-8035
>                 URL: https://issues.apache.org/jira/browse/KAFKA-8035
>             Project: Kafka
>          Issue Type: Test
>          Components: streams
>            Reporter: Bruno Cadonna
>            Priority: Major
>              Labels: unit-test
>
> 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|https://github.com/apache/kafka/pull/5273#discussion_r216810275]).
> 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
> {code:java}
> <KR, VR> KStream<KR, VR> flatMap(final KeyValueMapper<? super K, ? super V, ? 
> extends Iterable<? extends KeyValue<? extends KR, ? extends VR>>> mapper);
> {code}
> 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:
> {code:java}
> stream
>     .flatMap((Integer key, Integer value) -> Arrays.asList(
>         KeyValue.pair(key, value),
>         KeyValue.pair(key, value),
>         KeyValue.pair(key, value)))
>     .foreach(action);
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to