public void MaxAddCountIsBucketSizeBecauseCacheIsFullTest()
        {
            Guid   streamGuid      = Guid.NewGuid();
            string streamNamespace = "TestTimedCache";

            Mock <IBatchContainer> batchMock1 = GenerateBatchContainerMock(streamGuid, streamNamespace, 1);
            Mock <IBatchContainer> batchMock2 = GenerateBatchContainerMock(streamGuid, streamNamespace, 2);
            Mock <IBatchContainer> batchMock3 = GenerateBatchContainerMock(streamGuid, streamNamespace, 3);
            Mock <IBatchContainer> batchMock4 = GenerateBatchContainerMock(streamGuid, streamNamespace, 4);
            Mock <IBatchContainer> batchMock5 = GenerateBatchContainerMock(streamGuid, streamNamespace, 5);
            Mock <IBatchContainer> batchMock6 = GenerateBatchContainerMock(streamGuid, streamNamespace, 6);

            List <IBatchContainer> msgs = new List <IBatchContainer>()
            {
                batchMock1.Object, batchMock2.Object, batchMock3.Object, batchMock4.Object, batchMock5.Object, batchMock6.Object
            };

            var cache = new TimedQueueCache(_defaultId, TimeSpan.FromSeconds(1), msgs.Count, msgs.Count / 2, _logger);

            cache.AddToCache(msgs);

            Task.Delay(TimeSpan.FromSeconds(2)).Wait();

            Assert.IsTrue(!cache.IsUnderPressure());
            Assert.AreEqual(2, cache.MaxAddCount);
        }
        public void CacheUnderPressureBecauseTimespanGuaranteeTest()
        {
            Guid   streamGuid      = Guid.NewGuid();
            string streamNamespace = "TestTimedCache";

            Mock <IBatchContainer> batchMock1 = GenerateBatchContainerMock(streamGuid, streamNamespace, 1);
            Mock <IBatchContainer> batchMock2 = GenerateBatchContainerMock(streamGuid, streamNamespace, 2);
            Mock <IBatchContainer> batchMock3 = GenerateBatchContainerMock(streamGuid, streamNamespace, 3);

            List <IBatchContainer> msgs = new List <IBatchContainer>()
            {
                batchMock1.Object, batchMock2.Object, batchMock3.Object
            };

            var cache = new TimedQueueCache(_defaultId, TimeSpan.FromHours(1), msgs.Count, _defaultCacheBucketNum, _logger);

            cache.AddToCache(msgs);

            Assert.IsTrue(cache.IsUnderPressure());
        }
        public void CacheIsNotUnderPressureBecauseTimespanHasPassedAndNoSlowConsumersTest()
        {
            Guid   streamGuid      = Guid.NewGuid();
            string streamNamespace = "TestTimedCache";

            Mock <IBatchContainer> batchMock1 = GenerateBatchContainerMock(streamGuid, streamNamespace, 1);
            Mock <IBatchContainer> batchMock2 = GenerateBatchContainerMock(streamGuid, streamNamespace, 2);
            Mock <IBatchContainer> batchMock3 = GenerateBatchContainerMock(streamGuid, streamNamespace, 3);

            List <IBatchContainer> msgs = new List <IBatchContainer>()
            {
                batchMock1.Object, batchMock2.Object, batchMock3.Object
            };

            var cache = new TimedQueueCache(_defaultId, TimeSpan.FromSeconds(1), msgs.Count, _defaultCacheBucketNum, _logger);

            cache.AddToCache(msgs);

            Task.Delay(TimeSpan.FromSeconds(2)).Wait();

            Assert.IsTrue(!cache.IsUnderPressure());
            Assert.AreEqual(1, cache.MaxAddCount);
        }
        public void CacheUnderPressureBecauseOfSlowConsumersTest()
        {
            Guid   streamGuid      = Guid.NewGuid();
            string streamNamespace = "TestTimedCache";

            Mock <IBatchContainer> batchMock1 = GenerateBatchContainerMock(streamGuid, streamNamespace, 1);
            Mock <IBatchContainer> batchMock2 = GenerateBatchContainerMock(streamGuid, streamNamespace, 2);
            Mock <IBatchContainer> batchMock3 = GenerateBatchContainerMock(streamGuid, streamNamespace, 3);

            List <IBatchContainer> msgs = new List <IBatchContainer>()
            {
                batchMock1.Object, batchMock2.Object, batchMock3.Object
            };

            var cache = new TimedQueueCache(_defaultId, TimeSpan.FromSeconds(1), msgs.Count, _defaultCacheBucketNum, _logger);

            cache.AddToCache(msgs);

            var cursor = cache.GetCacheCursor(streamGuid, streamNamespace, batchMock1.Object.SequenceToken);

            Task.Delay(TimeSpan.FromSeconds(2)).Wait();

            Assert.IsTrue(cache.IsUnderPressure());
        }