コード例 #1
0
ファイル: TableRetryTests.cs プロジェクト: Ankitvaibs/SM
        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);
        }
コード例 #2
0
        public void TableServiceQueryExecuteSegmentedBasicAPM()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

            // Retrieve Entities
            TableServiceQuery <BaseEntity> query = (from ent in ctx.CreateQuery <BaseEntity>(currentTable.Name)
                                                    select ent).AsTableServiceQuery(ctx);

            List <BaseEntity> totalResults         = new List <BaseEntity>();
            TableQuerySegment <BaseEntity> segment = null;

            do
            {
                using (ManualResetEvent evt = new ManualResetEvent(false))
                {
                    IAsyncResult result = null;
                    query.BeginExecuteSegmented(segment != null ? segment.ContinuationToken : null,
                                                (res) =>
                    {
                        result = res;
                        evt.Set();
                    }, null);
                    evt.WaitOne();

                    segment = query.EndExecuteSegmented(result);
                }

                if (totalResults.Count == 0)
                {
                    // Assert first segment has continuation token

                    Assert.IsNotNull(segment.ContinuationToken);
                }

                totalResults.AddRange(segment);
            }while (segment.ContinuationToken != null);

            Assert.AreEqual(totalResults.Count, totalTestEntities);
        }
コード例 #3
0
        public void TableTestSegmentedQueryCancellation()
        {
            CloudTableClient    tableClient = GenerateCloudTableClient();
            TableServiceContext ctx         = tableClient.GetTableServiceContext();

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

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


            TestHelper.ExecuteAPMMethodWithCancellation(4000,
                                                        new[] { DelayBehaviors.DelayAllRequestsIf(4000 * 3, XStoreSelectors.TableTraffic().IfHostNameContains(tableClient.Credentials.AccountName)) },
                                                        (options, opContext, callback, state) => query.BeginExecuteSegmented(null, (TableRequestOptions)options, opContext, callback, state),
                                                        (res) => query.EndExecuteSegmented(res));
        }