use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState in project kafka by apache.
the class StopReplicaRequestTest method testGetErrorResponse.
@Test
public void testGetErrorResponse() {
List<StopReplicaTopicState> topicStates = topicStates(true);
Set<StopReplicaPartitionError> expectedPartitions = new HashSet<>();
for (StopReplicaTopicState topicState : topicStates) {
for (StopReplicaPartitionState partitionState : topicState.partitionStates()) {
expectedPartitions.add(new StopReplicaPartitionError().setTopicName(topicState.topicName()).setPartitionIndex(partitionState.partitionIndex()).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code()));
}
}
for (short version : STOP_REPLICA.allVersions()) {
StopReplicaRequest.Builder builder = new StopReplicaRequest.Builder(version, 0, 0, 0L, false, topicStates);
StopReplicaRequest request = builder.build();
StopReplicaResponse response = request.getErrorResponse(0, new ClusterAuthorizationException("Not authorized"));
assertEquals(Errors.CLUSTER_AUTHORIZATION_FAILED, response.error());
assertEquals(expectedPartitions, new HashSet<>(response.partitionErrors()));
}
}
use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState in project kafka by apache.
the class StopReplicaRequestTest method testBuilderNormalization.
private void testBuilderNormalization(boolean deletePartitions) {
List<StopReplicaTopicState> topicStates = topicStates(deletePartitions);
Map<TopicPartition, StopReplicaPartitionState> expectedPartitionStates = StopReplicaRequestTest.partitionStates(topicStates);
for (short version : STOP_REPLICA.allVersions()) {
StopReplicaRequest request = new StopReplicaRequest.Builder(version, 0, 1, 0, deletePartitions, topicStates).build(version);
StopReplicaRequestData data = request.data();
if (version < 1) {
Set<TopicPartition> partitions = new HashSet<>();
for (StopReplicaPartitionV0 partition : data.ungroupedPartitions()) {
partitions.add(new TopicPartition(partition.topicName(), partition.partitionIndex()));
}
assertEquals(expectedPartitionStates.keySet(), partitions);
assertEquals(deletePartitions, data.deletePartitions());
} else if (version < 3) {
Set<TopicPartition> partitions = new HashSet<>();
for (StopReplicaTopicV1 topic : data.topics()) {
for (Integer partition : topic.partitionIndexes()) {
partitions.add(new TopicPartition(topic.name(), partition));
}
}
assertEquals(expectedPartitionStates.keySet(), partitions);
assertEquals(deletePartitions, data.deletePartitions());
} else {
Map<TopicPartition, StopReplicaPartitionState> partitionStates = StopReplicaRequestTest.partitionStates(data.topicStates());
assertEquals(expectedPartitionStates, partitionStates);
// Always false from V3 on
assertFalse(data.deletePartitions());
}
}
}
use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState in project kafka by apache.
the class StopReplicaRequestTest method testPartitionStatesNormalization.
@Test
public void testPartitionStatesNormalization() {
List<StopReplicaTopicState> topicStates = topicStates(true);
for (short version : STOP_REPLICA.allVersions()) {
// Create a request for version to get its serialized form
StopReplicaRequest baseRequest = new StopReplicaRequest.Builder(version, 0, 1, 0, true, topicStates).build(version);
// Construct the request from the buffer
StopReplicaRequest request = StopReplicaRequest.parse(baseRequest.serialize(), version);
Map<TopicPartition, StopReplicaPartitionState> partitionStates = request.partitionStates();
assertEquals(6, partitionStates.size());
for (StopReplicaTopicState expectedTopicState : topicStates) {
for (StopReplicaPartitionState expectedPartitionState : expectedTopicState.partitionStates()) {
TopicPartition tp = new TopicPartition(expectedTopicState.topicName(), expectedPartitionState.partitionIndex());
StopReplicaPartitionState partitionState = partitionStates.get(tp);
assertEquals(expectedPartitionState.partitionIndex(), partitionState.partitionIndex());
assertTrue(partitionState.deletePartition());
if (version >= 3) {
assertEquals(expectedPartitionState.leaderEpoch(), partitionState.leaderEpoch());
} else {
assertEquals(-1, partitionState.leaderEpoch());
}
}
}
}
}
use of org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState in project kafka by apache.
the class StopReplicaResponseTest method testErrorCountsFromGetErrorResponse.
@Test
public void testErrorCountsFromGetErrorResponse() {
List<StopReplicaTopicState> topicStates = new ArrayList<>();
topicStates.add(new StopReplicaTopicState().setTopicName("foo").setPartitionStates(Arrays.asList(new StopReplicaPartitionState().setPartitionIndex(0), new StopReplicaPartitionState().setPartitionIndex(1))));
for (short version : STOP_REPLICA.allVersions()) {
StopReplicaRequest request = new StopReplicaRequest.Builder(version, 15, 20, 0, false, topicStates).build(version);
StopReplicaResponse response = request.getErrorResponse(0, Errors.CLUSTER_AUTHORIZATION_FAILED.exception());
assertEquals(Collections.singletonMap(Errors.CLUSTER_AUTHORIZATION_FAILED, 3), response.errorCounts());
}
}
Aggregations