Beispiel #1
0
        public void Run(TestConfig config)
        {
            Debug.Assert(!config.IsTransient);

            IDatabase db = DatabaseFactory.CreateDatabase();
            Tests.AssertDatabaseException(
                () => { var r = db.Root; },
                DatabaseException.ErrorCode.DATABASE_NOT_OPENED);

            db = config.GetDatabase();
            Root root = new Root();
            var idx = db.CreateIndex<string, RecordFull>(IndexType.NonUnique);
            root.idx = idx;
            db.Root = root;
            db.Commit();

            for (int i = 0; i < 10; i++)
            {
                var r = new RecordFull(i);
                idx.Put(r.StrVal, r);
            }
            var f = db.File;
            OsFile of = (OsFile)f;
            of.Close();

            IDatabase db2 = config.GetDatabase(false);
            try
            {
                db.Close();
            }
            catch
            {
            }
            db2.Close();
        }
Beispiel #2
0
        public void Run(TestConfig config)
        {
            IDatabase db   = config.GetDatabase();
            Root      root = new Root();
            var       r    = new RecordFull();

            root.r  = r;
            db.Root = root;
            db.Commit();
            // delete the object from the database
            r.Deallocate();
            db.Commit();
            db.Close();

            db = config.GetDatabase(false);
            // r was explicitly deleted from the database but it's
            // still referenced by db.Root. Loading root object will
            // try to recursively load Record object but since it's
            // been deleted, we should get an exception
            Tests.AssertDatabaseException(() =>
            {
                root = (Root)db.Root;
            }, DatabaseException.ErrorCode.DELETED_OBJECT);
            r = root.r;
            db.Close();
        }
Beispiel #3
0
        public void Run(TestConfig config)
        {
            IDatabase db = config.GetDatabase();
            Root root = new Root();
            var r = new RecordFull();
            root.r = r;
            db.Root = root;
            db.Commit();
            // delete the object from the database
            r.Deallocate();
            db.Commit();
            db.Close();

            db = config.GetDatabase(false);
            // r was explicitly deleted from the database but it's
            // still referenced by db.Root. Loading root object will
            // try to recursively load Record object but since it's
            // been deleted, we should get an exception
            Tests.AssertDatabaseException(() =>
            {
                root = (Root)db.Root;
            }, DatabaseException.ErrorCode.DELETED_OBJECT);
            r = root.r;
            db.Close();
        }
Beispiel #4
0
        public void Run(TestConfig config)
        {
            Debug.Assert(!config.IsTransient);

            IDatabase db = DatabaseFactory.CreateDatabase();

            Tests.AssertDatabaseException(
                () => { var r = db.Root; },
                DatabaseException.ErrorCode.DATABASE_NOT_OPENED);

            db = config.GetDatabase();
            Root root = new Root();
            var  idx  = db.CreateIndex <string, RecordFull>(IndexType.NonUnique);

            root.idx = idx;
            db.Root  = root;
            db.Commit();

            for (int i = 0; i < 10; i++)
            {
                var r = new RecordFull(i);
                idx.Put(r.StrVal, r);
            }
            var    f  = db.File;
            OsFile of = (OsFile)f;

            of.Close();

            IDatabase db2 = config.GetDatabase(false);

            try
            {
                db.Close();
            }
            catch
            {
            }
            db2.Close();
        }
Beispiel #5
0
        static int VerifyDictionaryEnumerator(IDictionaryEnumerator de, IterationOrder order)
        {
            long prev = long.MinValue;

            if (order == IterationOrder.DescentOrder)
            {
                prev = long.MaxValue;
            }
            int i = 0;

            while (de.MoveNext())
            {
                DictionaryEntry e1 = (DictionaryEntry)de.Current;
                DictionaryEntry e2 = de.Entry;
                Tests.Assert(e1.Equals(e2));
                long k  = (long)e1.Key;
                long k2 = (long)de.Key;
                Tests.Assert(k == k2);
                RecordFull v1 = (RecordFull)e1.Value;
                RecordFull v2 = (RecordFull)de.Value;
                Tests.Assert(v1.Equals(v2));
                Tests.Assert(v1.Int32Val == k);
                if (order == IterationOrder.AscentOrder)
                {
                    Tests.Assert(k >= prev);
                }
                else
                {
                    Tests.Assert(k <= prev);
                }
                prev = k;
                i++;
            }
            Tests.VerifyDictionaryEnumeratorDone(de);
            return(i);
        }
Beispiel #6
0
        static int VerifyDictionaryEnumerator(IDictionaryEnumerator de, IterationOrder order)
        {
            string prev = "";

            if (order == IterationOrder.DescentOrder)
            {
                prev = "9999999999999999999";
            }
            int i = 0;

            while (de.MoveNext())
            {
                DictionaryEntry e1 = (DictionaryEntry)de.Current;
                DictionaryEntry e2 = de.Entry;
                Tests.Assert(e1.Equals(e2));
                string k  = (string)e1.Key;
                string k2 = (string)de.Key;
                Tests.Assert(k == k2);
                RecordFull v1 = (RecordFull)e1.Value;
                RecordFull v2 = (RecordFull)de.Value;
                Tests.Assert(v1.Equals(v2));
                Tests.Assert(v1.StrVal == k);
                if (order == IterationOrder.AscentOrder)
                {
                    Tests.Assert(k.CompareTo(prev) >= 0);
                }
                else
                {
                    Tests.Assert(k.CompareTo(prev) <= 0);
                }
                prev = k;
                i++;
            }
            Tests.VerifyDictionaryEnumeratorDone(de);
            return(i);
        }
        public void Run(TestConfig config)
        {
            IDatabase db = config.GetDatabase();

            config.Result = new TestResult();
            Root root = new Root();

            root.idx = db.CreatePatriciaTrie <RecordFull>();
            db.Root  = root;
            int count = config.Count;

            Tests.Assert(0 == root.idx.Count);
            long            firstKey = 0;
            RecordFull      firstRec = null;
            PatriciaTrieKey pk;
            RecordFull      r;

            foreach (var key in Tests.KeySeq(count))
            {
                r  = new RecordFull(key);
                pk = new PatriciaTrieKey((ulong)key, 8);
                root.idx.Add(pk, r);
                if (null == firstRec)
                {
                    firstRec = r;
                    firstKey = key;
                }
            }
            Tests.Assert(count == root.idx.Count);
            Tests.Assert(root.idx.Contains(firstRec));
            Tests.Assert(!root.idx.Contains(new RecordFull(firstKey)));

            pk = new PatriciaTrieKey((ulong)firstKey, 8);
            r  = new RecordFull(firstKey);
            Tests.Assert(firstRec == root.idx.Add(pk, r));
            Tests.Assert(r == root.idx.FindExactMatch(pk));
            Tests.Assert(r == root.idx.FindBestMatch(pk));

            foreach (var key in Tests.KeySeq(count))
            {
                pk = new PatriciaTrieKey((ulong)key, 8);
                Tests.Assert(null != root.idx.Remove(pk));
            }

            // TODO: seems broken, there's a null entry left
            // in the index

            /*foreach (var rf in root.idx)
             * {
             *  pk = new PatriciaTrieKey(rf.UInt64Val, 8);
             *  Tests.Assert(null != root.idx.Remove(pk));
             * }*/

            //Tests.Assert(0 == root.idx.Count);
            root.idx.Clear();
            Tests.Assert(0 == root.idx.Count);

            pk = new PatriciaTrieKey((ulong)firstKey, 8);
            Tests.Assert(null == root.idx.Remove(pk));

            pk = PatriciaTrieKey.FromIpAddress(new System.Net.IPAddress(123));
            pk = PatriciaTrieKey.FromIpAddress("127.0.0.1");
            pk = PatriciaTrieKey.From7bitString("hola");
            pk = PatriciaTrieKey.From8bitString("hola");
            pk = PatriciaTrieKey.FromByteArray(new byte[4] {
                4, 2, 8, 3
            });
            pk = PatriciaTrieKey.FromDecimalDigits("9834");
            db.Close();
        }
