Esempio n. 1
0
        public async Task TestUpdateDictionary()
        {
            Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);


            await s_db.DropTypeAsync <WithDict>();

            await s_db.DropTypeAsync <JaggedTy>();

            await s_db.DropTypeAsync <NMatrixTy>();

            for (int i = 0; i < 10; i++)
            {
                WithDict dict = new WithDict();
                dict.DictInt     = new Dictionary <int, int>();
                dict.DictStr     = new Dictionary <byte, string>();
                dict.DictComplex = new Dictionary <JaggedTy, int>();
                dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                for (int j = 0; j < 5; j++)
                {
                    dict.DictInt[j]         = i + j;
                    dict.ZuperDict[(uint)j] = new NMatrixTy();
                    dict.DictStr[(byte)j]   = "sss" + i.ToString();
                    JaggedTy jt = new JaggedTy();
                    dict.DictComplex[jt] = j + i;
                }

                await s_db.StoreObjectAsync(dict);
            }
            await s_db.FlushAsync();

            IList <WithDict> all = await s_db.LoadAllAsync <WithDict>();

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    all[i].DictInt[j]         = i + j + 10;
                    all[i].DictStr[(byte)j]   = "updated test";
                    all[i].ZuperDict[(uint)j] = new NMatrixTy();
                }
                await s_db.StoreObjectAsync(all[i]);
            }
            await s_db.FlushAsync();

            all = await s_db.LoadAllAsync <WithDict>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j + 10, all[i].DictInt[j]);
                    Assert.AreEqual("updated test", all[i].DictStr[(byte)j]);
                    Assert.IsNotNull(all[i].ZuperDict[(uint)j]);
                }
            }
            s_db.Close();
            s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            all = await s_db.LoadAllAsync <WithDict>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j + 10, all[i].DictInt[j]);
                    Assert.AreEqual("updated test", all[i].DictStr[(byte)j]);
                    Assert.IsNotNull(all[i].ZuperDict[(uint)j]);
                }
            }
            var q = await(from WithDict d in s_db
                          where d.DictInt.ContainsKey(1)
                          select d).ToListAsync();

            Assert.AreEqual(10, q.ToList().Count);

            q = await(from WithDict d in s_db
                      where d.DictInt.ContainsValue(11)
                      select d).ToListAsync();

            Assert.AreEqual(2, q.ToList().Count);

            q = await(from WithDict d in s_db
                      where d.DictInt.ContainsKey(-1)
                      select d).ToListAsync();

            Assert.AreEqual(0, q.ToList().Count);
        }
Esempio n. 2
0
        public async Task TestStoreDictionaryTransactional()
        {
            Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);



            await s_db.DropTypeAsync <WithDict>();

            await s_db.DropTypeAsync <JaggedTy>();

            await s_db.DropTypeAsync <NMatrixTy>();

            ITransaction transaction = s_db.BeginTransaction();

            for (int i = 0; i < 10; i++)
            {
                WithDict dict = new WithDict();
                dict.DictInt     = new Dictionary <int, int>();
                dict.DictStr     = new Dictionary <byte, string>();
                dict.DictComplex = new Dictionary <JaggedTy, int>();
                dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                for (int j = 0; j < 5; j++)
                {
                    dict.DictInt[j]         = i + j;
                    dict.ZuperDict[(uint)j] = new NMatrixTy();
                    dict.DictStr[(byte)j]   = "sss" + i.ToString();
                    JaggedTy jt = new JaggedTy();
                    dict.DictComplex[jt] = j + i;
                }

                await s_db.StoreObjectAsync(dict, transaction);
            }
            await transaction.CommitAsync();

            bool mustRollBack = false;

            try
            {
                transaction = s_db.BeginTransaction();
                for (int i = 0; i < 10; i++)
                {
                    WithDict dict = new WithDict();
                    dict.DictInt     = new Dictionary <int, int>();
                    dict.DictStr     = new Dictionary <byte, string>();
                    dict.DictComplex = new Dictionary <JaggedTy, int>();
                    dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                    for (int j = 0; j < 5; j++)
                    {
                        dict.DictInt[j]         = i + j;
                        dict.ZuperDict[(uint)j] = new NMatrixTy();
                        dict.DictStr[(byte)j]   = "sss" + i.ToString();
                        JaggedTy jt = new JaggedTy();
                        dict.DictComplex[jt] = j + i;
                    }

                    await s_db.StoreObjectAsync(dict, transaction);

                    if (i == 5)
                    {
                        throw new Exception("need some rollback");
                    }
                }
                await transaction.CommitAsync();
            }
            catch (Exception ex)
            {
                if (ex.Message == "need some rollback")
                {
                    mustRollBack = true;
                }
                else
                {
                    throw ex;
                }
            }
            if (mustRollBack)
            {
                await transaction.RollbackAsync();
            }
            IList <WithDict> all = await s_db.LoadAllAsync <WithDict>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j, all[i].DictInt[j]);
                    Assert.AreEqual("sss" + i, all[i].DictStr[(byte)j]);
                    Assert.IsNotNull(all[i].ZuperDict[(uint)j]);
                }
            }
            s_db.Close();
            s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            all = await s_db.LoadAllAsync <WithDict>();

            Assert.AreEqual(10, all.Count);
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(5, all[i].DictInt.Keys.Count);
                Assert.AreEqual(5, all[i].DictStr.Keys.Count);
                Assert.AreEqual(5, all[i].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[i].ZuperDict.Keys.Count);
                for (int j = 0; j < 5; j++)
                {
                    Assert.AreEqual(i + j, all[i].DictInt[j]);
                    Assert.AreEqual("sss" + i, all[i].DictStr[(byte)j]);
                    Assert.IsTrue(all[i].ZuperDict[(uint)j].OID > 0);
                }
            }
            var q = await(from WithDict d in s_db
                          where d.DictInt.ContainsKey(1)
                          select d).ToListAsync();

            Assert.AreEqual(10, q.ToList().Count);

            q = await(from WithDict d in s_db
                      where d.DictInt.ContainsValue(1)
                      select d).ToListAsync();
            Assert.AreEqual(2, q.ToList().Count);

            q = await(from WithDict d in s_db
                      where d.DictInt.ContainsKey(-1)
                      select d).ToListAsync();

            Assert.AreEqual(0, q.ToList().Count);
        }
