use of org.apache.kafka.common.message.ApiVersionsResponseData in project kafka by apache.
the class NetworkClientTest method testInvalidApiVersionsRequest.
@Test
public void testInvalidApiVersionsRequest() {
// initiate the connection
client.ready(node, time.milliseconds());
// handle the connection, send the ApiVersionsRequest
client.poll(0, time.milliseconds());
// check that the ApiVersionsRequest has been initiated
assertTrue(client.hasInFlightRequests(node.idString()));
// prepare response
delayedApiVersionsResponse(0, ApiKeys.API_VERSIONS.latestVersion(), new ApiVersionsResponse(new ApiVersionsResponseData().setErrorCode(Errors.INVALID_REQUEST.code()).setThrottleTimeMs(0)));
// handle completed receives
client.poll(0, time.milliseconds());
// the ApiVersionsRequest is gone
assertFalse(client.hasInFlightRequests(node.idString()));
// various assertions
assertFalse(client.isReady(node, time.milliseconds()));
}
use of org.apache.kafka.common.message.ApiVersionsResponseData in project kafka by apache.
the class NetworkClientTest method testUnsupportedApiVersionsRequestWithVersionProvidedByTheBroker.
@Test
public void testUnsupportedApiVersionsRequestWithVersionProvidedByTheBroker() {
// initiate the connection
client.ready(node, time.milliseconds());
// handle the connection, initiate first ApiVersionsRequest
client.poll(0, time.milliseconds());
// ApiVersionsRequest is in flight but not sent yet
assertTrue(client.hasInFlightRequests(node.idString()));
// completes initiated sends
client.poll(0, time.milliseconds());
assertEquals(1, selector.completedSends().size());
ByteBuffer buffer = selector.completedSendBuffers().get(0).buffer();
RequestHeader header = parseHeader(buffer);
assertEquals(ApiKeys.API_VERSIONS, header.apiKey());
assertEquals(3, header.apiVersion());
// prepare response
ApiVersionCollection apiKeys = new ApiVersionCollection();
apiKeys.add(new ApiVersion().setApiKey(ApiKeys.API_VERSIONS.id).setMinVersion((short) 0).setMaxVersion((short) 2));
delayedApiVersionsResponse(0, (short) 0, new ApiVersionsResponse(new ApiVersionsResponseData().setErrorCode(Errors.UNSUPPORTED_VERSION.code()).setApiKeys(apiKeys)));
// handle ApiVersionResponse, initiate second ApiVersionRequest
client.poll(0, time.milliseconds());
// ApiVersionsRequest is in flight but not sent yet
assertTrue(client.hasInFlightRequests(node.idString()));
// ApiVersionsResponse has been received
assertEquals(1, selector.completedReceives().size());
// clean up the buffers
selector.completedSends().clear();
selector.completedSendBuffers().clear();
selector.completedReceives().clear();
// completes initiated sends
client.poll(0, time.milliseconds());
// ApiVersionsRequest has been sent
assertEquals(1, selector.completedSends().size());
buffer = selector.completedSendBuffers().get(0).buffer();
header = parseHeader(buffer);
assertEquals(ApiKeys.API_VERSIONS, header.apiKey());
assertEquals(2, header.apiVersion());
// prepare response
delayedApiVersionsResponse(1, (short) 0, defaultApiVersionsResponse());
// handle completed receives
client.poll(0, time.milliseconds());
// the ApiVersionsRequest is gone
assertFalse(client.hasInFlightRequests(node.idString()));
assertEquals(1, selector.completedReceives().size());
// the client is ready
assertTrue(client.isReady(node, time.milliseconds()));
}
use of org.apache.kafka.common.message.ApiVersionsResponseData in project kafka by apache.
the class RequestContextTest method testSerdeUnsupportedApiVersionRequest.
@Test
public void testSerdeUnsupportedApiVersionRequest() throws Exception {
int correlationId = 23423;
RequestHeader header = new RequestHeader(ApiKeys.API_VERSIONS, Short.MAX_VALUE, "", correlationId);
RequestContext context = new RequestContext(header, "0", InetAddress.getLocalHost(), KafkaPrincipal.ANONYMOUS, new ListenerName("ssl"), SecurityProtocol.SASL_SSL, ClientInformation.EMPTY, false);
assertEquals(0, context.apiVersion());
// Write some garbage to the request buffer. This should be ignored since we will treat
// the unknown version type as v0 which has an empty request body.
ByteBuffer requestBuffer = ByteBuffer.allocate(8);
requestBuffer.putInt(3709234);
requestBuffer.putInt(29034);
requestBuffer.flip();
RequestAndSize requestAndSize = context.parseRequest(requestBuffer);
assertTrue(requestAndSize.request instanceof ApiVersionsRequest);
ApiVersionsRequest request = (ApiVersionsRequest) requestAndSize.request;
assertTrue(request.hasUnsupportedRequestVersion());
Send send = context.buildResponseSend(new ApiVersionsResponse(new ApiVersionsResponseData().setThrottleTimeMs(0).setErrorCode(Errors.UNSUPPORTED_VERSION.code()).setApiKeys(new ApiVersionCollection())));
ByteBufferChannel channel = new ByteBufferChannel(256);
send.writeTo(channel);
ByteBuffer responseBuffer = channel.buffer();
responseBuffer.flip();
// strip off the size
responseBuffer.getInt();
ResponseHeader responseHeader = ResponseHeader.parse(responseBuffer, ApiKeys.API_VERSIONS.responseHeaderVersion(header.apiVersion()));
assertEquals(correlationId, responseHeader.correlationId());
ApiVersionsResponse response = (ApiVersionsResponse) AbstractResponse.parseResponse(ApiKeys.API_VERSIONS, responseBuffer, (short) 0);
assertEquals(Errors.UNSUPPORTED_VERSION.code(), response.data().errorCode());
assertTrue(response.data().apiKeys().isEmpty());
}
use of org.apache.kafka.common.message.ApiVersionsResponseData in project kafka by apache.
the class RequestResponseTest method createApiVersionResponse.
private ApiVersionsResponse createApiVersionResponse() {
ApiVersionCollection apiVersions = new ApiVersionCollection();
apiVersions.add(new ApiVersion().setApiKey((short) 0).setMinVersion((short) 0).setMaxVersion((short) 2));
return new ApiVersionsResponse(new ApiVersionsResponseData().setErrorCode(Errors.NONE.code()).setThrottleTimeMs(0).setApiKeys(apiVersions));
}
use of org.apache.kafka.common.message.ApiVersionsResponseData in project kafka by apache.
the class ApiVersionsResponse method createApiVersionsResponseData.
private static ApiVersionsResponseData createApiVersionsResponseData(final int throttleTimeMs, final Errors error, final ApiVersionCollection apiKeys, final Features<SupportedVersionRange> latestSupportedFeatures, final Features<FinalizedVersionRange> finalizedFeatures, final long finalizedFeaturesEpoch) {
final ApiVersionsResponseData data = new ApiVersionsResponseData();
data.setThrottleTimeMs(throttleTimeMs);
data.setErrorCode(error.code());
data.setApiKeys(apiKeys);
data.setSupportedFeatures(createSupportedFeatureKeys(latestSupportedFeatures));
data.setFinalizedFeatures(createFinalizedFeatureKeys(finalizedFeatures));
data.setFinalizedFeaturesEpoch(finalizedFeaturesEpoch);
return data;
}
Aggregations