public async Task QueueMessageBatchAsyncQueueingTwiceSameQueueTest() { Mock <IKafkaBatchFactory> factoryMock = new Mock <IKafkaBatchFactory>(); Dictionary <string, object> requestContext = new Dictionary <string, object>(); factoryMock.Setup(x => x.ToKafkaMessage(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <IEnumerable <int> >(), requestContext)).Returns(new Message() { Value = new byte[] { 0, 1, 2, 3 } }); KafkaQueueAdapter adapter = new KafkaQueueAdapter(_streamQueueMapper, _options, _providerName, factoryMock.Object, _logger); Guid myGuid = Guid.NewGuid(); await adapter.QueueMessageBatchAsync(myGuid, "Test", new List <int>() { 1, 2, 3, 4 }, null, requestContext); await adapter.QueueMessageBatchAsync(myGuid, "Test", new List <int>() { 1, 2, 3, 4 }, null, requestContext); }
public void QueueMessageBatchAsyncQueueingTwiceDifferentQueuesTest() { Mock <IKafkaBatchFactory> factoryMock = new Mock <IKafkaBatchFactory>(); Dictionary <string, object> requestContext = new Dictionary <string, object>(); factoryMock.Setup(x => x.ToKafkaMessage(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <IEnumerable <int> >(), requestContext)).Returns(new Message() { Value = new byte[] { 0, 1, 2, 3 } }); var twoQueuesStreamMapper = new HashRingBasedStreamQueueMapper(2, _options.TopicName); var twoQueuesOptions = new KafkaStreamProviderOptions(_options.ConnectionStrings, _options.TopicName, _options.ConsumerGroupName) { NumOfQueues = 2 }; KafkaQueueAdapter adapter = new KafkaQueueAdapter(_streamQueueMapper, _options, _providerName, factoryMock.Object, _logger); var first = Guid.NewGuid(); var second = Guid.NewGuid(); // Becuase we cannot mock the queue mapper.. we need to make sure we two guids that will return different queues... bool willGiveDifferentQueue = !(twoQueuesStreamMapper.GetQueueForStream(first, "test").Equals(twoQueuesStreamMapper.GetQueueForStream(second, "otherTest"))); while (!willGiveDifferentQueue) { second = Guid.NewGuid(); willGiveDifferentQueue = !(twoQueuesStreamMapper.GetQueueForStream(first, "test").Equals(twoQueuesStreamMapper.GetQueueForStream(second, "otherTest"))); } Task.WaitAll(adapter.QueueMessageBatchAsync(first, "test", new List <int>() { 1, 2, 3, 4 }, null, requestContext), adapter.QueueMessageBatchAsync(second, "otherTest", new List <int>() { 1, 2, 3, 4 }, null, requestContext)); }
public async Task QueueMessageBatchAsyncAllNoAck() { Mock <IKafkaBatchFactory> factoryMock = new Mock <IKafkaBatchFactory>(); Dictionary <string, object> requestContext = new Dictionary <string, object>(); factoryMock.Setup(x => x.ToKafkaMessage(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <IEnumerable <int> >(), requestContext)).Returns((Message)null); KafkaStreamProviderOptions differentOptions = new KafkaStreamProviderOptions(_options.ConnectionStrings, _options.TopicName, _options.ConsumerGroupName) { AckLevel = 0 }; KafkaQueueAdapter adapter = new KafkaQueueAdapter(_streamQueueMapper, differentOptions, _providerName, factoryMock.Object, _logger); Guid myGuid = Guid.NewGuid(); await adapter.QueueMessageBatchAsync(myGuid, "Test", new List <int>() { 1, 2, 3, 4 }, null, requestContext); }
public async Task QueueMessageBatchAsyncQueueingTwiceSameQueueTest() { Mock<IKafkaBatchFactory> factoryMock = new Mock<IKafkaBatchFactory>(); Dictionary<string, object> requestContext = new Dictionary<string, object>(); factoryMock.Setup(x => x.ToKafkaMessage(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<IEnumerable<int>>(), requestContext)).Returns(new Message() { Value = new byte[] { 0, 1, 2, 3 } }); KafkaQueueAdapter adapter = new KafkaQueueAdapter(_streamQueueMapper, _options, _providerName, factoryMock.Object, _logger); Guid myGuid = Guid.NewGuid(); await adapter.QueueMessageBatchAsync(myGuid, "Test", new List<int>() { 1, 2, 3, 4 }, null, requestContext); await adapter.QueueMessageBatchAsync(myGuid, "Test", new List<int>() { 1, 2, 3, 4 }, null, requestContext); }
public void QueueMessageBatchAsyncQueueingTwiceDifferentQueuesTest() { Mock<IKafkaBatchFactory> factoryMock = new Mock<IKafkaBatchFactory>(); Dictionary<string, object> requestContext = new Dictionary<string, object>(); factoryMock.Setup(x => x.ToKafkaMessage(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<IEnumerable<int>>(), requestContext)).Returns(new Message() { Value = new byte[] { 0, 1, 2, 3 } }); var twoQueuesStreamMapper = new HashRingBasedStreamQueueMapper(2, _options.TopicName); var twoQueuesOptions = new KafkaStreamProviderOptions(_options.ConnectionStrings, _options.TopicName, _options.ConsumerGroupName){NumOfQueues = 2}; KafkaQueueAdapter adapter = new KafkaQueueAdapter(_streamQueueMapper, _options, _providerName, factoryMock.Object, _logger); var first = Guid.NewGuid(); var second = Guid.NewGuid(); // Becuase we cannot mock the queue mapper.. we need to make sure we two guids that will return different queues... bool willGiveDifferentQueue = !(twoQueuesStreamMapper.GetQueueForStream(first, "test").Equals(twoQueuesStreamMapper.GetQueueForStream(second, "otherTest"))); while (!willGiveDifferentQueue) { second = Guid.NewGuid(); willGiveDifferentQueue = !(twoQueuesStreamMapper.GetQueueForStream(first, "test").Equals(twoQueuesStreamMapper.GetQueueForStream(second, "otherTest"))); } Task.WaitAll(adapter.QueueMessageBatchAsync(first, "test", new List<int>() { 1, 2, 3, 4 }, null, requestContext), adapter.QueueMessageBatchAsync(second, "otherTest", new List<int>() { 1, 2, 3, 4 }, null, requestContext)); }
public async Task QueueMessageBatchAsyncAllNoAck() { Mock<IKafkaBatchFactory> factoryMock = new Mock<IKafkaBatchFactory>(); Dictionary<string, object> requestContext = new Dictionary<string, object>(); factoryMock.Setup(x => x.ToKafkaMessage(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<IEnumerable<int>>(), requestContext)).Returns((Message)null); KafkaStreamProviderOptions differentOptions = new KafkaStreamProviderOptions(_options.ConnectionStrings, _options.TopicName, _options.ConsumerGroupName) {AckLevel = 0}; KafkaQueueAdapter adapter = new KafkaQueueAdapter(_streamQueueMapper, differentOptions, _providerName, factoryMock.Object, _logger); Guid myGuid = Guid.NewGuid(); await adapter.QueueMessageBatchAsync(myGuid, "Test", new List<int>() { 1, 2, 3, 4 }, null, requestContext); }