use of org.apache.kafka.common.requests.LeaveGroupResponse in project kafka by apache.
the class ConsumerCoordinatorTest method testMaybeLeaveGroup.
@Test
public void testMaybeLeaveGroup() {
final String consumerId = "consumer";
subscriptions.subscribe(singleton(topic1), rebalanceListener);
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady();
client.prepareResponse(joinGroupFollowerResponse(1, consumerId, "leader", Errors.NONE));
client.prepareResponse(syncGroupResponse(singletonList(t1p), Errors.NONE));
coordinator.joinGroupIfNeeded();
final AtomicBoolean received = new AtomicBoolean(false);
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
received.set(true);
LeaveGroupRequest leaveRequest = (LeaveGroupRequest) body;
return leaveRequest.memberId().equals(consumerId) && leaveRequest.groupId().equals(groupId);
}
}, new LeaveGroupResponse(Errors.NONE));
coordinator.maybeLeaveGroup();
assertTrue(received.get());
AbstractCoordinator.Generation generation = coordinator.generation();
assertNull(generation);
}
use of org.apache.kafka.common.requests.LeaveGroupResponse in project kafka by apache.
the class ConsumerCoordinatorTest method testLeaveGroupOnClose.
@Test
public void testLeaveGroupOnClose() {
final String consumerId = "consumer";
subscriptions.subscribe(singleton(topic1), rebalanceListener);
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady();
client.prepareResponse(joinGroupFollowerResponse(1, consumerId, "leader", Errors.NONE));
client.prepareResponse(syncGroupResponse(singletonList(t1p), Errors.NONE));
coordinator.joinGroupIfNeeded();
final AtomicBoolean received = new AtomicBoolean(false);
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
received.set(true);
LeaveGroupRequest leaveRequest = (LeaveGroupRequest) body;
return leaveRequest.memberId().equals(consumerId) && leaveRequest.groupId().equals(groupId);
}
}, new LeaveGroupResponse(Errors.NONE));
coordinator.close(0);
assertTrue(received.get());
}
use of org.apache.kafka.common.requests.LeaveGroupResponse in project kafka by apache.
the class KafkaConsumerTest method testGracefulClose.
@Test
public void testGracefulClose() throws Exception {
Map<TopicPartition, Errors> response = new HashMap<>();
response.put(tp0, Errors.NONE);
OffsetCommitResponse commitResponse = offsetCommitResponse(response);
LeaveGroupResponse leaveGroupResponse = new LeaveGroupResponse(Errors.NONE);
consumerCloseTest(5000, Arrays.asList(commitResponse, leaveGroupResponse), 0, false);
}
use of org.apache.kafka.common.requests.LeaveGroupResponse in project kafka by apache.
the class ConsumerCoordinatorTest method testCommitAfterLeaveGroup.
@Test
public void testCommitAfterLeaveGroup() {
// enable auto-assignment
subscriptions.subscribe(singleton(topic1), rebalanceListener);
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady();
client.prepareResponse(joinGroupFollowerResponse(1, "consumer", "leader", Errors.NONE));
client.prepareResponse(syncGroupResponse(singletonList(t1p), Errors.NONE));
client.prepareMetadataUpdate(cluster, Collections.<String>emptySet());
coordinator.joinGroupIfNeeded();
// now switch to manual assignment
client.prepareResponse(new LeaveGroupResponse(Errors.NONE));
subscriptions.unsubscribe();
coordinator.maybeLeaveGroup();
subscriptions.assignFromUser(singleton(t1p));
// the client should not reuse generation/memberId from auto-subscribed generation
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
return commitRequest.memberId().equals(OffsetCommitRequest.DEFAULT_MEMBER_ID) && commitRequest.generationId() == OffsetCommitRequest.DEFAULT_GENERATION_ID;
}
}, offsetCommitResponse(Collections.singletonMap(t1p, Errors.NONE)));
AtomicBoolean success = new AtomicBoolean(false);
coordinator.commitOffsetsAsync(Collections.singletonMap(t1p, new OffsetAndMetadata(100L)), callback(success));
coordinator.invokeCompletedOffsetCommitCallbacks();
assertTrue(success.get());
}
use of org.apache.kafka.common.requests.LeaveGroupResponse in project kafka by apache.
the class ConsumerCoordinatorTest method gracefulCloseTest.
private void gracefulCloseTest(ConsumerCoordinator coordinator, boolean dynamicAssignment) throws Exception {
final AtomicBoolean commitRequested = new AtomicBoolean();
final AtomicBoolean leaveGroupRequested = new AtomicBoolean();
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
commitRequested.set(true);
OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
return commitRequest.groupId().equals(groupId);
}
}, new OffsetCommitResponse(new HashMap<TopicPartition, Errors>()));
client.prepareResponse(new MockClient.RequestMatcher() {
@Override
public boolean matches(AbstractRequest body) {
leaveGroupRequested.set(true);
LeaveGroupRequest leaveRequest = (LeaveGroupRequest) body;
return leaveRequest.groupId().equals(groupId);
}
}, new LeaveGroupResponse(Errors.NONE));
coordinator.close();
assertTrue("Commit not requested", commitRequested.get());
if (dynamicAssignment)
assertTrue("Leave group not requested", leaveGroupRequested.get());
}
Aggregations