use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion 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.ApiVersion in project kafka by apache.
the class NodeApiVersionsTest method testVersionsToString.
@Test
public void testVersionsToString() {
List<ApiVersion> versionList = new ArrayList<>();
for (ApiKeys apiKey : ApiKeys.values()) {
if (apiKey == ApiKeys.DELETE_TOPICS) {
versionList.add(new ApiVersion().setApiKey(apiKey.id).setMinVersion((short) 10000).setMaxVersion((short) 10001));
} else
versionList.add(ApiVersionsResponse.toApiVersion(apiKey));
}
NodeApiVersions versions = new NodeApiVersions(versionList);
StringBuilder bld = new StringBuilder();
String prefix = "(";
for (ApiKeys apiKey : ApiKeys.values()) {
bld.append(prefix);
if (apiKey == ApiKeys.DELETE_TOPICS) {
bld.append("DeleteTopics(20): 10000 to 10001 [unusable: node too new]");
} else {
bld.append(apiKey.name).append("(").append(apiKey.id).append("): ");
if (apiKey.oldestVersion() == apiKey.latestVersion()) {
bld.append(apiKey.oldestVersion());
} else {
bld.append(apiKey.oldestVersion()).append(" to ").append(apiKey.latestVersion());
}
bld.append(" [usable: ").append(apiKey.latestVersion()).append("]");
}
prefix = ", ";
}
bld.append(")");
assertEquals(bld.toString(), versions.toString());
}
use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.
the class NodeApiVersionsTest method testUsableVersionLatestVersions.
@ParameterizedTest
@EnumSource(ApiMessageType.ListenerType.class)
public void testUsableVersionLatestVersions(ApiMessageType.ListenerType scope) {
ApiVersionsResponse defaultResponse = ApiVersionsResponse.defaultApiVersionsResponse(scope);
List<ApiVersion> versionList = new LinkedList<>(defaultResponse.data().apiKeys());
// Add an API key that we don't know about.
versionList.add(new ApiVersion().setApiKey((short) 100).setMinVersion((short) 0).setMaxVersion((short) 1));
NodeApiVersions versions = new NodeApiVersions(versionList);
for (ApiKeys apiKey : ApiKeys.apisForListener(scope)) {
assertEquals(apiKey.latestVersion(), versions.latestUsableVersion(apiKey));
}
}
use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.
the class ApiVersionsResponseTest method shouldHaveCommonlyAgreedApiVersionResponseWithControllerOnForwardableAPIs.
@Test
public void shouldHaveCommonlyAgreedApiVersionResponseWithControllerOnForwardableAPIs() {
final ApiKeys forwardableAPIKey = ApiKeys.CREATE_ACLS;
final ApiKeys nonForwardableAPIKey = ApiKeys.JOIN_GROUP;
final short minVersion = 0;
final short maxVersion = 1;
Map<ApiKeys, ApiVersion> activeControllerApiVersions = Utils.mkMap(Utils.mkEntry(forwardableAPIKey, new ApiVersion().setApiKey(forwardableAPIKey.id).setMinVersion(minVersion).setMaxVersion(maxVersion)), Utils.mkEntry(nonForwardableAPIKey, new ApiVersion().setApiKey(nonForwardableAPIKey.id).setMinVersion(minVersion).setMaxVersion(maxVersion)));
ApiVersionCollection commonResponse = ApiVersionsResponse.intersectForwardableApis(ApiMessageType.ListenerType.ZK_BROKER, RecordVersion.current(), activeControllerApiVersions);
verifyVersions(forwardableAPIKey.id, minVersion, maxVersion, commonResponse);
verifyVersions(nonForwardableAPIKey.id, ApiKeys.JOIN_GROUP.oldestVersion(), ApiKeys.JOIN_GROUP.latestVersion(), commonResponse);
}
use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.
the class ApiVersionsResponseTest method shouldHaveCorrectDefaultApiVersionsResponse.
@ParameterizedTest
@EnumSource(ApiMessageType.ListenerType.class)
public void shouldHaveCorrectDefaultApiVersionsResponse(ApiMessageType.ListenerType scope) {
ApiVersionsResponse defaultResponse = ApiVersionsResponse.defaultApiVersionsResponse(scope);
assertEquals(ApiKeys.apisForListener(scope).size(), defaultResponse.data().apiKeys().size(), "API versions for all API keys must be maintained.");
for (ApiKeys key : ApiKeys.apisForListener(scope)) {
ApiVersion version = defaultResponse.apiVersion(key.id);
assertNotNull(version, "Could not find ApiVersion for API " + key.name);
assertEquals(version.minVersion(), key.oldestVersion(), "Incorrect min version for Api " + key.name);
assertEquals(version.maxVersion(), key.latestVersion(), "Incorrect max version for Api " + key.name);
// Check if versions less than min version are indeed set as null, i.e., deprecated.
for (int i = 0; i < version.minVersion(); ++i) {
assertNull(key.messageType.requestSchemas()[i], "Request version " + i + " for API " + version.apiKey() + " must be null");
assertNull(key.messageType.responseSchemas()[i], "Response version " + i + " for API " + version.apiKey() + " must be null");
}
// Check if versions between min and max versions are non null, i.e., valid.
for (int i = version.minVersion(); i <= version.maxVersion(); ++i) {
assertNotNull(key.messageType.requestSchemas()[i], "Request version " + i + " for API " + version.apiKey() + " must not be null");
assertNotNull(key.messageType.responseSchemas()[i], "Response version " + i + " for API " + version.apiKey() + " must not be null");
}
}
assertTrue(defaultResponse.data().supportedFeatures().isEmpty());
assertTrue(defaultResponse.data().finalizedFeatures().isEmpty());
assertEquals(ApiVersionsResponse.UNKNOWN_FINALIZED_FEATURES_EPOCH, defaultResponse.data().finalizedFeaturesEpoch());
}
Aggregations