Exemple #1
0
        public async Task ShutdownRespectsTimeout()
        {
            var logger = new Mock <ILogger>()
            {
                DefaultValue = DefaultValue.Mock
            };
            var dataAdapter = new Mock <IRedisDataAdapter> {
                DefaultValue = DefaultValue.Mock
            };
            var queueId = QueueId.GetQueueId(TestConstants.ValidQueueName, 0, 0);

            var rqar = (RedisQueueAdapterReceiver)RedisQueueAdapterReceiver.Create(
                logger.Object,
                queueId,
                TestConstants.ValidServiceId,
                TestConstants.ValidClusterId,
                TestConstants.ValidRedisStreamOptions,
                CachedConnectionMultiplexerFactory.Default,
                dataAdapter.Object);

            var rdm = new Mock <IRedisDataManager> {
                DefaultValue = DefaultValue.Mock
            };

            rqar.TestHook_Queue = rdm.Object;

            rdm
            .Setup(x => x.UnsubscribeAsync(It.IsAny <CancellationToken>()))
            .Callback((CancellationToken ct) => Thread.Sleep(100))
            .Returns(Task.CompletedTask);

            await AssertEx.ThrowsAnyAsync <OperationCanceledException>(() => rqar.Shutdown(TimeSpan.FromMilliseconds(0)));
        }
Exemple #2
0
 public IEnumerable <QueueId> GetAllQueues()
 {
     return(_queueMap.Values
            .SelectMany(queueMap => queueMap.GetAllRingMembers())
            .Select(identifiers =>
                    QueueId.GetQueueId(identifiers.QueueNamePrefix, identifiers.QueueId, identifiers.UniformHashCache)));
 }
Exemple #3
0
        public async Task QueueMessageBatchAsyncWithSingleEventPublishesToRedisChannel()
        {
            var logger = new Mock <ILogger>()
            {
                DefaultValue = DefaultValue.Mock
            };
            var mockConnectionMultiplexer = new Mock <IConnectionMultiplexer> {
                DefaultValue = DefaultValue.Mock
            };
            var mockSubscriber = new Mock <ISubscriber> {
                DefaultValue = DefaultValue.Mock
            };

            mockConnectionMultiplexer.Setup(x => x.GetSubscriber(It.IsAny <object>())).Returns(mockSubscriber.Object);

            var actualMessages = new List <RedisValue>();

            mockSubscriber
            .Setup(x => x.PublishAsync(It.IsAny <RedisChannel>(), It.IsAny <RedisValue>(), It.IsAny <CommandFlags>()))
            .Callback((RedisChannel channel, RedisValue redisValue, CommandFlags commandFlags) => actualMessages.Add(redisValue))
            .ReturnsAsync(0);

            var mockRedisDataAdapter = new Mock <IRedisDataAdapter> {
                DefaultValue = DefaultValue.Mock
            };

            mockRedisDataAdapter
            .Setup(x => x.ToRedisValue <string>(ValidStreamGuid, ValidStreamNamespace, It.IsAny <IEnumerable <string> >(), null))
            .Returns((Guid streamGuid, string streamNamespace, IEnumerable <string> events, Dictionary <string, object> requestContext) => JsonConvert.SerializeObject(events));

            var mockQueueStreamMapper = new Mock <IStreamQueueMapper> {
                DefaultValue = DefaultValue.Mock
            };

            mockQueueStreamMapper
            .Setup(x => x.GetQueueForStream(ValidStreamGuid, ValidStreamNamespace))
            .Returns(QueueId.GetQueueId(null, 0, 0));

            var rqa = new RedisQueueAdapter(
                ValidRedisStreamOptions,
                MockConnectionMultiplexerFactory.Returns(mockConnectionMultiplexer.Object),
                mockRedisDataAdapter.Object,
                mockQueueStreamMapper.Object,
                logger.Object,
                ValidServiceId,
                ValidClusterId,
                ValidProviderName);

            var expectedMessages = new List <RedisValue>();

            for (var i = 0; i < 100; i++)
            {
                var message = new[] { i.ToString() };
                expectedMessages.Add(JsonConvert.SerializeObject(message));
                await rqa.QueueMessageBatchAsync(ValidStreamGuid, ValidStreamNamespace, message, null, null);
            }

            AssertEx.Equal(expectedMessages, actualMessages);
        }
Exemple #4
0
 public IEnumerable <QueueId> GetQueuesForRange(IRingRange range)
 {
     return
         (from ring in _queueMap.Values
          from queueId in ring.GetAllRingMembers()
          where range.InRange(queueId.GetUniformHashCode())
          select QueueId.GetQueueId(queueId.QueueNamePrefix, queueId.QueueId, queueId.UniformHashCache));
 }
        public TimedQueueCacheTests()
        {
            Mock <Logger> loggerMock = new Mock <Logger>();

            _logger                = loggerMock.Object;
            _defaultId             = QueueId.GetQueueId("defaultQueue");
            _defaultCacheSize      = 4096;
            _defaultCacheBucketNum = 10;
        }
Exemple #6
0
        public QueueId GetQueueForStream(Guid streamGuid, string streamNamespace)
        {
            if (!_queueMap.ContainsKey(streamNamespace))
            {
                throw new ArgumentException("No queue for supplied namespace");
            }

            var identifier = _queueMap[streamNamespace].CalculateResponsible(streamGuid);             // todo: Error handling

            return(QueueId.GetQueueId(identifier.QueueNamePrefix, identifier.QueueId, identifier.UniformHashCache));
        }
Exemple #7
0
        public KafkaQueueAdapterReceiverUnitTests()
        {
            Mock <Logger> loggerMock = new Mock <Logger>();

            _logger = loggerMock.Object;

            var connectionStrings = new List <Uri> {
                new Uri("http://192.168.10.27:9092")
            };
            var topicName         = "TestTopic";
            var consumerGroupName = "TestConsumerGroup";

            _options = new KafkaStreamProviderOptions(connectionStrings.ToArray(), topicName, consumerGroupName);
            _id      = QueueId.GetQueueId("test", 0, 0);
        }