public ScaleoutStreamManager(Func<int, IList<Message>, Task> send,
                                     Action<int, ulong, ScaleoutMessage> receive,
                                     int streamCount,
                                     ILogger logger,
                                     IPerformanceCounterManager performanceCounters,
                                     ScaleoutOptions configuration)
        {
            if (configuration.QueueBehavior != QueuingBehavior.Disabled && configuration.MaxQueueLength == 0)
            {
                throw new InvalidOperationException(Resources.Error_ScaleoutQueuingConfig);
            }

            _streams = new ScaleoutStream[streamCount];
            _send = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            performanceCounters.ScaleoutStreamCountTotal.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountBuffering.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountOpen.RawValue = 0;

            for (int i = 0; i < streamCount; i++)
            {
                _streams[i] = new ScaleoutStream(logger, "Stream(" + i + ")", configuration.QueueBehavior, configuration.MaxQueueLength, performanceCounters);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection<ScaleoutMappingStore>(receiveMapping);
        }
        public ScaleoutStreamManager(Func <int, IList <Message>, Task> send,
                                     Action <int, ulong, ScaleoutMessage> receive,
                                     int streamCount,
                                     ILogger logger,
                                     IPerformanceCounterManager performanceCounters,
                                     ScaleoutOptions configuration)
        {
            if (configuration.QueueBehavior != QueuingBehavior.Disabled && configuration.MaxQueueLength == 0)
            {
                throw new InvalidOperationException(Resources.Error_ScaleoutQueuingConfig);
            }

            _streams = new ScaleoutStream[streamCount];
            _send    = send;
            _receive = receive;

            var receiveMapping = new ScaleoutMappingStore[streamCount];

            performanceCounters.ScaleoutStreamCountTotal.RawValue     = streamCount;
            performanceCounters.ScaleoutStreamCountBuffering.RawValue = streamCount;
            performanceCounters.ScaleoutStreamCountOpen.RawValue      = 0;

            for (int i = 0; i < streamCount; i++)
            {
                _streams[i]       = new ScaleoutStream(logger, "Stream(" + i + ")", configuration.QueueBehavior, configuration.MaxQueueLength, performanceCounters);
                receiveMapping[i] = new ScaleoutMappingStore();
            }

            Streams = new ReadOnlyCollection <ScaleoutMappingStore>(receiveMapping);
        }
        public void StreamManagerValidatesScaleoutConfig()
        {
            var loggerFactory = new Mock<ILoggerFactory>();
            var perfCounters = new SignalRPerformanceCounterManager(loggerFactory.Object);
            var config = new ScaleoutOptions();

            config.QueueBehavior = QueuingBehavior.Always;
            config.MaxQueueLength = 0;

            Assert.Throws<InvalidOperationException>(() => new ScaleoutStreamManager((int x, IList<Message> list) => { return TaskAsyncHelper.Empty; },
                (int x, ulong y, ScaleoutMessage msg) => { },
                0,
                new Mock<ILogger>().Object,
                perfCounters,
                config));
        }