public void TestShrinkWithoutComplex() { Siaqodb s_db = new Siaqodb(objPath); s_db.DropType <AEmpty>(); List <AEmpty> objs = new List <AEmpty>(); for (int i = 0; i < 10; i++) { AEmpty ae = new AEmpty() { MyInt = i }; ae.SomeStrings = new List <string>(); ae.SomeStrings.Add("aaa" + i.ToString()); s_db.StoreObject(ae); objs.Add(ae); } for (int i = 0; i < 5; i++) { s_db.Delete(objs[i]); } s_db.Close(); SiaqodbUtil.Shrink(objPath, ShrinkType.Total); s_db = new Siaqodb(objPath); IList <AEmpty> all = s_db.LoadAll <AEmpty>(); for (int i = 0; i < 5; i++) { Assert.AreEqual(i + 1, s_db.GetOID(all[i])); } }
public void TestShrinkComplex() { Siaqodb s_db = new Siaqodb(objPath); s_db.DropType <A>(); s_db.DropType <B>(); s_db.DropType <C>(); for (int i = 0; i < 100; i++) { A a = new A(); a.aId = i; a.BVar = new B(); a.BVar.bId = 11; a.BVar.Ci = new C(); a.BVar.Ci.ACircular = a; a.BVar.Ci.cId = i; s_db.StoreObject(a); } IList <A> all = s_db.LoadAll <A>(); for (int i = 0; i < 50; i++) { s_db.Delete(all[i]); s_db.Delete(all[i].BVar); s_db.Delete(all[i].BVar.Ci); } s_db.Close(); DateTime startDate = DateTime.Now; SiaqodbUtil.Shrink(objPath, ShrinkType.Total); string date = (DateTime.Now - startDate).ToString(); s_db = new Siaqodb(objPath); all = s_db.LoadAll <A>(); Assert.AreEqual(50, all.Count); for (int i = 0; i < 50; i++) { Assert.AreEqual(i + 1, all[i].OID); Assert.AreEqual(i + 1, all[i].BVar.OID); Assert.AreEqual(i + 1, all[i].BVar.Ci.OID); Assert.AreEqual(i + 50, all[i].aId); Assert.AreEqual(11, all[i].BVar.bId); Assert.AreEqual(i + 50, all[i].BVar.Ci.cId); Assert.AreEqual(all[i].OID, all[i].BVar.Ci.ACircular.OID); } }
public void TestStoreDictionaryAndShrink() { Siaqodb s_db = new Siaqodb(objPath); s_db.DropType <WithDict>(); s_db.DropType <JaggedTy>(); s_db.DropType <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; } s_db.StoreObject(dict); } IList <WithDict> all = s_db.LoadAll <WithDict>(); for (int i = 0; i < 10; i++) { s_db.Delete(all[i]); } s_db.Close(); SiaqodbUtil.Shrink(objPath, ShrinkType.Normal); SiaqodbUtil.Shrink(objPath, ShrinkType.ForceClaimSpace); s_db = new Siaqodb(objPath); all = s_db.LoadAll <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 = from WithDict d in s_db where d.DictInt.ContainsKey(1) select d; Assert.AreEqual(10, q.ToList().Count); q = from WithDict d in s_db where d.DictInt.ContainsValue(11) select d; Assert.AreEqual(2, q.ToList().Count); q = from WithDict d in s_db where d.DictInt.ContainsKey(-1) select d; Assert.AreEqual(0, q.ToList().Count); }
public void TestStoreSimpleJaggedAndShrink() { Siaqodb s_db = new Siaqodb(objPath); s_db.DropType <JaggedTy>(); for (int i = 0; i < 20; i++) { JaggedTy jg = new JaggedTy(); jg.jaggedByte = new byte[2][]; jg.jaggedByte[0] = new byte[2]; jg.jaggedByte[0][0] = (byte)i; jg.jaggedByte[0][1] = (byte)(i + 1); jg.jaggedByte[1] = new byte[2]; jg.jaggedByte[1][0] = (byte)(i + 2); jg.jaggedByte[1][1] = (byte)(i + 3); jg.jaggedInt = new int[2][]; jg.jaggedInt[0] = new int[2]; jg.jaggedInt[0][0] = i; jg.jaggedInt[0][1] = (i + 1); jg.jaggedInt[1] = new int[2]; jg.jaggedInt[1][0] = (i + 2); jg.jaggedInt[1][1] = (i + 3); jg.jaggedList = new List <List <int> >(); List <int> myList = new List <int>(); myList.Add(i); myList.Add(i + 1); List <int> myList2 = new List <int>(); myList2.Add(i * 10); myList2.Add(i * 100); jg.jaggedList.Add(myList); jg.jaggedList.Add(myList2); jg.jaggedListStr = new List <List <string> >(); List <string> myListStr = new List <string>(); myListStr.Add("ws" + i.ToString()); myListStr.Add("second" + i.ToString()); jg.jaggedListStr.Add(myListStr); SimpleClass simple = new SimpleClass(); simple.Name = "ssss"; jg.complexJaggedList = new List <List <SimpleClass> >(); List <SimpleClass> listSimple = new List <SimpleClass>(); listSimple.Add(simple); jg.complexJaggedList.Add(listSimple); jg.complexJaggedList.Add(listSimple); s_db.StoreObject(jg); } IList <JaggedTy> all = s_db.LoadAll <JaggedTy>(); for (int i = 0; i < 10; i++) { s_db.Delete(all[i]); } s_db.Close(); SiaqodbUtil.Shrink(objPath, ShrinkType.Normal); SiaqodbUtil.Shrink(objPath, ShrinkType.ForceClaimSpace); s_db = new Siaqodb(objPath); all = s_db.LoadAll <JaggedTy>(); for (int i = 10; i < 20; i++) { int j = i - 10; Assert.AreEqual((byte)i, all[j].jaggedByte[0][0]); Assert.AreEqual((byte)(i + 1), all[j].jaggedByte[0][1]); Assert.AreEqual((byte)(i + 2), all[j].jaggedByte[1][0]); Assert.AreEqual((byte)(i + 3), all[j].jaggedByte[1][1]); Assert.AreEqual(i, all[j].jaggedInt[0][0]); Assert.AreEqual((i + 1), all[j].jaggedInt[0][1]); Assert.AreEqual((i + 2), all[j].jaggedInt[1][0]); Assert.AreEqual((i + 3), all[j].jaggedInt[1][1]); Assert.AreEqual(2, all[j].jaggedList[0].Count); Assert.AreEqual(2, all[j].jaggedList.Count); Assert.AreEqual(i, all[j].jaggedList[0][0]); Assert.AreEqual(i + 1, all[j].jaggedList[0][1]); Assert.AreEqual(i * 10, all[j].jaggedList[1][0]); Assert.AreEqual(i * 100, all[j].jaggedList[1][1]); Assert.AreEqual(1, all[j].jaggedListStr.Count); Assert.AreEqual(2, all[j].jaggedListStr[0].Count); Assert.AreEqual("ws" + i, all[j].jaggedListStr[0][0]); Assert.AreEqual("second" + i, all[j].jaggedListStr[0][1]); Assert.AreEqual(2, all[j].complexJaggedList.Count); Assert.IsNotNull(all[j].complexJaggedList[0][0]); } var q = from JaggedTy jgd in s_db where jgd.jaggedInt.Length == 2 select jgd; Assert.AreEqual(10, q.ToList().Count); List <int> myInList = new List <int>(); myInList.Add(10); myInList.Add(11); var q2 = from JaggedTy jgd in s_db where jgd.jaggedList.Contains(myInList) select jgd; Assert.AreEqual(1, q2.ToList().Count); }