Example #1
0
        public void SetCollectionHugeValues(MutatorSpec mutatorSpec)
        {
            const int K         = 1024;
            const int M         = K * K;
            var       hugeValue = new byte[M];

            new Random().NextBytes(hugeValue);

            var key = new Key {
                ColumnFamily = "a"
            };
            var cells = new List <Cell> {
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, hugeValue)
            };

            using (var mutator = table.CreateMutator()) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells)
            {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }
        }
Example #2
0
        public void AsyncSetAccrossInstances(MutatorSpec mutatorSpec)
        {
            if (IsThrift)
            {
                return; // TODO, check what is wrong
            }

            var key = new Key {
                ColumnFamily = "a"
            };

            using (var asyncResult = new AsyncResult()) {
                using (var mutatorA = tableA.CreateAsyncMutator(asyncResult, mutatorSpec))
                    using (var mutatorB = tableB.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                        for (var n = 0; n < CountA; ++n)
                        {
                            key.Row = Guid.NewGuid().ToString();
                            mutatorA.Set(key, Encoding.GetBytes(key.Row));
                            key.Row = Guid.NewGuid().ToString();
                            mutatorB.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(CountA, GetCellCount(tableA));
                Assert.AreEqual(CountA, GetCellCount(tableB));
            }
        }
Example #3
0
        public void SetPeriodicFlush(MutatorSpec mutatorSpec)
        {
            if (!HasPeriodicFlushTableMutator)
            {
                return;
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var i = 0; i < 5; ++i)
                {
                    var row      = string.Format("periodicFlush-{0}", i);
                    var scanSpec = new ScanSpec(row).AddColumn("a");
                    var key      = new Key(row, "a");
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    using (var scanner = table.CreateScanner(scanSpec)) {
                        Cell cell;
                        Assert.IsFalse(scanner.Next(out cell), string.Format("iteration {0}", i));
                    }

                    Thread.Sleep(3000); // wait enough

                    using (var scanner = table.CreateScanner(scanSpec)) {
                        Cell cell;
                        Assert.IsTrue(scanner.Next(out cell), string.Format("iteration {0}", i));
                        Assert.AreEqual(row, cell.Key.Row);
                    }
                }
            }
        }
Example #4
0
        private static void InitializeTableData(ITable _table)
        {
            var key = new Key();

            using (var mutator = _table.CreateMutator(MutatorSpec.CreateChunked())) {
                for (var n = 0; n < CountA; ++n)
                {
                    key.ColumnFamily = "a";
                    key.Row          = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));

                    if (n < CountB)
                    {
                        key.ColumnFamily = "b";
                        mutator.Set(key, Encoding.GetBytes(key.Row));
                    }

                    if (n < CountC)
                    {
                        key.ColumnFamily = "c";
                        mutator.Set(key, Encoding.GetBytes(key.Row));
                    }
                }
            }
        }
Example #5
0
        public void SetCollectionThreaded(MutatorSpec mutatorSpec)
        {
            var key = new Key {
                ColumnFamily = "a"
            };
            var cells1 = new List <Cell>();

            for (var n = 0; n < 16; ++n)
            {
                cells1.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            var cells2 = new List <Cell>();

            for (var n = 0; n < 16; ++n)
            {
                cells2.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                var c1 = 0;
                var c2 = 0;

                var t1 = new Thread(
                    () =>
                {
                    for (var n = 0; n < Count; ++n, ++c1)
                    {
                        mutator.Set(cells1, true);
                        if (n == Count / 2)
                        {
                            mutator.Flush();
                        }
                    }
                });

                var t2 = new Thread(
                    () =>
                {
                    for (var n = 0; n < Count; ++n, ++c2)
                    {
                        mutator.Set(cells2, true);
                        if (n == Count / 2)
                        {
                            mutator.Flush();
                        }
                    }
                });

                t1.Start();
                t2.Start();
                t1.Join();
                t2.Join();
                Assert.IsTrue(c1 > 0);
                Assert.IsTrue(c2 > 0);
            }
        }
Example #6
0
        public void Revisions(MutatorSpec mutatorSpec)
        {
            Assert.AreEqual(0, this.GetCellCount());

            var key = new Key(Guid.NewGuid().ToString())
            {
                ColumnFamily = "a", ColumnQualifier = "tag"
            };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(key, Encoding.GetBytes(key.Row));
                mutator.Flush();

                Cell cell1;
                Cell cellNone;
                using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                    Assert.IsTrue(scanner.Next(out cell1));
                    Assert.IsFalse(scanner.Next(out cellNone));
                }

                Assert.AreEqual(cell1.Key.Row, Encoding.GetString(cell1.Value));

                mutator.Set(key, Encoding.GetBytes("abc"));
                mutator.Flush();

                Cell cell2;
                using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                    Assert.IsTrue(scanner.Next(out cell1));
                    Assert.IsTrue(scanner.Next(out cell2));
                    Assert.IsFalse(scanner.Next(out cellNone));
                }

                Assert.IsTrue(cell1.Key.Timestamp > cell2.Key.Timestamp);
                Assert.AreEqual("abc", Encoding.GetString(cell1.Value));
                Assert.AreEqual(cell2.Key.Row, Encoding.GetString(cell2.Value));

                cell1.Value = Encoding.GetBytes("def");
                mutator.Set(cell1); // does NOT create a new revision
                mutator.Flush();

                Cell cell1_1;
                using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                    Assert.IsTrue(scanner.Next(out cell1_1));
                    Assert.IsTrue(scanner.Next(out cell2));
                    Assert.IsFalse(scanner.Next(out cellNone));
                }

                Assert.IsTrue(cell1.Key == cell1_1.Key);
                Assert.AreEqual(cell1.Key, cell1_1.Key);
                Assert.AreEqual(0, cell1.Key.CompareTo(cell1_1.Key));
                Assert.AreEqual(0, Key.Compare(cell1.Key, cell1_1.Key));
                Assert.AreEqual(cell1.Key.GetHashCode(), cell1_1.Key.GetHashCode());
                Assert.AreEqual("def", Encoding.GetString(cell1_1.Value));
                Assert.AreEqual(cell2.Key.Row, Encoding.GetString(cell2.Value));
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PersistenceConfiguration" /> class.
        /// </summary>
        /// <param name="configuration">
        ///     The configuration.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="configuration" /> is null.
        /// </exception>
        public PersistenceConfiguration(PersistenceConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            this.rootNamespace        = configuration.RootNamespace;
            this.Binding              = new BindingContext(configuration.Binding);
            this.mutatorSpec          = new MutatorSpec(configuration.MutatorSpec);
            this.UseAsyncTableScanner = configuration.UseAsyncTableScanner;
            this.ReviewScanSpec       = configuration.ReviewScanSpec;
        }
