Search in sources :

Example 1 with OffsetCommitResponse

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

the class KafkaConsumerTest method testLeaveGroupTimeout.

@Test
public void testLeaveGroupTimeout() throws Exception {
    Map<TopicPartition, Errors> response = new HashMap<>();
    response.put(tp0, Errors.NONE);
    OffsetCommitResponse commitResponse = offsetCommitResponse(response);
    consumerCloseTest(5000, Arrays.asList(commitResponse), 5000, false);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) Test(org.junit.Test)

Example 2 with OffsetCommitResponse

use of org.apache.kafka.common.requests.OffsetCommitResponse 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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) Test(org.junit.Test)

Example 3 with OffsetCommitResponse

use of org.apache.kafka.common.requests.OffsetCommitResponse 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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) OffsetCommitRequest(org.apache.kafka.common.requests.OffsetCommitRequest) HashMap(java.util.HashMap) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) AbstractRequest(org.apache.kafka.common.requests.AbstractRequest) LeaveGroupRequest(org.apache.kafka.common.requests.LeaveGroupRequest) MockClient(org.apache.kafka.clients.MockClient)

Aggregations

HashMap (java.util.HashMap)3 OffsetCommitResponse (org.apache.kafka.common.requests.OffsetCommitResponse)3 LinkedHashMap (java.util.LinkedHashMap)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 Errors (org.apache.kafka.common.protocol.Errors)2 LeaveGroupResponse (org.apache.kafka.common.requests.LeaveGroupResponse)2 Test (org.junit.Test)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MockClient (org.apache.kafka.clients.MockClient)1 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)1 LeaveGroupRequest (org.apache.kafka.common.requests.LeaveGroupRequest)1 OffsetCommitRequest (org.apache.kafka.common.requests.OffsetCommitRequest)1