public void TwoUpdaters2() { Assert.Throws <OpenDatabaseException>(() => { UInt64 id; try { using (var session = new SessionNoServerShared(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; session.FlushUpdates(); using (SessionNoServer session2 = new SessionNoServer(systemDir)) { session2.BeginRead(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); man2.Age = ++man.Age; // We'll get the OpenDatabase exception here since we are not in an update transaction session2.Commit(); } session.Commit(); session.Verify(); } } finally { System.GC.Collect(); } }); }
public void ModelInfo() { ModelInfo model = new ModelInfo(); BomTable bt = new BomTable() { BomName = Guid.NewGuid().ToString(), Header = new List <string>() { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }, TotalCols = 2, TotalRow = 10, //Rows = new List<BomTableRow>() }; //for (int i = 0; i < 10; i++) //{ // BomTableRow row = new BomTableRow(); // //for (int j = 0; j < 10; j++) // //{ // // row.Cells.Add("Value " + j.ToString()); // //} // bt.Rows.Add(row); //} model.BomTables = new List <BomTable>(); model.BomTables.Add(bt); try { using (SessionNoServerShared session = new SessionNoServerShared(s_systemDir)) { session.BeginUpdate(); //session.Persist(model.BomTables); session.Persist(model); session.Commit(); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } try { using (SessionNoServerShared session = new SessionNoServerShared(s_systemDir)) { session.BeginRead(); //var models1 = session.AllObjects<List<BomTable>>().ToList(); var models = session.AllObjects <ModelInfo>().ToList(); session.Commit(); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } }
public void LocalDateTest() { LocalDate d1 = new LocalDate(2016, 1, 10); LocalDate d2 = new LocalDate(2016, 1, 1); LocalDate d1other = new LocalDate(2016, 1, 10); Assert.AreNotEqual(d1, d2); Assert.AreEqual(d1, d1other); using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); LocalDateField test1 = new LocalDateField("def", d1); session.Persist(test1); LocalDateField test = new LocalDateField("abc", d2); session.Persist(test); var result1 = session.AllObjects <LocalDateField>().First(t => t.Field2.Equals(d2)); // this works session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { session.BeginRead(); var result2 = session.AllObjects <LocalDateField>().First(t => { var l = t.Field2; return(l.Equals(d2)); }); // this should work and doesnt session.Commit(); } }
public void CompareInt32DescendingComparisonArray() { #if DEBUG Assert.Throws <NotImplementedException>(() => { using (var session = new SessionNoServerShared(systemDir)) { session.BeginUpdate(); AllSupported obj = new AllSupported(2, session); CompareByField <AllSupported> compareByField = new CompareByField <AllSupported>("int32", session, false, false, false); BTreeSet <AllSupported> sortedSet = new BTreeSet <AllSupported>(compareByField, session, 1000, sizeof(Int32), true); for (int i = 0; i < 100000; i++) { obj = new AllSupported(1, session); obj.int32 = randGen.Next(Int32.MinValue, Int32.MaxValue); sortedSet.Add(obj); } int ct = 0; AllSupported prior = null; foreach (AllSupported currentObj in (IEnumerable <AllSupported>)sortedSet) { if (prior != null) { Assert.Greater(prior.int32, currentObj.int32); } prior = currentObj; ct++; } session.Commit(); } }); #endif }
public void hashCodeComparerStringTest() { Oid id; using (SessionNoServer session = new SessionNoServer(systemDir)) { Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue); session.Compact(); session.BeginUpdate(); HashCodeComparer <string> hashCodeComparer = new HashCodeComparer <string>(); BTreeSet <string> bTree = new BTreeSet <string>(hashCodeComparer, session); bTree.Persist(place, session); id = bTree.Oid; for (int i = 0; i < 100000; i++) { bTree.Add(i.ToString()); } session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { session.BeginRead(); BTreeSet <string> bTree = (BTreeSet <string>)session.Open(id); int count = 0; foreach (string str in bTree) { count++; } Assert.True(100000 == count); session.Commit(); } }
public void FixedSizeManyTest(int howMany) { using (var session = new SessionNoServer(systemDir)) { session.BeginUpdate(); FixedSize fixedSize; FixedSize fixedSizePrior = new FixedSize(); for (int i = 0; i < howMany; i++) { fixedSize = new FixedSize(); fixedSize.Persist(session, fixedSizePrior); fixedSizePrior = fixedSize; } session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { session.BeginRead(); Database db = session.OpenDatabase(FixedSize.PlaceInDatabase); foreach (Page page in db) { if (page.PageNumber > 0) { foreach (FixedSize fixedSize in page) { --howMany; Assert.NotNull(fixedSize); } } } session.Commit(); } }
public void zeroSizeByInterface() { UInt64 id = 0; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < 100000; i++) { var o = new EFTPOSMachineParent(); session.Persist(o); if (i % 25000 == 0) { id = o.Id; } } var o2 = (EFTPOSMachineParent)session.Open(id); session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); var o2 = (EFTPOSMachineParent)session.Open(id); Assert.NotNull(o2); Assert.NotNull(o2.TransactionFacilitator); session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { session.BeginUpdate(); var o2 = (EFTPOSMachineParent)session.Open(id); Assert.NotNull(o2); Assert.NotNull(o2.TransactionFacilitator); o2.Unpersist(session); session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); var o2 = (EFTPOSMachineParent)session.Open(id); Assert.Null(o2); id++; o2 = (EFTPOSMachineParent)session.Open(id); Assert.NotNull(o2); Assert.NotNull(o2.TransactionFacilitator); session.Commit(); } }
public void LazyLoadDepth() { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); LazyLoadByDepth lazy = null; for (uint i = 1; i <= 100; i++) { lazy = new LazyLoadByDepth(i, lazy); } session.Persist(lazy); id = lazy.Id; session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { UInt32 ct = 100; session.BeginRead(); LazyLoadByDepth lazy = (LazyLoadByDepth)session.Open(id, false, false, 0); // load only the root of the object graph Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); lazy = lazy.MyRef; Assert.AreEqual(ct--, lazy.MyCt); Assert.IsNull(lazy.MyRefPeek); Assert.NotNull(lazy.MyRef); Assert.NotNull(lazy.MyRefPeek); session.Commit(); } }
public void CreateTicksCompareFieldsOidShort(int numberOfTicks, int nodeSize) { using (var session = new SessionNoServer(systemDir)) { session.BeginRead(); session.Open(10, 1, 1, false); session.Open(10, 1, 2, false); session.Open(10, 2, 1, false); session.Open(10, 2, 2, false); session.Commit(); } using (var session = new SessionNoServerShared(systemDir, 2000, false)) { //session.SetTraceAllDbActivity(); //session.ClientCache.MinimumAvailableMegaBytes = 1100; session.BeginUpdate(); CompareByField <Tick> compareByField = new CompareByField <Tick>("<Bid>k__BackingField", session, true); //compareByField.AddFieldToCompare("<Timestamp>k__BackingField"); BTreeSetOidShort <Tick> bTree = new BTreeSetOidShort <Tick>(compareByField, session, (UInt16)nodeSize, sizeof(double), true); Placement place = new Placement((UInt32)numberOfTicks, 1, 1, UInt16.MaxValue, UInt16.MaxValue); Placement ticksPlace = new Placement((UInt32)numberOfTicks, 10000, 1, UInt16.MaxValue, UInt16.MaxValue); bTree.Persist(place, session); int i = 0; int dublicates = 0; foreach (var record in Tick.GenerateRandom((ulong)numberOfTicks)) { session.Persist(record, ticksPlace); if (bTree.Add(record)) { i++; } else { dublicates++; } } session.Commit(); Console.WriteLine("Done creating and sorting with BTreeSetOidShort<Tick>" + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates); } }
public void Create4Projects(int numberOfProjects) { Project project = null; Project priorProject = null; for (int i = 0; i < numberOfProjects; i++) { using (var session = new SessionNoServerShared(systemDir)) { session.BeginUpdate(); IssueTracker issueTracker = session.AllObjects <IssueTracker>(false).FirstOrDefault(); User user = issueTracker.UserSet.Keys[rand.Next(issueTracker.UserSet.Keys.Count - 1)]; string p = "project" + i.ToString(); string d = "pdescription" + i.ToString(); project = new Project(user, p, d); session.Persist(project); priorProject = project; issueTracker.ProjectSet.Add(project); session.Commit(); } } }
public void SingleReaderSingleUpdater2() { UInt64 id; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Man man = new Man(); man.Persist(session, man); id = man.Id; session.Commit(); session.BeginUpdate(); man.Age = ++man.Age; using (var session2 = new SessionNoServerShared(systemDir)) { session2.BeginRead(); Man man2 = (Man)session2.Open(id); Assert.Less(man2.Age, man.Age); session2.Commit(); } session.Commit(); } System.GC.Collect(); }
public void aSyncNewDatabases() { using (var session = new SessionNoServerShared(s_sync1)) { session.EnableSyncByTrackingChanges = true; using (var trans = session.BeginUpdate()) { for (uint i = 10; i < 50; i++) { var database = session.NewDatabase(i); Assert.NotNull(database); } session.Commit(); } } using (SessionBase readFromSession = new SessionNoServer(s_sync1)) { using (SessionBase updateSession = new SessionNoServer(s_sync2)) { updateSession.SyncWith(readFromSession); } } using (SessionBase readFromSession = new SessionNoServer(s_sync1)) { readFromSession.BeginRead(); using (SessionBase updateSession = new SessionNoServer(s_sync2)) { using (var trans = updateSession.BeginRead()) { Assert.AreEqual(updateSession.OpenAllDatabases().Count, readFromSession.OpenAllDatabases().Count - 1); // - 1 due to additional change tracking databases in original } } } }
public void CreateDataAndIterateDb(int numObj) { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.Verify(); session.BeginUpdate(); UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage)); Database db = session.OpenDatabase(dbNum, true, false); if (db != null) { session.DeleteDatabase(db); } dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA)); db = session.OpenDatabase(dbNum, true, false); if (db != null) { session.DeleteDatabase(db); } dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB)); db = session.OpenDatabase(dbNum, true, false); if (db != null) { session.DeleteDatabase(db); } session.Commit(); } using (var session = new SessionNoServerShared(s_systemDir)) { session.Verify(); session.BeginUpdate(); UInt32 dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB)); Placement place = new Placement(dbNum, 100); for (int i = 0; i < numObj; i++) { NotSharingPage ns = new NotSharingPage(); session.Persist(ns); SharingPageTypeA sA = new SharingPageTypeA(); session.Persist(sA); SharingPageTypeB sB = new SharingPageTypeB(); if (i % 5 == 0) { sB.Persist(session, place); } else if (i % 1001 == 0) { sB.Persist(session, sA); } else if (i % 3001 == 0) { sB.Persist(session, ns); } else { session.Persist(sB); } } session.Commit(); } using (SessionNoServer session = new SessionNoServer(s_systemDir)) { session.BeginRead(); session.Verify(); UInt32 dbNum = session.DatabaseNumberOf(typeof(NotSharingPage)); Database db = session.OpenDatabase(dbNum); AllObjects <NotSharingPage> all = db.AllObjects <NotSharingPage>(); ulong ct = all.Count(); dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeA)); OfType ofType = db.OfType(typeof(NotSharingPage)); ulong ct2 = ofType.Count(); Assert.AreEqual(ct, ct2); Database dbA = session.OpenDatabase(dbNum); dbNum = session.DatabaseNumberOf(typeof(SharingPageTypeB)); Database dbB = session.OpenDatabase(dbNum); AllObjects <SharingPageTypeA> allA = dbA.AllObjects <SharingPageTypeA>(); AllObjects <SharingPageTypeB> allB = dbB.AllObjects <SharingPageTypeB>(); OfType allA2 = dbA.OfType(typeof(SharingPageTypeA)); int start = numObj / 2; NotSharingPage ns = all.ElementAt(numObj); SharingPageTypeA sA = allA.ElementAt(numObj); SharingPageTypeA sA2 = (SharingPageTypeA)allA2.ElementAt(numObj); Assert.AreEqual(sA, sA2); sA = allA.ElementAt(10); sA2 = (SharingPageTypeA)allA2.ElementAt(10); Assert.AreEqual(sA, sA2); //MethodInfo method = typeof(Database).GetMethod("AllObjects"); //MethodInfo generic = method.MakeGenericMethod(sA.GetType()); //dynamic itr = generic.Invoke(dbA, new object[]{ true }); //SharingPageTypeA sAb = itr.ElementAt(numObj); //Assert.AreEqual(sA, sAb); //SharingPageTypeA sAc = itr.ElementAt(numObj); SharingPageTypeB sB = allB.ElementAt(numObj); List <NotSharingPage> notSharingPageList = all.Skip(100).ToList(); List <SharingPageTypeA> sharingPageTypeA = allA.Take(5).Skip(100).ToList(); for (int i = start; i < numObj; i++) { sA = allA.ElementAt(i); } for (int i = start; i < numObj; i += 5) { ns = all.ElementAt(i); } for (int i = start; i < numObj; i += 5) { sB = allB.ElementAt(i); } for (int i = 0; i < numObj; i += 45000) { ns = all.ElementAt(i); } int allB_count = (int)allB.Count(); for (int i = 0; i < allB_count - 1; i++) { Assert.NotNull(allB.ElementAt(i)); } session.Checkpoint(); session.DeleteDatabase(db); session.DeleteDatabase(dbA); session.DeleteDatabase(dbB); session.Commit(); } }
public void AllSupported() { UInt64 id; AllSupported allSuported, allSupported2; AllSuportedSub1 allSuportedSub1, allSuportedSub2; AllSuportedSub2 allSuportedSub2_1, allSuportedSub2_2; AllSuportedSub3 allSuportedSub3_1, allSuportedSub3_2; AllSuportedSub4 allSuportedSub4; AllSupported[,] a1 = new AllSupported[10, 5]; AllSupported[,,] a2 = new AllSupported[8, 4, 3]; AllSupported[,,,] a3 = new AllSupported[7, 6, 2, 1]; Dictionary <int, string>[,,] a4 = new Dictionary <int, string> [2, 4, 33]; string s1str = DataMember.TypeToString(a1.GetType()); string s2str = DataMember.TypeToString(a2.GetType()); string s3str = DataMember.TypeToString(a3.GetType()); string s4str = DataMember.TypeToString(a4.GetType()); bool typeUpdated; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); Type t1 = DataMember.StringToType(s1str, session, out typeUpdated); Type t2 = DataMember.StringToType(s2str, session, out typeUpdated); Type t3 = DataMember.StringToType(s3str, session, out typeUpdated); Type t4 = DataMember.StringToType(s4str, session, out typeUpdated); Assert.AreEqual(t1, a1.GetType()); Assert.AreEqual(t2, a2.GetType()); Assert.AreEqual(t3, a3.GetType()); Assert.AreEqual(t4, a4.GetType()); allSuportedSub4 = new AllSuportedSub4(); session.Persist(allSuportedSub4); id = allSuportedSub4.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); allSuportedSub4 = (AllSuportedSub4)session.Open(id); Assert.NotNull(allSuportedSub4); session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); allSuportedSub1 = new AllSuportedSub1(3); allSuportedSub1.Persist(session, allSuportedSub1); foreach (var o in allSuportedSub1.PetListOidShort) { session.Persist(o, allSuportedSub1); } id = allSuportedSub1.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); allSuportedSub2 = (AllSuportedSub1)session.Open(id); Assert.NotNull(allSuportedSub2); Assert.AreEqual(allSuportedSub2.m_type[0], typeof(Pet)); session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); allSuportedSub2_1 = new AllSuportedSub2(3); allSuportedSub2_1.Persist(session, allSuportedSub2_1); id = allSuportedSub2_1.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginRead(); allSuportedSub2_2 = (AllSuportedSub2)session.Open(id); Assert.NotNull(allSuportedSub2_2); session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); allSuportedSub3_1 = new AllSuportedSub3(3); allSuportedSub3_1.Persist(session, allSuportedSub3_1); id = allSuportedSub3_1.Id; session.Commit(); } using (var session = new SessionNoServerShared(systemDir)) { session.BeginRead(); allSuportedSub3_2 = (AllSuportedSub3)session.Open(id); Assert.NotNull(allSuportedSub3_2); session.Commit(); } using (var session = new SessionNoServer(systemDir)) { session.BeginUpdate(); var x = new AllSuportedSub5(); session.Persist(x); id = x.Id; session.Commit(); } using (var session = new SessionNoServer(systemDir)) { session.BeginUpdate(); var x = (AllSuportedSub5)session.Open(id); x.Update(); x.nullableaDouble = 0.5; session.Commit(); } using (var session = new SessionNoServer(systemDir)) { session.BeginUpdate(); var x = new AllSuportedSub6(); session.Persist(x); id = x.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); var x = (AllSuportedSub6)session.Open(id); x.Update(); session.Commit(); } using (var session = new SessionNoServer(systemDir)) { session.BeginUpdate(); allSuported = new AllSupported(3, session); allSuported.Persist(session, allSuported); allSuported.m_weakRefArray[0] = new WeakIOptimizedPersistableReference <IOptimizedPersistable>(allSuported); allSuported.m_objectArray[0] = new WeakIOptimizedPersistableReference <IOptimizedPersistable>(allSuported); id = allSuported.Id; session.Commit(); } using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); allSupported2 = (AllSupported)session.Open(id); allSupported2.Update(); allSupported2.nullableaDouble = 0.5; allSupported2.NullableDateTime = DateTime.MaxValue; allSupported2 = null; session.Commit(); } using (var session = new SessionNoServer(systemDir)) { session.BeginRead(); allSupported2 = (AllSupported)session.Open(id); Assert.NotNull(allSupported2); Assert.AreEqual(allSupported2.nullableaDouble, 0.5); Assert.AreEqual(allSupported2.NullableDateTime, DateTime.MaxValue); session.Commit(); session.BeginUpdate(); allSupported2.NullableDateTime = DateTime.UtcNow; session.Commit(); session.BeginRead(); allSupported2 = (AllSupported)session.Open(id); Assert.AreEqual(DateTimeKind.Utc, allSupported2.NullableDateTime.Value.Kind); session.Commit(); } }