/// <exception cref="System.Exception"></exception> private void TestChangeTrackerBackoff(CustomizableMockHttpClient mockHttpClient) { Uri testURL = GetReplicationURL(); CountDownLatch changeTrackerFinishedSignal = new CountDownLatch(1); ChangeTrackerClient client = new _ChangeTrackerClient_234(changeTrackerFinishedSignal , mockHttpClient); ChangeTracker changeTracker = new ChangeTracker(testURL, ChangeTracker.ChangeTrackerMode .LongPoll, false, 0, client); changeTracker.Start(); // sleep for a few seconds Sharpen.Thread.Sleep(5 * 1000); // make sure we got less than 10 requests in those 10 seconds (if it was hammering, we'd get a lot more) NUnit.Framework.Assert.IsTrue(mockHttpClient.GetCapturedRequests().Count < 25); NUnit.Framework.Assert.IsTrue(changeTracker.backoff.GetNumAttempts() > 0); mockHttpClient.ClearResponders(); mockHttpClient.AddResponderReturnEmptyChangesFeed(); // at this point, the change tracker backoff should cause it to sleep for about 3 seconds // and so lets wait 3 seconds until it wakes up and starts getting valid responses Sharpen.Thread.Sleep(3 * 1000); // now find the delta in requests received in a 2s period int before = mockHttpClient.GetCapturedRequests().Count; Sharpen.Thread.Sleep(2 * 1000); int after = mockHttpClient.GetCapturedRequests().Count; // assert that the delta is high, because at this point the change tracker should // be hammering away NUnit.Framework.Assert.IsTrue((after - before) > 25); // the backoff numAttempts should have been reset to 0 NUnit.Framework.Assert.IsTrue(changeTracker.backoff.GetNumAttempts() == 0); changeTracker.Stop(); try { bool success = changeTrackerFinishedSignal.Await(300, TimeUnit.Seconds); NUnit.Framework.Assert.IsTrue(success); } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } }