/// <exception cref="System.Exception"></exception> public virtual void TestChangeTrackerBackoffExceptions() { CustomizableMockHttpClient mockHttpClient = new CustomizableMockHttpClient(); mockHttpClient.AddResponderThrowExceptionAllRequests(); TestChangeTrackerBackoff(mockHttpClient); }
public HttpClient GetHttpClient() { CustomizableMockHttpClient mockHttpClient = new CustomizableMockHttpClient(); mockHttpClient.AddResponderThrowExceptionAllRequests(); return(mockHttpClient); }
/// <exception cref="System.Exception"></exception> public virtual void TestHeaders() { CustomizableMockHttpClient mockHttpClient = new CustomizableMockHttpClient(); mockHttpClient.AddResponderThrowExceptionAllRequests(); HttpClientFactory mockHttpClientFactory = new _HttpClientFactory_741(mockHttpClient ); Uri remote = GetReplicationURL(); manager.SetDefaultHttpClientFactory(mockHttpClientFactory); Replication puller = database.CreatePullReplication(remote); IDictionary <string, object> headers = new Dictionary <string, object>(); headers.Put("foo", "bar"); puller.SetHeaders(headers); puller.Start(); Sharpen.Thread.Sleep(2000); puller.Stop(); bool foundFooHeader = false; IList <HttpWebRequest> requests = mockHttpClient.GetCapturedRequests(); foreach (HttpWebRequest request in requests) { Header[] requestHeaders = request.GetHeaders("foo"); foreach (Header requestHeader in requestHeaders) { foundFooHeader = true; NUnit.Framework.Assert.AreEqual("bar", requestHeader.GetValue()); } } NUnit.Framework.Assert.IsTrue(foundFooHeader); manager.SetDefaultHttpClientFactory(null); }
/// <exception cref="System.Exception"></exception> public virtual void TestChangeTrackerInvalidJson() { Uri testURL = GetReplicationURL(); CustomizableMockHttpClient mockHttpClient = new CustomizableMockHttpClient(); mockHttpClient.AddResponderThrowExceptionAllRequests(); IChangeTrackerClient client = new _ChangeTrackerClient_290(mockHttpClient); ChangeTracker changeTracker = new ChangeTracker(testURL, ChangeTracker.ChangeTrackerMode .LongPoll, 0, client); var task = Task.Factory.StartNew(() => { changeTracker.Start(); }); task.Start(); try { // expected behavior: // when: // mockHttpClient throws IOExceptions -> it should start high and then back off and numTimesExecute should be low for (int i = 0; i < 30; i++) { int numTimesExectutedAfter10seconds = 0; try { Sharpen.Thread.Sleep(1000); // take a snapshot of num times the http client was called after 10 seconds if (i == 10) { numTimesExectutedAfter10seconds = mockHttpClient.GetCapturedRequests().Count; } // take another snapshot after 20 seconds have passed if (i == 20) { // by now it should have backed off, so the delta between 10s and 20s should be small int delta = mockHttpClient.GetCapturedRequests().Count - numTimesExectutedAfter10seconds; NUnit.Framework.Assert.IsTrue(delta < 25); } } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } } } finally { changeTracker.Stop(); } }