mimaison commented on a change in pull request #11393: URL: https://github.com/apache/kafka/pull/11393#discussion_r765833040
########## File path: clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java ########## @@ -247,403 +280,123 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +// This class performs tests requests and responses for all API keys public class RequestResponseTest { // Exception includes a message that we verify is not included in error responses private final UnknownServerException unknownServerException = new UnknownServerException("secret"); + + @Test + public void testSerialization() { + Map<ApiKeys, List<Short>> toSkip = new HashMap<>(); + // It's not possible to create a MetadataRequest v0 via the builder + toSkip.put(METADATA, singletonList((short) 0)); + // DescribeLogDirsResponse does not have a top level error field + toSkip.put(DESCRIBE_LOG_DIRS, DESCRIBE_LOG_DIRS.allVersions()); + // ElectLeaders v0 does not have a top level error field, when accessing it, it defaults to NONE + toSkip.put(ELECT_LEADERS, singletonList((short) 0)); + + for (ApiKeys apikey : ApiKeys.values()) { + for (short version : apikey.allVersions()) { + if (toSkip.containsKey(apikey) && toSkip.get(apikey).contains(version)) continue; + AbstractRequest request = getRequest(apikey, version); + checkRequest(request); + checkErrorResponse(request, unknownServerException); + checkResponse(getResponse(apikey, version), version); + } + } + } + + // This test validates special cases that are not checked in testSerialization @Test - public void testSerialization() throws Exception { - checkRequest(createControlledShutdownRequest(), true); - checkResponse(createControlledShutdownResponse(), 1, true); - checkErrorResponse(createControlledShutdownRequest(), unknownServerException, true); - checkErrorResponse(createControlledShutdownRequest(0), unknownServerException, true); - checkRequest(createFetchRequest(4), true); - checkResponse(createFetchResponse(true), 4, true); + public void testSerializationSpecialCases() { Review comment: It's much harder to cover all special cases. Are we missing coverage for some special cases? Possibly! But at least for the common case, we should be covered now. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org