Example #8
0
        public void PersistLoggingMaxPerformance()
        {
            if (IsOdbc)
            {
                return; //TODO temporary skipped
            }

            var ea = new EntityA();

            TestBase.TestSerialization(ea);

            var eb = new EntityB();

            TestBase.TestSerialization(eb);

            var rng = new Random();

            for (var j = 0; j < 5; ++j)
            {
                using (var em = Emf.CreateEntityManager())
                {
                    var mutatorSpec = new MutatorSpec(MutatorKind.Chunked)
                    {
                        Queued = true,
                        //// MaxCellCount = 8 * 1024,
                        MaxChunkSize   = 64 * 1024,
                        FlushEachChunk = true,
                        Capacity       = 32768
                    };

                    using (var ma = em.GetTable <EntityA>().CreateMutator(mutatorSpec))
                        using (var mb = em.GetTable <EntityB>().CreateMutator(mutatorSpec))
                        {
                            for (var i = 0; i < 100000; ++i)
                            {
                                ea = new EntityA();
                                rng.NextBytes(ea.Value);
                                ma.Set(new Key {
                                    ColumnFamily = "a"
                                }, Serializer.ToByteArray(ea), true);

                                eb = new EntityB();
                                rng.NextBytes(eb.Value);
                                mb.Set(new Key {
                                    ColumnFamily = "b"
                                }, Serializer.ToByteArray(ea), true);
                            }
                        }
                }
            }
        }
Example #9
0
        public void SetCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    var key = new Key {
                        ColumnFamily = "b"
                    };
                    mutator.Set(key, Encoding.GetBytes(Guid.NewGuid().ToString()));
                    Assert.IsFalse(string.IsNullOrEmpty(key.Row));
                }
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #10
0
        public void Set(MutatorSpec mutatorSpec)
        {
            var key = new Key {
                ColumnFamily = "a"
            };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #11
0
        public void SetCollectionDifferentSizedValues(MutatorSpec mutatorSpec)
        {
            var sb = new StringBuilder();

            for (var n = 0; n < 0x40; ++n)
            {
                sb.Append(Guid.NewGuid().ToString());
            }

            var largeValue = Encoding.GetBytes(sb.ToString());

            for (var n = 0; n < 0x4000; ++n)
            {
                sb.Append(Guid.NewGuid().ToString());
            }

            var hugeValue  = Encoding.GetBytes(sb.ToString());
            var smallValue = Encoding.GetBytes(Guid.NewGuid().ToString());

            var key = new Key {
                ColumnFamily = "a"
            };
            var cells = new List <Cell> {
                new Cell(key.Clone() as Key, smallValue),
                new Cell(key.Clone() as Key, null),
                new Cell(key.Clone() as Key, smallValue),
                new Cell(key.Clone() as Key, largeValue),
                new Cell(key.Clone() as Key, null),
                new Cell(key.Clone() as Key, smallValue),
                new Cell(key.Clone() as Key, largeValue),
                new Cell(key.Clone() as Key, hugeValue),
                new Cell(key.Clone() as Key, null),
                new Cell(key.Clone() as Key, smallValue),
                new Cell(key.Clone() as Key, largeValue)
            };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells)
            {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }
        }
Example #12
0
        public void SetCollection(MutatorSpec mutatorSpec)
        {
            var key = new Key {
                ColumnFamily = "a"
            };
            var cells = new List <Cell>();

            for (var n = 0; n < Count; ++n)
            {
                key.Row = Guid.NewGuid().ToString();
                cells.Add(new Cell(key, Encoding.GetBytes(key.Row), true));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #13
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PersistenceConfiguration" /> class.
        /// </summary>
        /// <param name="configuration">
        ///     The configuration.
        /// </param>
        /// <param name="bindingContext">
        ///     The binding context.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="configuration" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="bindingContext" /> is null.
        /// </exception>
        internal PersistenceConfiguration(PersistenceConfiguration configuration, BindingContext bindingContext)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            this.rootNamespace              = configuration.RootNamespace;
            this.Binding                    = bindingContext;
            this.mutatorSpec                = new MutatorSpec(configuration.MutatorSpec);
            this.UseAsyncTableScanner       = configuration.UseAsyncTableScanner;
            this.UseParallelDeserialization = configuration.UseParallelDeserialization;
            this.ReviewScanSpec             = configuration.ReviewScanSpec;
            this.ReviewKey                  = configuration.ReviewKey;
            this.Context                    = configuration.Context;
        }
Example #14
0
        public void SetThreaded(MutatorSpec mutatorSpec)
        {
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                var c1 = 0;
                var c2 = 0;

                var t1 = new Thread(
                    () =>
                {
                    var key = new Key {
                        ColumnFamily = "a"
                    };
                    for (var n = 0; n < Count; ++n, ++c1)
                    {
                        key.Row = Guid.NewGuid().ToString();
                        mutator.Set(key, Encoding.GetBytes(key.Row));
                    }
                });

                var t2 = new Thread(
                    () =>
                {
                    var key = new Key {
                        ColumnFamily = "a"
                    };
                    for (var n = 0; n < Count; ++n, ++c2)
                    {
                        key.Row = Guid.NewGuid().ToString();
                        mutator.Set(key, Encoding.GetBytes(key.Row));
                    }
                });

                t1.Start();
                t2.Start();
                t1.Join();
                t2.Join();
                Assert.IsTrue(c1 > 0);
                Assert.IsTrue(c2 > 0);
            }
        }