Beispiel #8
0
        public void Run(TestConfig config)
        {
            int count = config.Count;
            var res   = new TestIndexResult();

            config.Result = res;
            IDatabase db = config.GetDatabase();

            if (config.Serializable)
            {
                db.BeginThreadTransaction(TransactionMode.Serializable);
            }

            Root root = (Root)db.Root;

            Tests.Assert(null == root);
            root           = new Root();
            root.strIndex  = db.CreateIndex <string, RecordFull>(IndexType.Unique);
            root.longIndex = db.CreateIndex <long, RecordFull>(IndexType.Unique);
            db.Root        = root;
            var strIndex = root.strIndex;

            Tests.Assert(typeof(string) == strIndex.KeyType);
            var longIndex = root.longIndex;

            Tests.Assert(typeof(long) == longIndex.KeyType);
            DateTime start         = DateTime.Now;
            int      startWithOne  = 0;
            int      startWithFive = 0;
            string   strFirst      = "z";
            string   strLast       = "0";

            int n = 0;

            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec = new RecordFull(key);
                if (rec.StrVal[0] == '1')
                {
                    startWithOne += 1;
                }
                else if (rec.StrVal[0] == '5')
                {
                    startWithFive += 1;
                }
                if (rec.StrVal.CompareTo(strFirst) < 0)
                {
                    strFirst = rec.StrVal;
                }
                else if (rec.StrVal.CompareTo(strLast) > 0)
                {
                    strLast = rec.StrVal;
                }
                longIndex[rec.Int32Val] = rec;
                strIndex[rec.StrVal]    = rec;
                n++;
                if (n % 100 == 0)
                {
                    MyCommit(db, config.Serializable);
                }
            }
            MyCommit(db, config.Serializable);

            Tests.Assert(longIndex.Count == count);
            Tests.Assert(strIndex.Count == count);

            res.InsertTime = DateTime.Now - start;
            start          = System.DateTime.Now;

            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec1 = longIndex[key];
                RecordFull rec2 = strIndex[Convert.ToString(key)];
                Tests.Assert(rec1 != null && rec2 != null);
                Tests.Assert(rec1 == rec2);
            }
            res.IndexSearchTime = DateTime.Now - start;
            start = System.DateTime.Now;

            var k = Int64.MinValue;

            n = 0;
            foreach (RecordFull rec in longIndex)
            {
                Tests.Assert(rec.Int32Val >= k);
                k  = rec.Int32Val;
                n += 1;
            }
            Tests.Assert(n == count);

            String strKey = "";

            n = 0;
            foreach (RecordFull rec in strIndex)
            {
                Tests.Assert(rec.StrVal.CompareTo(strKey) >= 0);
                strKey = rec.StrVal;
                n     += 1;
            }
            Tests.Assert(n == count);
            res.IterationTime = DateTime.Now - start;
            start             = System.DateTime.Now;

            IDictionaryEnumerator de = longIndex.GetDictionaryEnumerator();

            n = VerifyDictionaryEnumerator(de, IterationOrder.AscentOrder);
            Tests.Assert(n == count);

            long mid = 0;
            long max = long.MaxValue;

            de = longIndex.GetDictionaryEnumerator(new Key(mid), new Key(max), IterationOrder.DescentOrder);
            VerifyDictionaryEnumerator(de, IterationOrder.DescentOrder);

            Tests.AssertDatabaseException(() => longIndex.PrefixSearch("1"),
                                          DatabaseException.ErrorCode.INCOMPATIBLE_KEY_TYPE);
            RecordFull[] recs = strIndex.PrefixSearch("1");
            Tests.Assert(startWithOne == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("1"));
            }
            recs = strIndex.PrefixSearch("5");
            Tests.Assert(startWithFive == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("5"));
            }
            recs = strIndex.PrefixSearch("0");
            Tests.Assert(0 == recs.Length);

            recs = strIndex.PrefixSearch("a");
            Tests.Assert(0 == recs.Length);

            recs = strIndex.PrefixSearch(strFirst);
            Tests.Assert(recs.Length >= 1);
            Tests.Assert(recs[0].StrVal == strFirst);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith(strFirst));
            }

            recs = strIndex.PrefixSearch(strLast);
            Tests.Assert(recs.Length == 1);
            Tests.Assert(recs[0].StrVal == strLast);

            n = 0;
            RecordFull oneRemoved = null;

            foreach (var key in Tests.KeySeq(count))
            {
                n++;
                if (n % 3 == 0)
                {
                    continue;
                }
                RecordFull rec     = longIndex.Get(key);
                RecordFull removed = longIndex.RemoveKey(key);
                Tests.Assert(removed == rec);
                strIndex.Remove(new Key(System.Convert.ToString(key)), rec);
                Tests.Assert(!strIndex.Contains(removed));
                if (null == oneRemoved)
                {
                    oneRemoved = removed;
                }
            }
            db.Rollback();
            //TODO: shouldn't this be true?
            //Tests.Assert(strIndex.Contains(oneRemoved));

            res.RemoveTime = DateTime.Now - start;
            db.Close();
            if (config.IsTransient)
            {
                return;
            }

            db        = config.GetDatabase(false);
            root      = (Root)db.Root;
            longIndex = root.longIndex;
            strIndex  = root.strIndex;
            k         = Int64.MinValue;
            n         = 0;
            RecordFull firstRec   = null;
            RecordFull removedRec = null;

            foreach (RecordFull rec in longIndex)
            {
                Tests.Assert(rec.Int32Val >= k);
                k = rec.Int32Val;
                if (null == firstRec)
                {
                    firstRec = rec;
                }
                else if (null == removedRec)
                {
                    removedRec = rec;
                    strIndex.Remove(removedRec.StrVal, removedRec);
                }
                n++;
            }
            Tests.Assert(longIndex.Count == n);
            Tests.Assert(strIndex.Count == n - 1);
            Tests.Assert(longIndex.Contains(firstRec));
            Tests.Assert(strIndex.Contains(firstRec));
            Tests.Assert(!strIndex.Contains(removedRec));
            RecordFull notPresent = new RecordFull();

            Tests.Assert(!strIndex.Contains(notPresent));
            Tests.Assert(!longIndex.Contains(notPresent));
            longIndex.Clear();
            Tests.Assert(!longIndex.Contains(firstRec));
            db.Close();
        }
