Search in sources :

Example 1 with ConsumerGroup

use of io.confluent.kafkarest.entities.ConsumerGroup in project kafka-rest by confluentinc.

the class ConsumerLagManagerImplTest method getConsumerLag_nonExistingPartitionAssignment_returnsConsumerLag.

@Test
public void getConsumerLag_nonExistingPartitionAssignment_returnsConsumerLag() throws Exception {
    final Consumer consumer = Consumer.builder().setClusterId(CLUSTER_ID).setConsumerGroupId(CONSUMER_GROUP_ID).setConsumerId("").setClientId("").setHost("11.12.12.14").setAssignedPartitions(Collections.singletonList(Partition.create(CLUSTER_ID, /* topicName= */
    "topic-1", /* partitionId= */
    1, /* replicas= */
    emptyList()))).build();
    final ConsumerGroup consumerGroup = ConsumerGroup.builder().setClusterId(CLUSTER_ID).setConsumerGroupId(CONSUMER_GROUP_ID).setSimple(true).setPartitionAssignor("org.apache.kafka.clients.consumer.RangeAssignor").setState(State.STABLE).setCoordinator(BROKER_1).setConsumers(Collections.singletonList(consumer)).build();
    final ConsumerLag expectedConsumerLag = ConsumerLag.builder().setClusterId(CLUSTER_ID).setConsumerGroupId(CONSUMER_GROUP_ID).setTopicName("topic-1").setPartitionId(1).setConsumerId("").setClientId("").setCurrentOffset(0L).setLogEndOffset(100L).build();
    expect(consumerGroupManager.getConsumerGroup(CLUSTER_ID, CONSUMER_GROUP_ID)).andReturn(completedFuture(Optional.of(consumerGroup)));
    expect(kafkaAdminClient.listConsumerGroupOffsets(eq(CONSUMER_GROUP_ID), anyObject(ListConsumerGroupOffsetsOptions.class))).andReturn(listConsumerGroupOffsetsResult);
    expect(listConsumerGroupOffsetsResult.partitionsToOffsetAndMetadata()).andReturn(KafkaFuture.completedFuture(OFFSET_AND_METADATA_MAP));
    final Capture<Map<TopicPartition, OffsetSpec>> capturedOffsetSpec = newCapture();
    final Capture<ListOffsetsOptions> capturedListOffsetsOptions = newCapture();
    expect(kafkaAdminClient.listOffsets(capture(capturedOffsetSpec), capture(capturedListOffsetsOptions))).andReturn(new ListOffsetsResult(LATEST_OFFSETS_MAP));
    replay(consumerGroupManager, kafkaAdminClient, listConsumerGroupOffsetsResult);
    ConsumerLag consumerLag = consumerLagManager.getConsumerLag(CLUSTER_ID, CONSUMER_GROUP_ID, "topic-1", 1).get().get();
    assertEquals(OFFSET_AND_METADATA_MAP.keySet(), capturedOffsetSpec.getValue().keySet());
    assertEquals(IsolationLevel.READ_COMMITTED, capturedListOffsetsOptions.getValue().isolationLevel());
    assertEquals(expectedConsumerLag, consumerLag);
}
Also used : ListConsumerGroupOffsetsOptions(org.apache.kafka.clients.admin.ListConsumerGroupOffsetsOptions) ListOffsetsResult(org.apache.kafka.clients.admin.ListOffsetsResult) ConsumerLag(io.confluent.kafkarest.entities.ConsumerLag) Consumer(io.confluent.kafkarest.entities.Consumer) ListOffsetsOptions(org.apache.kafka.clients.admin.ListOffsetsOptions) HashMap(java.util.HashMap) Map(java.util.Map) ConsumerGroup(io.confluent.kafkarest.entities.ConsumerGroup) Test(org.junit.jupiter.api.Test)

Example 2 with ConsumerGroup

use of io.confluent.kafkarest.entities.ConsumerGroup in project kafka-rest by confluentinc.

the class ConsumerGroupManagerImplTest method getConsumerGroup_returnsConsumerGroup.

@Test
public void getConsumerGroup_returnsConsumerGroup() throws Exception {
    expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
    expect(adminClient.describeConsumerGroups(singletonList(CONSUMER_GROUPS[0].getConsumerGroupId()))).andReturn(describeConsumerGroupsResult);
    expect(describeConsumerGroupsResult.all()).andReturn(KafkaFuture.completedFuture(singletonMap(CONSUMER_GROUPS[0].getConsumerGroupId(), consumerGroupDescriptions[0])));
    expect(consumerGroupDescriptions[0].groupId()).andStubReturn(CONSUMER_GROUPS[0].getConsumerGroupId());
    expect(consumerGroupDescriptions[0].isSimpleConsumerGroup()).andStubReturn(CONSUMER_GROUPS[0].isSimple());
    expect(consumerGroupDescriptions[0].partitionAssignor()).andStubReturn(CONSUMER_GROUPS[0].getPartitionAssignor());
    expect(consumerGroupDescriptions[0].state()).andStubReturn(CONSUMER_GROUPS[0].getState().toConsumerGroupState());
    expect(consumerGroupDescriptions[0].coordinator()).andStubReturn(CONSUMER_GROUPS[0].getCoordinator().toNode());
    expect(consumerGroupDescriptions[0].members()).andStubReturn(Arrays.asList(memberDescriptions[0]));
    for (int j = 0; j < CONSUMER_GROUPS[0].getConsumers().size(); j++) {
        expect(memberDescriptions[0][j].consumerId()).andStubReturn(CONSUMERS[0][j].getConsumerId());
        expect(memberDescriptions[0][j].groupInstanceId()).andStubReturn(CONSUMERS[0][j].getInstanceId());
        expect(memberDescriptions[0][j].clientId()).andStubReturn(CONSUMERS[0][j].getClientId());
        expect(memberDescriptions[0][j].host()).andStubReturn(CONSUMERS[0][j].getHost());
        expect(memberDescriptions[0][j].assignment()).andStubReturn(memberAssignments[0][j]);
        expect(memberAssignments[0][j].topicPartitions()).andStubReturn(CONSUMERS[0][j].getAssignedPartitions().stream().map(Partition::toTopicPartition).collect(Collectors.toSet()));
        replay(memberDescriptions[0][j], memberAssignments[0][j]);
    }
    replay(clusterManager, adminClient, listConsumerGroupsResult, describeConsumerGroupsResult, consumerGroupDescriptions[0]);
    ConsumerGroup consumerGroup = consumerGroupManager.getConsumerGroup(CLUSTER_ID, CONSUMER_GROUPS[0].getConsumerGroupId()).get().get();
    assertEquals(CONSUMER_GROUPS[0], consumerGroup);
}
Also used : Partition(io.confluent.kafkarest.entities.Partition) ConsumerGroup(io.confluent.kafkarest.entities.ConsumerGroup) Test(org.junit.jupiter.api.Test)

Aggregations

ConsumerGroup (io.confluent.kafkarest.entities.ConsumerGroup)2 Test (org.junit.jupiter.api.Test)2 Consumer (io.confluent.kafkarest.entities.Consumer)1 ConsumerLag (io.confluent.kafkarest.entities.ConsumerLag)1 Partition (io.confluent.kafkarest.entities.Partition)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ListConsumerGroupOffsetsOptions (org.apache.kafka.clients.admin.ListConsumerGroupOffsetsOptions)1 ListOffsetsOptions (org.apache.kafka.clients.admin.ListOffsetsOptions)1 ListOffsetsResult (org.apache.kafka.clients.admin.ListOffsetsResult)1