public void TestConsumer_ConsumerGroupCommit() { var mocks = InitCluster(); mocks.Group.SetupGet(g => g.Configuration) .Returns(new ConsumerGroupConfiguration { AutoCommitEveryMs = -1, SessionTimeoutMs = 10 }); var consumer = new ConsumeRouter(mocks.Cluster.Object, new Configuration { TaskScheduler = new CurrentThreadTaskScheduler(), ConsumeBatchSize = 1 }, 1); consumer.StartConsumeSubscription(mocks.Group.Object, new[] { "the topic" }); Thread.Sleep(10); // wait for at least one heartbeat to be sent consumer.Acknowledge(new CommonAcknowledgement <FetchResponse> { ReceivedDate = DateTime.UtcNow, Response = new FetchResponse { FetchPartitionResponse = new CommonResponse <FetchPartitionResponse> { TopicsResponse = new[] { new TopicData <FetchPartitionResponse> { TopicName = "the topic", PartitionsData = new[] { new FetchPartitionResponse { Partition = 1, Messages = new List <ResponseMessage> { new ResponseMessage { Offset = 28, Message = new Message() } } } } } } } } }); mocks.Group.Verify(g => g.Commit(It.IsAny <IEnumerable <TopicData <OffsetCommitPartitionData> > >()), Times.Never); // no auto commit consumer.RequireCommit(); mocks.Group.Verify(g => g.Commit(It.Is <IEnumerable <TopicData <OffsetCommitPartitionData> > >(l => l.Count() == 1 && l.First().TopicName == "the topic" && l.First().PartitionsData.Count() == 2 && l.First().PartitionsData.First().Partition == 1 && l.First().PartitionsData.First().Metadata == "" && l.First().PartitionsData.First().Offset == 29)), // Offset saved should be next expected offset Times.Once); }