public void CouldAssingConsumerForTopicWatermark() { // Arrange var topicName = new TopicName("Test"); var offset = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); var watermark = new PartitionWatermark(topicName, offset, partition); var topicWatermark = new TopicWatermark(new[] { watermark }); var consumerMock = new Mock <IConsumer <object, object> >(); var consumer = consumerMock.Object; // Act var exception = Record.Exception(() => topicWatermark.AssignWithConsumer(consumer)); // Assert exception.Should().BeNull(); consumerMock.Verify(x => x.Assign(It.Is <IEnumerable <TopicPartitionOffset> >(value => value.Single().Topic == topicName.Value && value.Single().Partition == partition && value.Single().Offset == offset.High && value.Single().TopicPartition.Topic == topicName.Value && value.Single().TopicPartition.Partition == partition ) ), Times.Once); }
public void AssingWithConsumerFailsOnNullConsumer() { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); var pw = new PartitionWatermark(topicName, offsets, partition); IConsumer <object, object> consumer = null !; // Act var exception = Record.Exception(() => pw.AssingWithConsumer(consumer)); // Assert exception.Should().NotBeNull().And.BeOfType <ArgumentNullException>(); }
public void IsWatermarkAchievedByFailsOnNullResult() { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); ConsumeResult <object, object> result = null !; var pw = new PartitionWatermark(topicName, offsets, partition); // Act var exception = Record.Exception(() => pw.IsWatermarkAchievedBy(result)); // Assert exception.Should().NotBeNull().And.BeOfType <ArgumentNullException>(); }
public void IsReadyToReadReactsCorrectlyOnOffsetValues(int startOffset, int endOffset, bool condition) { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(startOffset), new Offset(endOffset)); var partition = new Partition(1); var pw = new PartitionWatermark(topicName, offsets, partition); var result = false; // Act var exception = Record.Exception(() => result = pw.IsReadyToRead()); // Assert exception.Should().BeNull(); result.Should().Be(condition); }
public void PartitionWatermarkCouldBeAssingToConsumer() { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); var pw = new PartitionWatermark(topicName, offsets, partition); var consumerMock = new Mock <IConsumer <object, object> >(); var consumer = consumerMock.Object; // Act var exception = Record.Exception(() => pw.AssingWithConsumer(consumer)); // Assert exception.Should().BeNull(); consumerMock.Verify(x => x.Assign(It.Is <TopicPartition>(a => a.Topic == topicName.Value && a.Partition == partition)), Times.Once); }
public void PartitionWatermarkCanBeCreated() { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); PartitionWatermark result = null !; // Act var exception = Record.Exception(() => result = new PartitionWatermark(topicName, offsets, partition)); // Assert exception.Should().BeNull(); result.Partition.Should().Be(partition); result.Offset.Should().Be(offsets); result.TopicName.Should().Be(topicName); }
public void TopicPartitionOffsetCreatesCorrectly() { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); var pw = new PartitionWatermark(topicName, offsets, partition); TopicPartitionOffset res = null !; // Act var exception = Record.Exception(() => res = pw.CreateTopicPartitionWithHighOffset()); // Assert exception.Should().BeNull(); res.Offset.Should().Be(offsets.High); res.Topic.Should().Be(topicName.Value); res.TopicPartition.Partition.Should().Be(partition); res.TopicPartition.Topic.Should().Be(topicName.Value); }
public void IsWatermarkAchievedByReatcsOnNotRightOffset() { // Arrange var topicName = new TopicName("Test"); var offsets = new WatermarkOffsets(new Offset(1), new Offset(2)); var partition = new Partition(1); var result = new ConsumeResult <object, object>() { Offset = offsets.Low }; var pw = new PartitionWatermark(topicName, offsets, partition); var status = false; // Act var exception = Record.Exception(() => status = pw.IsWatermarkAchievedBy(result)); // Assert exception.Should().BeNull(); status.Should().BeFalse(); }