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);
                    }
                }
            }
        }
Example #2
0
        public void ScanTableAccrossInstancesBlockingAsync()
        {
            if (IsThrift)
            {
                return; // TODO, check what is wrong
            }

            InitializeTableData(tableA);
            InitializeTableData(tableB);

            var c = 0;

            using (var asyncResult = new BlockingAsyncResult()) {
                tableA.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                tableB.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                IList <Cell> cells;
                while (asyncResult.TryGetCells(out cells))
                {
                    foreach (var cell in cells)
                    {
                        Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                        ++c;
                    }
                }

                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }

            Assert.AreEqual(CountA + CountB, c);

            c = 0;
            using (var asyncResult = new BlockingAsyncResult()) {
                tableA.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                tableB.BeginScan(asyncResult, new ScanSpec().AddColumn("c"));
                IList <Cell> cells;
                while (asyncResult.TryGetCells(out cells))
                {
                    foreach (var cell in cells)
                    {
                        Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                        ++c;
                    }
                }

                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }

            Assert.AreEqual(CountB + CountC, c);
        }
        public void ScanMultipleTableColumnFamilyBlockingAsync()
        {
            if (!HasAsyncTableScanner)
            {
                return;
            }

            using (var table2 = EnsureTable("ScanMultipleTableColumnFamilyBlockingAsync", Schema)) {
                InitializeTableData(table2);

                var c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    table.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                    table2.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                    IList <Cell> cells;
                    while (asyncResult.TryGetCells(out cells))
                    {
                        foreach (var cell in cells)
                        {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountA + CountB, c);

                c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    table2.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                    table.BeginScan(asyncResult, new ScanSpec().AddColumn("c"));
                    IList <Cell> cells;
                    while (asyncResult.TryGetCells(out cells))
                    {
                        foreach (var cell in cells)
                        {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountB + CountC, c);
            }
        }
        public void ScanTableBlockingAsync()
        {
            if (!HasAsyncTableScanner)
            {
                return;
            }

            var c = 0;

            using (var asyncResult = new BlockingAsyncResult(4 * 1024)) {
                AsyncScannerContext asyncScannerContext;
                IList <Cell>        cells;

                table.BeginScan(asyncResult);
                while (asyncResult.TryGetCells(out asyncScannerContext, out cells))
                {
                    Assert.AreSame(table, asyncScannerContext.Table);
                    foreach (var cell in cells)
                    {
                        Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                        ++c;
                    }
                }

                Assert.AreEqual(CountA + CountB + CountC, c);

                c = 0;
                table.BeginScan(asyncResult);
                while (asyncResult.TryGetCells(out asyncScannerContext, out cells))
                {
                    Assert.AreSame(table, asyncScannerContext.Table);
                    foreach (var cell in cells)
                    {
                        Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                        ++c;
                    }
                }

                Assert.AreEqual(CountA + CountB + CountC, c);
            }
        }
Example #5
0
        public void ScanTableDifferentContextBlockingAsync()
        {
            if (!HasAsyncTableScanner) {
                return;
            }

            if (!IsHyper && !IsThrift) {
                Assert.Fail("Check implementation below for the new provider {0}", ProviderName);
            }

            var properties = new Dictionary<string, object> { { "Provider", IsHyper ? "Thrift" : "Hyper" } };
            using (var ctx = Hypertable.Context.Create(ConnectionString, properties))
            using (var client = ctx.CreateClient()) {
                var nsNameOther = NsName + "/other";
                try {
                    using (var nsOther = client.OpenNamespace(nsNameOther, OpenDispositions.OpenAlways))
                    using (var tableOther = nsOther.OpenTable("ScanTableDifferentContextBlockingAsync", Schema, OpenDispositions.CreateAlways)) {
                        InitializeTableData(tableOther);

                        var c = 0;
                        using (var asyncResult = new BlockingAsyncResult()) {
                            table.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                            tableOther.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                            IList<Cell> cells;
                            while (asyncResult.TryGetCells(out cells)) {
                                foreach (var cell in cells) {
                                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                                    ++c;
                                }
                            }

                            Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                            Assert.IsTrue(asyncResult.IsCompleted);
                        }

                        Assert.AreEqual(CountA + CountB, c);

                        c = 0;
                        using (var asyncResult = new BlockingAsyncResult()) {
                            table.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                            tableOther.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                            IList<Cell> cells;
                            while (asyncResult.TryGetCells(out cells)) {
                                foreach (var cell in cells) {
                                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                                    ++c;
                                }
                            }

                            Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                            Assert.IsTrue(asyncResult.IsCompleted);
                        }

                        Assert.AreEqual(CountB + CountA, c);
                    }
                }
                finally {
                    client.DropNamespace(nsNameOther, DropDispositions.Complete);
                }
            }
        }
Example #6
0
        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]);
                }
            }
        }
