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

Jason Gustafson updated KAFKA-12263:
------------------------------------
    Description: 
MockClient has a RequestMatcher interface which is used to verify that a 
request received by the client matches an expected type:

{code}
    @FunctionalInterface
    public interface RequestMatcher {
        boolean matches(AbstractRequest body);
    }
{code}

The interface is awkward in practice because there is nothing we can do except 
fail the test if the request does not match. But in that case, the MockClient 
does not have enough context to throw a useful error explaining why the match 
failed. Instead we just print a generic message about the match failure.

A better approach would probably to turn this into more of a RequestAssertion:

{code}
    @FunctionalInterface
    public interface RequestAssertion {
        void assertRequest(AbstractRequest body);
    }
{code}

Then implementations could then be constructed of a sequence of Junit 
assertions. When there is a failure, we can trace it back to the specific 
assertion that failed. Of course they can do that now with RequestMatcher as 
well, but the expectation would be more explicit.


  was:
MockClient has a RequestMatcher interface which is used to verify that a 
request received by the client matches an expected type:

    @FunctionalInterface
    public interface RequestMatcher {
        boolean matches(AbstractRequest body);
    }

The interface is awkward in practice because there is nothing we can do except 
fail the test if the request does not match. But in that case, the MockClient 
does not have enough context to throw a useful error explaining why the match 
failed. Instead we just print a generic message about the match failure.

A better approach would probably to turn this into more of a RequestAssertion:

    @FunctionalInterface
    public interface RequestAssertion {
        void assertRequest(AbstractRequest body);
    }

Then implementations could then be constructed of a sequence of Junit 
assertions. When there is a failure, we can trace it back to the specific 
assertion that failed. Of course they can do that now with RequestMatcher as 
well, but the expectation would be more explicit.



> Improve MockClient RequestMatcher interface
> -------------------------------------------
>
>                 Key: KAFKA-12263
>                 URL: https://issues.apache.org/jira/browse/KAFKA-12263
>             Project: Kafka
>          Issue Type: Improvement
>            Reporter: Jason Gustafson
>            Priority: Major
>
> MockClient has a RequestMatcher interface which is used to verify that a 
> request received by the client matches an expected type:
> {code}
>     @FunctionalInterface
>     public interface RequestMatcher {
>         boolean matches(AbstractRequest body);
>     }
> {code}
> The interface is awkward in practice because there is nothing we can do 
> except fail the test if the request does not match. But in that case, the 
> MockClient does not have enough context to throw a useful error explaining 
> why the match failed. Instead we just print a generic message about the match 
> failure.
> A better approach would probably to turn this into more of a RequestAssertion:
> {code}
>     @FunctionalInterface
>     public interface RequestAssertion {
>         void assertRequest(AbstractRequest body);
>     }
> {code}
> Then implementations could then be constructed of a sequence of Junit 
> assertions. When there is a failure, we can trace it back to the specific 
> assertion that failed. Of course they can do that now with RequestMatcher as 
> well, but the expectation would be more explicit.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to