Search in sources :

Example 1 with StopReplicaResponseData

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));
}
Also used : ArrayList(java.util.ArrayList) StopReplicaResponseData(org.apache.kafka.common.message.StopReplicaResponseData)

Example 2 with StopReplicaResponseData

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());
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) StopReplicaPartitionError(org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError) ArrayList(java.util.ArrayList) StopReplicaResponseData(org.apache.kafka.common.message.StopReplicaResponseData) Test(org.junit.jupiter.api.Test)

Example 3 with StopReplicaResponseData

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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) StopReplicaPartitionError(org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError) StopReplicaTopicState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState) ArrayList(java.util.ArrayList) StopReplicaPartitionState(org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState) StopReplicaResponseData(org.apache.kafka.common.message.StopReplicaResponseData)

Example 4 with StopReplicaResponseData

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()));
}
Also used : StopReplicaPartitionError(org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError) ArrayList(java.util.ArrayList) StopReplicaResponseData(org.apache.kafka.common.message.StopReplicaResponseData) Test(org.junit.jupiter.api.Test)

Example 5 with StopReplicaResponseData

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());
}
Also used : StopReplicaPartitionError(org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError) ArrayList(java.util.ArrayList) StopReplicaResponseData(org.apache.kafka.common.message.StopReplicaResponseData) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)5 StopReplicaResponseData (org.apache.kafka.common.message.StopReplicaResponseData)5 StopReplicaPartitionError (org.apache.kafka.common.message.StopReplicaResponseData.StopReplicaPartitionError)4 Test (org.junit.jupiter.api.Test)3 Errors (org.apache.kafka.common.protocol.Errors)2 StopReplicaPartitionState (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaPartitionState)1 StopReplicaTopicState (org.apache.kafka.common.message.StopReplicaRequestData.StopReplicaTopicState)1