Esempio n. 1
0
		public void ReadStriping()
		{
			var replicationInformer = new ReplicationInformer(new DocumentConvention
			{
				FailoverBehavior = FailoverBehavior.ReadFromAllServers
			})
			{
				ReplicationDestinations =
					{
						new OperationMetadata("http://localhost:2"),
						new OperationMetadata("http://localhost:3"),
						new OperationMetadata("http://localhost:4"),
					}
			};

			var urlsTried = new List<Tuple<int, string>>();
			for (int i = 0; i < 10; i++)
			{
				var req = i + 1;
				replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), req, req, url =>
				{
					urlsTried.Add(Tuple.Create(req, url.Url));
					return 1;
				});
			}
			var expectedUrls = GetExpectedUrlForReadStriping().Take(urlsTried.Count).ToList();

			Assert.Equal(expectedUrls, urlsTried);
		}
Esempio n. 2
0
		public void ReplicationInformerShouldThrowAfterSecondTimeoutIfReadStripingEnabled()
		{
			var replicationInformer = new ReplicationInformer(new DocumentConvention
			{
				FailoverBehavior = FailoverBehavior.ReadFromAllServers
			})
			{
				ReplicationDestinations =
					{
						new OperationMetadata("http://localhost:2"),
						new OperationMetadata("http://localhost:3"),
						new OperationMetadata("http://localhost:4")
					}
			};

			var urlsTried = new List<string>();

			var webException = Assert.Throws<WebException>(() =>
			{
				replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), 1, 1, url =>
				{
					urlsTried.Add(url.Url);
					throw new WebException("Timeout", WebExceptionStatus.Timeout);

					return 1;
				});
			});

			Assert.Equal(2, urlsTried.Count);
			Assert.Equal("http://localhost:3", urlsTried[0]); // striped
			Assert.Equal("http://localhost:1", urlsTried[1]); // master

			Assert.Equal(WebExceptionStatus.Timeout, webException.Status);
		}
Esempio n. 3
0
		public void BackoffStrategy()
		{
			var replicationInformer = new ReplicationInformer(new DocumentConvention())
			{
				ReplicationDestinations =
					{
						new OperationMetadata("http://localhost:2")
					}
			};

			var urlsTried = new List<Tuple<int, string>>();
			for (int i = 0; i < 5000; i++)
			{
				var req = i + 1;
				replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), req, 1, url =>
				{
					urlsTried.Add(Tuple.Create(req, url.Url));
					if (url.Url.EndsWith("1"))
						throw new WebException("bad", WebExceptionStatus.ConnectFailure);

					return 1;
				});
			}
			var expectedUrls = GetExpectedUrlForFailure().Take(urlsTried.Count).ToList();

			Assert.Equal(expectedUrls, urlsTried);
		}
Esempio n. 4
0
        public void ReplicationInformerShouldThrowAfterSecondTimeoutIfReadStripingEnabled()
        {
            var replicationInformer = new ReplicationInformer(new DocumentConvention
            {
                FailoverBehavior = FailoverBehavior.ReadFromAllServers
            })
            {
                ReplicationDestinations =
                {
                    new OperationMetadata("http://localhost:2"),
                    new OperationMetadata("http://localhost:3"),
                    new OperationMetadata("http://localhost:4")
                }
            };

            var urlsTried = new List <string>();

            var webException = Assert.Throws <WebException>(() =>
            {
                replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), 1, 1, url =>
                {
                    urlsTried.Add(url.Url);
                    throw new WebException("Timeout", WebExceptionStatus.Timeout);

                    return(1);
                });
            });

            Assert.Equal(2, urlsTried.Count);
            Assert.Equal("http://localhost:3", urlsTried[0]);             // striped
            Assert.Equal("http://localhost:1", urlsTried[1]);             // master

            Assert.Equal(WebExceptionStatus.Timeout, webException.Status);
        }
