private void checkOlderFetchVersions() throws Exception { int latestVersion = ApiKeys.FETCH.latestVersion(); for (int i = 0; i < latestVersion; ++i) { checkErrorResponse(createFetchRequest(i), new UnknownServerException()); checkRequest(createFetchRequest(i)); checkResponse(createFetchResponse(), i); } }
@Test public void testSerialization() throws Exception { checkRequest(createFindCoordinatorRequest(0)); checkRequest(createFindCoordinatorRequest(1)); checkErrorResponse(createFindCoordinatorRequest(0), new UnknownServerException()); checkErrorResponse(createFindCoordinatorRequest(1), new UnknownServerException()); checkResponse(createFindCoordinatorResponse(), 0); checkResponse(createFindCoordinatorResponse(), 1); checkRequest(createControlledShutdownRequest()); checkResponse(createControlledShutdownResponse(), 1); checkErrorResponse(createControlledShutdownRequest(), new UnknownServerException()); checkErrorResponse(createControlledShutdownRequest(0), new UnknownServerException()); checkRequest(createFetchRequest(4)); checkResponse(createFetchResponse(), 4); List<TopicPartition> toForgetTopics = new ArrayList<>(); toForgetTopics.add(new TopicPartition("foo", 0)); toForgetTopics.add(new TopicPartition("foo", 2)); toForgetTopics.add(new TopicPartition("bar", 0)); checkRequest(createFetchRequest(7, new FetchMetadata(123, 456), toForgetTopics)); checkResponse(createFetchResponse(123), 7); checkResponse(createFetchResponse(Errors.FETCH_SESSION_ID_NOT_FOUND, 123), 7); checkErrorResponse(createFetchRequest(4), new UnknownServerException()); checkRequest(createHeartBeatRequest()); checkErrorResponse(createHeartBeatRequest(), new UnknownServerException()); checkResponse(createHeartBeatResponse(), 0); checkRequest(createJoinGroupRequest(1)); checkErrorResponse(createJoinGroupRequest(0), new UnknownServerException()); checkErrorResponse(createJoinGroupRequest(1), new UnknownServerException()); checkResponse(createJoinGroupResponse(), 0); checkRequest(createLeaveGroupRequest());
private void checkRequest(AbstractRequest req) throws Exception { // Check that we can serialize, deserialize and serialize again // We don't check for equality or hashCode because it is likely to fail for any request containing a HashMap checkRequest(req, false); }
private void checkErrorResponse(AbstractRequest req, Throwable e) throws Exception { checkResponse(req.getErrorResponse(e), req.version()); }