コード例 #1
0
        public void CursorRunningOnCacheMessagesFromMultipleStreamsGettingCursorWithOldTokenTest()
        {
            Guid   streamGuid      = Guid.NewGuid();
            string streamNamespace = "TestTimedCache";

            Guid   otherGuid      = Guid.NewGuid();
            string otherNamespace = "Other";

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

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

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

            cache.AddToCache(msgs);

            Exception placeholder;

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

            Assert.AreEqual(5, cache.Size);

            Assert.IsTrue(cursor.MoveNext(), "Couldn't move next on cursor");
            Assert.AreEqual(cursor.GetCurrent(out placeholder), batchMock5.Object, "Didn't get the first object");
            Assert.IsTrue(cursor.MoveNext(), "Couldn't move next on cursor");
            Assert.AreEqual(cursor.GetCurrent(out placeholder), batchMock6.Object, "Didn't get the second object");
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void InsertOneMessageEmptyCollection()
        {
            List <IBatchContainer> msgs = new List <IBatchContainer>();

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

            cache.AddToCache(msgs);

            Assert.AreEqual(0, cache.Size);
        }
コード例 #4
0
        public void InsertOneMessageTest()
        {
            Mock <IBatchContainer> batchMock = new Mock <IBatchContainer>();
            List <IBatchContainer> msgs      = new List <IBatchContainer>()
            {
                batchMock.Object
            };

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

            cache.AddToCache(msgs);

            Assert.AreEqual(1, cache.Size);
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public void MessageRemovalTest()
        {
            Mock <IBatchContainer> batchMock1 = new Mock <IBatchContainer>();
            Mock <IBatchContainer> batchMock2 = new Mock <IBatchContainer>();
            Mock <IBatchContainer> batchMock3 = new Mock <IBatchContainer>();

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

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

            cache.AddToCache(msgs);

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

            IList <IBatchContainer> outContainers = new List <IBatchContainer>();

            cache.TryPurgeFromCache(out outContainers);

            Assert.AreEqual(0, cache.Size);
            Assert.AreEqual(3, outContainers.Count);
        }
コード例 #8
0
        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());
        }