Beispiel #9
0
        public void Run(TestConfig config)
        {
            int i;
            int count = config.Count;
            var res = new TestIndexNumericResult();
            config.Result = res;

            var start = DateTime.Now;
            IDatabase db = config.GetDatabase();
            Tests.Assert(null == db.Root);
            var set = db.CreateSet<RecordFull>();
            db.Root = set;
            long val = 1999;
            var recs = new List<RecordFull>();
            var rand = new Random();
            for (i = 0; i < count; i++)
            {
                var r = new RecordFull(val);
                Tests.Assert(!set.Contains(r));
                set.Add(r);
                set.Add(r);
                if (recs.Count < 10 && rand.Next(0, 20) == 4)
                    recs.Add(r);

                Tests.Assert(set.Contains(r));
                if (i % 100 == 0)
                    db.Commit();
                val = (3141592621L * val + 2718281829L) % 1000000007L;
            }

            Tests.Assert(set.Count == count);
            db.Commit();
            Tests.Assert(set.Count == count);
            Tests.Assert(set.IsReadOnly == false);
            Tests.Assert(set.ContainsAll(recs));

            var rOne = new RecordFull(val);
            Tests.Assert(!set.Contains(rOne));
            Tests.Assert(!set.ContainsAll(new RecordFull[] { rOne }));
            Tests.Assert(set.AddAll(new RecordFull[] { rOne }));
            Tests.Assert(!set.AddAll(recs));
            Tests.Assert(set.Count == count + 1);
            Tests.Assert(set.Remove(rOne));
            Tests.Assert(!set.Remove(rOne));

            Tests.Assert(set.RemoveAll(recs));
            Tests.Assert(!set.RemoveAll(recs));
            Tests.Assert(set.Count == count - recs.Count);
            Tests.Assert(set.AddAll(recs));
            Tests.Assert(set.Count == count);
            db.Commit();

            res.InsertTime = DateTime.Now - start;

            IEnumerator e = set.GetEnumerator();
            Tests.Assert(e != null);

            start = System.DateTime.Now;
            Tests.Assert(!set.Equals(null));
            Tests.Assert(set.Equals(set));

            var set2 = db.CreateSet<RecordFull>();
            Tests.Assert(!set.Equals(set2));
            foreach (var r2 in set)
            {
                Tests.Assert(set.Contains(r2));
                set2.Add(r2);
            }
            Tests.Assert(set.Equals(set2));

            RecordFull[] recsArr = set.ToArray();
            Tests.Assert(recsArr.Length == count);
            set.Clear();
            Tests.Assert(set.Count == 0);
            db.Commit();
            Tests.Assert(set.Count == 0);
            set.Invalidate();
            set.Load();
            set.AddAll(recs);
            Tests.Assert(set.Count == recs.Count);
            db.Commit();
            Tests.Assert(set.Count == recs.Count);
            Tests.Assert(set.GetHashCode() > 0);
            db.Gc();

            // tests for PersistentString
            var ps = new PersistentString();
            Tests.Assert(ps.Get() == "");
            ps = new PersistentString("Hello");
            var s = ps.ToString();
            Tests.Assert(s == "Hello");
            ps.Append("2");
            Tests.Assert("Hello2" == ps.Get());
            ps.Set("Lala");
            Tests.Assert("Lala" == ps.Get());
            string s2 = ps;
            Tests.Assert("Lala" == s2);
            PersistentString ps2 = "Lulu";
            Tests.Assert(ps2.Get() == "Lulu");
            db.Root = ps;
            set.Deallocate();
            db.Gc();
            db.Commit();
            db.Close();
        }
Beispiel #10
0
        public void Run(TestConfig config)
        {
            int count = config.Count;
            var res   = new TestIndexResult();

            config.Result = res;
            IDatabase db = config.GetDatabase();

            Root root = (Root)db.Root;

            Tests.Assert(null == root);
            root         = new Root();
            root.strIdx  = db.CreateThickIndex <string, RecordFull>();
            root.byteIdx = db.CreateThickIndex <byte, RecordFull>();
            db.Root      = root;
            Tests.Assert(typeof(string) == root.strIdx.KeyType);
            Tests.Assert(typeof(byte) == root.byteIdx.KeyType);

            int    startWithOne  = 0;
            int    startWithFive = 0;
            string strFirst      = "z";
            string strLast       = "0";

            int n            = 0;
            var inThickIndex = new Dictionary <byte, List <RecordFull> >();

            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec = new RecordFull(key);
                if (rec.StrVal[0] == '1')
                {
                    startWithOne += 1;
                }
                else if (rec.StrVal[0] == '5')
                {
                    startWithFive += 1;
                }
                if (rec.StrVal.CompareTo(strFirst) < 0)
                {
                    strFirst = rec.StrVal;
                }
                else if (rec.StrVal.CompareTo(strLast) > 0)
                {
                    strLast = rec.StrVal;
                }
                root.strIdx.Put(rec.StrVal, rec);
                root.byteIdx.Put(rec.ByteVal, rec);
                n++;
                if (n % 100 == 0)
                {
                    db.Commit();
                }
                ;
            }
            db.Commit();

            Tests.Assert(root.strIdx.Count == count);
            Tests.Assert(root.byteIdx.Count <= count);

            Tests.AssertDatabaseException(() =>
                                          { root.strIdx.RemoveKey(""); },
                                          DatabaseException.ErrorCode.KEY_NOT_UNIQUE);

            Tests.AssertDatabaseException(() =>
                                          { root.strIdx.Remove(new Key("")); },
                                          DatabaseException.ErrorCode.KEY_NOT_UNIQUE);

            foreach (var mk in inThickIndex.Keys)
            {
                var list = inThickIndex[mk];
                while (list.Count > 1)
                {
                    var el = list[0];
                    list.Remove(el);
                    root.byteIdx.Remove(el.ByteVal, el);
                }
            }

            RecordFull[] recs;
            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec1 = root.strIdx[Convert.ToString(key)];
                recs = root.byteIdx[rec1.ByteVal, rec1.ByteVal];
                Tests.Assert(rec1 != null && recs.Length >= 1);
                Tests.Assert(rec1.ByteVal == recs[0].ByteVal);
            }

            // test for non-existent key
            Tests.Assert(null == root.strIdx.Get("-122"));

            recs = root.byteIdx.ToArray();
            Tests.Assert(recs.Length == root.byteIdx.Count);

            var prevByte = byte.MinValue;

            n = 0;
            foreach (RecordFull rec in root.byteIdx)
            {
                Tests.Assert(rec.ByteVal >= prevByte);
                prevByte = rec.ByteVal;
                n       += 1;
            }
            Tests.Assert(n == count);

            String prevStrKey = "";

            n = 0;
            foreach (RecordFull rec in  root.strIdx)
            {
                Tests.Assert(rec.StrVal.CompareTo(prevStrKey) >= 0);
                prevStrKey = rec.StrVal;
                n         += 1;
            }
            IDictionaryEnumerator de = root.strIdx.GetDictionaryEnumerator();

            n = VerifyDictionaryEnumerator(de, IterationOrder.AscentOrder);
            Tests.Assert(n == count);

            string mid = "0";
            string max = long.MaxValue.ToString();;

            de = root.strIdx.GetDictionaryEnumerator(new Key(mid), new Key(max), IterationOrder.DescentOrder);
            VerifyDictionaryEnumerator(de, IterationOrder.DescentOrder);

            Tests.AssertDatabaseException(
                () => root.byteIdx.PrefixSearch("1"),
                DatabaseException.ErrorCode.INCOMPATIBLE_KEY_TYPE);
            // TODO: FAILED_TEST broken for altbtree, returns no results
            if (!config.AltBtree)
            {
                recs = root.strIdx.GetPrefix("1");
                Tests.Assert(recs.Length > 0);
                foreach (var r in recs)
                {
                    Tests.Assert(r.StrVal.StartsWith("1"));
                }
            }
            recs = root.strIdx.PrefixSearch("1");
            Tests.Assert(startWithOne == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("1"));
            }
            recs = root.strIdx.PrefixSearch("5");
            Tests.Assert(startWithFive == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("5"));
            }
            recs = root.strIdx.PrefixSearch("0");
            Tests.Assert(0 == recs.Length);

            recs = root.strIdx.PrefixSearch("a");
            Tests.Assert(0 == recs.Length);

            recs = root.strIdx.PrefixSearch(strFirst);
            Tests.Assert(recs.Length >= 1);
            Tests.Assert(recs[0].StrVal == strFirst);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith(strFirst));
            }

            recs = root.strIdx.PrefixSearch(strLast);
            Tests.Assert(recs.Length == 1);
            Tests.Assert(recs[0].StrVal == strLast);

            n = 0;
            foreach (var key in Tests.KeySeq(count))
            {
                n++;
                if (n % 3 == 0)
                {
                    continue;
                }
                string     strKey = key.ToString();
                RecordFull rec    = root.strIdx.Get(strKey);
                root.strIdx.Remove(strKey, rec);
            }
            root.byteIdx.Clear();

            int  BTREE_THRESHOLD = 128;
            byte bKey            = 1;

            for (int i = 0; i < BTREE_THRESHOLD + 10; i++)
            {
                RecordFull r = new RecordFull(0);
                if (i == 0)
                {
                    root.byteIdx[bKey] = r;
                    continue;
                }
                if (i == 1)
                {
                    root.byteIdx.Set(bKey, r);
                    continue;
                }
                root.byteIdx.Put(bKey, r);
            }

            Tests.AssertDatabaseException(
                () => root.byteIdx.Set(bKey, new RecordFull(1)),
                DatabaseException.ErrorCode.KEY_NOT_UNIQUE);
            Tests.AssertDatabaseException(
                () => root.byteIdx.Get(bKey),
                DatabaseException.ErrorCode.KEY_NOT_UNIQUE);
            recs = root.byteIdx.ToArray();
            foreach (var r in recs)
            {
                root.byteIdx.Remove(bKey, r);
            }
            Tests.AssertDatabaseException(
                () => root.byteIdx.Remove(bKey, new RecordFull(0)),
                DatabaseException.ErrorCode.KEY_NOT_FOUND);
            IEnumerator <RecordFull> e = root.byteIdx.GetEnumerator();

            while (e.MoveNext())
            {
            }
            Tests.Assert(!e.MoveNext());
            db.Close();
        }