Esempio n. 5
0
        public void BackoffStrategy()
        {
            var replicationInformer = new ReplicationInformer(new DocumentConvention())
            {
                ReplicationDestinations =
                {
                    new ReplicationDestinationData
                    {
                        Url = "http://localhost:2"
                    },
                }
            };

            var urlsTried = new List <Tuple <int, string> >();

            for (int i = 0; i < 5000; i++)
            {
                var req = i + 1;
                replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", req, 1, url =>
                {
                    urlsTried.Add(Tuple.Create(req, url));
                    if (url.EndsWith("1"))
                    {
                        throw new WebException("bad", WebExceptionStatus.ConnectFailure);
                    }

                    return(1);
                });
            }
            var expectedUrls = GetExepctedUrlForFailure().Take(urlsTried.Count).ToList();

            Assert.Equal(expectedUrls, urlsTried);
        }
Esempio n. 6
0
        public void ReadStriping()
        {
            var replicationInformer = new ReplicationInformer(new DocumentConvention
            {
                FailoverBehavior = FailoverBehavior.ReadFromAllServers
            })
            {
                ReplicationDestinations =
                {
                    new OperationMetadata("http://localhost:2"),
                    new OperationMetadata("http://localhost:3"),
                    new OperationMetadata("http://localhost:4"),
                }
            };

            var urlsTried = new List <Tuple <int, string> >();

            for (int i = 0; i < 10; i++)
            {
                var req = i + 1;
                replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), req, req, url =>
                {
                    urlsTried.Add(Tuple.Create(req, url.Url));
                    return(1);
                });
            }
            var expectedUrls = GetExpectedUrlForReadStriping().Take(urlsTried.Count).ToList();

            Assert.Equal(expectedUrls, urlsTried);
        }
Esempio n. 7
0
		public void ReplicationInformerShouldThrowAfterSecondTimeout()
		{
			var replicationInformer = new ReplicationInformer(new DocumentConvention
			{
				FailoverBehavior = FailoverBehavior.AllowReadsFromSecondariesAndWritesToSecondaries
			})
			{
				ReplicationDestinations =
					{
						new ReplicationDestinationData
						{
							Url = "http://localhost:2"
						},
						new ReplicationDestinationData
						{
							Url = "http://localhost:3"
						},
						new ReplicationDestinationData
						{
							Url = "http://localhost:4"
						},
					}
			};

			var urlsTried = new List<string>();

			var webException = Assert.Throws<WebException>(() =>
			{
				replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", 1, 1, url =>
				{
					urlsTried.Add(url);
					throw new WebException("Timeout", WebExceptionStatus.Timeout);

					return 1;
				});
			});

			Assert.Equal(2, urlsTried.Count);
			Assert.Equal("http://localhost:1", urlsTried[0]);
			Assert.Equal("http://localhost:2", urlsTried[1]);

			Assert.Equal(WebExceptionStatus.Timeout, webException.Status);
		}
Esempio n. 8
0
        public void ReplicationInformerShouldThrowAfterSecondTimeout()
        {
            var replicationInformer = new ReplicationInformer(new DocumentConvention
            {
                FailoverBehavior = FailoverBehavior.AllowReadsFromSecondariesAndWritesToSecondaries
            })
            {
                ReplicationDestinations =
                {
                    new ReplicationDestinationData
                    {
                        Url = "http://localhost:2"
                    },
                    new ReplicationDestinationData
                    {
                        Url = "http://localhost:3"
                    },
                    new ReplicationDestinationData
                    {
                        Url = "http://localhost:4"
                    },
                }
            };

            var urlsTried = new List <string>();

            var webException = Assert.Throws <WebException>(() =>
            {
                replicationInformer.ExecuteWithReplication("GET", "http://localhost:1", 1, 1, url =>
                {
                    urlsTried.Add(url);
                    throw new WebException("Timeout", WebExceptionStatus.Timeout);

                    return(1);
                });
            });

            Assert.Equal(2, urlsTried.Count);
            Assert.Equal("http://localhost:1", urlsTried[0]);
            Assert.Equal("http://localhost:2", urlsTried[1]);

            Assert.Equal(WebExceptionStatus.Timeout, webException.Status);
        }