Example #15
0
        public void SetCollectionCreateKey(MutatorSpec mutatorSpec)
        {
            var key = new Key {
                ColumnFamily = "a"
            };
            var cells = new List <Cell>();

            for (var n = 0; n < Count; ++n)
            {
                cells.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells)
            {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #16
0
        public void SetCollectionCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell>();
            for (var n = 0; n < Count; ++n) {
                key.Row = (n % 3) == 0 ? Guid.NewGuid().ToString() : null;
                cells.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            foreach (var cell in cells) {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #17
0
        public void SetCollection(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell>();
            for (var n = 0; n < Count; ++n) {
                key.Row = Guid.NewGuid().ToString();
                cells.Add(new Cell(key, Encoding.GetBytes(key.Row), true));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #18
0
        public void Revisions(MutatorSpec mutatorSpec)
        {
            Assert.AreEqual(0, this.GetCellCount());

            var key = new Key(Guid.NewGuid().ToString()) { ColumnFamily = "a", ColumnQualifier = "tag" };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(key, Encoding.GetBytes(key.Row));
                mutator.Flush();

                Cell cell1;
                Cell cellNone;
                using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                    Assert.IsTrue(scanner.Next(out cell1));
                    Assert.IsFalse(scanner.Next(out cellNone));
                }

                Assert.AreEqual(cell1.Key.Row, Encoding.GetString(cell1.Value));

                mutator.Set(key, Encoding.GetBytes("abc"));
                mutator.Flush();

                Cell cell2;
                using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                    Assert.IsTrue(scanner.Next(out cell1));
                    Assert.IsTrue(scanner.Next(out cell2));
                    Assert.IsFalse(scanner.Next(out cellNone));
                }

                Assert.IsTrue(cell1.Key.Timestamp > cell2.Key.Timestamp);
                Assert.AreEqual("abc", Encoding.GetString(cell1.Value));
                Assert.AreEqual(cell2.Key.Row, Encoding.GetString(cell2.Value));

                cell1.Value = Encoding.GetBytes("def");
                mutator.Set(cell1); // does NOT create a new revision
                mutator.Flush();

                Cell cell1_1;
                using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                    Assert.IsTrue(scanner.Next(out cell1_1));
                    Assert.IsTrue(scanner.Next(out cell2));
                    Assert.IsFalse(scanner.Next(out cellNone));
                }

                Assert.IsTrue(cell1.Key == cell1_1.Key);
                Assert.AreEqual(cell1.Key, cell1_1.Key);
                Assert.AreEqual(0, cell1.Key.CompareTo(cell1_1.Key));
                Assert.AreEqual(0, Key.Compare(cell1.Key, cell1_1.Key));
                Assert.AreEqual(cell1.Key.GetHashCode(), cell1_1.Key.GetHashCode());
                Assert.AreEqual("def", Encoding.GetString(cell1_1.Value));
                Assert.AreEqual(cell2.Key.Row, Encoding.GetString(cell2.Value));
            }
        }
Example #19
0
        public void SetThreaded(MutatorSpec mutatorSpec)
        {
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                var c1 = 0;
                var c2 = 0;

                var t1 = new Thread(
                    () =>
                        {
                            var key = new Key { ColumnFamily = "a" };
                            for (var n = 0; n < Count; ++n, ++c1) {
                                key.Row = Guid.NewGuid().ToString();
                                mutator.Set(key, Encoding.GetBytes(key.Row));
                            }
                        });

                var t2 = new Thread(
                    () =>
                        {
                            var key = new Key { ColumnFamily = "a" };
                            for (var n = 0; n < Count; ++n, ++c2) {
                                key.Row = Guid.NewGuid().ToString();
                                mutator.Set(key, Encoding.GetBytes(key.Row));
                            }
                        });

                t1.Start();
                t2.Start();
                t1.Join();
                t2.Join();
                Assert.IsTrue(c1 > 0);
                Assert.IsTrue(c2 > 0);
            }
        }
Example #20
0
        public void SetCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    var key = new Key { ColumnFamily = "b" };
                    mutator.Set(key, Encoding.GetBytes(Guid.NewGuid().ToString()));
                    Assert.IsFalse(string.IsNullOrEmpty(key.Row));
                }
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #21
0
        public void SetCollectionHugeValues(MutatorSpec mutatorSpec)
        {
            const int K = 1024;
            const int M = K * K;
            var hugeValue = new byte[M];
            new Random().NextBytes(hugeValue);

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue)
                };

            using (var mutator = table.CreateMutator()) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells) {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }
        }
