Example #1
0
 internal async Task <string> UpsertRow(ReminderTableEntry reminderEntry)
 {
     try
     {
         return(await UpsertTableEntryAsync(reminderEntry));
     }
     catch (Exception exc)
     {
         HttpStatusCode httpStatusCode;
         string         restStatus;
         if (AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus))
         {
             if (Logger.IsVerbose2)
             {
                 Logger.Verbose2("UpsertRow failed with httpStatusCode={0}, restStatus={1}", httpStatusCode, restStatus);
             }
             if (AzureStorageUtils.IsContentionError(httpStatusCode))
             {
                 return(null);                                                     // false;
             }
         }
         throw;
     }
 }
Example #2
0
 /// <summary> Decodes Storage exceptions.</summary>
 public bool DecodeException(Exception e, out HttpStatusCode httpStatusCode, out string restStatus, bool getRESTErrors = false)
 {
     return(AzureStorageUtils.EvaluateException(e, out httpStatusCode, out restStatus, getRESTErrors));
 }
Example #3
0
        public async Task AzureTableDataManager_UpdateTableEntryAsync()
        {
            var data = GenerateNewData();

            try
            {
                await manager.UpdateTableEntryAsync(data, AzureStorageUtils.ANY_ETAG);

                Assert.True(false, "Should have thrown StorageException.");
            }
            catch (StorageException exc)
            {
                Assert.Equal((int)HttpStatusCode.NotFound, exc.RequestInformation.HttpStatusCode);  // "Update before insert."
                HttpStatusCode httpStatusCode;
                string         restStatus;
                AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus, true);
                Assert.Equal(HttpStatusCode.NotFound, httpStatusCode);
                Assert.Equal(StorageErrorCodeStrings.ResourceNotFound, restStatus);
            }

            await manager.UpsertTableEntryAsync(data);

            var tuple = await manager.ReadSingleTableEntryAsync(data.PartitionKey, data.RowKey);

            Assert.Equal(data.StringData, tuple.Item1.StringData);

            var data2 = data.Clone();

            data2.StringData = "NewData";
            string eTag1 = await manager.UpdateTableEntryAsync(data2, AzureStorageUtils.ANY_ETAG);

            tuple = await manager.ReadSingleTableEntryAsync(data2.PartitionKey, data2.RowKey);

            Assert.Equal(data2.StringData, tuple.Item1.StringData);

            var data3 = data.Clone();

            data3.StringData = "EvenNewerData";
            string ignoredETag = await manager.UpdateTableEntryAsync(data3, eTag1);

            tuple = await manager.ReadSingleTableEntryAsync(data3.PartitionKey, data3.RowKey);

            Assert.Equal(data3.StringData, tuple.Item1.StringData);

            try
            {
                string eTag3 = await manager.UpdateTableEntryAsync(data3.Clone(), eTag1);

                Assert.True(false, "Should have thrown StorageException.");
            }
            catch (StorageException exc)
            {
                Assert.Equal((int)HttpStatusCode.PreconditionFailed, exc.RequestInformation.HttpStatusCode);  // "Wrong eTag"
                HttpStatusCode httpStatusCode;
                string         restStatus;
                AzureStorageUtils.EvaluateException(exc, out httpStatusCode, out restStatus, true);
                Assert.Equal(HttpStatusCode.PreconditionFailed, httpStatusCode);
                Assert.True(restStatus == TableErrorCodeStrings.UpdateConditionNotSatisfied ||
                            restStatus == StorageErrorCodeStrings.ConditionNotMet, restStatus);
            }
        }