public void ScanTableCancelAsyncScanner() { if (!HasAsyncTableScanner) { return; } var rng = new Random(); for (var r = 0; r < 5; ++r) { var ca = 0; var caLimit = rng.Next(CountA / 2); var caTotal = 0; var cb = 0; var cbLimit = rng.Next(CountB / 2); var cbTotal = 0; var cc = 0; using (var asyncResult = new AsyncResult()) { table.BeginScan( asyncResult, new ScanSpec().AddColumn("a"), (ctx, cells) => { ca += cells.Count; if (caTotal == 0 && ca > caLimit) { caTotal = ca; return AsyncCallbackResult.Cancel; } return AsyncCallbackResult.Continue; }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("a", "b", "c"), (ctx, cells) => { cb += cells.Count; if (cbTotal == 0 && cb > cbLimit) { cbTotal = cb; return AsyncCallbackResult.Cancel; } return AsyncCallbackResult.Continue; }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("b", "c"), (ctx, cells) => { cc += cells.Count; return AsyncCallbackResult.Continue; }); asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(caTotal, ca); Assert.AreEqual(cbTotal, cb); Assert.AreEqual(CountB + CountC, cc); ca = 0; caLimit = rng.Next(CountA / 2); caTotal = 0; cb = 0; cbLimit = rng.Next(CountB / 2); cbTotal = 0; cc = 0; table.BeginScan( asyncResult, new ScanSpec().AddColumn("a"), (ctx, cells) => { ca += cells.Count; if (caTotal == 0 && ca > caLimit) { caTotal = ca; asyncResult.CancelAsyncScanner(ctx); } return AsyncCallbackResult.Continue; }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("a", "b", "c"), (ctx, cells) => { cb += cells.Count; if (cbTotal == 0 && cb > cbLimit) { cbTotal = cb; asyncResult.CancelAsyncScanner(ctx); } return AsyncCallbackResult.Continue; }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("b", "c"), (ctx, cells) => { cc += cells.Count; return AsyncCallbackResult.Continue; }); asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(caTotal, ca); Assert.AreEqual(cbTotal, cb); Assert.AreEqual(CountB + CountC, cc); } } }
public void ScanTableCancelAsyncScanner() { if (!HasAsyncTableScanner) { return; } var rng = new Random(); for (var r = 0; r < 5; ++r) { var ca = 0; var caLimit = rng.Next(CountA / 2); var caTotal = 0; var cb = 0; var cbLimit = rng.Next(CountB / 2); var cbTotal = 0; var cc = 0; using (var asyncResult = new AsyncResult()) { table.BeginScan( asyncResult, new ScanSpec().AddColumn("a"), (ctx, cells) => { ca += cells.Count; if (caTotal == 0 && ca > caLimit) { caTotal = ca; return(AsyncCallbackResult.Cancel); } return(AsyncCallbackResult.Continue); }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("a", "b", "c"), (ctx, cells) => { cb += cells.Count; if (cbTotal == 0 && cb > cbLimit) { cbTotal = cb; return(AsyncCallbackResult.Cancel); } return(AsyncCallbackResult.Continue); }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("b", "c"), (ctx, cells) => { cc += cells.Count; return(AsyncCallbackResult.Continue); }); asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(caTotal, ca); Assert.AreEqual(cbTotal, cb); Assert.AreEqual(CountB + CountC, cc); ca = 0; caLimit = rng.Next(CountA / 2); caTotal = 0; cb = 0; cbLimit = rng.Next(CountB / 2); cbTotal = 0; cc = 0; table.BeginScan( asyncResult, new ScanSpec().AddColumn("a"), (ctx, cells) => { ca += cells.Count; if (caTotal == 0 && ca > caLimit) { caTotal = ca; asyncResult.CancelAsyncScanner(ctx); } return(AsyncCallbackResult.Continue); }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("a", "b", "c"), (ctx, cells) => { cb += cells.Count; if (cbTotal == 0 && cb > cbLimit) { cbTotal = cb; asyncResult.CancelAsyncScanner(ctx); } return(AsyncCallbackResult.Continue); }); table.BeginScan( asyncResult, new ScanSpec().AddColumn("b", "c"), (ctx, cells) => { cc += cells.Count; return(AsyncCallbackResult.Continue); }); asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(caTotal, ca); Assert.AreEqual(cbTotal, cb); Assert.AreEqual(CountB + CountC, cc); } } }