Example #22
0
        public void AsyncRevisions(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            Assert.AreEqual(0, this.GetCellCount());

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    var key = new Key(Guid.NewGuid().ToString()) { ColumnFamily = "a" };
                    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);

                    Cell cell1, cell2, cellNone;

                    using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                        Assert.IsTrue(scanner.Next(out cell1));
                        Assert.IsFalse(scanner.Next(out cellNone));
                    }

                    Assert.AreEqual(cell1.Key.Row, Encoding.GetString(cell1.Value));

                    mutator.Set(key, Encoding.GetBytes("abc"));
                    asyncResult.Join();
                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);

                    using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                        Assert.IsTrue(scanner.Next(out cell1));
                        Assert.IsTrue(scanner.Next(out cell2));
                        Assert.IsFalse(scanner.Next(out cellNone));
                    }

                    Assert.IsTrue(cell1.Key.Timestamp > cell2.Key.Timestamp);
                    Assert.AreEqual("abc", Encoding.GetString(cell1.Value));
                    Assert.AreEqual(cell2.Key.Row, Encoding.GetString(cell2.Value));

                    cell1.Value = Encoding.GetBytes("def");
                    mutator.Set(cell1); // does NOT create a new revision
                    asyncResult.Join();
                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);

                    Cell cell1_1;
                    using (var scanner = table.CreateScanner(new ScanSpec(key.Row).AddColumn("a"))) {
                        Assert.IsTrue(scanner.Next(out cell1_1));
                        Assert.IsTrue(scanner.Next(out cell2));
                        Assert.IsFalse(scanner.Next(out cellNone));
                    }

                    Assert.IsTrue(cell1.Key == cell1_1.Key);
                    Assert.AreEqual(cell1.Key, cell1_1.Key);
                    Assert.AreEqual(0, cell1.Key.CompareTo(cell1_1.Key));
                    Assert.AreEqual(0, Key.Compare(cell1.Key, cell1_1.Key));
                    Assert.AreEqual(cell1.Key.GetHashCode(), cell1_1.Key.GetHashCode());
                    Assert.AreEqual("def", Encoding.GetString(cell1_1.Value));
                    Assert.AreEqual(cell2.Key.Row, Encoding.GetString(cell2.Value));
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }
        }
