use of org.apache.kafka.common.protocol.ApiKeys in project kafka by apache.
the class NodeApiVersionsTest method testUnsupportedVersionsToString.
@Test
public void testUnsupportedVersionsToString() {
NodeApiVersions versions = new NodeApiVersions(Collections.<ApiVersion>emptyList());
StringBuilder bld = new StringBuilder();
String prefix = "(";
for (ApiKeys apiKey : ApiKeys.values()) {
bld.append(prefix).append(apiKey.name).append("(").append(apiKey.id).append("): UNSUPPORTED");
prefix = ", ";
}
bld.append(")");
assertEquals(bld.toString(), versions.toString());
}
use of org.apache.kafka.common.protocol.ApiKeys 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.CONTROLLED_SHUTDOWN_KEY) {
versionList.add(new ApiVersion(apiKey.id, (short) 0, (short) 0));
} else if (apiKey == ApiKeys.DELETE_TOPICS) {
versionList.add(new ApiVersion(apiKey.id, (short) 10000, (short) 10001));
} else {
versionList.add(new ApiVersion(apiKey));
}
}
NodeApiVersions versions = new NodeApiVersions(versionList);
StringBuilder bld = new StringBuilder();
String prefix = "(";
for (ApiKeys apiKey : ApiKeys.values()) {
bld.append(prefix);
if (apiKey == ApiKeys.CONTROLLED_SHUTDOWN_KEY) {
bld.append("ControlledShutdown(7): 0 [unusable: node too old]");
} else 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.protocol.ApiKeys in project kafka by apache.
the class NodeApiVersionsTest method testUsableVersionLatestVersions.
@Test
public void testUsableVersionLatestVersions() {
List<ApiVersion> versionList = new LinkedList<>();
for (ApiVersion apiVersion : ApiVersionsResponse.API_VERSIONS_RESPONSE.apiVersions()) {
versionList.add(apiVersion);
}
// Add an API key that we don't know about.
versionList.add(new ApiVersion((short) 100, (short) 0, (short) 1));
NodeApiVersions versions = new NodeApiVersions(versionList);
for (ApiKeys apiKey : ApiKeys.values()) {
assertEquals(apiKey.latestVersion(), versions.usableVersion(apiKey));
}
}
use of org.apache.kafka.common.protocol.ApiKeys in project kafka by apache.
the class AbstractRequest method getRequest.
/**
* Factory method for getting a request object based on ApiKey ID and a buffer
*/
public static RequestAndSize getRequest(int requestId, short version, ByteBuffer buffer) {
ApiKeys apiKey = ApiKeys.forId(requestId);
Struct struct = apiKey.parseRequest(version, buffer);
AbstractRequest request;
switch(apiKey) {
case PRODUCE:
request = new ProduceRequest(struct, version);
break;
case FETCH:
request = new FetchRequest(struct, version);
break;
case LIST_OFFSETS:
request = new ListOffsetRequest(struct, version);
break;
case METADATA:
request = new MetadataRequest(struct, version);
break;
case OFFSET_COMMIT:
request = new OffsetCommitRequest(struct, version);
break;
case OFFSET_FETCH:
request = new OffsetFetchRequest(struct, version);
break;
case GROUP_COORDINATOR:
request = new GroupCoordinatorRequest(struct, version);
break;
case JOIN_GROUP:
request = new JoinGroupRequest(struct, version);
break;
case HEARTBEAT:
request = new HeartbeatRequest(struct, version);
break;
case LEAVE_GROUP:
request = new LeaveGroupRequest(struct, version);
break;
case SYNC_GROUP:
request = new SyncGroupRequest(struct, version);
break;
case STOP_REPLICA:
request = new StopReplicaRequest(struct, version);
break;
case CONTROLLED_SHUTDOWN_KEY:
request = new ControlledShutdownRequest(struct, version);
break;
case UPDATE_METADATA_KEY:
request = new UpdateMetadataRequest(struct, version);
break;
case LEADER_AND_ISR:
request = new LeaderAndIsrRequest(struct, version);
break;
case DESCRIBE_GROUPS:
request = new DescribeGroupsRequest(struct, version);
break;
case LIST_GROUPS:
request = new ListGroupsRequest(struct, version);
break;
case SASL_HANDSHAKE:
request = new SaslHandshakeRequest(struct, version);
break;
case API_VERSIONS:
request = new ApiVersionsRequest(struct, version);
break;
case CREATE_TOPICS:
request = new CreateTopicsRequest(struct, version);
break;
case DELETE_TOPICS:
request = new DeleteTopicsRequest(struct, version);
break;
default:
throw new AssertionError(String.format("ApiKey %s is not currently handled in `getRequest`, the " + "code should be updated to do so.", apiKey));
}
return new RequestAndSize(request, struct.sizeOf());
}
Aggregations