use of org.apache.kafka.common.message.StopReplicaResponseData in project kafka by apache.
the class RequestResponseTest method createStopReplicaResponse.
private StopReplicaResponse createStopReplicaResponse() {
List<StopReplicaResponseData.StopReplicaPartitionError> partitions = new ArrayList<>();
partitions.add(new StopReplicaResponseData.StopReplicaPartitionError().setTopicName("test").setPartitionIndex(0).setErrorCode(Errors.NONE.code()));
return new StopReplicaResponse(new StopReplicaResponseData().setErrorCode(Errors.NONE.code()).setPartitionErrors(partitions));
}
use of org.apache.kafka.common.message.StopReplicaResponseData 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 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 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 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