use of org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState in project kafka by apache.
the class PartitionRegistrationTest method testToLeaderAndIsrPartitionState.
@Test
public void testToLeaderAndIsrPartitionState() {
PartitionRegistration a = new PartitionRegistration(new int[] { 1, 2, 3 }, new int[] { 1, 2 }, Replicas.NONE, Replicas.NONE, 1, 123, 456);
PartitionRegistration b = new PartitionRegistration(new int[] { 2, 3, 4 }, new int[] { 2, 3, 4 }, Replicas.NONE, Replicas.NONE, 2, 234, 567);
assertEquals(new LeaderAndIsrPartitionState().setTopicName("foo").setPartitionIndex(1).setControllerEpoch(-1).setLeader(1).setLeaderEpoch(123).setIsr(Arrays.asList(1, 2)).setZkVersion(456).setReplicas(Arrays.asList(1, 2, 3)).setAddingReplicas(Collections.emptyList()).setRemovingReplicas(Collections.emptyList()).setIsNew(true).toString(), a.toLeaderAndIsrPartitionState(new TopicPartition("foo", 1), true).toString());
assertEquals(new LeaderAndIsrPartitionState().setTopicName("bar").setPartitionIndex(0).setControllerEpoch(-1).setLeader(2).setLeaderEpoch(234).setIsr(Arrays.asList(2, 3, 4)).setZkVersion(567).setReplicas(Arrays.asList(2, 3, 4)).setAddingReplicas(Collections.emptyList()).setRemovingReplicas(Collections.emptyList()).setIsNew(false).toString(), b.toLeaderAndIsrPartitionState(new TopicPartition("bar", 0), false).toString());
}
use of org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState in project kafka by apache.
the class LeaderAndIsrRequest method getErrorResponse.
@Override
public LeaderAndIsrResponse getErrorResponse(int throttleTimeMs, Throwable e) {
LeaderAndIsrResponseData responseData = new LeaderAndIsrResponseData();
Errors error = Errors.forException(e);
responseData.setErrorCode(error.code());
if (version() < 5) {
List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
for (LeaderAndIsrPartitionState partition : partitionStates()) {
partitions.add(new LeaderAndIsrPartitionError().setTopicName(partition.topicName()).setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
}
responseData.setPartitionErrors(partitions);
} else {
for (LeaderAndIsrTopicState topicState : data.topicStates()) {
List<LeaderAndIsrPartitionError> partitions = new ArrayList<>(topicState.partitionStates().size());
for (LeaderAndIsrPartitionState partition : topicState.partitionStates()) {
partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
}
responseData.topics().add(new LeaderAndIsrTopicError().setTopicId(topicState.topicId()).setPartitionErrors(partitions));
}
}
return new LeaderAndIsrResponse(responseData, version());
}
Aggregations