Example #23
0
        public void Delete(MutatorSpec mutatorSpec)
        {
            var key = new Key {
                ColumnFamily = "a"
            };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row = "Row does not exist";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var rowKeys = new SortedSet <string>();

            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while (scanner.Move(cell))
                {
                    rowKeys.Add(cell.Key.Row);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                foreach (var rowKey in rowKeys)
                {
                    mutator.Delete(rowKey);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key {
                ColumnFamily = "a"
            };
            using (var mutator = table.CreateMutator(mutatorSpec))
            {
                key.Row = "Row does not exist";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            using (var scanner = table.CreateScanner(new ScanSpec {
                KeysOnly = true
            }))
                using (var mutator = table.CreateMutator())
                {
                    var cell = new Cell();
                    while (scanner.Move(cell))
                    {
                        mutator.Delete(cell.Key);
                    }
                }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key {
                ColumnFamily = "a"
            };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            rowKeys = new SortedSet <string>();
            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while (scanner.Move(cell))
                {
                    rowKeys.Add(cell.Key.Row);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key = new Key();
                foreach (var rowKey in rowKeys)
                {
                    key.Row = rowKey;
                    mutator.Delete(key);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key {
                ColumnFamily = "a"
            };
            var keys = new List <Key>();

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    keys.Add((Key)key.Clone());
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(keys);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key {
                ColumnFamily = "a", ColumnQualifier = null
            };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var cells = new List <Cell>();

            using (var scanner = table.CreateScanner()) {
                Cell cell;
                while (scanner.Next(out cell))
                {
                    cells.Add(cell);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key {
                ColumnFamily = "a", ColumnQualifier = string.Empty
            };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            cells = new List <Cell>();
            using (var scanner = table.CreateScanner()) {
                Cell cell;
                while (scanner.Next(out cell))
                {
                    cells.Add(cell);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row          = Guid.NewGuid().ToString();
                key.ColumnFamily = "a";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnFamily = "b";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            Assert.AreEqual(2, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while (scanner.Move(cell))
                {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily    = "b";
                key.ColumnQualifier = "1";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "2";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "3";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = string.Empty;
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "4";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            Assert.AreEqual(6, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(5, this.GetCellCount());

            key.ColumnQualifier = "1";
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(4, this.GetCellCount());

            key.ColumnQualifier = string.Empty;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(3, this.GetCellCount());

            key.ColumnQualifier = null;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while (scanner.Move(cell))
                {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            key.ColumnFamily = string.Empty; // usually use null
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key(); // FIXME(remove this line), issue 'delete with unspecified timestamp applying to all future inserts'

            var dateTimes = new List <DateTime>();

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily    = "b";
                key.ColumnQualifier = "1";
                key.DateTime        = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
            }

            Assert.AreEqual(6, dateTimes.Count);
            Assert.AreEqual(6, this.GetCellCount());

            key.DateTime = dateTimes[1];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(4, this.GetCellCount());

            key.ColumnQualifier = null;
            key.DateTime        = dateTimes[3];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(2, this.GetCellCount());

            key.ColumnFamily    = null;
            key.ColumnQualifier = null;
            key.DateTime        = dateTimes[4];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(1, this.GetCellCount());

            key.ColumnFamily    = null;
            key.ColumnQualifier = null;
            key.DateTime        = dateTimes[5];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(0, this.GetCellCount());
        }
Example #24
0
 public void SetThreadedQueued()
 {
     this.SetThreaded(MutatorSpec.CreateQueued());
 }
Example #25
0
 public void RevisionsQueued()
 {
     this.Revisions(MutatorSpec.CreateQueued());
 }
Example #26
0
 public void SetCollectionHugeValuesQueued()
 {
     this.SetCollectionHugeValues(MutatorSpec.CreateQueued());
 }
Example #27
0
        public void AsyncSetAccrossInstances(MutatorSpec mutatorSpec)
        {
            if (IsThrift) {
                return; // TODO, check what is wrong
            }

            var key = new Key { ColumnFamily = "a" };
            using (var asyncResult = new AsyncResult()) {
                using (var mutatorA = tableA.CreateAsyncMutator(asyncResult, mutatorSpec))
                using (var mutatorB = tableB.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    for (var n = 0; n < CountA; ++n) {
                        key.Row = Guid.NewGuid().ToString();
                        mutatorA.Set(key, Encoding.GetBytes(key.Row));
                        key.Row = Guid.NewGuid().ToString();
                        mutatorB.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(CountA, GetCellCount(tableA));
                Assert.AreEqual(CountA, GetCellCount(tableB));
            }
        }
Example #28
0
 public void SetCollectionCreateKeyLazyKeyQueued()
 {
     this.SetCollectionCreateKeyLazy(MutatorSpec.CreateQueued());
 }
Example #29
0
 public void DeleteSetQueued()
 {
     this.DeleteSet(MutatorSpec.CreateQueued());
 }
Example #30
0
        public void AsyncSetCollectionCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell>();
            for (var n = 0; n < Count; ++n) {
                key.Row = (n % 3) == 0 ? Guid.NewGuid().ToString() : null;
                cells.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    mutator.Set(cells);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
                foreach (var cell in cells) {
                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                }

                Assert.AreEqual(Count, this.GetCellCount());
            }
        }
Example #31
0
 public void SetCollectionThreadedQueued()
 {
     this.SetCollectionThreaded(MutatorSpec.CreateQueued());
 }
Example #32
0
        public void AsyncSetCollectionDifferentSizedValues(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var sb = new StringBuilder();
            for (var n = 0; n < 0x40; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var largeValue = Encoding.GetBytes(sb.ToString());
            for (var n = 0; n < 0x4000; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var hugeValue = Encoding.GetBytes(sb.ToString());
            var smallValue = Encoding.GetBytes(Guid.NewGuid().ToString());

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue)
                };

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    mutator.Set(cells, true);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
                foreach (var cell in cells) {
                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                }
            }
        }
Example #33
0
        public void SetCollectionThreaded(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };
            var cells1 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells1.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            var cells2 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells2.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                var c1 = 0;
                var c2 = 0;

                var t1 = new Thread(
                    () =>
                        {
                            for (var n = 0; n < Count; ++n, ++c1) {
                                mutator.Set(cells1, true);
                                if (n == Count / 2) {
                                    mutator.Flush();
                                }
                            }
                        });

                var t2 = new Thread(
                    () =>
                        {
                            for (var n = 0; n < Count; ++n, ++c2) {
                                mutator.Set(cells2, true);
                                if (n == Count / 2) {
                                    mutator.Flush();
                                }
                            }
                        });

                t1.Start();
                t2.Start();
                t1.Join();
                t2.Join();
                Assert.IsTrue(c1 > 0);
                Assert.IsTrue(c2 > 0);
            }
        }
Example #34
0
        public void AsyncSetCollectionHugeValues(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            const int K = 1024;
            const int M = K * K;
            var hugeValue = new byte[M];
            new Random().NextBytes(hugeValue);

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, hugeValue)
                };

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    mutator.Set(cells, true);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
                foreach (var cell in cells) {
                    Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                }
            }
        }
Example #35
0
        public void SetPeriodicFlush(MutatorSpec mutatorSpec)
        {
            if (!HasPeriodicFlushTableMutator) {
                return;
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var i = 0; i < 5; ++i) {
                    var row = string.Format("periodicFlush-{0}", i);
                    var scanSpec = new ScanSpec(row).AddColumn("a");
                    var key = new Key(row, "a");
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    using (var scanner = table.CreateScanner(scanSpec)) {
                        Cell cell;
                        Assert.IsFalse(scanner.Next(out cell), string.Format("iteration {0}", i));
                    }

                    Thread.Sleep(3000); // wait enough

                    using (var scanner = table.CreateScanner(scanSpec)) {
                        Cell cell;
                        Assert.IsTrue(scanner.Next(out cell), string.Format("iteration {0}", i));
                        Assert.AreEqual(row, cell.Key.Row);
                    }
                }
            }
        }
Example #36
0
 public void SetQueued()
 {
     this.Set(MutatorSpec.CreateQueued());
 }
Example #37
0
        public void DeleteSet(MutatorSpec mutatorSpec)
        {
            Cell cell;
            var key = new Key();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    key.ColumnFamily = "a";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    key.ColumnFamily = "b";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var cells = new List<Cell>();
            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell)) {
                    cells.Add(new Cell(new Key(cell.Key.Row), CellFlag.DeleteRow));
                }
            }

            Assert.AreEqual(2 * Count, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    key.ColumnFamily = "a";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    key.ColumnFamily = "b";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            cells.Clear();
            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell)) {
                    cells.Add(new Cell(cell.Key, CellFlag.DeleteRow));
                }
            }

            Assert.AreEqual(2 * Count, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    key.ColumnFamily = "a";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    key.ColumnFamily = "b";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            cells.Clear();
            using (var scanner = table.CreateScanner(new ScanSpec().AddColumn("b"))) {
                while (scanner.Next(out cell)) {
                    cells.Add(new Cell(cell.Key, CellFlag.DeleteColumnFamily));
                }
            }

            Assert.AreEqual(Count, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(Count, this.GetCellCount());

            cells.Clear();
            using (var scanner = table.CreateScanner(new ScanSpec().AddColumn("a"))) {
                while (scanner.Next(out cell)) {
                    cells.Add(new Cell(cell.Key, CellFlag.DeleteCell));
                }
            }

            Assert.AreEqual(Count, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            Cell cellDelete;
            key = new Key();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row = Guid.NewGuid().ToString();
                key.ColumnFamily = "a";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnFamily = "b";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                cellDelete = new Cell(key, CellFlag.DeleteCell, true);
            }

            Assert.AreEqual(2, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell)) {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily = "b";
                key.ColumnQualifier = "1";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "2";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "3";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = string.Empty;
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "4";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                cellDelete = new Cell(key, CellFlag.DeleteCell, true);
            }

            Assert.AreEqual(6, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(5, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = "1";
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(4, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = string.Empty;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(3, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = null;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell)) {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            cellDelete.Key.ColumnFamily = string.Empty; // usually use null
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key(); // FIXME(remove this line), issue 'delete with unspecified timestamp applying to all future inserts'

            var dateTimes = new List<DateTime>();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily = "b";
                key.ColumnQualifier = "1";
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                cellDelete = new Cell(key, CellFlag.DeleteCell, true);
            }

            Assert.AreEqual(8, this.GetCellCount());
            Assert.AreEqual(8, dateTimes.Count);

            cells.Clear();
            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell)) {
                    cells.Add(cell);
                }
            }

            Assert.AreEqual(8, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(new Cell(cells[7].Key, CellFlag.DeleteCellVersion, true));
            }

            Assert.AreEqual(7, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(new Cell(cells[1].Key, CellFlag.DeleteCellVersion, true));
            }

            Assert.AreEqual(6, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(new Cell(cells[0].Key, CellFlag.DeleteCellVersion, true));
            }

            Assert.AreEqual(5, this.GetCellCount());

            cellDelete.Key.DateTime = dateTimes[1];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(4, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = null;
            cellDelete.Key.DateTime = dateTimes[3];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(2, this.GetCellCount());

            cellDelete.Key.ColumnFamily = null;
            cellDelete.Key.ColumnQualifier = null;
            cellDelete.Key.DateTime = dateTimes[4];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(1, this.GetCellCount());

            cellDelete.Key.ColumnFamily = null;
            cellDelete.Key.ColumnQualifier = null;
            cellDelete.Key.DateTime = dateTimes[5];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(0, this.GetCellCount());
        }
Example #38
0
        public void PersistLoggingMaxPerformance()
        {
            if (IsOdbc)
            {
                return; //TODO temporary skipped
            }

            var ea = new EntityA();
            TestBase.TestSerialization(ea);

            var eb = new EntityB();
            TestBase.TestSerialization(eb);

            var rng = new Random();
            for (var j = 0; j < 5; ++j)
            {
                using (var em = Emf.CreateEntityManager())
                {
                    var mutatorSpec = new MutatorSpec(MutatorKind.Chunked)
                        {
                            Queued = true,
                            //// MaxCellCount = 8 * 1024,
                            MaxChunkSize = 64 * 1024,
                            FlushEachChunk = true,
                            Capacity = 32768
                        };

                    using (var ma = em.GetTable<EntityA>().CreateMutator(mutatorSpec))
                    using (var mb = em.GetTable<EntityB>().CreateMutator(mutatorSpec))
                    {
                        for (var i = 0; i < 100000; ++i)
                        {
                            ea = new EntityA();
                            rng.NextBytes(ea.Value);
                            ma.Set(new Key { ColumnFamily = "a" }, Serializer.ToByteArray(ea), true);

                            eb = new EntityB();
                            rng.NextBytes(eb.Value);
                            mb.Set(new Key { ColumnFamily = "b" }, Serializer.ToByteArray(ea), true);
                        }
                    }
                }
            }
        }
Example #39
0
        public void Set(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            Assert.AreEqual(Count, this.GetCellCount());
        }
Example #40
0
 public void AsyncSetAccrossInstancesQueued()
 {
     this.AsyncSetAccrossInstances(MutatorSpec.CreateQueued());
 }
Example #41
0
        public void Delete(MutatorSpec mutatorSpec)
        {
            var key = new Key { ColumnFamily = "a" };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row = "Row does not exist";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var rowKeys = new SortedSet<string>();
            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while( scanner.Move(cell) ) {
                    rowKeys.Add(cell.Key.Row);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                foreach (var rowKey in rowKeys) {
                    mutator.Delete(rowKey);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a" };
            using (var mutator = table.CreateMutator(mutatorSpec))
            {
                key.Row = "Row does not exist";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                for (var n = 0; n < Count; ++n)
                {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            using (var scanner = table.CreateScanner(new ScanSpec { KeysOnly = true }))
            using (var mutator = table.CreateMutator())
            {
                var cell = new Cell();
                while (scanner.Move(cell))
                {
                    mutator.Delete(cell.Key);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a" };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            rowKeys = new SortedSet<string>();
            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while( scanner.Move(cell) ) {
                    rowKeys.Add(cell.Key.Row);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key = new Key();
                foreach (var rowKey in rowKeys) {
                    key.Row = rowKey;
                    mutator.Delete(key);
                }
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a" };
            var keys = new List<Key>();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    keys.Add((Key)key.Clone());
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(keys);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a", ColumnQualifier = null };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var cells = new List<Cell>();
            using (var scanner = table.CreateScanner()) {
                Cell cell;
                while (scanner.Next(out cell)) {
                    cells.Add(cell);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key { ColumnFamily = "a", ColumnQualifier = string.Empty };
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n) {
                    key.Row = Guid.NewGuid().ToString();
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            cells = new List<Cell>();
            using (var scanner = table.CreateScanner()) {
                Cell cell;
                while (scanner.Next(out cell)) {
                    cells.Add(cell);
                }
            }

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row = Guid.NewGuid().ToString();
                key.ColumnFamily = "a";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnFamily = "b";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            Assert.AreEqual(2, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while( scanner.Move(cell) ) {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily = "b";
                key.ColumnQualifier = "1";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "2";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "3";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = string.Empty;
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "4";
                mutator.Set(key, Encoding.GetBytes(key.Row));
            }

            Assert.AreEqual(6, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(5, this.GetCellCount());

            key.ColumnQualifier = "1";
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(4, this.GetCellCount());

            key.ColumnQualifier = string.Empty;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(3, this.GetCellCount());

            key.ColumnQualifier = null;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            using (var scanner = table.CreateScanner()) {
                var cell = new Cell();
                while( scanner.Move(cell) ) {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            key.ColumnFamily = string.Empty; // usually use null
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key(); // FIXME(remove this line), issue 'delete with unspecified timestamp applying to all future inserts'

            var dateTimes = new List<DateTime>();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily = "b";
                key.ColumnQualifier = "1";
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                Assert.IsTrue(dateTimes[dateTimes.Count - 1] < key.DateTime);
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
            }

            Assert.AreEqual(6, dateTimes.Count);
            Assert.AreEqual(6, this.GetCellCount());

            key.DateTime = dateTimes[1];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(4, this.GetCellCount());

            key.ColumnQualifier = null;
            key.DateTime = dateTimes[3];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(2, this.GetCellCount());

            key.ColumnFamily = null;
            key.ColumnQualifier = null;
            key.DateTime = dateTimes[4];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(1, this.GetCellCount());

            key.ColumnFamily = null;
            key.ColumnQualifier = null;
            key.DateTime = dateTimes[5];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Delete(key);
            }

            Assert.AreEqual(0, this.GetCellCount());
        }
Example #42
0
 public void SetCreateKeyQueued()
 {
     this.SetCreateKey(MutatorSpec.CreateQueued());
 }
Example #43
0
        public void SetCollectionDifferentSizedValues(MutatorSpec mutatorSpec)
        {
            var sb = new StringBuilder();
            for (var n = 0; n < 0x40; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var largeValue = Encoding.GetBytes(sb.ToString());
            for (var n = 0; n < 0x4000; ++n) {
                sb.Append(Guid.NewGuid().ToString());
            }

            var hugeValue = Encoding.GetBytes(sb.ToString());
            var smallValue = Encoding.GetBytes(Guid.NewGuid().ToString());

            var key = new Key { ColumnFamily = "a" };
            var cells = new List<Cell> {
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue),
                    new Cell(key.Clone() as Key, hugeValue),
                    new Cell(key.Clone() as Key, null),
                    new Cell(key.Clone() as Key, smallValue),
                    new Cell(key.Clone() as Key, largeValue)
                };

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells, true);
            }

            foreach (var cell in cells) {
                Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
            }
        }
Example #44
0
        public void AsyncSetThreaded(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var key = new Key { ColumnFamily = "a" };
            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    var c1 = 0;
                    var c2 = 0;

                    var t1 = new Thread(
                        () =>
                            {
                                for (var n = 0; n < Count; ++n, ++c1) {
                                    key.Row = Guid.NewGuid().ToString();
                                    mutator.Set(key, Encoding.GetBytes(key.Row));
                                }
                            });

                    var t2 = new Thread(
                        () =>
                            {
                                for (var n = 0; n < Count; ++n, ++c2) {
                                    key.Row = Guid.NewGuid().ToString();
                                    mutator.Set(key, Encoding.GetBytes(key.Row));
                                }
                            });

                    t1.Start();
                    t2.Start();
                    t1.Join();
                    t2.Join();
                    Assert.IsTrue(c1 > 0);
                    Assert.IsTrue(c2 > 0);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }
        }
Example #45
0
        public void AsyncSetCreateKeyLazy(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    for (var n = 0; n < Count; ++n) {
                        var key = new Key { ColumnFamily = "b" };
                        mutator.Set(key, Encoding.GetBytes(Guid.NewGuid().ToString()));
                        Assert.IsFalse(string.IsNullOrEmpty(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());
            }
        }
Example #46
0
        public void DeleteSet(MutatorSpec mutatorSpec)
        {
            Cell cell;
            var  key = new Key();

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row          = Guid.NewGuid().ToString();
                    key.ColumnFamily = "a";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    key.ColumnFamily = "b";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            var cells = new List <Cell>();

            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell))
                {
                    cells.Add(new Cell(new Key(cell.Key.Row), CellFlag.DeleteRow));
                }
            }

            Assert.AreEqual(2 * Count, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row          = Guid.NewGuid().ToString();
                    key.ColumnFamily = "a";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    key.ColumnFamily = "b";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            cells.Clear();
            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell))
                {
                    cells.Add(new Cell(cell.Key, CellFlag.DeleteRow));
                }
            }

            Assert.AreEqual(2 * Count, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                for (var n = 0; n < Count; ++n)
                {
                    key.Row          = Guid.NewGuid().ToString();
                    key.ColumnFamily = "a";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                    key.ColumnFamily = "b";
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }
            }

            cells.Clear();
            using (var scanner = table.CreateScanner(new ScanSpec().AddColumn("b"))) {
                while (scanner.Next(out cell))
                {
                    cells.Add(new Cell(cell.Key, CellFlag.DeleteColumnFamily));
                }
            }

            Assert.AreEqual(Count, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(Count, this.GetCellCount());

            cells.Clear();
            using (var scanner = table.CreateScanner(new ScanSpec().AddColumn("a"))) {
                while (scanner.Next(out cell))
                {
                    cells.Add(new Cell(cell.Key, CellFlag.DeleteCell));
                }
            }

            Assert.AreEqual(Count, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cells);
            }

            Assert.AreEqual(0, this.GetCellCount());

            Cell cellDelete;

            key = new Key();
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.Row          = Guid.NewGuid().ToString();
                key.ColumnFamily = "a";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnFamily = "b";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                cellDelete = new Cell(key, CellFlag.DeleteCell, true);
            }

            Assert.AreEqual(2, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell))
                {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily    = "b";
                key.ColumnQualifier = "1";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "2";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "3";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = string.Empty;
                mutator.Set(key, Encoding.GetBytes(key.Row));
                key.ColumnQualifier = "4";
                mutator.Set(key, Encoding.GetBytes(key.Row));
                cellDelete = new Cell(key, CellFlag.DeleteCell, true);
            }

            Assert.AreEqual(6, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(5, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = "1";
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(4, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = string.Empty;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(3, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = null;
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell))
                {
                    Assert.AreEqual("a", cell.Key.ColumnFamily);
                }
            }

            Assert.AreEqual(1, this.GetCellCount());

            cellDelete.Key.ColumnFamily = string.Empty; // usually use null
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(0, this.GetCellCount());

            key = new Key(); // FIXME(remove this line), issue 'delete with unspecified timestamp applying to all future inserts'

            var dateTimes = new List <DateTime>();

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                key.ColumnFamily    = "b";
                key.ColumnQualifier = "1";
                key.DateTime        = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                Thread.Sleep(200);
                key.DateTime = DateTime.UtcNow;
                mutator.Set(key, Encoding.GetBytes(key.DateTime.ToString()));
                dateTimes.Add(key.DateTime);
                cellDelete = new Cell(key, CellFlag.DeleteCell, true);
            }

            Assert.AreEqual(8, this.GetCellCount());
            Assert.AreEqual(8, dateTimes.Count);

            cells.Clear();
            using (var scanner = table.CreateScanner()) {
                while (scanner.Next(out cell))
                {
                    cells.Add(cell);
                }
            }

            Assert.AreEqual(8, cells.Count);

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(new Cell(cells[7].Key, CellFlag.DeleteCellVersion, true));
            }

            Assert.AreEqual(7, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(new Cell(cells[1].Key, CellFlag.DeleteCellVersion, true));
            }

            Assert.AreEqual(6, this.GetCellCount());

            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(new Cell(cells[0].Key, CellFlag.DeleteCellVersion, true));
            }

            Assert.AreEqual(5, this.GetCellCount());

            cellDelete.Key.DateTime = dateTimes[1];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(4, this.GetCellCount());

            cellDelete.Key.ColumnQualifier = null;
            cellDelete.Key.DateTime        = dateTimes[3];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(2, this.GetCellCount());

            cellDelete.Key.ColumnFamily    = null;
            cellDelete.Key.ColumnQualifier = null;
            cellDelete.Key.DateTime        = dateTimes[4];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(1, this.GetCellCount());

            cellDelete.Key.ColumnFamily    = null;
            cellDelete.Key.ColumnQualifier = null;
            cellDelete.Key.DateTime        = dateTimes[5];
            using (var mutator = table.CreateMutator(mutatorSpec)) {
                mutator.Set(cellDelete);
            }

            Assert.AreEqual(0, this.GetCellCount());
        }
Example #47
0
 public void SetCollectionDifferentSizedValuesQueued()
 {
     this.SetCollectionDifferentSizedValues(MutatorSpec.CreateQueued());
 }
Example #48
0
        public void AsyncSetDifferentContext(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                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("AsyncSetDifferentContext", Schema, OpenDispositions.CreateAlways)) {
                        var key = new Key { ColumnFamily = "a" };
                        using (var asyncResult = new AsyncResult()) {
                            using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec))
                            using (var mutatorOther = tableOther.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                                for (var n = 0; n < Count; ++n) {
                                    key.Row = Guid.NewGuid().ToString();
                                    mutator.Set(key, Encoding.GetBytes(key.Row));
                                    key.Row = Guid.NewGuid().ToString();
                                    mutatorOther.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());
                            Assert.AreEqual(Count, GetCellCount(tableOther));
                        }
                    }
                }
                finally {
                    client.DropNamespace(nsNameOther, DropDispositions.Complete);
                }
            }
        }