Beispiel #11
0
        public void Run(TestConfig config)
        {
            int count = config.Count;
            var res = new TestIndexResult();
            config.Result = res;
            IDatabase db = config.GetDatabase();
            if (config.Serializable)
                db.BeginThreadTransaction(TransactionMode.Serializable);

            Root root = (Root)db.Root;
            Tests.Assert(null == root);
            root = new Root();
            root.strIndex = db.CreateIndex<string, RecordFull>(IndexType.Unique);
            root.longIndex = db.CreateIndex<long, RecordFull>(IndexType.Unique);
            db.Root = root;
            var strIndex = root.strIndex;
            Tests.Assert(typeof(string) == strIndex.KeyType);
            var longIndex = root.longIndex;
            Tests.Assert(typeof(long) == longIndex.KeyType);
            DateTime start = DateTime.Now;
            int startWithOne = 0;
            int startWithFive = 0;
            string strFirst = "z";
            string strLast  = "0";

            int n = 0;
            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec = new RecordFull(key);
                if (rec.StrVal[0] == '1')
                    startWithOne += 1;
                else if (rec.StrVal[0] == '5')
                    startWithFive += 1;
                if (rec.StrVal.CompareTo(strFirst) < 0)
                    strFirst = rec.StrVal;
                else if (rec.StrVal.CompareTo(strLast) > 0)
                    strLast = rec.StrVal;
                longIndex[rec.Int32Val] = rec;
                strIndex[rec.StrVal] = rec;
                n++;
                if (n % 100 == 0)
                    MyCommit(db, config.Serializable);
            }
            MyCommit(db, config.Serializable);

            Tests.Assert(longIndex.Count == count);
            Tests.Assert(strIndex.Count == count);

            res.InsertTime = DateTime.Now - start;
            start = System.DateTime.Now;

            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec1 = longIndex[key];
                RecordFull rec2 = strIndex[Convert.ToString(key)];
                Tests.Assert(rec1 != null && rec2 != null);
                Tests.Assert(rec1 == rec2);
            }
            res.IndexSearchTime = DateTime.Now - start;
            start = System.DateTime.Now;

            var k = Int64.MinValue;
            n = 0;
            foreach (RecordFull rec in longIndex)
            {
                Tests.Assert(rec.Int32Val >= k);
                k = rec.Int32Val;
                n += 1;
            }
            Tests.Assert(n == count);

            String strKey = "";
            n = 0;
            foreach (RecordFull rec in strIndex)
            {
                Tests.Assert(rec.StrVal.CompareTo(strKey) >= 0);
                strKey = rec.StrVal;
                n += 1;
            }
            Tests.Assert(n == count);
            res.IterationTime = DateTime.Now - start;
            start = System.DateTime.Now;

            IDictionaryEnumerator de = longIndex.GetDictionaryEnumerator();
            n = VerifyDictionaryEnumerator(de, IterationOrder.AscentOrder);
            Tests.Assert(n == count);

            long mid = 0;
            long max = long.MaxValue;
            de = longIndex.GetDictionaryEnumerator(new Key(mid), new Key(max), IterationOrder.DescentOrder);
            VerifyDictionaryEnumerator(de, IterationOrder.DescentOrder);

            Tests.AssertDatabaseException(() => longIndex.PrefixSearch("1"),
                DatabaseException.ErrorCode.INCOMPATIBLE_KEY_TYPE);
            RecordFull[] recs = strIndex.PrefixSearch("1");
            Tests.Assert(startWithOne == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("1"));
            }
            recs = strIndex.PrefixSearch("5");
            Tests.Assert(startWithFive == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("5"));
            }
            recs = strIndex.PrefixSearch("0");
            Tests.Assert(0 == recs.Length);

            recs = strIndex.PrefixSearch("a");
            Tests.Assert(0 == recs.Length);

            recs = strIndex.PrefixSearch(strFirst);
            Tests.Assert(recs.Length >= 1);
            Tests.Assert(recs[0].StrVal == strFirst);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith(strFirst));
            }

            recs = strIndex.PrefixSearch(strLast);
            Tests.Assert(recs.Length == 1);
            Tests.Assert(recs[0].StrVal == strLast);

            n = 0;
            RecordFull oneRemoved = null;
            foreach (var key in Tests.KeySeq(count))
            {
                n++;
                if (n % 3 == 0)
                    continue;
                RecordFull rec = longIndex.Get(key);
                RecordFull removed = longIndex.RemoveKey(key);
                Tests.Assert(removed == rec);
                strIndex.Remove(new Key(System.Convert.ToString(key)), rec);
                Tests.Assert(!strIndex.Contains(removed));
                if (null == oneRemoved)
                    oneRemoved = removed;
            }
            db.Rollback();
            //TODO: shouldn't this be true?
            //Tests.Assert(strIndex.Contains(oneRemoved));

            res.RemoveTime = DateTime.Now - start;
            db.Close();
            if (config.IsTransient)
                return;

            db = config.GetDatabase(false);
            root = (Root)db.Root;
            longIndex = root.longIndex;
            strIndex = root.strIndex;
            k = Int64.MinValue;
            n = 0;
            RecordFull firstRec = null;
            RecordFull removedRec = null;
            foreach (RecordFull rec in longIndex)
            {
                Tests.Assert(rec.Int32Val >= k);
                k = rec.Int32Val;
                if (null == firstRec)
                    firstRec = rec;
                else if (null == removedRec)
                {
                    removedRec = rec;
                    strIndex.Remove(removedRec.StrVal, removedRec);
                }
                n++;
            }
            Tests.Assert(longIndex.Count == n);
            Tests.Assert(strIndex.Count == n-1);
            Tests.Assert(longIndex.Contains(firstRec));
            Tests.Assert(strIndex.Contains(firstRec));
            Tests.Assert(!strIndex.Contains(removedRec));
            RecordFull notPresent = new RecordFull();
            Tests.Assert(!strIndex.Contains(notPresent));
            Tests.Assert(!longIndex.Contains(notPresent));
            longIndex.Clear();
            Tests.Assert(!longIndex.Contains(firstRec));
            db.Close();
        }
