Search in sources :

Example 1 with OffsetCommitResponseData

use of org.apache.kafka.common.message.OffsetCommitResponseData in project kafka by apache.

the class OffsetCommitResponseTest method testParse.

@Test
public void testParse() {
    OffsetCommitResponseData data = new OffsetCommitResponseData().setTopics(Arrays.asList(new OffsetCommitResponseTopic().setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setPartitionIndex(partitionOne).setErrorCode(errorOne.code()))), new OffsetCommitResponseTopic().setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setPartitionIndex(partitionTwo).setErrorCode(errorTwo.code()))))).setThrottleTimeMs(throttleTimeMs);
    for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
        ByteBuffer buffer = MessageUtil.toByteBuffer(data, version);
        OffsetCommitResponse response = OffsetCommitResponse.parse(buffer, version);
        assertEquals(expectedErrorCounts, response.errorCounts());
        if (version >= 3) {
            assertEquals(throttleTimeMs, response.throttleTimeMs());
        } else {
            assertEquals(DEFAULT_THROTTLE_TIME, response.throttleTimeMs());
        }
        assertEquals(version >= 4, response.shouldClientThrottle(version));
    }
}
Also used : OffsetCommitResponseTopic(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic) ByteBuffer(java.nio.ByteBuffer) OffsetCommitResponseData(org.apache.kafka.common.message.OffsetCommitResponseData) OffsetCommitResponsePartition(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition) Test(org.junit.jupiter.api.Test)

Example 2 with OffsetCommitResponseData

use of org.apache.kafka.common.message.OffsetCommitResponseData in project kafka by apache.

the class ConsumerCoordinatorTest method gracefulCloseTest.

