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); }
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)); }