public void ReplicationInformerShouldThrowAfterSecondTimeoutIfReadStripingEnabled() { using (var replicationInformer = new ReplicationInformer(new DocumentConvention { FailoverBehavior = FailoverBehavior.ReadFromAllServers }, new HttpJsonRequestFactory(MaxNumber)) { ReplicationDestinations = { new OperationMetadata("http://localhost:2"), new OperationMetadata("http://localhost:3"), new OperationMetadata("http://localhost:4") } }) { var urlsTried = new List<string>(); var webException = (WebException) Assert.Throws<AggregateException>(() => replicationInformer.ExecuteWithReplicationAsync<int>("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), 1, 1, url => { urlsTried.Add(url.Url); throw new WebException("Timeout", WebExceptionStatus.Timeout); }).Wait()).ExtractSingleInnerException(); 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); } }
public void ReplicationInformerShouldThrowAfterSecondTimeout() { using (var replicationInformer = new ReplicationInformer(new DocumentConvention { FailoverBehavior = FailoverBehavior.AllowReadsFromSecondariesAndWritesToSecondaries }) { ReplicationDestinations = { new OperationMetadata("http://localhost:2"), new OperationMetadata("http://localhost:3"), new OperationMetadata("http://localhost:4") } }) { var urlsTried = new List<string>(); var webException = (WebException)Assert.Throws<AggregateException>(() => { replicationInformer.ExecuteWithReplicationAsync("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), 1, 1, async url => { urlsTried.Add(url.Url); throw new WebException("Timeout", WebExceptionStatus.Timeout); return 1; }).Wait(); }).ExtractSingleInnerException(); 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); } }
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.ExecuteWithReplicationAsync("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), req, req, async url => { urlsTried.Add(Tuple.Create(req, url.Url)); return 1; }).Wait(); } var expectedUrls = GetExpectedUrlForReadStriping().Take(urlsTried.Count).ToList(); Assert.Equal(expectedUrls, urlsTried); }
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.ExecuteWithReplicationAsync("GET", "http://localhost:1", new OperationCredentials(null, CredentialCache.DefaultNetworkCredentials), req, 1,async url => { urlsTried.Add(Tuple.Create(req, url.Url)); if (url.Url.EndsWith("1")) throw new WebException("bad", WebExceptionStatus.ConnectFailure); return 1; }).Wait(); } var expectedUrls = GetExpectedUrlForFailure().Take(urlsTried.Count).ToList(); Assert.Equal(expectedUrls, urlsTried); }
public async Task DeleteTypeAsync(string type, CancellationToken token = default(CancellationToken)) { AssertInitialized(); if (string.IsNullOrEmpty(type)) { throw new InvalidOperationException("Prefix cannot be empty"); } await ReplicationInformer.UpdateReplicationInformationIfNeededAsync().ConfigureAwait(false); await ReplicationInformer.ExecuteWithReplicationAsync(Url, HttpMethods.Delete, async (url, timeSeriesName) => { var requestUriString = string.Format(CultureInfo.InvariantCulture, "{0}ts/{1}/types/{2}", url, timeSeriesName, type); using (var request = CreateHttpJsonRequest(requestUriString, HttpMethods.Delete)) { return(await request.ReadResponseJsonAsync().WithCancellation(token).ConfigureAwait(false)); } }, token).ConfigureAwait(false); }
public async Task DeleteKeyAsync(string type, string key, CancellationToken token = new CancellationToken()) { AssertInitialized(); if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(key)) { throw new InvalidOperationException("Data is invalid"); } await ReplicationInformer.UpdateReplicationInformationIfNeededAsync().ConfigureAwait(false); await ReplicationInformer.ExecuteWithReplicationAsync(Url, HttpMethods.Post, async (url, timeSeriesName) => { var requestUriString = string.Format(CultureInfo.InvariantCulture, "{0}ts/{1}/delete-key/{2}?key={3}", url, timeSeriesName, type, Uri.EscapeDataString(key)); using (var request = CreateHttpJsonRequest(requestUriString, HttpMethods.Delete)) { return(await request.ReadResponseJsonAsync().WithCancellation(token).ConfigureAwait(false)); } }, token).ConfigureAwait(false); }
public void ReplicationInformerShouldThrowAfterSecondTimeoutIfReadStripingEnabled_Async() { var replicationInformer = new ReplicationInformer(new DocumentConvention { FailoverBehavior = FailoverBehavior.ReadFromAllServers }) { 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 aggregateException = Assert.Throws<AggregateException>(() => replicationInformer.ExecuteWithReplicationAsync<int>("GET", "http://localhost:1", 1, 1, url => { urlsTried.Add(url); return new CompletedTask<int>(new WebException("Timeout", WebExceptionStatus.Timeout)); }).Wait() ); var webException = aggregateException.ExtractSingleInnerException() as WebException; Assert.NotNull(webException); Assert.Equal(WebExceptionStatus.Timeout, webException.Status); Assert.Equal(2, urlsTried.Count); Assert.Equal("http://localhost:3", urlsTried[0]); // striped Assert.Equal("http://localhost:1", urlsTried[1]); // master }