Search in sources :

Example 31 with ConsumerGroupMetadata

use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.

the class TaskManagerTest method shouldCommitViaProducerIfEosV2Enabled.

@Test
public void shouldCommitViaProducerIfEosV2Enabled() {
    final StreamsProducer producer = mock(StreamsProducer.class);
    expect(activeTaskCreator.threadProducer()).andReturn(producer);
    final Map<TopicPartition, OffsetAndMetadata> offsetsT01 = singletonMap(t1p1, new OffsetAndMetadata(0L, null));
    final Map<TopicPartition, OffsetAndMetadata> offsetsT02 = singletonMap(t1p2, new OffsetAndMetadata(1L, null));
    final Map<TopicPartition, OffsetAndMetadata> allOffsets = new HashMap<>();
    allOffsets.putAll(offsetsT01);
    allOffsets.putAll(offsetsT02);
    producer.commitTransaction(allOffsets, new ConsumerGroupMetadata("appId"));
    expectLastCall();
    shouldCommitViaProducerIfEosEnabled(ProcessingMode.EXACTLY_ONCE_V2, producer, offsetsT01, offsetsT02);
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Test(org.junit.Test)

Example 32 with ConsumerGroupMetadata

use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.

the class ConsumerCoordinatorTest method testGetGroupMetadata.

@Test
public void testGetGroupMetadata() {
    final ConsumerGroupMetadata groupMetadata = coordinator.groupMetadata();
    assertNotNull(groupMetadata);
    assertEquals(groupId, groupMetadata.groupId());
    assertEquals(JoinGroupRequest.UNKNOWN_GENERATION_ID, groupMetadata.generationId());
    assertEquals(JoinGroupRequest.UNKNOWN_MEMBER_ID, groupMetadata.memberId());
    assertFalse(groupMetadata.groupInstanceId().isPresent());
    try (final ConsumerCoordinator coordinator = prepareCoordinatorForCloseTest(true, true, groupInstanceId)) {
        coordinator.ensureActiveGroup();
        final ConsumerGroupMetadata joinedGroupMetadata = coordinator.groupMetadata();
        assertNotNull(joinedGroupMetadata);
        assertEquals(groupId, joinedGroupMetadata.groupId());
        assertEquals(1, joinedGroupMetadata.generationId());
        assertEquals(consumerId, joinedGroupMetadata.memberId());
        assertEquals(groupInstanceId, joinedGroupMetadata.groupInstanceId());
    }
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) Test(org.junit.jupiter.api.Test)

Example 33 with ConsumerGroupMetadata

use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.

the class MockProducerTest method shouldPreserveOffsetsFromCommitByGroupMetadataOnAbortIfTransactionsAreEnabled.

@Test
public void shouldPreserveOffsetsFromCommitByGroupMetadataOnAbortIfTransactionsAreEnabled() {
    buildMockProducer(true);
    producer.initTransactions();
    producer.beginTransaction();
    String group = "g";
    Map<TopicPartition, OffsetAndMetadata> groupCommit = new HashMap<TopicPartition, OffsetAndMetadata>() {

        {
            put(new TopicPartition(topic, 0), new OffsetAndMetadata(42L, null));
            put(new TopicPartition(topic, 1), new OffsetAndMetadata(73L, null));
        }
    };
    producer.sendOffsetsToTransaction(groupCommit, new ConsumerGroupMetadata(group));
    producer.commitTransaction();
    producer.beginTransaction();
    String group2 = "g2";
    Map<TopicPartition, OffsetAndMetadata> groupCommit2 = new HashMap<TopicPartition, OffsetAndMetadata>() {

        {
            put(new TopicPartition(topic, 2), new OffsetAndMetadata(53L, null));
            put(new TopicPartition(topic, 3), new OffsetAndMetadata(84L, null));
        }
    };
    producer.sendOffsetsToTransaction(groupCommit2, new ConsumerGroupMetadata(group2));
    producer.abortTransaction();
    Map<String, Map<TopicPartition, OffsetAndMetadata>> expectedResult = new HashMap<>();
    expectedResult.put(group, groupCommit);
    assertEquals(Collections.singletonList(expectedResult), producer.consumerGroupOffsetsHistory());
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 34 with ConsumerGroupMetadata

use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.

the class MockProducerTest method shouldPublishLatestAndCumulativeConsumerGroupOffsetsOnlyAfterCommitIfTransactionsAreEnabled.

@Test
public void shouldPublishLatestAndCumulativeConsumerGroupOffsetsOnlyAfterCommitIfTransactionsAreEnabled() {
    buildMockProducer(true);
    producer.initTransactions();
    producer.beginTransaction();
    String group = "g";
    Map<TopicPartition, OffsetAndMetadata> groupCommit1 = new HashMap<TopicPartition, OffsetAndMetadata>() {

        {
            put(new TopicPartition(topic, 0), new OffsetAndMetadata(42L, null));
            put(new TopicPartition(topic, 1), new OffsetAndMetadata(73L, null));
        }
    };
    Map<TopicPartition, OffsetAndMetadata> groupCommit2 = new HashMap<TopicPartition, OffsetAndMetadata>() {

        {
            put(new TopicPartition(topic, 1), new OffsetAndMetadata(101L, null));
            put(new TopicPartition(topic, 2), new OffsetAndMetadata(21L, null));
        }
    };
    producer.sendOffsetsToTransaction(groupCommit1, new ConsumerGroupMetadata(group));
    producer.sendOffsetsToTransaction(groupCommit2, new ConsumerGroupMetadata(group));
    assertTrue(producer.consumerGroupOffsetsHistory().isEmpty());
    Map<String, Map<TopicPartition, OffsetAndMetadata>> expectedResult = new HashMap<>();
    expectedResult.put(group, new HashMap<TopicPartition, OffsetAndMetadata>() {

        {
            put(new TopicPartition(topic, 0), new OffsetAndMetadata(42L, null));
            put(new TopicPartition(topic, 1), new OffsetAndMetadata(101L, null));
            put(new TopicPartition(topic, 2), new OffsetAndMetadata(21L, null));
        }
    });
    producer.commitTransaction();
    assertEquals(Collections.singletonList(expectedResult), producer.consumerGroupOffsetsHistory());
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 35 with ConsumerGroupMetadata

use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.

the class MockProducerTest method shouldPreserveOffsetsFromCommitByGroupIdOnAbortIfTransactionsAreEnabled.

@Test
public void shouldPreserveOffsetsFromCommitByGroupIdOnAbortIfTransactionsAreEnabled() {
    buildMockProducer(true);
    producer.initTransactions();
    producer.beginTransaction();
    String group = "g";
    Map<TopicPartition, OffsetAndMetadata> groupCommit = new HashMap<TopicPartition, OffsetAndMetadata>() {

        {
            put(new TopicPartition(topic, 0), new OffsetAndMetadata(42L, null));
            put(new TopicPartition(topic, 1), new OffsetAndMetadata(73L, null));
        }
    };
    producer.sendOffsetsToTransaction(groupCommit, new ConsumerGroupMetadata(group));
    producer.commitTransaction();
    producer.beginTransaction();
    producer.abortTransaction();
    Map<String, Map<TopicPartition, OffsetAndMetadata>> expectedResult = new HashMap<>();
    expectedResult.put(group, groupCommit);
    assertEquals(Collections.singletonList(expectedResult), producer.consumerGroupOffsetsHistory());
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ConsumerGroupMetadata (org.apache.kafka.clients.consumer.ConsumerGroupMetadata)64 TopicPartition (org.apache.kafka.common.TopicPartition)34 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)29 Test (org.junit.Test)28 HashMap (java.util.HashMap)25 Test (org.junit.jupiter.api.Test)24 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)14 TaskId (org.apache.kafka.streams.processor.TaskId)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 LogContext (org.apache.kafka.common.utils.LogContext)8 Collection (java.util.Collection)7 LinkedList (java.util.LinkedList)7 Map (java.util.Map)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 KafkaException (org.apache.kafka.common.KafkaException)7 TimeoutException (org.apache.kafka.common.errors.TimeoutException)7 TaskCorruptedException (org.apache.kafka.streams.errors.TaskCorruptedException)7 Collections.emptySet (java.util.Collections.emptySet)6 HashSet (java.util.HashSet)6