use of org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError in project kafka by apache.
the class StopReplicaResponseTest method testErrorCountsNoTopLevelError.
@Test
public void testErrorCountsNoTopLevelError() {
List<StopReplicaPartitionError> errors = new ArrayList<>();
errors.add(new StopReplicaPartitionError().setTopicName("foo").setPartitionIndex(0));
errors.add(new StopReplicaPartitionError().setTopicName("foo").setPartitionIndex(1).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code()));
StopReplicaResponse response = new StopReplicaResponse(new StopReplicaResponseData().setErrorCode(Errors.NONE.code()).setPartitionErrors(errors));
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.message.StopReplicaResponseData.StopReplicaPartitionError in project kafka by apache.
the class StopReplicaRequest method getErrorResponse.
@Override
public StopReplicaResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
StopReplicaResponseData data = new StopReplicaResponseData();
data.setErrorCode(error.code());
List<StopReplicaPartitionError> partitions = new ArrayList<>();
for (StopReplicaTopicState topic : topicStates()) {
for (StopReplicaPartitionState partition : topic.partitionStates()) {
partitions.add(new StopReplicaPartitionError().setTopicName(topic.topicName()).setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
}
}
data.setPartitionErrors(partitions);
return new StopReplicaResponse(data);
}
use of org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError 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.StopReplicaResponseData.StopReplicaPartitionError in project kafka by apache.
the class StopReplicaResponseTest method testToString.
@Test
public void testToString() {
List<StopReplicaPartitionError> errors = new ArrayList<>();
errors.add(new StopReplicaPartitionError().setTopicName("foo").setPartitionIndex(0));
errors.add(new StopReplicaPartitionError().setTopicName("foo").setPartitionIndex(1).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code()));
StopReplicaResponse response = new StopReplicaResponse(new StopReplicaResponseData().setPartitionErrors(errors));
String responseStr = response.toString();
assertTrue(responseStr.contains(StopReplicaResponse.class.getSimpleName()));
assertTrue(responseStr.contains(errors.toString()));
assertTrue(responseStr.contains("errorCode=" + Errors.NONE.code()));
}
use of org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError in project kafka by apache.
the class StopReplicaResponseTest method testErrorCountsWithTopLevelError.
@Test
public void testErrorCountsWithTopLevelError() {
List<StopReplicaPartitionError> errors = new ArrayList<>();
errors.add(new StopReplicaPartitionError().setTopicName("foo").setPartitionIndex(0));
errors.add(new StopReplicaPartitionError().setTopicName("foo").setPartitionIndex(1).setErrorCode(Errors.NOT_LEADER_OR_FOLLOWER.code()));
StopReplicaResponse response = new StopReplicaResponse(new StopReplicaResponseData().setErrorCode(Errors.UNKNOWN_SERVER_ERROR.code()).setPartitionErrors(errors));
assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 3), response.errorCounts());
}
Aggregations