Example #7
0
        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);
                    }
                }
            }
        }
Example #8
0
        public void ScanTableBlockingAsync()
        {
            if (!HasAsyncTableScanner) {
                return;
            }

            var c = 0;
            using (var asyncResult = new BlockingAsyncResult(4 * 1024)) {
                AsyncScannerContext asyncScannerContext;
                IList<Cell> cells;

                table.BeginScan(asyncResult);
                while (asyncResult.TryGetCells(out asyncScannerContext, out cells)) {
                    Assert.AreSame(table, asyncScannerContext.Table);
                    foreach (var cell in cells) {
                        Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                        ++c;
                    }
                }

                Assert.AreEqual(CountA + CountB + CountC, c);

                c = 0;
                table.BeginScan(asyncResult);
                while (asyncResult.TryGetCells(out asyncScannerContext, out cells)) {
                    Assert.AreSame(table, asyncScannerContext.Table);
                    foreach (var cell in cells) {
                        Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                        ++c;
                    }
                }

                Assert.AreEqual(CountA + CountB + CountC, c);
            }
        }
Example #9
0
        public void ScanMultipleTableColumnFamilyBlockingAsync()
        {
            if (!HasAsyncTableScanner) {
                return;
            }

            using (var table2 = EnsureTable("ScanMultipleTableColumnFamilyBlockingAsync", Schema)) {
                InitializeTableData(table2);

                var c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    table.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                    table2.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                    IList<Cell> cells;
                    while (asyncResult.TryGetCells(out cells)) {
                        foreach (var cell in cells) {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountA + CountB, c);

                c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    table2.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                    table.BeginScan(asyncResult, new ScanSpec().AddColumn("c"));
                    IList<Cell> cells;
                    while (asyncResult.TryGetCells(out cells)) {
                        foreach (var cell in cells) {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountB + CountC, c);
            }
        }
Example #10
0
        public void ScanMultipleTableBlockingAsync()
        {
            if (!HasAsyncTableScanner) {
                return;
            }

            const int CountTables = 10;
            var tables = new List<ITable>();
            try {
                for (var t = 0; t < CountTables; ++t) {
                    var testTable = EnsureTable(string.Format("ScanMultipleTableBlockingAsync-{0}", t), Schema);
                    InitializeTableData(testTable);
                    tables.Add(testTable);
                }

                var c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("a")));
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("b")));
                    IList<Cell> cells;
                    while (asyncResult.TryGetCells(out cells)) {
                        foreach (var cell in cells) {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountTables * (CountA + CountB), c);

                c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("b")));
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("c")));
                    IList<Cell> cells;
                    while (asyncResult.TryGetCells(out cells)) {
                        foreach (var cell in cells) {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountTables * (CountB + CountC), c);
            }
            finally {
                tables.ForEach(t => t.Dispose());
                for (var t = 0; t < CountTables; ++t) {
                    Ns.DropTable(string.Format("ScanMultipleTableBlockingAsync-{0}", t), DropDispositions.IfExists);
                }
            }
        }
