public void ScanTableCancelBlockingAsync() { if (!HasAsyncTableScanner) { return; } for (var r = 0; r < 5; ++r) { var c = 0; using (var asyncResult = new BlockingAsyncResult()) { table.BeginScan(asyncResult); IList <Cell> cells; while (asyncResult.TryGetCells(out cells)) { foreach (var cell in cells) { if (c == CountC) { asyncResult.Cancel(); Assert.IsTrue(asyncResult.IsCancelled); break; } c++; } } Assert.IsTrue(asyncResult.IsCancelled); asyncResult.Join(); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsTrue(asyncResult.IsCancelled); Assert.AreEqual(CountC, c); // The official Hypertable version does not support re-using of the future object using the thrift API if (!IsThrift) { c = 0; table.BeginScan(asyncResult); Assert.IsFalse(asyncResult.IsCancelled); while (asyncResult.TryGetCells(out cells)) { c += cells.Count; } asyncResult.Join(); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(CountA + CountB + CountC, c); } } } }
public void ScanTableCancelBlockingAsyncScanner() { if (!HasAsyncTableScanner) { return; } var rng = new Random(); var scanSpecA = new ScanSpec().AddColumn("a"); var scanSpecB = new ScanSpec().AddColumn("a", "b", "c"); var scanSpecC = new ScanSpec().AddColumn("b", "c"); for (var r = 0; r < 5; ++r) { var c = new Dictionary<ScanSpec, int>(); var limit = new Dictionary<ScanSpec, int>(); var total = new Dictionary<ScanSpec, int>(); c[scanSpecA] = 0; c[scanSpecB] = 0; c[scanSpecC] = 0; limit[scanSpecA] = rng.Next(CountA / 2); limit[scanSpecB] = rng.Next(CountB / 2); limit[scanSpecC] = int.MaxValue; using (var asyncResult = new BlockingAsyncResult()) { table.BeginScan(asyncResult, scanSpecA); table.BeginScan(asyncResult, scanSpecB); table.BeginScan(asyncResult, scanSpecC); AsyncScannerContext ctx; IList<Cell> cells; while (asyncResult.TryGetCells(out ctx, out cells)) { c[ctx.ScanSpec] += cells.Count; if (!total.ContainsKey(ctx.ScanSpec) && c[ctx.ScanSpec] > limit[ctx.ScanSpec]) { total.Add(ctx.ScanSpec, c[ctx.ScanSpec]); asyncResult.CancelAsyncScanner(ctx); } } asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(total[scanSpecA], c[scanSpecA]); Assert.AreEqual(total[scanSpecB], c[scanSpecB]); Assert.AreEqual(CountB + CountC, c[scanSpecC]); total = new Dictionary<ScanSpec, int>(); c[scanSpecA] = 0; c[scanSpecB] = 0; c[scanSpecC] = 0; limit[scanSpecA] = rng.Next(CountA / 2); limit[scanSpecB] = rng.Next(CountB / 2); limit[scanSpecC] = int.MaxValue; table.BeginScan(asyncResult, scanSpecC); table.BeginScan(asyncResult, scanSpecB); table.BeginScan(asyncResult, scanSpecA); while (asyncResult.TryGetCells(out ctx, out cells)) { c[ctx.ScanSpec] += cells.Count; if (!total.ContainsKey(ctx.ScanSpec) && c[ctx.ScanSpec] > limit[ctx.ScanSpec]) { total.Add(ctx.ScanSpec, c[ctx.ScanSpec]); asyncResult.CancelAsyncScanner(ctx); } } asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(total[scanSpecA], c[scanSpecA]); Assert.AreEqual(total[scanSpecB], c[scanSpecB]); Assert.AreEqual(CountB + CountC, c[scanSpecC]); } } }
public void ScanTableCancelBlockingAsync() { if (!HasAsyncTableScanner) { return; } for (var r = 0; r < 5; ++r) { var c = 0; using (var asyncResult = new BlockingAsyncResult()) { table.BeginScan(asyncResult); IList<Cell> cells; while (asyncResult.TryGetCells(out cells)) { foreach (var cell in cells) { if (c == CountC) { asyncResult.Cancel(); Assert.IsTrue(asyncResult.IsCancelled); break; } c++; } } Assert.IsTrue(asyncResult.IsCancelled); asyncResult.Join(); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsTrue(asyncResult.IsCancelled); Assert.AreEqual(CountC, c); // The official Hypertable version does not support re-using of the future object using the thrift API if (!IsThrift) { c = 0; table.BeginScan(asyncResult); Assert.IsFalse(asyncResult.IsCancelled); while (asyncResult.TryGetCells(out cells)) { c += cells.Count; } asyncResult.Join(); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(CountA + CountB + CountC, c); } } } }
public void ScanTableCancelBlockingAsyncScanner() { if (!HasAsyncTableScanner) { return; } var rng = new Random(); var scanSpecA = new ScanSpec().AddColumn("a"); var scanSpecB = new ScanSpec().AddColumn("a", "b", "c"); var scanSpecC = new ScanSpec().AddColumn("b", "c"); for (var r = 0; r < 5; ++r) { var c = new Dictionary <ScanSpec, int>(); var limit = new Dictionary <ScanSpec, int>(); var total = new Dictionary <ScanSpec, int>(); c[scanSpecA] = 0; c[scanSpecB] = 0; c[scanSpecC] = 0; limit[scanSpecA] = rng.Next(CountA / 2); limit[scanSpecB] = rng.Next(CountB / 2); limit[scanSpecC] = int.MaxValue; using (var asyncResult = new BlockingAsyncResult()) { table.BeginScan(asyncResult, scanSpecA); table.BeginScan(asyncResult, scanSpecB); table.BeginScan(asyncResult, scanSpecC); AsyncScannerContext ctx; IList <Cell> cells; while (asyncResult.TryGetCells(out ctx, out cells)) { c[ctx.ScanSpec] += cells.Count; if (!total.ContainsKey(ctx.ScanSpec) && c[ctx.ScanSpec] > limit[ctx.ScanSpec]) { total.Add(ctx.ScanSpec, c[ctx.ScanSpec]); asyncResult.CancelAsyncScanner(ctx); } } asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(total[scanSpecA], c[scanSpecA]); Assert.AreEqual(total[scanSpecB], c[scanSpecB]); Assert.AreEqual(CountB + CountC, c[scanSpecC]); total = new Dictionary <ScanSpec, int>(); c[scanSpecA] = 0; c[scanSpecB] = 0; c[scanSpecC] = 0; limit[scanSpecA] = rng.Next(CountA / 2); limit[scanSpecB] = rng.Next(CountB / 2); limit[scanSpecC] = int.MaxValue; table.BeginScan(asyncResult, scanSpecC); table.BeginScan(asyncResult, scanSpecB); table.BeginScan(asyncResult, scanSpecA); while (asyncResult.TryGetCells(out ctx, out cells)) { c[ctx.ScanSpec] += cells.Count; if (!total.ContainsKey(ctx.ScanSpec) && c[ctx.ScanSpec] > limit[ctx.ScanSpec]) { total.Add(ctx.ScanSpec, c[ctx.ScanSpec]); asyncResult.CancelAsyncScanner(ctx); } } asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.IsFalse(asyncResult.IsCancelled); Assert.AreEqual(total[scanSpecA], c[scanSpecA]); Assert.AreEqual(total[scanSpecB], c[scanSpecB]); Assert.AreEqual(CountB + CountC, c[scanSpecC]); } } }
public void AsyncSet(MutatorSpec mutatorSpec) { if (!HasAsyncTableMutator) { return; } var key = new Key { ColumnFamily = "a" }; using (var asyncResult = new AsyncResult()) { using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) { for (var n = 0; n < Count; ++n) { key.Row = Guid.NewGuid().ToString(); mutator.Set(key, Encoding.GetBytes(key.Row)); } } asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.AreEqual(Count, this.GetCellCount()); } using (var asyncResult = new BlockingAsyncResult()) { using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) { for (var n = 0; n < Count; ++n) { key.Row = Guid.NewGuid().ToString(); mutator.Set(key, Encoding.GetBytes(key.Row)); } } asyncResult.Join(); Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty); Assert.IsTrue(asyncResult.IsCompleted); Assert.AreEqual(2 * Count, this.GetCellCount()); } }