Example #49
0
        public void AsyncSetCollectionThreaded(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

            var key = new Key { ColumnFamily = "a" };
            var cells1 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells1.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            var cells2 = new List<Cell>();
            for (var n = 0; n < 16; ++n) {
                cells2.Add(new Cell(key.Clone() as Key, Encoding.GetBytes(Guid.NewGuid().ToString())));
            }

            using (var asyncResult = new AsyncResult()) {
                using (var mutator = table.CreateAsyncMutator(asyncResult, mutatorSpec)) {
                    var c1 = 0;
                    var c2 = 0;

                    var t1 = new Thread(
                        () =>
                            {
                                for (var n = 0; n < Count; ++n, ++c1) {
                                    mutator.Set(cells1, true);
                                    if (n == Count / 2) {
                                        mutator.Flush();
                                    }
                                }
                            });

                    var t2 = new Thread(
                        () =>
                            {
                                for (var n = 0; n < Count; ++n, ++c2) {
                                    mutator.Set(cells2, true);
                                    if (n == Count / 2) {
                                        mutator.Flush();
                                    }
                                }
                            });

                    t1.Start();
                    t2.Start();
                    t1.Join();
                    t2.Join();
                    Assert.IsTrue(c1 > 0);
                    Assert.IsTrue(c2 > 0);
                }

                asyncResult.Join();
                Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                Assert.IsTrue(asyncResult.IsCompleted);
            }
        }
Example #50
0
        public void AsyncSetMultipleTables(MutatorSpec mutatorSpec)
        {
            if (!HasAsyncTableMutator) {
                return;
            }

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

                var key = new Key { ColumnFamily = "a" };
                using (var asyncResult = new AsyncResult()) {
                    var mutators = new List<ITableMutator>();
                    try {
                        tables.ForEach(t => mutators.Add(t.CreateAsyncMutator(asyncResult, mutatorSpec)));
                        for (var n = 0; n < Count; ++n) {
                            mutators.ForEach(m => m.Set(key, Encoding.GetBytes(key.Row = Guid.NewGuid().ToString())));
                        }

                        asyncResult.Join();
                        Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                        Assert.IsTrue(asyncResult.IsCompleted);
                        tables.ForEach(t => Assert.AreEqual(Count, GetCellCount(t)));
                    }
                    finally {
                        mutators.ForEach(m => m.Dispose());
                    }
                }
            }
            finally {
                tables.ForEach(t => t.Dispose());
                for (var t = 0; t < CountTables; ++t) {
                    Ns.DropTable(string.Format("AsyncSetMultipleTables-{0}", t), DropDispositions.IfExists);
                }
            }
        }