Search in sources :

Example 1 with StopReplicaPartitionError

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());
}
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 2 with StopReplicaPartitionError

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);
}
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 3 with StopReplicaPartitionError

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

Example 4 with StopReplicaPartitionError

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()));
}
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 StopReplicaPartitionError

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());
}
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

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