Exemple #1
0
        public void WatchIndexes_Retries_Until_Timeout_And_Returns_Last_Result()
        {
            var mockBucket = new Mock <IBucket>();

            mockBucket.Setup(x => x.Name).Returns("default");
            mockBucket.Setup(x => x.Query <IndexInfo>(It.IsAny <QueryRequest>()))
            .Returns(() => new QueryResult <IndexInfo>
            {
                Success = true,
                Rows    = new List <IndexInfo>
                {
                    new IndexInfo {
                        Name = "foo", State = "pending"
                    }
                }
            });

            var indexNamesToWatch = new List <string> {
                "foo"
            };

            var manager = new TestableBucketManager(mockBucket.Object);
            var result  = manager.WatchN1qlIndexes(indexNamesToWatch, TimeSpan.FromSeconds(1));

            Assert.IsTrue(result.Success);
            Assert.AreEqual(1, result.Value.Count);
            Assert.AreEqual("foo", result.Value.First().Name);
            Assert.AreEqual("pending", result.Value.First().State);

            mockBucket.Verify(x => x.Query <IndexInfo>(It.IsAny <QueryRequest>()), Times.AtLeastOnce);
        }
Exemple #2
0
        public void WatchIndexes_Retries_Until_Indexes_Are_Online()
        {
            var attempts = 0;

            var mockBucket = new Mock <IBucket>();

            mockBucket.Setup(x => x.Name).Returns("default");
            mockBucket.Setup(x => x.Query <IndexInfo>(It.IsAny <QueryRequest>()))
            .Returns(() => new QueryResult <IndexInfo>
            {
                Success = true,
                Rows    = new List <IndexInfo>
                {
                    new IndexInfo {
                        Name = "foo", State = attempts++ < 2 ? "pending" : "online"
                    }
                }
            });

            var indexNamesToWatch = new List <string> {
                "foo"
            };

            var manager = new TestableBucketManager(mockBucket.Object);
            var result  = manager.WatchN1qlIndexes(indexNamesToWatch, TimeSpan.MaxValue);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(1, result.Value.Count);
            Assert.AreEqual("foo", result.Value.First().Name);
            Assert.AreEqual("online", result.Value.First().State);

            mockBucket.Verify(x => x.Query <IndexInfo>(It.IsAny <QueryRequest>()), Times.Exactly(3));
        }
Exemple #3
0
        public void WatchIndexes_Returns_When_Query_Failed()
        {
            var mockBucket = new Mock <IBucket>();

            mockBucket.Setup(x => x.Name).Returns("default");
            mockBucket.Setup(x => x.Query <IndexInfo>(It.IsAny <QueryRequest>()))
            .Returns(new QueryResult <IndexInfo>
            {
                Success = false
            });

            var indexNamesToWatch = new List <string> {
                "foo"
            };

            var manager = new TestableBucketManager(mockBucket.Object);
            var result  = manager.WatchN1qlIndexes(indexNamesToWatch, TimeSpan.FromSeconds(20));

            Assert.IsFalse(result.Success);
            Assert.AreEqual(0, result.Value.Count);

            mockBucket.Verify(x => x.Query <IndexInfo>(It.IsAny <QueryRequest>()), Times.Exactly(1));
        }
        public void WatchIndexes_Retries_Until_Timeout_And_Returns_Last_Result()
        {
            var mockBucket = new Mock<IBucket>();
            mockBucket.Setup(x => x.Name).Returns("default");
            mockBucket.Setup(x => x.Query<IndexInfo>(It.IsAny<QueryRequest>()))
                .Returns(() => new QueryResult<IndexInfo>
                {
                    Success = true,
                    Rows = new List<IndexInfo>
                    {
                        new IndexInfo {Name = "foo", State = "pending"}
                    }
                });

            var indexNamesToWatch = new List<string> { "foo" };

            var manager = new TestableBucketManager(mockBucket.Object);
            var result = manager.WatchN1qlIndexes(indexNamesToWatch, TimeSpan.FromSeconds(1));

            Assert.IsTrue(result.Success);
            Assert.AreEqual(1, result.Value.Count);
            Assert.AreEqual("foo", result.Value.First().Name);
            Assert.AreEqual("pending", result.Value.First().State);

            mockBucket.Verify(x => x.Query<IndexInfo>(It.IsAny<QueryRequest>()), Times.AtLeastOnce);
        }
        public void WatchIndexes_Returns_When_Query_Failed()
        {
            var mockBucket = new Mock<IBucket>();
            mockBucket.Setup(x => x.Name).Returns("default");
            mockBucket.Setup(x => x.Query<IndexInfo>(It.IsAny<QueryRequest>()))
                .Returns(new QueryResult<IndexInfo>
                {
                    Success = false
                });

            var indexNamesToWatch = new List<string> { "foo" };

            var manager = new TestableBucketManager(mockBucket.Object);
            var result = manager.WatchN1qlIndexes(indexNamesToWatch, TimeSpan.FromSeconds(20));

            Assert.IsFalse(result.Success);
            Assert.AreEqual(0, result.Value.Count);

            mockBucket.Verify(x => x.Query<IndexInfo>(It.IsAny<QueryRequest>()), Times.Exactly(1));
        }
        public void WatchIndexes_Retries_Until_Indexes_Are_Online()
        {
            var attempts = 0;

            var mockBucket = new Mock<IBucket>();
            mockBucket.Setup(x => x.Name).Returns("default");
            mockBucket.Setup(x => x.Query<IndexInfo>(It.IsAny<QueryRequest>()))
                .Returns(() => new QueryResult<IndexInfo>
                {
                    Success = true,
                    Rows = new List<IndexInfo>
                    {
                        new IndexInfo {Name = "foo", State = attempts++ < 2 ? "pending" : "online"}
                    }
                });

            var indexNamesToWatch = new List<string> { "foo" };

            var manager = new TestableBucketManager(mockBucket.Object);
            var result = manager.WatchN1qlIndexes(indexNamesToWatch, TimeSpan.MaxValue);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(1, result.Value.Count);
            Assert.AreEqual("foo", result.Value.First().Name);
            Assert.AreEqual("online", result.Value.First().State);

            mockBucket.Verify(x => x.Query<IndexInfo>(It.IsAny<QueryRequest>()), Times.Exactly(3));
        }