Beispiel #12
0
        public void Run(TestConfig config)
        {
            int count = config.Count;
            var res = new TestIndexResult();
            config.Result = res;
            IDatabase db = config.GetDatabase();

            Root root = (Root)db.Root;
            Tests.Assert(null == root);
            root = new Root();
            root.strIdx = db.CreateThickIndex<string, RecordFull>();
            root.byteIdx = db.CreateThickIndex<byte, RecordFull>();
            db.Root = root;
            Tests.Assert(typeof(string) == root.strIdx.KeyType);
            Tests.Assert(typeof(byte) == root.byteIdx.KeyType);

            int startWithOne = 0;
            int startWithFive = 0;
            string strFirst = "z";
            string strLast = "0";

            int n = 0;
            var inThickIndex = new Dictionary<byte, List<RecordFull>>();
            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec = new RecordFull(key);
                if (rec.StrVal[0] == '1')
                    startWithOne += 1;
                else if (rec.StrVal[0] == '5')
                    startWithFive += 1;
                if (rec.StrVal.CompareTo(strFirst) < 0)
                    strFirst = rec.StrVal;
                else if (rec.StrVal.CompareTo(strLast) > 0)
                    strLast = rec.StrVal;
                root.strIdx.Put(rec.StrVal, rec);
                root.byteIdx.Put(rec.ByteVal, rec);
                n++;
                if (n % 100 == 0)
                    db.Commit(); ;
            }
            db.Commit();

            Tests.Assert(root.strIdx.Count == count);
            Tests.Assert(root.byteIdx.Count <= count);

            Tests.AssertDatabaseException(() =>
                { root.strIdx.RemoveKey(""); },
                DatabaseException.ErrorCode.KEY_NOT_UNIQUE);

            Tests.AssertDatabaseException(() =>
                { root.strIdx.Remove(new Key("")); },
                DatabaseException.ErrorCode.KEY_NOT_UNIQUE);

            foreach (var mk in inThickIndex.Keys)
            {
                var list = inThickIndex[mk];
                while (list.Count > 1)
                {
                    var el = list[0];
                    list.Remove(el);
                    root.byteIdx.Remove(el.ByteVal, el);
                }
            }

            RecordFull[] recs;
            foreach (var key in Tests.KeySeq(count))
            {
                RecordFull rec1 = root.strIdx[Convert.ToString(key)];
                recs = root.byteIdx[rec1.ByteVal, rec1.ByteVal];
                Tests.Assert(rec1 != null && recs.Length >= 1);
                Tests.Assert(rec1.ByteVal == recs[0].ByteVal);
            }

            // test for non-existent key
            Tests.Assert(null == root.strIdx.Get("-122"));

            recs = root.byteIdx.ToArray();
            Tests.Assert(recs.Length == root.byteIdx.Count);

            var prevByte = byte.MinValue;
            n = 0;
            foreach (RecordFull rec in root.byteIdx)
            {
                Tests.Assert(rec.ByteVal >= prevByte);
                prevByte = rec.ByteVal;
                n += 1;
            }
            Tests.Assert(n == count);

            String prevStrKey = "";
            n = 0;
            foreach (RecordFull rec in  root.strIdx)
            {
                Tests.Assert(rec.StrVal.CompareTo(prevStrKey) >= 0);
                prevStrKey = rec.StrVal;
                n += 1;
            }
            IDictionaryEnumerator de = root.strIdx.GetDictionaryEnumerator();
            n = VerifyDictionaryEnumerator(de, IterationOrder.AscentOrder);
            Tests.Assert(n == count);

            string mid = "0";
            string max = long.MaxValue.ToString(); ;
            de = root.strIdx.GetDictionaryEnumerator(new Key(mid), new Key(max), IterationOrder.DescentOrder);
            VerifyDictionaryEnumerator(de, IterationOrder.DescentOrder);

            Tests.AssertDatabaseException(
                () => root.byteIdx.PrefixSearch("1"),
                DatabaseException.ErrorCode.INCOMPATIBLE_KEY_TYPE);
            // TODO: FAILED_TEST broken for altbtree, returns no results
            if (!config.AltBtree)
            {
                recs = root.strIdx.GetPrefix("1");
                Tests.Assert(recs.Length > 0);
                foreach (var r in recs)
                {
                    Tests.Assert(r.StrVal.StartsWith("1"));
                }
            }
            recs = root.strIdx.PrefixSearch("1");
            Tests.Assert(startWithOne == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("1"));
            }
            recs = root.strIdx.PrefixSearch("5");
            Tests.Assert(startWithFive == recs.Length);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith("5"));
            }
            recs = root.strIdx.PrefixSearch("0");
            Tests.Assert(0 == recs.Length);

            recs = root.strIdx.PrefixSearch("a");
            Tests.Assert(0 == recs.Length);

            recs = root.strIdx.PrefixSearch(strFirst);
            Tests.Assert(recs.Length >= 1);
            Tests.Assert(recs[0].StrVal == strFirst);
            foreach (var r in recs)
            {
                Tests.Assert(r.StrVal.StartsWith(strFirst));
            }

            recs = root.strIdx.PrefixSearch(strLast);
            Tests.Assert(recs.Length == 1);
            Tests.Assert(recs[0].StrVal == strLast);

            n = 0;
            foreach (var key in Tests.KeySeq(count))
            {
                n++;
                if (n % 3 == 0)
                    continue;
                string strKey = key.ToString();
                RecordFull rec = root.strIdx.Get(strKey);
                root.strIdx.Remove(strKey, rec);
            }
            root.byteIdx.Clear();

            int BTREE_THRESHOLD = 128;
            byte bKey = 1;
            for (int i = 0; i < BTREE_THRESHOLD + 10; i++)
            {
                RecordFull r = new RecordFull(0);
                if (i == 0)
                {
                    root.byteIdx[bKey] = r;
                    continue;
                }
                if (i == 1)
                {
                    root.byteIdx.Set(bKey, r);
                    continue;
                }
                root.byteIdx.Put(bKey, r);
            }

            Tests.AssertDatabaseException(
                () => root.byteIdx.Set(bKey, new RecordFull(1)),
                DatabaseException.ErrorCode.KEY_NOT_UNIQUE);
            Tests.AssertDatabaseException(
                () => root.byteIdx.Get(bKey),
                DatabaseException.ErrorCode.KEY_NOT_UNIQUE);
            recs = root.byteIdx.ToArray();
            foreach (var r in recs)
            {
                root.byteIdx.Remove(bKey, r);
            }
            Tests.AssertDatabaseException(
                () => root.byteIdx.Remove(bKey, new RecordFull(0)),
                DatabaseException.ErrorCode.KEY_NOT_FOUND);
            IEnumerator<RecordFull> e = root.byteIdx.GetEnumerator();
            while (e.MoveNext()) { }
            Tests.Assert(!e.MoveNext());
            db.Close();
        }