Esempio n. 3
0
        public async Task TestStoreDictionaryAndShrink()
        {
            Siaqodb s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);


            await s_db.DropTypeAsync <WithDict>();

            await s_db.DropTypeAsync <JaggedTy>();

            await s_db.DropTypeAsync <NMatrixTy>();

            for (int i = 0; i < 20; i++)
            {
                WithDict dict = new WithDict();
                dict.DictInt     = new Dictionary <int, int>();
                dict.DictStr     = new Dictionary <byte, string>();
                dict.DictComplex = new Dictionary <JaggedTy, int>();
                dict.ZuperDict   = new Dictionary <uint, NMatrixTy>();

                for (int j = 0; j < 5; j++)
                {
                    dict.DictInt[j]         = i + j;
                    dict.ZuperDict[(uint)j] = new NMatrixTy();
                    dict.DictStr[(byte)j]   = "sss" + i.ToString();
                    JaggedTy jt = new JaggedTy();
                    dict.DictComplex[jt] = j + i;
                }

                await s_db.StoreObjectAsync(dict);
            }
            await s_db.FlushAsync();

            IList <WithDict> all = await s_db.LoadAllAsync <WithDict>();

            for (int i = 0; i < 10; i++)
            {
                await s_db.DeleteAsync(all[i]);
            }
            await s_db.FlushAsync();

            s_db.Close();

            await SiaqodbUtil.ShrinkAsync(dbFolder, ShrinkType.Normal);

            await SiaqodbUtil.ShrinkAsync(dbFolder, ShrinkType.ForceClaimSpace);

            s_db = new Siaqodb(); await s_db.OpenAsync(dbFolder);

            all = await s_db.LoadAllAsync <WithDict>();

            for (int i = 10; i < 20; i++)
            {
                int j = i - 10;
                Assert.AreEqual(5, all[j].DictInt.Keys.Count);
                Assert.AreEqual(5, all[j].DictStr.Keys.Count);
                Assert.AreEqual(5, all[j].DictComplex.Keys.Count);
                Assert.AreEqual(5, all[j].ZuperDict.Keys.Count);
                for (int k = 0; k < 5; k++)
                {
                    Assert.AreEqual(i + k, all[j].DictInt[k]);
                    Assert.AreEqual("sss" + i, all[j].DictStr[(byte)k]);
                    Assert.IsNotNull(all[j].ZuperDict[(uint)k]);
                }
            }


            var q = await(from WithDict d in s_db
                          where d.DictInt.ContainsKey(1)
                          select d).ToListAsync();

            Assert.AreEqual(10, q.Count);
            q = await(from WithDict d in s_db
                      where d.DictInt.ContainsValue(11)
                      select d).ToListAsync();
            Assert.AreEqual(2, q.Count);

            q = await(from WithDict d in s_db
                      where d.DictInt.ContainsKey(-1)
                      select d).ToListAsync();
            Assert.AreEqual(0, q.Count);
        }