public void MaximumMinimum()
 {
     var random = new Random();
     var max = (ushort)random.Next(ushort.MinValue, 9);
     var queue = Substitute.For<IQueueCount>();
     var qs = new QueueScaler<object>(queue, max);
     Assert.AreEqual(250, qs.Maximum);
 }
示例#2
0
        public void MaximumMinimum()
        {
            var random = new Random();
            var max    = (ushort)random.Next(ushort.MinValue, 9);
            var queue  = Substitute.For <IQueueCount>();
            var qs     = new QueueScaler <object>(queue, max);

            Assert.AreEqual(250, qs.Maximum);
        }
        public void ShouldScaleUp()
        {
            var queue = Substitute.For<IQueueCount>();
            queue.ApproixmateMessageCount().Returns(Task.FromResult<long?>(10000));

            var qs = new QueueScaler<object>(queue);
            var result = qs.ShouldScale();

            Assert.IsTrue(result.Value);

            queue.Received().ApproixmateMessageCount();
        }
示例#4
0
        public void ShouldScaleUp()
        {
            var queue = Substitute.For <IQueueCount>();

            queue.ApproixmateMessageCount().Returns(Task.FromResult <long?>(10000));

            var qs     = new QueueScaler <object>(queue);
            var result = qs.ShouldScale();

            Assert.IsTrue(result.Value);

            queue.Received().ApproixmateMessageCount();
        }
示例#5
0
        public void ShouldScaleThrows()
        {
            var queue = Substitute.For <IQueueCount>();

            queue.When(q => q.ApproixmateMessageCount()).Do(x => { throw new Exception(); });

            var qs     = new QueueScaler <object>(queue);
            var result = qs.ShouldScale();

            Assert.IsFalse(result.HasValue);

            queue.Received().ApproixmateMessageCount();
        }
        public void ShouldScaleDown()
        {
            var factory = Substitute.For<ITaskFactory<object>>();
            var queue = Substitute.For<IQueueCount>();
            queue.ApproixmateMessageCount().Returns(Task.FromResult<long?>(1));

            var qs = new QueueScaler<object>(queue, 12);
            qs.ScaleUp(factory, new object(), Guid.NewGuid().ToString());
            qs.ScaleUp(factory, new object(), Guid.NewGuid().ToString());

            var result = qs.ShouldScale();

            Assert.IsFalse(result.Value);

            queue.Received().ApproixmateMessageCount();
        }
示例#7
0
        public void ShouldScaleDown()
        {
            var factory = Substitute.For <ITaskFactory <object> >();
            var queue   = Substitute.For <IQueueCount>();

            queue.ApproixmateMessageCount().Returns(Task.FromResult <long?>(1));

            var qs = new QueueScaler <object>(queue, 12);

            qs.ScaleUp(factory, new object(), Guid.NewGuid().ToString());
            qs.ScaleUp(factory, new object(), Guid.NewGuid().ToString());

            var result = qs.ShouldScale();

            Assert.IsFalse(result.Value);

            queue.Received().ApproixmateMessageCount();
        }
示例#8
0
        public void ShouldScaleOptimal()
        {
            var random = new Random();
            var count  = (ushort)random.Next(ushort.MinValue, ushort.MaxValue);

            var factory = Substitute.For <ITaskFactory <object> >();

            var queue = Substitute.For <IQueueCount>();

            queue.ApproixmateMessageCount().Returns(Task.FromResult <long?>(count));

            var qs = new QueueScaler <object>(queue, count);

            qs.ScaleUp(factory, new object(), Guid.NewGuid().ToString());

            var result = qs.ShouldScale();

            Assert.IsNull(result);

            queue.Received().ApproixmateMessageCount();
        }
        public void ShouldScaleOptimal()
        {
            var random = new Random();
            var count = (ushort)random.Next(ushort.MinValue, ushort.MaxValue);

            var factory = Substitute.For<ITaskFactory<object>>();

            var queue = Substitute.For<IQueueCount>();
            queue.ApproixmateMessageCount().Returns(Task.FromResult<long?>(count));

            var qs = new QueueScaler<object>(queue, count);
            qs.ScaleUp(factory, new object(), Guid.NewGuid().ToString());

            var result = qs.ShouldScale();

            Assert.IsNull(result);

            queue.Received().ApproixmateMessageCount();
        }
        public void ShouldScaleThrows()
        {
            var queue = Substitute.For<IQueueCount>();
            queue.When(q => q.ApproixmateMessageCount()).Do(x => { throw new Exception(); });

            var qs = new QueueScaler<object>(queue);
            var result = qs.ShouldScale();

            Assert.IsFalse(result.HasValue);

            queue.Received().ApproixmateMessageCount();
        }