Beispiel #13
0
        public void Run(TestConfig config)
        {
            RecordFull r;
            RelMember  rm;

            RecordFull[] recs;
            RelMember[]  rmArr;
            RecordFull   notInArr1;
            IDatabase    db = config.GetDatabase();

            config.Result = new TestResult();
            Root root = new Root();
            var  arr  = db.CreateArray <RecordFull>(256);

            arr = db.CreateArray <RecordFull>();
            var link = db.CreateLink <RecordFull>(256);

            link          = db.CreateLink <RecordFull>();
            root.relOwner = new RecordFull();
            var rel = db.CreateRelation <RelMember, RecordFull>(root.relOwner);

            Tests.Assert(rel.Owner == root.relOwner);
            rel.SetOwner(new RecordFull(88));
            Tests.Assert(rel.Owner != root.relOwner);
            rel.Owner = root.relOwner;
            Tests.Assert(rel.Owner == root.relOwner);
            root.arr  = arr;
            root.link = link;
            root.rel  = rel;
            db.Root   = root;
            Tests.Assert(arr.Count == 0);
            Tests.Assert(((IGenericPArray)arr).Size() == 0);

            var inMem = new List <RecordFull>();

            for (long i = 0; i < 256; i++)
            {
                r  = new RecordFull(i);
                rm = new RelMember(i);
                inMem.Add(r);
                arr.Add(r);
                Tests.Assert(arr.Count == i + 1);
                link.Add(r);
                rel.Add(rm);
                Tests.Assert(link.Count == i + 1);
            }
            recs  = arr.ToArray();
            rmArr = rel.ToArray();
            Tests.Assert(recs.Length == rmArr.Length);
            Tests.Assert(rel.Count == rel.Length);
            Tests.Assert(rel.Size() == rel.Count);
            rel.CopyTo(rmArr, 0);
            Tests.Assert(recs.Length == arr.Length);
            for (int j = 0; j < recs.Length; j++)
            {
                Tests.Assert(recs[j] == arr[j]);
                Tests.Assert(rmArr[j] == rel[j]);
            }
            recs = inMem.ToArray();

            arr.AddAll(recs);

            rel.AddAll(rmArr);

            notInArr1 = new RecordFull(256);
            inMem.Add(notInArr1);
            db.Commit();

            var e   = link.GetEnumerator();
            int idx = 0;

            while (e.MoveNext())
            {
                Tests.Assert(e.Current == inMem[idx++]);
            }
            Tests.AssertException <InvalidOperationException>(
                () => { var tmp = e.Current; });
            Tests.Assert(!e.MoveNext());
            e.Reset();
            idx = 0;
            int nullCount = 0;

            while (e.MoveNext())
            {
                Tests.Assert(e.Current == inMem[idx++]);
                IEnumerator e2 = (IEnumerator)e;
                if (e2.Current == null)
                {
                    nullCount++;
                }
            }

            var e3 = rel.GetEnumerator();

            while (e3.MoveNext())
            {
                Tests.Assert(e3.Current != null);
            }
            Tests.Assert(!e3.MoveNext());
            Tests.AssertException <InvalidOperationException>(
                () => { var tmp = e3.Current; });
            e3.Reset();
            Tests.Assert(e3.MoveNext());

            nullCount = 0;
            foreach (var r2 in link)
            {
                if (null == r2)
                {
                    nullCount++;
                }
            }

            Tests.Assert(arr.Length == 512);
            Array a = arr.ToArray();

            Tests.Assert(a.Length == 512);
            a = arr.ToRawArray();
            Tests.Assert(a.Length == 512);

            arr.RemoveAt(0);
            db.Commit();

            Tests.Assert(arr.Count == 511);
            arr.RemoveAt(arr.Count - 1);
            db.Commit();
            Tests.Assert(arr.Count == 510);
            r = arr[5];
            Tests.Assert(arr.Contains(r));
            Tests.Assert(!arr.Contains(null));
            Tests.Assert(!arr.Contains(notInArr1));
            Tests.Assert(arr.ContainsElement(5, r));
            Tests.Assert(!arr.IsReadOnly);
            Tests.Assert(!link.IsReadOnly);
            Tests.Assert(5 == arr.IndexOf(r));
            Tests.Assert(-1 == arr.IndexOf(notInArr1));
            Tests.Assert(-1 == arr.IndexOf(null));
            Tests.Assert(r.Oid == arr.GetOid(5));
            arr[5] = new RecordFull(17);
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { r = arr[1024]; });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.Insert(9999, null); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { link.Insert(9999, null); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.Insert(-1, null); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { link.Insert(-1, null); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.RemoveAt(9999); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.RemoveAt(-1); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.GetOid(9999); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.GetOid(-1); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.GetRaw(9999); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.GetRaw(-1); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.Set(9999, new RecordFull(9988)); });
            Tests.AssertException <IndexOutOfRangeException>(() =>
                                                             { arr.Set(-1, new RecordFull(9988)); });

            Tests.Assert(null != arr.GetRaw(8));

            arr.Set(25, arr[24]);
            arr.Pin();
            arr.Unpin();
            Tests.Assert(arr.Remove(arr[12]));
            Tests.Assert(!arr.Remove(notInArr1));
            Tests.Assert(link.Remove(link[3]));
            Tests.Assert(!link.Remove(notInArr1));
            Tests.Assert(arr.Length == 509);
            arr.Insert(5, new RecordFull(88));
            Tests.Assert(arr.Length == 510);
            link.Insert(5, new RecordFull(88));
            int expectedCount = arr.Count + link.Count;

            arr.AddAll(link);
            Tests.Assert(arr.Count == expectedCount);

            Tests.Assert(null != arr.GetEnumerator());
            Tests.Assert(null != link.GetEnumerator());

            link.Length = 1024;
            Tests.Assert(link.Length == 1024);
            link.Length = 128;
            Tests.Assert(link.Length == 128);
            link.AddAll(arr);
            arr.Clear();
            Tests.Assert(0 == arr.Length);
            db.Commit();
            arr.AddAll(link);
            arr.AddAll(arr);
            recs = arr.ToArray();
            link.AddAll(new RecordFull[1] {
                recs[0]
            });
            link.AddAll(recs, 1, 1);
            db.Commit();
            recs = link.ToArray();
            Tests.Assert(recs.Length == link.Length);
            link.Length = link.Length - 2;

            rel.Length = rel.Length / 2;
            idx        = rel.Length / 2;
            Tests.Assert(null != rel.Get(idx));
            rel[idx] = new RelMember(55);
            db.Commit();
            IPersistent raw = rel.GetRaw(idx);

            Tests.Assert(raw.IsRaw());
            rm = rel[idx];
            Tests.Assert(rel.Contains(rm));
            Tests.Assert(rel.ContainsElement(idx, rm));
            Tests.Assert(rel.Remove(rm));
            Tests.Assert(!rel.Contains(rm));
            Tests.Assert(!rel.Remove(rm));
            idx = rel.Length / 2;
            rm  = rel[idx];
            Tests.Assert(idx == rel.IndexOf(rm));
            int cnt = rel.Count;

            rel.RemoveAt(idx);
            Tests.Assert(rel.Count == cnt - 1);
            Tests.Assert(!rel.Contains(rm));
            rel.Add(rm);
            db.Commit();
            //TODO: LinkImpl.ToRawArray() seems wrong but changing it
            //breaks a lot of code
            //Array ra = rel.ToRawArray();
            Array ra2 = rel.ToArray();

            //Tests.Assert(ra2.Length == ra.Length);
            //Tests.Assert(ra.Length == rel.Count);
            rel.Insert(1, new RelMember(123));
            //Tests.Assert(rel.Count == ra.Length + 1);
            rel.Unpin();
            rel.Pin();
            rel.Unpin();
            rel.Clear();
            Tests.Assert(rel.Count == 0);
            db.Close();
        }
