public void MediaRetryPolicyTestExecuteActionNonTransient() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null); int exceptionCount = 2; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.TrustFailure); Func <int> func = () => { if (--exceptionCount > 0) { throw fakeException; } return(expected); }; try { target.ExecuteAction(func); } catch (WebException x) { Assert.AreEqual(1, exceptionCount); Assert.AreEqual(fakeException, x); throw; } Assert.Fail("Expected exception"); }
public void MediaRetryPolicyTestExecuteActionBackoff() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(); int exceptionCount = 5; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); TimeSpan lastInterval = TimeSpan.Zero; DateTime lastInvoked = DateTime.UtcNow; Func<int> func = () => { TimeSpan newInterval = DateTime.UtcNow - lastInvoked; TimeSpan delta = newInterval - lastInterval; Assert.IsTrue(exceptionCount > 3 || delta.TotalMilliseconds > 1, "Iterations left:{0} interval increase too small from {1} to {2}", exceptionCount, lastInterval, newInterval, delta); lastInvoked = DateTime.UtcNow; lastInterval = newInterval; if (--exceptionCount > 0) throw fakeException; return expected; }; int actual = target.ExecuteAction(func); Assert.AreEqual(expected, actual); Assert.AreEqual(0, exceptionCount); }
public void MediaRetryPolicyTestExecuteActionBackoff() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null); int exceptionCount = 5; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); TimeSpan lastInterval = TimeSpan.Zero; DateTime lastInvoked = DateTime.UtcNow; Func <int> func = () => { TimeSpan newInterval = DateTime.UtcNow - lastInvoked; TimeSpan delta = newInterval - lastInterval; Assert.IsTrue(exceptionCount > 3 || delta.TotalMilliseconds > 1, "Iterations left:{0} interval increase too small from {1} to {2}", exceptionCount, lastInterval, newInterval, delta); lastInvoked = DateTime.UtcNow; lastInterval = newInterval; if (--exceptionCount > 0) { throw fakeException; } return(expected); }; int actual = target.ExecuteAction(func); Assert.AreEqual(expected, actual); Assert.AreEqual(0, exceptionCount); }
public void DefaultMediaRetryPolicyTestExecuteActionNonTransient() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null); int exceptionCount = 2; int expected = 10; //IOException should not be retried when using default TestMediaServicesClassFactory instead of //CustomTestMediaServicesClassFactory var fakeException = new IOException("CustomRetryPolicyException"); Func <int> func = () => { if (--exceptionCount > 0) { throw fakeException; } return(expected); }; try { target.ExecuteAction(func); } catch (IOException x) { Assert.AreEqual(1, exceptionCount); Assert.AreEqual(fakeException, x); throw; } Assert.Fail("Expected exception"); }
public void MediaRetryPolicyTestExecuteActionTrivial() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null); int expected = 10; Func <int> func = () => expected; int actual = target.ExecuteAction(func); Assert.AreEqual(expected, actual); }
public void MediaRetryPolicyTestExecuteActionAdapter() { var adapter = new TestRetryAdapter(); MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(adapter); int exceptionCount = 2; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); Func<int> func = () => { if (--exceptionCount > 0) throw fakeException; return expected; }; Assert.AreEqual(expected, target.ExecuteAction(func)); Assert.AreEqual(2, adapter.FuncExecutedCountByExecuteAction); Assert.AreEqual(1, adapter.NumberOfAdaptCalled); }
public void MediaRetryPolicyTestExecuteActionRetry() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null); int exceptionCount = 2; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); Func <int> func = () => { if (--exceptionCount > 0) { throw fakeException; } return(expected); }; int actual = target.ExecuteAction(func); Assert.AreEqual(expected, actual); Assert.AreEqual(0, exceptionCount); }
public void MediaRetryPolicyTestExecuteActionAdapter() { var adapter = new TestRetryAdapter(); MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(adapter); int exceptionCount = 2; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); Func <int> func = () => { if (--exceptionCount > 0) { throw fakeException; } return(expected); }; Assert.AreEqual(expected, target.ExecuteAction(func)); Assert.AreEqual(2, adapter.FuncExecutedCountByExecuteAction); Assert.AreEqual(1, adapter.NumberOfAdaptCalled); }
public void MediaRetryPolicyTestExecuteActionNonTransient() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(); int exceptionCount = 2; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.RequestCanceled); Func<int> func = () => { if (--exceptionCount > 0) throw fakeException; return expected; }; try { target.ExecuteAction(func); } catch (WebException x) { Assert.AreEqual(1, exceptionCount); Assert.AreEqual(fakeException, x); throw; } Assert.Fail("Expected exception"); }
public void MediaRetryPolicyTestExecuteActionTrivial() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(); int expected = 10; Func<int> func = () => expected; int actual = target.ExecuteAction(func); Assert.AreEqual(expected, actual); }
public void MediaRetryPolicyTestExecuteActionRetry() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(); int exceptionCount = 2; int expected = 10; var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed); Func<int> func = () => { if (--exceptionCount > 0) throw fakeException; return expected; }; int actual = target.ExecuteAction(func); Assert.AreEqual(expected, actual); Assert.AreEqual(0, exceptionCount); }
public void DefaultMediaRetryPolicyTestExecuteActionNonTransient() { MediaRetryPolicy target = new TestMediaServicesClassFactory(null).GetSaveChangesRetryPolicy(null); int exceptionCount = 2; int expected = 10; //IOException should not be retried when using default TestMediaServicesClassFactory instead of //CustomTestMediaServicesClassFactory var fakeException = new IOException("CustomRetryPolicyException"); Func<int> func = () => { if (--exceptionCount > 0) throw fakeException; return expected; }; try { target.ExecuteAction(func); } catch (IOException x) { Assert.AreEqual(1, exceptionCount); Assert.AreEqual(fakeException, x); throw; } Assert.Fail("Expected exception"); }