You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Jason Gustafson (Jira)" <ji...@apache.org> on 2021/02/01 17:39:00 UTC

[jira] [Created] (KAFKA-12263) Improve MockClient RequestMatcher interface

Jason Gustafson created KAFKA-12263:
---------------------------------------

             Summary: Improve MockClient RequestMatcher interface
                 Key: KAFKA-12263
                 URL: https://issues.apache.org/jira/browse/KAFKA-12263
             Project: Kafka
          Issue Type: Improvement
            Reporter: Jason Gustafson


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.




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