Example #11
0
        public void ScanTableAccrossInstancesBlockingAsync()
        {
            if (IsThrift) {
                return; // TODO, check what is wrong
            }

            InitializeTableData(tableA);
            InitializeTableData(tableB);

            var c = 0;
            using (var asyncResult = new BlockingAsyncResult()) {
                tableA.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                tableB.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                IList<Cell> cells;
                while (asyncResult.TryGetCells(out cells)) {
                    foreach (var cell in cells) {
                        Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                        ++c;
                    }
                }

                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }

            Assert.AreEqual(CountA + CountB, c);

            c = 0;
            using (var asyncResult = new BlockingAsyncResult()) {
                tableA.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                tableB.BeginScan(asyncResult, new ScanSpec().AddColumn("c"));
                IList<Cell> cells;
                while (asyncResult.TryGetCells(out cells)) {
                    foreach (var cell in cells) {
                        Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                        ++c;
                    }
                }

                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }

            Assert.AreEqual(CountB + CountC, c);
        }
Example #12
0
        public void ScanTableDifferentContextBlockingAsync()
        {
            if (!HasAsyncTableScanner)
            {
                return;
            }

            if (!IsHyper && !IsThrift)
            {
                Assert.Fail("Check implementation below for the new provider {0}", ProviderName);
            }
            else if (!HasHypertable || !HasHypertableThrift)
            {
                return;
            }

            var properties = new Dictionary <string, object> {
                { "Provider", IsHyper ? "Thrift" : "Hyper" }
            };

            using (var ctx = Hypertable.Context.Create(ConnectionString, properties))
                using (var client = ctx.CreateClient()) {
                    var nsNameOther = NsName + "/other";
                    try {
                        using (var nsOther = client.OpenNamespace(nsNameOther, OpenDispositions.OpenAlways))
                            using (var tableOther = nsOther.OpenTable("ScanTableDifferentContextBlockingAsync", Schema, OpenDispositions.CreateAlways)) {
                                InitializeTableData(tableOther);

                                var c = 0;
                                using (var asyncResult = new BlockingAsyncResult()) {
                                    table.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                                    tableOther.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                                    IList <Cell> cells;
                                    while (asyncResult.TryGetCells(out cells))
                                    {
                                        foreach (var cell in cells)
                                        {
                                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                                            ++c;
                                        }
                                    }

                                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                                    Assert.IsTrue(asyncResult.IsCompleted);
                                }

                                Assert.AreEqual(CountA + CountB, c);

                                c = 0;
                                using (var asyncResult = new BlockingAsyncResult()) {
                                    table.BeginScan(asyncResult, new ScanSpec().AddColumn("b"));
                                    tableOther.BeginScan(asyncResult, new ScanSpec().AddColumn("a"));
                                    IList <Cell> cells;
                                    while (asyncResult.TryGetCells(out cells))
                                    {
                                        foreach (var cell in cells)
                                        {
                                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                                            ++c;
                                        }
                                    }

                                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                                    Assert.IsTrue(asyncResult.IsCompleted);
                                }

                                Assert.AreEqual(CountB + CountA, c);
                            }
                    }
                    finally {
                        client.DropNamespace(nsNameOther, DropDispositions.Complete);
                    }
                }
        }
Example #13
0
        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]);
                }
            }
        }
Example #14
0
        public void ScanMultipleTableBlockingAsync()
        {
            if (!HasAsyncTableScanner)
            {
                return;
            }

            const int CountTables = 10;
            var       tables      = new List <ITable>();

            try {
                for (var t = 0; t < CountTables; ++t)
                {
                    var testTable = EnsureTable(string.Format("ScanMultipleTableBlockingAsync-{0}", t), Schema);
                    InitializeTableData(testTable);
                    tables.Add(testTable);
                }

                var c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("a")));
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("b")));
                    IList <Cell> cells;
                    while (asyncResult.TryGetCells(out cells))
                    {
                        foreach (var cell in cells)
                        {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountTables * (CountA + CountB), c);

                c = 0;
                using (var asyncResult = new BlockingAsyncResult()) {
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("b")));
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("c")));
                    IList <Cell> cells;
                    while (asyncResult.TryGetCells(out cells))
                    {
                        foreach (var cell in cells)
                        {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            ++c;
                        }
                    }

                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountTables * (CountB + CountC), c);
            }
            finally {
                tables.ForEach(t => t.Dispose());
                for (var t = 0; t < CountTables; ++t)
                {
                    Ns.DropTable(string.Format("ScanMultipleTableBlockingAsync-{0}", t), DropDispositions.IfExists);
                }
            }
        }
Example #15
0
        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());
            }
        }