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