示例#1
0
        public async Task add_key_exception_once_get_both()
        {
            _store.Setup(x => x.WriteEvents(Moq.It.IsAny <string>(), Moq.It.IsAny <IFullEvent[]>(), Moq.It.IsAny <IDictionary <string, string> >(), Moq.It.IsAny <long?>())).Throws <Exception>();

            _cache = new Internal.DelayedCache(_metrics.Object, _store.Object, TimeSpan.FromSeconds(5), "test", int.MaxValue, int.MaxValue, TimeSpan.MaxValue, (a, b, c, d, e) => "test");

            var msg = new Moq.Mock <IDelayedMessage>();

            msg.Setup(x => x.MessageId).Returns("test");
            await _cache.Add("test", null, new[] { msg.Object });

            await _cache.Add("test", "test", new[] { msg.Object });

            var size = await _cache.Size("test", "test");

            Assert.AreEqual(1, size);

            // Verify that Pull will get the null key message AND the "test" key message
            var result = await _cache.Pull("test", "test");

            // Todo: cache uses rand to pull non-specific channel, will have to fake rand to turn this into
            // Assert.AreEqual(2, result.Length);
            Assert.GreaterOrEqual(1, result.Length);
            _store.Verify(x => x.WriteEvents(Moq.It.IsAny <string>(), Moq.It.IsAny <IFullEvent[]>(), Moq.It.IsAny <IDictionary <string, string> >(), Moq.It.IsAny <long?>()), Moq.Times.Once);
        }
示例#2
0
        public async Task add_and_pull()
        {
            _cache = new Internal.DelayedCache(_metrics.Object, _store.Object, TimeSpan.FromSeconds(1), "test", int.MaxValue, int.MaxValue, TimeSpan.MaxValue, (a, b, c, d, e) => "test");

            var msg = new Moq.Mock <IDelayedMessage>();

            msg.Setup(x => x.MessageId).Returns("test");
            await _cache.Add("test", "test", new[] { msg.Object });

            var size = await _cache.Size("test", "test");

            Assert.AreEqual(1, size);

            var result = await _cache.Pull("test", "test");

            Assert.AreEqual(1, result.Length);
            Assert.AreEqual("test", result[0].MessageId);
        }
示例#3
0
        public async Task add_no_key_flushes_to_store()
        {
            _store.Setup(x => x.WriteEvents(Moq.It.IsAny <string>(), Moq.It.IsAny <IFullEvent[]>(), Moq.It.IsAny <IDictionary <string, string> >(), Moq.It.IsAny <long?>())).Returns(Task.FromResult(0L));

            _cache = new Internal.DelayedCache(_metrics.Object, _store.Object, TimeSpan.FromSeconds(5), "test", int.MaxValue, int.MaxValue, TimeSpan.MaxValue, (a, b, c, d, e) => "test");

            var msg = new Moq.Mock <IDelayedMessage>();

            msg.Setup(x => x.MessageId).Returns("test");
            await _cache.Add("test", null, new[] { msg.Object });

            var size = await _cache.Size("test", "test");

            Assert.AreEqual(0, size);

            var result = await _cache.Pull("test", "test");

            Assert.AreEqual(0, result.Length);
            _store.Verify(x => x.WriteEvents(Moq.It.IsAny <string>(), Moq.It.IsAny <IFullEvent[]>(), Moq.It.IsAny <IDictionary <string, string> >(), Moq.It.IsAny <long?>()), Moq.Times.Once);
        }