private void gracefulCloseTest(ConsumerCoordinator coordinator, boolean shouldLeaveGroup) {
    final AtomicBoolean commitRequested = new AtomicBoolean();
    final AtomicBoolean leaveGroupRequested = new AtomicBoolean();
    client.prepareResponse(body -> {
        commitRequested.set(true);
        OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
        return commitRequest.data().groupId().equals(groupId);
    }, new OffsetCommitResponse(new OffsetCommitResponseData()));
    if (shouldLeaveGroup)
        client.prepareResponse(body -> {
            leaveGroupRequested.set(true);
            LeaveGroupRequest leaveRequest = (LeaveGroupRequest) body;
            return leaveRequest.data().groupId().equals(groupId);
        }, new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code())));
    client.prepareResponse(body -> {
        commitRequested.set(true);
        OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
        return commitRequest.data().groupId().equals(groupId);
    }, new OffsetCommitResponse(new OffsetCommitResponseData()));
    coordinator.close();
    assertTrue(commitRequested.get(), "Commit not requested");
    assertEquals(shouldLeaveGroup, leaveGroupRequested.get(), "leaveGroupRequested should be " + shouldLeaveGroup);
    if (shouldLeaveGroup) {
        assertEquals(1, rebalanceListener.revokedCount);
        assertEquals(singleton(t1p), rebalanceListener.revoked);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MockTime(org.apache.kafka.common.utils.MockTime) Arrays(java.util.Arrays) ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) LeaveGroupRequest(org.apache.kafka.common.requests.LeaveGroupRequest) KafkaException(org.apache.kafka.common.KafkaException) OffsetResetStrategy(org.apache.kafka.clients.consumer.OffsetResetStrategy) HeartbeatResponse(org.apache.kafka.common.requests.HeartbeatResponse) Collections.singletonList(java.util.Collections.singletonList) Future(java.util.concurrent.Future) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) SyncGroupRequest(org.apache.kafka.common.requests.SyncGroupRequest) RecordBatch(org.apache.kafka.common.record.RecordBatch) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) OffsetCommitCallback(org.apache.kafka.clients.consumer.OffsetCommitCallback) TestUtils(org.apache.kafka.test.TestUtils) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) Executors(java.util.concurrent.Executors) Metrics(org.apache.kafka.common.metrics.Metrics) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Errors(org.apache.kafka.common.protocol.Errors) Node(org.apache.kafka.common.Node) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) NodeApiVersions(org.apache.kafka.clients.NodeApiVersions) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) RetriableCommitFailedException(org.apache.kafka.clients.consumer.RetriableCommitFailedException) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) RequestTestUtils(org.apache.kafka.common.requests.RequestTestUtils) ArrayList(java.util.ArrayList) Type(org.apache.kafka.common.protocol.types.Type) OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Topic(org.apache.kafka.common.internals.Topic) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) SyncGroupResponseData(org.apache.kafka.common.message.SyncGroupResponseData) SystemTime(org.apache.kafka.common.utils.SystemTime) Schema(org.apache.kafka.common.protocol.types.Schema) FencedInstanceIdException(org.apache.kafka.common.errors.FencedInstanceIdException) Struct(org.apache.kafka.common.protocol.types.Struct) TestUtils.toSet(org.apache.kafka.test.TestUtils.toSet) OffsetCommitResponseData(org.apache.kafka.common.message.OffsetCommitResponseData) AfterEach(org.junit.jupiter.api.AfterEach) COOPERATIVE_STICKY_ASSIGNOR_NAME(org.apache.kafka.clients.consumer.CooperativeStickyAssignor.COOPERATIVE_STICKY_ASSIGNOR_NAME) GroupRebalanceConfig(org.apache.kafka.clients.GroupRebalanceConfig) CommitFailedException(org.apache.kafka.clients.consumer.CommitFailedException) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) FindCoordinatorResponse(org.apache.kafka.common.requests.FindCoordinatorResponse) JoinGroupRequest(org.apache.kafka.common.requests.JoinGroupRequest) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) TimeoutException(java.util.concurrent.TimeoutException) MemberIdentity(org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity) ByteBuffer(java.nio.ByteBuffer) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Metric(org.apache.kafka.common.Metric) MetricName(org.apache.kafka.common.MetricName) OffsetCommitRequestData(org.apache.kafka.common.message.OffsetCommitRequestData) EAGER(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.RebalanceProtocol.EAGER) TopicPartition(org.apache.kafka.common.TopicPartition) HeartbeatResponseData(org.apache.kafka.common.message.HeartbeatResponseData) WakeupException(org.apache.kafka.common.errors.WakeupException) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners) RebalanceInProgressException(org.apache.kafka.common.errors.RebalanceInProgressException) Test(org.junit.jupiter.api.Test) List(java.util.List) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Optional(java.util.Optional) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Field(org.apache.kafka.common.protocol.types.Field) Pattern(java.util.regex.Pattern) JoinGroupResponse(org.apache.kafka.common.requests.JoinGroupResponse) ClientResponse(org.apache.kafka.clients.ClientResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) HashSet(java.util.HashSet) OffsetMetadataTooLarge(org.apache.kafka.common.errors.OffsetMetadataTooLarge) ArgumentCaptor(org.mockito.ArgumentCaptor) SyncGroupResponse(org.apache.kafka.common.requests.SyncGroupResponse) Collections.singletonMap(java.util.Collections.singletonMap) COOPERATIVE(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.RebalanceProtocol.COOPERATIVE) ExecutorService(java.util.concurrent.ExecutorService) ConsumerPartitionAssignor(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor) Utils(org.apache.kafka.common.utils.Utils) OffsetCommitRequest(org.apache.kafka.common.requests.OffsetCommitRequest) MockClient(org.apache.kafka.clients.MockClient) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) JoinGroupResponseData(org.apache.kafka.common.message.JoinGroupResponseData) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) DisconnectException(org.apache.kafka.common.errors.DisconnectException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) JoinGroupRequestData(org.apache.kafka.common.message.JoinGroupRequestData) Collections(java.util.Collections) ApiException(org.apache.kafka.common.errors.ApiException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) OffsetCommitRequest(org.apache.kafka.common.requests.OffsetCommitRequest) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) LeaveGroupRequest(org.apache.kafka.common.requests.LeaveGroupRequest) OffsetCommitResponseData(org.apache.kafka.common.message.OffsetCommitResponseData)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1