Пример #1
0
        internal T RunTransaction <T>(AccessMode mode, Func <ITransaction, T> work, Action <TransactionConfigBuilder> action)
        {
            return(_retryLogic.Retry(() =>
            {
                using (var txc = BeginTransaction(mode, action))
                {
                    try
                    {
                        var result = work(txc);
                        if (txc.IsOpen)
                        {
                            txc.Commit();
                        }

                        return result;
                    }
                    catch
                    {
                        if (txc.IsOpen)
                        {
                            txc.Rollback();
                        }

                        throw;
                    }
                }
            }));
        }
        private void Retry(int index, IRetryLogic retryLogic)
        {
            var timer = new Stopwatch();

            timer.Start();
            var e = Record.Exception(() => retryLogic.Retry <int>(() =>
            {
                var errorMessage = $"Thread {index} Failed at {timer.Elapsed}";
                throw new SessionExpiredException(errorMessage);
            }));

            timer.Stop();

            var error       = e as AggregateException;
            var innerErrors = error.Flatten().InnerExceptions;

            innerErrors.Count.Should().BeGreaterOrEqualTo(5);
            timer.Elapsed.TotalSeconds.Should().BeGreaterOrEqualTo(30);
        }
Пример #3
0
 private T RunTransaction <T>(AccessMode mode, Func <ITransaction, T> work)
 {
     return(TryExecute(() => _retryLogic.Retry(() =>
     {
         using (var tx = BeginTransactionWithoutLogging(mode))
         {
             try
             {
                 var result = work(tx);
                 tx.Success();
                 return result;
             }
             catch
             {
                 tx.Failure();
                 throw;
             }
         }
     })));
 }
Пример #4
0
 internal T RunTransaction <T>(AccessMode mode, Func <ITransaction, T> work, TransactionConfig txConfig)
 {
     return(_retryLogic.Retry(() =>
     {
         using (var txc = BeginTransaction(mode, txConfig))
         {
             try
             {
                 var result = work(txc);
                 txc.Success();
                 return result;
             }
             catch
             {
                 txc.Failure();
                 throw;
             }
         }
     }));
 }
Пример #5
0
        private void Retry(int index, IRetryLogic retryLogic)
        {
            var timer = new Stopwatch();

            timer.Start();
            var runCounter = 0;
            var e          = Record.Exception(() => retryLogic.Retry <int>(() =>
            {
                runCounter++;
                Interlocked.Increment(ref _globalCounter);
                var errorMessage = $"Thread {index} Failed at {timer.Elapsed}";
                throw new SessionExpiredException(errorMessage);
            }));

            timer.Stop();

            e.Should().BeOfType <ServiceUnavailableException>();
            var error       = e.InnerException as AggregateException;
            var innerErrors = error.Flatten().InnerExceptions;

            innerErrors.Count.Should().Be(runCounter);
            timer.Elapsed.TotalSeconds.Should().BeGreaterOrEqualTo(5);
        }