Beispiel #14
0
        public void Run(TestConfig config)
        {
            RecordFull r;
            RelMember rm;
            RecordFull[] recs;
            RelMember[] rmArr;
            RecordFull notInArr1;
            IDatabase db = config.GetDatabase();
            config.Result = new TestResult();
            Root root = new Root();
            var arr = db.CreateArray<RecordFull>(256);
            arr = db.CreateArray<RecordFull>();
            var link = db.CreateLink<RecordFull>(256);
            link = db.CreateLink<RecordFull>();
            root.relOwner = new RecordFull();
            var rel = db.CreateRelation<RelMember, RecordFull>(root.relOwner);
            Tests.Assert(rel.Owner == root.relOwner);
            rel.SetOwner(new RecordFull(88));
            Tests.Assert(rel.Owner != root.relOwner);
            rel.Owner = root.relOwner;
            Tests.Assert(rel.Owner == root.relOwner);
            root.arr = arr;
            root.link = link;
            root.rel = rel;
            db.Root = root;
            Tests.Assert(arr.Count == 0);
            Tests.Assert(((IGenericPArray)arr).Size() == 0);

            var inMem = new List<RecordFull>();
            for (long i = 0; i < 256; i++)
            {
                r = new RecordFull(i);
                rm = new RelMember(i);
                inMem.Add(r);
                arr.Add(r);
                Tests.Assert(arr.Count == i + 1);
                link.Add(r);
                rel.Add(rm);
                Tests.Assert(link.Count == i + 1);
            }
            recs = arr.ToArray();
            rmArr = rel.ToArray();
            Tests.Assert(recs.Length == rmArr.Length);
            Tests.Assert(rel.Count == rel.Length);
            Tests.Assert(rel.Size() == rel.Count);
            rel.CopyTo(rmArr, 0);
            Tests.Assert(recs.Length == arr.Length);
            for (int j = 0; j < recs.Length; j++)
            {
                Tests.Assert(recs[j] == arr[j]);
                Tests.Assert(rmArr[j] == rel[j]);
            }
            recs = inMem.ToArray();

            arr.AddAll(recs);

            rel.AddAll(rmArr);

            notInArr1 = new RecordFull(256);
            inMem.Add(notInArr1);
            db.Commit();

            var e = link.GetEnumerator();
            int idx = 0;
            while (e.MoveNext())
            {
                Tests.Assert(e.Current == inMem[idx++]);
            }
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = e.Current; });
            Tests.Assert(!e.MoveNext());
            e.Reset();
            idx = 0;
            int nullCount = 0;
            while (e.MoveNext())
            {
                Tests.Assert(e.Current == inMem[idx++]);
                IEnumerator e2 = (IEnumerator)e;
                if (e2.Current == null)
                    nullCount++;
            }

            var e3 = rel.GetEnumerator();
            while (e3.MoveNext())
            {
                Tests.Assert(e3.Current != null);
            }
            Tests.Assert(!e3.MoveNext());
            Tests.AssertException<InvalidOperationException>(
                () => { var tmp = e3.Current; });
            e3.Reset();
            Tests.Assert(e3.MoveNext());

            nullCount = 0;
            foreach (var r2 in link)
            {
                if (null == r2)
                    nullCount++;
            }

            Tests.Assert(arr.Length == 512);
            Array a = arr.ToArray();
            Tests.Assert(a.Length == 512);
            a = arr.ToRawArray();
            Tests.Assert(a.Length == 512);

            arr.RemoveAt(0);
            db.Commit();

            Tests.Assert(arr.Count == 511);
            arr.RemoveAt(arr.Count - 1);
            db.Commit();
            Tests.Assert(arr.Count == 510);
            r = arr[5];
            Tests.Assert(arr.Contains(r));
            Tests.Assert(!arr.Contains(null));
            Tests.Assert(!arr.Contains(notInArr1));
            Tests.Assert(arr.ContainsElement(5, r));
            Tests.Assert(!arr.IsReadOnly);
            Tests.Assert(!link.IsReadOnly);
            Tests.Assert(5 == arr.IndexOf(r));
            Tests.Assert(-1 == arr.IndexOf(notInArr1));
            Tests.Assert(-1 == arr.IndexOf(null));
            Tests.Assert(r.Oid == arr.GetOid(5));
            arr[5] = new RecordFull(17);
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { r = arr[1024]; });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.Insert(9999, null); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { link.Insert(9999, null); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.Insert(-1, null); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { link.Insert(-1, null); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.RemoveAt(9999); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.RemoveAt(-1); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.GetOid(9999); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.GetOid(-1); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.GetRaw(9999); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.GetRaw(-1); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.Set(9999, new RecordFull(9988)); });
            Tests.AssertException<IndexOutOfRangeException>(() =>
            { arr.Set(-1, new RecordFull(9988)); });

            Tests.Assert(null != arr.GetRaw(8));

            arr.Set(25, arr[24]);
            arr.Pin();
            arr.Unpin();
            Tests.Assert(arr.Remove(arr[12]));
            Tests.Assert(!arr.Remove(notInArr1));
            Tests.Assert(link.Remove(link[3]));
            Tests.Assert(!link.Remove(notInArr1));
            Tests.Assert(arr.Length == 509);
            arr.Insert(5, new RecordFull(88));
            Tests.Assert(arr.Length == 510);
            link.Insert(5, new RecordFull(88));
            int expectedCount = arr.Count + link.Count;
            arr.AddAll(link);
            Tests.Assert(arr.Count == expectedCount);

            Tests.Assert(null != arr.GetEnumerator());
            Tests.Assert(null != link.GetEnumerator());

            link.Length = 1024;
            Tests.Assert(link.Length == 1024);
            link.Length = 128;
            Tests.Assert(link.Length == 128);
            link.AddAll(arr);
            arr.Clear();
            Tests.Assert(0 == arr.Length);
            db.Commit();
            arr.AddAll(link);
            arr.AddAll(arr);
            recs = arr.ToArray();
            link.AddAll(new RecordFull[1] { recs[0] });
            link.AddAll(recs, 1, 1);
            db.Commit();
            recs = link.ToArray();
            Tests.Assert(recs.Length == link.Length);
            link.Length = link.Length - 2;

            rel.Length = rel.Length / 2;
            idx = rel.Length / 2;
            Tests.Assert(null != rel.Get(idx));
            rel[idx] = new RelMember(55);
            db.Commit();
            IPersistent raw = rel.GetRaw(idx);
            Tests.Assert(raw.IsRaw());
            rm = rel[idx];
            Tests.Assert(rel.Contains(rm));
            Tests.Assert(rel.ContainsElement(idx, rm));
            Tests.Assert(rel.Remove(rm));
            Tests.Assert(!rel.Contains(rm));
            Tests.Assert(!rel.Remove(rm));
            idx = rel.Length / 2;
            rm = rel[idx];
            Tests.Assert(idx == rel.IndexOf(rm));
            int cnt = rel.Count;
            rel.RemoveAt(idx);
            Tests.Assert(rel.Count == cnt - 1);
            Tests.Assert(!rel.Contains(rm));
            rel.Add(rm);
            db.Commit();
            //TODO: LinkImpl.ToRawArray() seems wrong but changing it
            //breaks a lot of code
            //Array ra = rel.ToRawArray();
            Array ra2 = rel.ToArray();
            //Tests.Assert(ra2.Length == ra.Length);
            //Tests.Assert(ra.Length == rel.Count);
            rel.Insert(1, new RelMember(123));
            //Tests.Assert(rel.Count == ra.Length + 1);
            rel.Unpin();
            rel.Pin();
            rel.Unpin();
            rel.Clear();
            Tests.Assert(rel.Count == 0);
            db.Close();
        }
