/// <summary>A helper subtest to test invalid value given to the constructor.</summary> private void SubtestConstructor_InvalidValue(TimeSpan ts, int max = 10) { try { ExponentialBackOff backOff = new ExponentialBackOff(ts, max); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } }
public void GetNextBackOff_InvalidValue() { ExponentialBackOff backOff = new ExponentialBackOff(); try { backOff.GetNextBackOff(0); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } try { backOff.GetNextBackOff(-2); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } }
/// <summary> /// Waits for a report file to generate by polling for its status using exponential backoff. In the worst case, /// there will be 10 attempts to determine if the report is no longer processing. /// </summary> /// <param name="service">DfaReporting service object used to run the requests.</param> /// <param name="userProfileId">The ID number of the DFA user profile to run this request as.</param> /// <param name="file">The report file to poll the status of.</param> /// <returns>The report file object, either once it is no longer processing or /// once too much time has passed.</returns> private static File WaitForReportRunCompletion(DfareportingService service, long userProfileId, File file) { ExponentialBackOff backOff = new ExponentialBackOff(); TimeSpan interval; file = service.Reports.Files.Get(userProfileId, file.ReportId.Value, file.Id.Value).Execute(); for (int i = 1; i <= backOff.MaxNumOfRetries; i++) { if (!file.Status.Equals("PROCESSING")) { break; } interval = backOff.GetNextBackOff(i); Console.WriteLine("Polling again in {0} seconds.", interval); Thread.Sleep(interval); file = service.Reports.Files.Get(userProfileId, file.ReportId.Value, file.Id.Value).Execute(); } return file; }
/// <summary>A helper test for testing the <c>GetNextBackOff</c> logic.</summary> private void SubtestGetNextBackOff_MaxNumRetries(int max) { ExponentialBackOff backOff = new ExponentialBackOff(TimeSpan.Zero, max); for (int i = 1; i <= 10; ++i) { if (i <= max) { Assert.AreNotEqual(TimeSpan.MinValue, backOff.GetNextBackOff(i)); } else { Assert.AreEqual(TimeSpan.MinValue, backOff.GetNextBackOff(i)); } } }