public void TableOperationExecuteRetryAPM()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", "foo");

            for (int m = 0; m < 20; m++)
            {
                insertEntity.Properties.Add("prop" + m.ToString(), new EntityProperty(new byte[50 * 1024]));
            }

            TestHelper.ExecuteAPMMethodWithRetry(3,
                                                 new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertUpstreamNetworkDelay(10000,
                                                                XStoreSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName),
                                                                new BehaviorOptions(2)),
                // After 500 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    XStoreSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName),
                                                    new BehaviorOptions(2))
            },
                                                 (options, opContext, callback, state) => currentTable.BeginExecute(TableOperation.Insert(insertEntity), (TableRequestOptions)options, opContext, callback, state),
                                                 (res) => currentTable.EndExecute(res));
        }
        public void TableQueryWithRetrySync()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableBatchOperation batch       = new TableBatchOperation();

            for (int m = 0; m < 1500; m++)
            {
                // Insert Entity
                DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", m.ToString());
                batch.Insert(insertEntity);

                if ((m + 1) % 100 == 0)
                {
                    currentTable.ExecuteBatch(batch);
                    batch = new TableBatchOperation();
                }
            }

            TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "insert test"));

            TestHelper.ExecuteMethodWithRetry(
                4, // 2 segments, 2 failures
                new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertDownstreamNetworkDelay(10000,
                                                                  XStoreSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true),
                                                                  new BehaviorOptions(4)),
                // After 100 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    XStoreSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true),
                                                    new BehaviorOptions(4))
            },
                (options, opContext) => currentTable.ExecuteQuery(query, (TableRequestOptions)options, opContext).ToList());
        }
Beispiel #3
0
        public void TableServiceContextSaveChangesRetryAPM()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            for (int m = 0; m < 100; m++)
            {
                // Insert Entity
                ComplexEntity insertEntity = new ComplexEntity("insert test", m.ToString());
                insertEntity.Binary = new byte[20 * 1024];
                ctx.AddObject(currentTable.Name, insertEntity);
            }

            TestHelper.ExecuteAPMMethodWithRetry(3,
                                                 new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertUpstreamNetworkDelay(10000,
                                                                AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName),
                                                                new BehaviorOptions(2)),
                // After 500 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName),
                                                    new BehaviorOptions(2))
            },
                                                 (options, opContext, callback, state) => ctx.BeginSaveChangesWithRetries(SaveChangesOptions.Batch, (TableRequestOptions)options, opContext, callback, state),
                                                 (res) => ctx.EndSaveChangesWithRetries(res));
        }
Beispiel #4
0
        public void TableServiceQueryWithRetryAPM()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            for (int m = 0; m < 1000; m++)
            {
                // Insert Entity
                ComplexEntity insertEntity = new ComplexEntity("insert test", m.ToString());
                ctx.AddObject(currentTable.Name, insertEntity);

                if ((m + 1) % 100 == 0)
                {
                    ctx.SaveChangesWithRetries(SaveChangesOptions.Batch);
                }
            }

            TableServiceQuery <ComplexEntity> query = (from ent in ctx.CreateQuery <ComplexEntity>(currentTable.Name)
                                                       select ent).AsTableServiceQuery(ctx);

            TestHelper.ExecuteAPMMethodWithRetry(
                2, // 1 failure, one success
                new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertDownstreamNetworkDelay(10000,
                                                                  AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true)),
                // After 100 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true))
            },
                (options, opContext, callback, state) => query.BeginExecuteSegmented(null, (TableRequestOptions)options, opContext, callback, state),
                query.EndExecuteSegmented);
        }
Beispiel #5
0
        public void TableQueryWithRetryAPM()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableBatchOperation batch       = new TableBatchOperation();

            for (int m = 0; m < 1500; m++)
            {
                // Insert Entity
                DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", m.ToString());
                insertEntity.Properties.Add("prop" + m.ToString(), new EntityProperty(new byte[1 * 1024]));
                batch.Insert(insertEntity);

                if ((m + 1) % 100 == 0)
                {
                    currentTable.ExecuteBatch(batch);
                    batch = new TableBatchOperation();
                }
            }

            TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "insert test"));

            TestHelper.ExecuteAPMMethodWithRetry(
                2, // 1 failure, one success
                new[] {
                //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                PerformanceBehaviors.InsertDownstreamNetworkDelay(10000,
                                                                  AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true)),
                // After 100 ms return throttle message
                DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                    100,
                                                    AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true))
            },
                (options, opContext, callback, state) => currentTable.BeginExecuteQuerySegmented(query, null, (TableRequestOptions)options, opContext, callback, state),
                (res) => currentTable.EndExecuteQuerySegmented(res));
        }
Beispiel #6
0
        public void TableOperationNoRetry()
        {
            CloudTableClient tableClient = GenerateCloudTableClient();

            tableClient.DefaultRequestOptions.RetryPolicy = new NoRetry();
            CloudTable currentTable = tableClient.GetTableReference("noretrytable");

            currentTable.CreateIfNotExists();
            DynamicTableEntity insertEntity = new DynamicTableEntity("insert test", "foo");

            currentTable.Execute(TableOperation.Insert(insertEntity));
            TableQuery query = new TableQuery().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "insert test"));

            try
            {
                TestHelper.ExecuteMethodWithRetry(
                    1,
                    new[] {
                    //Insert upstream network delay to prevent upload to server @ 1000ms / kb
                    PerformanceBehaviors.InsertDownstreamNetworkDelay(10000,
                                                                      AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true)),
                    // After 100 ms return throttle message
                    DelayedActionBehaviors.ExecuteAfter(Actions.ThrottleTableRequest,
                                                        100,
                                                        AzureStorageSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName).Alternating(true))
                },
                    (options, opContext) => currentTable.ExecuteQuery(query, (TableRequestOptions)options, opContext).ToList());
            }
            catch (StorageException ex)
            {
                Assert.IsTrue(ex.RequestInformation.HttpStatusCode == 503);
            }
            finally
            {
                currentTable.DeleteIfExists();
            }
        }