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 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 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 override void Init(int flowCount, long flowRecordCount) { mapId = new UInt64(); session = new SessionNoServerShared(DataDirectory); session.BeginUpdate(); session.DefaultDatabaseLocation().CompressPages = false; session.RegisterClass(typeof(VelocityTick)); session.RegisterClass(typeof(BTreeMapOidShort <long, VelocityTick>)); }
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 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 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(); } }