示例#1
0
        public void CheckConcurrentModificationException()
        {
            ConcurrentModificationException concurrentModificationException = null;

            Category originalCategory = this.errorsFixture.CategoryFixture.CreateCategory();
            //update it, then it has a newer version
            Category updatedCategory = this.errorsFixture.CategoryFixture.UpdateCategorySetRandomKey(originalCategory);

            // then if we try to update the original category it will throw ConCurrentModification Exception
            try
            {
                this.errorsFixture.CategoryFixture.UpdateCategorySetRandomKey(originalCategory);
            }
            catch (Exception ex)
            {
                if (ex is AggregateException && ex.InnerException is ConcurrentModificationException exception)
                {
                    concurrentModificationException = exception;
                }
            }

            this.errorsFixture.CategoryFixture.CategoriesToDelete.Add(updatedCategory);
            Assert.NotNull(concurrentModificationException);
            Assert.Single(concurrentModificationException.ErrorResponse.Errors);
            Assert.IsType <ConcurrentModificationError>(concurrentModificationException.ErrorResponse.Errors[0]);
            Assert.Equal(concurrentModificationException.GetCurrentVersion(), updatedCategory.Version);
        }
示例#2
0
 public override void Run()
 {
     while (runThread)
     {
         try
         {
             UserGroupInformation.GetCurrentUser().GetCredentials();
         }
         catch (ConcurrentModificationException cme)
         {
             this.cme = cme;
             Runtime.PrintStackTrace(cme);
             runThread = false;
         }
         catch (IOException ex)
         {
             Runtime.PrintStackTrace(ex);
         }
     }
 }
        /// <summary>
        /// Translate certain "special" classes of exception to classes that can be passed through the service boundary.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private static bool TranslateException(ref Exception e)
        {
            // special handling of EntityVersionException
            // assume all such exceptions occured because of concurrent modifications
            // wrap in ConcurrentModificationException will be used in the fault contract
            if (e is EntityVersionException)
            {
                e = new ConcurrentModificationException(e.Message);
                return(true);
            }

            // special handling of EntityValidationException
            // convert to RequestValidationException
            if (e is EntityValidationException)
            {
                e = new RequestValidationException(e.Message);
                return(true);
            }

            return(false);
        }