use of org.apache.kafka.common.Uuid in project kafka by apache.
the class LeaderAndIsrResponseTest method testErrorCountsNoTopLevelError.
@Test
public void testErrorCountsNoTopLevelError() {
for (short version : LEADER_AND_ISR.allVersions()) {
LeaderAndIsrResponse response;
if (version < 5) {
List<LeaderAndIsrPartitionError> partitions = createPartitions("foo", asList(Errors.NONE, Errors.CLUSTER_AUTHORIZATION_FAILED));
response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setPartitionErrors(partitions), version);
} else {
Uuid id = Uuid.randomUuid();
LeaderAndIsrTopicErrorCollection topics = createTopic(id, asList(Errors.NONE, Errors.CLUSTER_AUTHORIZATION_FAILED));
response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.NONE.code()).setTopics(topics), version);
}
Map<Errors, Integer> errorCounts = response.errorCounts();
assertEquals(2, errorCounts.size());
assertEquals(2, errorCounts.get(Errors.NONE).intValue());
assertEquals(1, errorCounts.get(Errors.CLUSTER_AUTHORIZATION_FAILED).intValue());
}
}
use of org.apache.kafka.common.Uuid in project kafka by apache.
the class LeaderAndIsrResponseTest method testErrorCountsWithTopLevelError.
@Test
public void testErrorCountsWithTopLevelError() {
for (short version : LEADER_AND_ISR.allVersions()) {
LeaderAndIsrResponse response;
if (version < 5) {
List<LeaderAndIsrPartitionError> partitions = createPartitions("foo", asList(Errors.NONE, Errors.NOT_LEADER_OR_FOLLOWER));
response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.UNKNOWN_SERVER_ERROR.code()).setPartitionErrors(partitions), version);
} else {
Uuid id = Uuid.randomUuid();
LeaderAndIsrTopicErrorCollection topics = createTopic(id, asList(Errors.NONE, Errors.NOT_LEADER_OR_FOLLOWER));
response = new LeaderAndIsrResponse(new LeaderAndIsrResponseData().setErrorCode(Errors.UNKNOWN_SERVER_ERROR.code()).setTopics(topics), version);
}
assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 3), response.errorCounts());
}
}
use of org.apache.kafka.common.Uuid in project kafka by apache.
the class DeleteTopicsRequestTest method testTopicIdsField.
@Test
public void testTopicIdsField() {
for (short version : DELETE_TOPICS.allVersions()) {
// Check topic IDs are handled correctly. We should only use this field on versions 6+.
Uuid topicId1 = Uuid.randomUuid();
Uuid topicId2 = Uuid.randomUuid();
List<Uuid> topicIds = Arrays.asList(topicId1, topicId2);
DeleteTopicsRequest requestWithIds = new DeleteTopicsRequest.Builder(new DeleteTopicsRequestData().setTopics(Arrays.asList(new DeleteTopicsRequestData.DeleteTopicState().setTopicId(topicId1), new DeleteTopicsRequestData.DeleteTopicState().setTopicId(topicId2)))).build(version);
if (version >= 6) {
DeleteTopicsRequest requestWithIdsSerialized = DeleteTopicsRequest.parse(requestWithIds.serialize(), version);
assertEquals(topicIds, requestWithIds.topicIds());
assertEquals(topicIds, requestWithIdsSerialized.topicIds());
// All topic names should be replaced with null
requestWithIds.data().topics().forEach(topic -> assertNull(topic.name()));
requestWithIdsSerialized.data().topics().forEach(topic -> assertNull(topic.name()));
} else {
// We should fail if version is less than 6.
assertThrows(UnsupportedVersionException.class, () -> requestWithIds.serialize());
}
}
}
use of org.apache.kafka.common.Uuid in project kafka by apache.
the class RequestResponseTest method createLeaderAndIsrRequest.
private LeaderAndIsrRequest createLeaderAndIsrRequest(short version) {
List<LeaderAndIsrPartitionState> partitionStates = new ArrayList<>();
List<Integer> isr = asList(1, 2);
List<Integer> replicas = asList(1, 2, 3, 4);
partitionStates.add(new LeaderAndIsrPartitionState().setTopicName("topic5").setPartitionIndex(105).setControllerEpoch(0).setLeader(2).setLeaderEpoch(1).setIsr(isr).setZkVersion(2).setReplicas(replicas).setIsNew(false));
partitionStates.add(new LeaderAndIsrPartitionState().setTopicName("topic5").setPartitionIndex(1).setControllerEpoch(1).setLeader(1).setLeaderEpoch(1).setIsr(isr).setZkVersion(2).setReplicas(replicas).setIsNew(false));
partitionStates.add(new LeaderAndIsrPartitionState().setTopicName("topic20").setPartitionIndex(1).setControllerEpoch(1).setLeader(0).setLeaderEpoch(1).setIsr(isr).setZkVersion(2).setReplicas(replicas).setIsNew(false));
Set<Node> leaders = Utils.mkSet(new Node(0, "test0", 1223), new Node(1, "test1", 1223));
Map<String, Uuid> topicIds = new HashMap<>();
topicIds.put("topic5", Uuid.randomUuid());
topicIds.put("topic20", Uuid.randomUuid());
return new LeaderAndIsrRequest.Builder(version, 1, 10, 0, partitionStates, topicIds, leaders).build();
}
use of org.apache.kafka.common.Uuid in project kafka by apache.
the class FetchRequestTest method testToReplaceWithDifferentVersions.
@ParameterizedTest
@MethodSource("fetchVersions")
public void testToReplaceWithDifferentVersions(short version) {
boolean fetchRequestUsesTopicIds = version >= 13;
Uuid topicId = Uuid.randomUuid();
TopicIdPartition tp = new TopicIdPartition(topicId, 0, "topic");
Map<TopicPartition, FetchRequest.PartitionData> partitionData = Collections.singletonMap(tp.topicPartition(), new FetchRequest.PartitionData(topicId, 0, 0, 0, Optional.empty()));
List<TopicIdPartition> toReplace = Collections.singletonList(tp);
FetchRequest fetchRequest = FetchRequest.Builder.forReplica(version, 0, 1, 1, partitionData).removed(Collections.emptyList()).replaced(toReplace).metadata(FetchMetadata.newIncremental(123)).build(version);
// If version < 13, we should not see any partitions in forgottenTopics. This is because we can not
// distinguish different topic IDs on versions earlier than 13.
assertEquals(fetchRequestUsesTopicIds, fetchRequest.data().forgottenTopicsData().size() > 0);
fetchRequest.data().forgottenTopicsData().forEach(forgottenTopic -> {
// Since we didn't serialize, we should see the topic name and ID regardless of the version.
assertEquals(tp.topic(), forgottenTopic.topic());
assertEquals(topicId, forgottenTopic.topicId());
});
assertEquals(1, fetchRequest.data().topics().size());
fetchRequest.data().topics().forEach(topic -> {
// Since we didn't serialize, we should see the topic name and ID regardless of the version.
assertEquals(tp.topic(), topic.topic());
assertEquals(topicId, topic.topicId());
});
}
Aggregations