Beispiel #15
0
        public void Run(TestConfig config)
        {
            int i;
            int count = config.Count;
            var res   = new TestIndexNumericResult();

            config.Result = res;

            var       start = DateTime.Now;
            IDatabase db    = config.GetDatabase();

            Tests.Assert(null == db.Root);
            var set = db.CreateSet <RecordFull>();

            db.Root = set;
            long val  = 1999;
            var  recs = new List <RecordFull>();
            var  rand = new Random();

            for (i = 0; i < count; i++)
            {
                var r = new RecordFull(val);
                Tests.Assert(!set.Contains(r));
                set.Add(r);
                set.Add(r);
                if (recs.Count < 10 && rand.Next(0, 20) == 4)
                {
                    recs.Add(r);
                }

                Tests.Assert(set.Contains(r));
                if (i % 100 == 0)
                {
                    db.Commit();
                }
                val = (3141592621L * val + 2718281829L) % 1000000007L;
            }

            Tests.Assert(set.Count == count);
            db.Commit();
            Tests.Assert(set.Count == count);
            Tests.Assert(set.IsReadOnly == false);
            Tests.Assert(set.ContainsAll(recs));

            var rOne = new RecordFull(val);

            Tests.Assert(!set.Contains(rOne));
            Tests.Assert(!set.ContainsAll(new RecordFull[] { rOne }));
            Tests.Assert(set.AddAll(new RecordFull[] { rOne }));
            Tests.Assert(!set.AddAll(recs));
            Tests.Assert(set.Count == count + 1);
            Tests.Assert(set.Remove(rOne));
            Tests.Assert(!set.Remove(rOne));

            Tests.Assert(set.RemoveAll(recs));
            Tests.Assert(!set.RemoveAll(recs));
            Tests.Assert(set.Count == count - recs.Count);
            Tests.Assert(set.AddAll(recs));
            Tests.Assert(set.Count == count);
            db.Commit();

            res.InsertTime = DateTime.Now - start;

            IEnumerator e = set.GetEnumerator();

            Tests.Assert(e != null);

            start = System.DateTime.Now;
            Tests.Assert(!set.Equals(null));
            Tests.Assert(set.Equals(set));

            var set2 = db.CreateSet <RecordFull>();

            Tests.Assert(!set.Equals(set2));
            foreach (var r2 in set)
            {
                Tests.Assert(set.Contains(r2));
                set2.Add(r2);
            }
            Tests.Assert(set.Equals(set2));

            RecordFull[] recsArr = set.ToArray();
            Tests.Assert(recsArr.Length == count);
            set.Clear();
            Tests.Assert(set.Count == 0);
            db.Commit();
            Tests.Assert(set.Count == 0);
            set.Invalidate();
            set.Load();
            set.AddAll(recs);
            Tests.Assert(set.Count == recs.Count);
            db.Commit();
            Tests.Assert(set.Count == recs.Count);
            Tests.Assert(set.GetHashCode() > 0);
            db.Gc();

            // tests for PersistentString
            var ps = new PersistentString();

            Tests.Assert(ps.Get() == "");
            ps = new PersistentString("Hello");
            var s = ps.ToString();

            Tests.Assert(s == "Hello");
            ps.Append("2");
            Tests.Assert("Hello2" == ps.Get());
            ps.Set("Lala");
            Tests.Assert("Lala" == ps.Get());
            string s2 = ps;

            Tests.Assert("Lala" == s2);
            PersistentString ps2 = "Lulu";

            Tests.Assert(ps2.Get() == "Lulu");
            db.Root = ps;
            set.Deallocate();
            db.Gc();
            db.Commit();
            db.Close();
        }