public void WaitBeforeRetryControllerEnqabled() { var info = new ErrorRetryingInfo { Info = new[] { new ErrorRetryingItemInfo(1, 3, 60), new ErrorRetryingItemInfo(2, 3, 60), new ErrorRetryingItemInfo(3, 3, 60), } }; var retryingController = new WaitBeforeRetryController(new TestErrorRetryingWaiter(60), info); int counter = 0; int maxCounter = 2; var rez = retryingController.DoForAllTypesOfErrors(() => { if (counter < maxCounter) { ++counter; throw new TimeoutException(); } else { return(true); } }); Assert.IsTrue(rez); Assert.AreEqual(counter, maxCounter); }
//[ExpectedException(typeof(ArgumentException))] public void WaitBeforeRetryControllerEnqabled2() { var info = new ErrorRetryingInfo { Info = new[] { new ErrorRetryingItemInfo(1, 3, 60), new ErrorRetryingItemInfo(2, 3, 60), new ErrorRetryingItemInfo(3, 3, 60), }, }; var retryingController = new WaitBeforeRetryController(new TestErrorRetryingWaiter(60), info); int counter = 0; int maxCounter = 2; bool rez = false; rez = retryingController.Do <bool>(() => { if (counter < maxCounter) { ++counter; throw new TimeoutException(); } throw new ArgumentException(); }, ex => !(ex is ArgumentException)); Assert.IsFalse(rez); Assert.AreEqual(counter, maxCounter); }
public void WaitAndIncreaseWithLast() { var info = new ErrorRetryingInfo(true, 60, true) { Info = new[] { new ErrorRetryingItemInfo(1, 3, 60), new ErrorRetryingItemInfo(2, 3, 60), new ErrorRetryingItemInfo(3, 3, 60), }, }; var waiter = new TestErrorRetryingWaiter(60); var errRetrying = new WaitBeforeRetryHelper(waiter); WaitAndIncrease(info, errRetrying, waiter); bool needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 2); Assert.AreEqual(errRetrying.CountRetrying, 3); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue); Assert.IsFalse(waiter.IsRegularWaiterRaised.Value); //------------------- end needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsFalse(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 3); Assert.AreEqual(errRetrying.CountRetrying, 0); Assert.IsFalse(waiter.IsRegularWaiterRaised.HasValue); }
private UpdateActionResultInfo UpdateTransactionInfo(IDatabaseCustomerMarketPlace databaseCustomerMarketPlace, PayPalSecurityData securityInfo, MP_CustomerMarketplaceUpdatingHistory historyRecord) { var endDate = DateTime.UtcNow; var elapsedTimeInfo = new ElapsedTimeInfo(); DateTime?startDate = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds( elapsedTimeInfo, databaseCustomerMarketPlace.Id, ElapsedDataMemberType.RetrieveDataFromDatabase, () => Helper.GetLastPayPalTransactionDate(databaseCustomerMarketPlace) ); if (!startDate.HasValue) { startDate = endDate.AddMonths(-CurrentValues.Instance.PayPalTransactionSearchMonthsBack); } var errorRetryingInfo = new ErrorRetryingInfo((bool)CurrentValues.Instance.PayPalEnableRetrying, CurrentValues.Instance.PayPalMinorTimeoutInSeconds, CurrentValues.Instance.PayPalUseLastTimeOut); errorRetryingInfo.Info = new ErrorRetryingItemInfo[3]; errorRetryingInfo.Info[0] = new ErrorRetryingItemInfo(CurrentValues.Instance.PayPalIterationSettings1Index, CurrentValues.Instance.PayPalIterationSettings1CountRequestsExpectError, CurrentValues.Instance.PayPalIterationSettings1TimeOutAfterRetryingExpiredInMinutes); errorRetryingInfo.Info[1] = new ErrorRetryingItemInfo(CurrentValues.Instance.PayPalIterationSettings2Index, CurrentValues.Instance.PayPalIterationSettings2CountRequestsExpectError, CurrentValues.Instance.PayPalIterationSettings2TimeOutAfterRetryingExpiredInMinutes); errorRetryingInfo.Info[2] = new ErrorRetryingItemInfo(CurrentValues.Instance.PayPalIterationSettings3Index, CurrentValues.Instance.PayPalIterationSettings3CountRequestsExpectError, CurrentValues.Instance.PayPalIterationSettings3TimeOutAfterRetryingExpiredInMinutes); var reqInfo = new PayPalRequestInfo { SecurityInfo = securityInfo, StartDate = startDate.Value, EndDate = endDate, ErrorRetryingInfo = errorRetryingInfo, OpenTimeOutInMinutes = CurrentValues.Instance.PayPalOpenTimeoutInMinutes, SendTimeoutInMinutes = CurrentValues.Instance.PayPalSendTimeoutInMinutes, DaysPerRequest = CurrentValues.Instance.PayPalDaysPerRequest }; MP_PayPalTransaction mpTransaction = null; int numOfTransactions = 0; RequestsCounterData requestsCounter = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds( elapsedTimeInfo, databaseCustomerMarketPlace.Id, ElapsedDataMemberType.RetrieveDataFromExternalService, () => PayPalServiceHelper.GetTransactionData(reqInfo, data => { mpTransaction = Helper.SavePayPalTransactionInfo(databaseCustomerMarketPlace, data, historyRecord, mpTransaction); numOfTransactions += (data == null ? 0 : data.Count); return(true); }) ); return(new UpdateActionResultInfo { Name = UpdateActionResultType.TransactionItemsCount, Value = numOfTransactions, RequestsCounter = requestsCounter, ElapsedTime = elapsedTimeInfo }); }
public RequestsListInfo(AmazonRequestInfoBase amazonRequestInfo, string actionName, ActionAccessType access, ErrorRetryingInfo errorRetryingInfo, int timeOutInMinutes = 10) { UserId = amazonRequestInfo.MerchantId; MarketPlaceId = amazonRequestInfo.MarketplaceId; StartDate = amazonRequestInfo.StartDate; EndDate = amazonRequestInfo.EndDate; ActionName = actionName; Access = access; TimeOutInMinutes = timeOutInMinutes; ErrorRetryingInfo = errorRetryingInfo; RequestsCounter = new RequestsCounterData(); }
private static List <OrderItemTwo> GetOrders(int umi, ElapsedTimeInfo elapsedTimeInfo, AmazonServiceConnectionInfo _ConnectionInfo, int days, bool useReporting) { var session = ObjectFactory.GetInstance <ISession>(); var marketplace = session.Get <MP_CustomerMarketPlace>(umi); var securityInfo = Serialized.Deserialize <AmazonSecurityInfo>(marketplace.SecurityData); var endDate = DateTime.UtcNow; var startDate = endDate.AddDays(-days); var errorRetryingInfo = new ErrorRetryingInfo((bool)CurrentValues.Instance.AmazonEnableRetrying, CurrentValues.Instance.AmazonMinorTimeoutInSeconds, CurrentValues.Instance.AmazonUseLastTimeOut); errorRetryingInfo.Info = new ErrorRetryingItemInfo[2]; errorRetryingInfo.Info[0] = new ErrorRetryingItemInfo(CurrentValues.Instance.AmazonIterationSettings1Index, CurrentValues.Instance.AmazonIterationSettings1CountRequestsExpectError, CurrentValues.Instance.AmazonIterationSettings1TimeOutAfterRetryingExpiredInMinutes); errorRetryingInfo.Info[1] = new ErrorRetryingItemInfo(CurrentValues.Instance.AmazonIterationSettings2Index, CurrentValues.Instance.AmazonIterationSettings2CountRequestsExpectError, CurrentValues.Instance.AmazonIterationSettings2TimeOutAfterRetryingExpiredInMinutes); var amazonOrdersRequestInfo = new AmazonOrdersRequestInfo { StartDate = startDate, EndDate = endDate, MarketplaceId = securityInfo.MarketplaceId, MerchantId = securityInfo.MerchantId, ErrorRetryingInfo = errorRetryingInfo, }; List <OrderItemTwo> orders; if (useReporting) { var configurator = AmazonServiceConfigurationFactory.CreateServiceReportsConfigurator(_ConnectionInfo); orders = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds( elapsedTimeInfo, umi, ElapsedDataMemberType.RetrieveDataFromExternalService, () => AmazonServiceReports.GetUserOrders(configurator, amazonOrdersRequestInfo, ActionAccessType.Full)) .Select(OrderItemTwo.FromOrderItem) .ToList(); } else { var ordersList = ElapsedTimeHelper.CalculateAndStoreElapsedTimeForCallInSeconds(elapsedTimeInfo, umi, ElapsedDataMemberType.RetrieveDataFromExternalService, () => AmazonServiceHelper.GetListOrders(_ConnectionInfo, amazonOrdersRequestInfo, ActionAccessType.Full, null)); //todo make it work again orders = new List <OrderItemTwo>(); } return(orders); }
public void Serialize() { var info = new ErrorRetryingInfo { Info = new[] { new ErrorRetryingItemInfo(1, 3, 60), new ErrorRetryingItemInfo(2, 3, 60), new ErrorRetryingItemInfo(3, 3, 60), } }; Serialized.Serialize(@"d:/temp/ErrorRetryingInfo.xml", info); }
public void WaitBeforeRetryController() { var info = new ErrorRetryingInfo { Info = new[] { new ErrorRetryingItemInfo(1, 3, 60), new ErrorRetryingItemInfo(2, 3, 60), new ErrorRetryingItemInfo(3, 3, 60), } }; var retryingController = new WaitBeforeRetryController(new TestErrorRetryingWaiter(60), info); retryingController.DoForAllTypesOfErrors(() => true); }
public static T DoServiceAction <T>(ErrorRetryingInfo errorRetryingInfo, ITrapForThrottling trapForThrottling, string actionName, ActionAccessType access, RequestsCounterData requestCounter, Func <T> func, string details = null) { return(new AmazonWaitBeforeRetryHelper(errorRetryingInfo).DoServiceAction(trapForThrottling, actionName, access, requestCounter, func, details)); }
private AmazonWaitBeforeRetryHelper(ErrorRetryingInfo errorRetryingInfo) { _WaitBeforeRetryController = new WaitBeforeRetryController(new ErrorRetryingWaiter(), errorRetryingInfo); }
private void WaitAndIncrease(ErrorRetryingInfo info, WaitBeforeRetryHelper errRetrying, TestErrorRetryingWaiter waiter) { bool needRetrying = false; Assert.AreEqual(errRetrying.CountIteration, 0); Assert.AreEqual(errRetrying.CountRetrying, 0); Assert.IsTrue(waiter.IsRegularWaiterRaised == null); //var info = new ErrorRetryingInfo( 3, 3, 60 ); //------------------- Iteration I needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 0); Assert.AreEqual(errRetrying.CountRetrying, 1); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value); needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 0); Assert.AreEqual(errRetrying.CountRetrying, 2); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value); needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 0); Assert.AreEqual(errRetrying.CountRetrying, 3); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && !waiter.IsRegularWaiterRaised.Value); //------------------- Iteration II needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 1); Assert.AreEqual(errRetrying.CountRetrying, 1); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value); needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 1); Assert.AreEqual(errRetrying.CountRetrying, 2); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value); needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 1); Assert.AreEqual(errRetrying.CountRetrying, 3); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && !waiter.IsRegularWaiterRaised.Value); //------------------- Iteration I needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 2); Assert.AreEqual(errRetrying.CountRetrying, 1); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value); needRetrying = errRetrying.IncreaseAndWait(info); Assert.IsTrue(needRetrying); Assert.AreEqual(errRetrying.CountIteration, 2); Assert.AreEqual(errRetrying.CountRetrying, 2); Assert.IsTrue(waiter.IsRegularWaiterRaised.HasValue && waiter.IsRegularWaiterRaised.Value); }