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);
}
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());
}
}
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());
}
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());
}
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());
}
Aggregations