Search in sources :

Example 6 with JoinGroupResponse

use of org.apache.kafka.common.requests.JoinGroupResponse in project apache-kafka-on-k8s by banzaicloud.

the class WorkerCoordinatorTest method joinGroupLeaderResponse.

private JoinGroupResponse joinGroupLeaderResponse(int generationId, String memberId, Map<String, Long> configOffsets, Errors error) {
    Map<String, ByteBuffer> metadata = new HashMap<>();
    for (Map.Entry<String, Long> configStateEntry : configOffsets.entrySet()) {
        // We need a member URL, but it doesn't matter for the purposes of this test. Just set it to the member ID
        String memberUrl = configStateEntry.getKey();
        long configOffset = configStateEntry.getValue();
        ByteBuffer buf = ConnectProtocol.serializeMetadata(new ConnectProtocol.WorkerState(memberUrl, configOffset));
        metadata.put(configStateEntry.getKey(), buf);
    }
    return new JoinGroupResponse(error, generationId, WorkerCoordinator.DEFAULT_SUBPROTOCOL, memberId, memberId, metadata);
}
Also used : HashMap(java.util.HashMap) JoinGroupResponse(org.apache.kafka.common.requests.JoinGroupResponse) ByteBuffer(java.nio.ByteBuffer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with JoinGroupResponse

use of org.apache.kafka.common.requests.JoinGroupResponse in project kafka by apache.

the class ConsumerCoordinatorTest method joinGroupLeaderResponse.

private JoinGroupResponse joinGroupLeaderResponse(int generationId, String memberId, Map<String, List<String>> subscriptions, boolean skipAssignment, Errors error) {
    List<JoinGroupResponseData.JoinGroupResponseMember> metadata = new ArrayList<>();
    for (Map.Entry<String, List<String>> subscriptionEntry : subscriptions.entrySet()) {
        ConsumerPartitionAssignor.Subscription subscription = new ConsumerPartitionAssignor.Subscription(subscriptionEntry.getValue());
        ByteBuffer buf = ConsumerProtocol.serializeSubscription(subscription);
        metadata.add(new JoinGroupResponseData.JoinGroupResponseMember().setMemberId(subscriptionEntry.getKey()).setMetadata(buf.array()));
    }
    return new JoinGroupResponse(new JoinGroupResponseData().setErrorCode(error.code()).setGenerationId(generationId).setProtocolName(partitionAssignor.name()).setLeader(memberId).setSkipAssignment(skipAssignment).setMemberId(memberId).setMembers(metadata));
}
Also used : JoinGroupResponseData(org.apache.kafka.common.message.JoinGroupResponseData) JoinGroupResponse(org.apache.kafka.common.requests.JoinGroupResponse) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ConsumerPartitionAssignor(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap)

Example 8 with JoinGroupResponse

use of org.apache.kafka.common.requests.JoinGroupResponse in project kafka by apache.

the class AbstractCoordinatorTest method expectJoinGroup.

private void expectJoinGroup(String expectedMemberId, String expectedReason, int responseGeneration, String responseMemberId) {
    JoinGroupResponse response = joinGroupFollowerResponse(responseGeneration, responseMemberId, "leaderId", Errors.NONE, PROTOCOL_TYPE);
    mockClient.prepareResponse(body -> {
        if (!(body instanceof JoinGroupRequest)) {
            return false;
        }
        JoinGroupRequestData joinGroupRequest = ((JoinGroupRequest) body).data();
        // abstract coordinator never sets reason to null
        String actualReason = joinGroupRequest.reason();
        boolean isReasonMatching = expectedReason == null || expectedReason.equals(actualReason);
        return joinGroupRequest.memberId().equals(expectedMemberId) && joinGroupRequest.protocolType().equals(PROTOCOL_TYPE) && isReasonMatching;
    }, response);
}
Also used : JoinGroupRequest(org.apache.kafka.common.requests.JoinGroupRequest) JoinGroupResponse(org.apache.kafka.common.requests.JoinGroupResponse) JoinGroupRequestData(org.apache.kafka.common.message.JoinGroupRequestData)

Aggregations

JoinGroupResponse (org.apache.kafka.common.requests.JoinGroupResponse)8 ByteBuffer (java.nio.ByteBuffer)7 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)3 Collections.singletonList (java.util.Collections.singletonList)3 Collections.singletonMap (java.util.Collections.singletonMap)3 List (java.util.List)3 JoinGroupResponseData (org.apache.kafka.common.message.JoinGroupResponseData)3 MockClient (org.apache.kafka.clients.MockClient)2 Node (org.apache.kafka.common.Node)2 FetchRequest (org.apache.kafka.common.requests.FetchRequest)2 HeartbeatResponse (org.apache.kafka.common.requests.HeartbeatResponse)2 Collections.emptyList (java.util.Collections.emptyList)1 Metadata (org.apache.kafka.clients.Metadata)1 ConsumerPartitionAssignor (org.apache.kafka.clients.consumer.ConsumerPartitionAssignor)1 ConsumerMetadata (org.apache.kafka.clients.consumer.internals.ConsumerMetadata)1 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)1 Cluster (org.apache.kafka.common.Cluster)1 TopicIdPartition (org.apache.kafka.common.TopicIdPartition)1