public void schemaUpdateMultipleSessions() { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); Placement place = new Placement(555, 1, 1, 10, 10); Simple1 s1 = new Simple1(1); s1.Persist(place, session); s1 = null; using (ServerClientSession session2 = new ServerClientSession(systemDir)) { Placement place2 = new Placement(556, 1, 1, 10, 10); session2.BeginUpdate(); Simple2 s2 = new Simple2(2); s2.Persist(place2, session2); s2 = null; session.Commit(); session2.Commit(); // optemistic locking will fail due to session2 working with a stale schema (not the one updated by session 1) session.BeginUpdate(); s1 = (Simple1)session.Open(555, 1, 1, false); s2 = (Simple2)session.Open(556, 1, 1, false); session.Commit(); session2.BeginUpdate(); s1 = (Simple1)session2.Open(555, 1, 1, false); s2 = (Simple2)session2.Open(556, 1, 1, false); session2.Commit(); } } }
public void schemaUpdateMultipleSessions() { Assert.Throws <OptimisticLockingFailed>(() => { using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); Placement place = new Placement(555, 1, 1, 10, 10); Simple1 s1 = new Simple1(1); s1.Persist(place, session); s1 = null; using (ServerClientSession session2 = new ServerClientSession(systemDir)) { Placement place2 = new Placement(556, 1, 1, 10, 10); session2.BeginUpdate(); Simple2 s2 = new Simple2(2); s2.Persist(place2, session2); s2 = null; session.Commit(); session2.Commit(); // optemistic locking will fail due to session2 working with a stale schema (not the one updated by session 1) session.BeginUpdate(); s1 = (Simple1)session.Open(555, 1, 1, false); s2 = (Simple2)session.Open(556, 1, 1, false); session.Commit(); session2.BeginUpdate(); s1 = (Simple1)session2.Open(555, 1, 1, false); s2 = (Simple2)session2.Open(556, 1, 1, false); session2.Commit(); } } }); }
public static void WatchUser() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 1000, true, false)) { session.BeginRead(); session.SubscribeToChanges(typeof(Vertex)); Graph g = Graph.Open(session); session.Commit(); Thread.Sleep(5000); for (int i = 0; i < 50; i++) { List <Oid> changes = session.BeginReadWithEvents(); if (changes.Count == 0) { Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff")); Thread.Sleep(1000); } foreach (Oid id in changes) { object obj = session.Open(id); Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff"));; //session.UnsubscribeToChanges(typeof(Person)); } session.Commit(); Thread.Sleep(2000); } } }
static void Main(string[] args) { using (ServerClientSession session = new ServerClientSession(s_systemDir)) { session.BeginUpdate(); File.Copy(s_licenseDbFile, Path.Combine(s_systemDir, "4.odb"), true); session.RegisterClass(typeof(Woman)); session.RegisterClass(typeof(Man)); session.SubscribeToChanges(typeof(Person)); session.SubscribeToChanges(typeof(Woman), "OlderThan50"); Person robinHood = new Person("Robin", "Hood", 30, 1234, null, null); session.Persist(robinHood); Person billGates = new Person("Bill", "Gates", 56, 234, robinHood, null); session.Persist(billGates); Person steveJobs = new Person("Steve", "Jobs", 56, 456, billGates, null); session.Persist(steveJobs); session.Commit(); Thread t = new Thread(UpdaterThread); t.Start(); Thread.Sleep(600); for (int i = 0; i < 50; i++) { List<Oid> changes = session.BeginReadWithEvents(); if (changes.Count == 0) { Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff")); Thread.Sleep(250); } foreach (Oid id in changes) { object obj = session.Open(id); Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff"));; //session.UnsubscribeToChanges(typeof(Person)); } Console.WriteLine(); session.Commit(); } t.Join(); } }
static void Main(string[] args) { using (ServerClientSession session = new ServerClientSession(s_systemDir)) { session.BeginUpdate(); File.Copy(s_licenseDbFile, Path.Combine(s_systemDir, "4.odb"), true); session.RegisterClass(typeof(Woman)); session.RegisterClass(typeof(Man)); session.SubscribeToChanges(typeof(Person)); session.SubscribeToChanges(typeof(Woman), "OlderThan50"); Person robinHood = new Person("Robin", "Hood", 30, 1234, null, null); session.Persist(robinHood); Person billGates = new Person("Bill", "Gates", 56, 234, robinHood, null); session.Persist(billGates); Person steveJobs = new Person("Steve", "Jobs", 56, 456, billGates, null); session.Persist(steveJobs); session.Commit(); Thread t = new Thread(UpdaterThread); t.Start(); Thread.Sleep(600); for (int i = 0; i < 50; i++) { List <Oid> changes = session.BeginReadWithEvents(); if (changes.Count == 0) { Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff")); Thread.Sleep(250); } foreach (Oid id in changes) { object obj = session.Open(id); Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff"));; //session.UnsubscribeToChanges(typeof(Person)); } Console.WriteLine(); session.Commit(); } t.Join(); } }
public void SingleServerReaderSingleServerUpdater1() { ServerClientSession updater = new ServerClientSession(systemDir); ServerClientSession reader = new ServerClientSession(systemDir); const UInt32 dbNum = 345; try { updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); Database db = reader.OpenDatabase(dbNum); foreach (Page page in db) Assert.True(page.PageInfo.VersionNumber == 1); reader.Commit(); updater.BeginUpdate(); reader.BeginRead(); for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } reader.Commit(); reader.BeginRead(); updater.Commit(); updater.BeginUpdate(); reader.ForceDatabaseCacheValidation(); // we now validate on BeginRead so to make this test pass, we need to add this call after updater commit. } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.Commit(); updater.BeginUpdate(); foreach (Page page in db2) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } finally { updater.Dispose(); reader.Dispose(); } }
public void SingleServerReaderSingleServerUpdater2(bool useReaderCommit) { const UInt32 dbNum = 567; using (ServerClientSession updater = new ServerClientSession(systemDir)) using (ServerClientSession reader = new ServerClientSession(systemDir, null, 2000, true, false, CacheEnum.No)) // CacheEnum.No or cache validating on session.Begin() - makes test fail { updater.BeginUpdate(); Database db = updater.OpenDatabase(dbNum, true, false); if (db != null) updater.DeleteDatabase(db); updater.Commit(); updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); db = reader.OpenDatabase(dbNum); foreach (Page page in db) Assert.True(page.PageInfo.VersionNumber == 1); if (useReaderCommit) reader.Commit(); updater.BeginUpdate(); if (useReaderCommit) reader.BeginRead(); else reader.ForceDatabaseCacheValidation(); for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } if (useReaderCommit) { reader.Commit(); reader.BeginRead(); } else reader.ForceDatabaseCacheValidation(); updater.Commit(); updater.BeginUpdate(); } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.FlushUpdates(); // now server will see updated version of pages foreach (Page page in db2) { if (page.PageNumber > 0) { // BUG Nov 8, 2011 1.0.4.0 reader sees version 28 when it should see version 27 Assert.True(page.PageInfo.VersionNumber == (ulong)i); // reader should see the commited version of the page, not the uncommited updated version Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) updater.Commit(); updater.BeginUpdate(); } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } }
public void SimpleApiServer() { long ssn = 555555; UInt16 age = 1; VelocityDbSchema.Person mats; Placement place; using (ServerClientSession session = new ServerClientSession(systemDir)) { // skip delete database since it invalidates indices session.BeginUpdate(); Database db = session.OpenDatabase(10, true, false); if (db != null) { session.DeleteDatabase(db); } session.Commit(); session.BeginUpdate(); place = new Placement(10, 2, 1, 1, 10); DateTime birthday = new DateTime(1960, 6, 13); mats = new Man("Mats", "Persson", age++, ssn++, birthday); mats.Persist(place, session); session.Commit(); session.ClearServerCache(); } UInt64 mOid1 = Oid.Encode(10, 2, 1); using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); UInt32 dbNum = Oid.DatabaseNumber(mOid1); mats = (VelocityDbSchema.Person)session.Open(mOid1); Woman kinga = null; mats = new Man("Mats", "Persson", age++, ssn++, new DateTime(1960, 6, 13)); Cat cat = new Cat("Boze", 8); mats.m_pets.Add(cat); Bird bird = new Bird("Pippi", 1); cat.friends.Add(bird); mats.Persist(place, session); kinga = new Woman("Kinga", "Persson", age, ssn, mats, mats); kinga.Persist(place, session); VelocityDbSchema.Person robin = new VelocityDbSchema.Person("Robin", "Persson", 13, 1, mats, null); robin.Persist(place, session); mOid1 = mats.Id; mats = null; mats = (VelocityDbSchema.Person)session.Open(mOid1); session.Commit(); session.ClearServerCache(); } using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginUpdate(); mats = (VelocityDbSchema.Person)session.Open(mOid1); session.Commit(); session.ClearServerCache(); } using (ServerClientSession session = new ServerClientSession(systemDir)) { session.BeginRead(); ulong mOid2 = mats.Id; mats = (VelocityDbSchema.Person)session.Open(mOid2); session.Commit(); session.ClearServerCache(); } }
public void CachedSessionTest() { ServerClientSession lSession = GetCachedSession(); //lets simulate that we did some prior work, return the session and get it again ReturnSessionToCache(lSession); lSession = GetCachedSession(); TestClass lTestClass = new TestClass(); lTestClass.SomeIntVar = 123; lTestClass.SomeStringVar = "test"; UInt64 id = lTestClass.Persist(lSession, lTestClass); var c = new Class_A(); UInt64 id2 = lSession.Persist(c); Class_B class_b = new Class_B(); class_b.IntField = 11; class_b.StringField = "sss"; Class_A class_a = new Class_A(); class_a.string_field = "xxx"; class_a.b_field = class_b; UInt64 id3 = lSession.Persist(class_a); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); lSession.Abort(); lSession.BeginUpdate(); Class_A cA = lSession.Open <Class_A>(id2); cA = lSession.Open <Class_A>(id3); lTestClass = lSession.Open <TestClass>(id); Assert.NotNull(lTestClass.GeoCord); Assert.NotNull(lTestClass.StoredStructInObjectField); lTestClass.SomeIntVar = 1234; lTestClass.SomeStringVar = "test2"; lTestClass.Persist(lSession, lTestClass); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); counter = (int)lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); Thread lThread = new Thread(new ThreadStart(() => { lSession = GetCachedSession(); counter = (int)lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); })); lThread.Start(); lEvent.WaitOne(5000); if (lThread.IsAlive) { lThread.Abort(); } Assert.AreNotEqual(0, counter, "Invalid number of objects retrieved"); }
public void SingleServerReaderSingleServerUpdater2(bool useReaderCommit) { const UInt32 dbNum = 567; using (ServerClientSession updater = new ServerClientSession(systemDir)) using (ServerClientSession reader = new ServerClientSession(systemDir, null, 2000, true, false, CacheEnum.No)) // CacheEnum.No or cache validating on session.Begin() - makes test fail { updater.BeginUpdate(); Database db = updater.OpenDatabase(dbNum, true, false); if (db != null) { updater.DeleteDatabase(db); } updater.Commit(); updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); db = reader.OpenDatabase(dbNum); foreach (Page page in db) { Assert.True(page.PageInfo.VersionNumber == 1); } if (useReaderCommit) { reader.Commit(); } updater.BeginUpdate(); if (useReaderCommit) { reader.BeginRead(); } else { reader.ForceDatabaseCacheValidation(); } for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } if (useReaderCommit) { reader.Commit(); reader.BeginRead(); } else { reader.ForceDatabaseCacheValidation(); } updater.Commit(); updater.BeginUpdate(); } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.FlushUpdates(); // now server will see updated version of pages foreach (Page page in db2) { if (page.PageNumber > 0) { // BUG Nov 8, 2011 1.0.4.0 reader sees version 28 when it should see version 27 Assert.True(page.PageInfo.VersionNumber == (ulong)i); // reader should see the commited version of the page, not the uncommited updated version Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) updater.Commit(); updater.BeginUpdate(); } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } }
public void SingleServerReaderSingleServerUpdater1() { ServerClientSession updater = new ServerClientSession(systemDir); ServerClientSession reader = new ServerClientSession(systemDir); const UInt32 dbNum = 345; try { updater.BeginUpdate(); Man man; Placement place = new Placement(dbNum, 1, 1, 2); for (int i = 0; i < 100; i++) { man = new Man(); man.Persist(place, updater); } updater.Commit(); reader.BeginRead(); Database db = reader.OpenDatabase(dbNum); foreach (Page page in db) { Assert.True(page.PageInfo.VersionNumber == 1); } reader.Commit(); updater.BeginUpdate(); reader.BeginRead(); for (int i = 1; i < 25; i++) { db = reader.OpenDatabase(dbNum); foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } reader.Commit(); reader.BeginRead(); updater.Commit(); updater.BeginUpdate(); reader.ForceDatabaseCacheValidation(); // we now validate on BeginRead so to make this test pass, we need to add this call after updater commit. } Database db2 = reader.OpenDatabase(dbNum); db = updater.OpenDatabase(dbNum); for (int i = 25; i < 50; i++) { foreach (Page page in db) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i); Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true); } } updater.Commit(); updater.BeginUpdate(); foreach (Page page in db2) { if (page.PageNumber > 0) { Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1); Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false); } } reader.ClearPageCache(); // required or else we will use cached page and Assert (see line above) will fail System.GC.Collect(); // force weak referenced pages to be garbage collected (again to avoid Assert failure) } reader.Commit(); updater.DeleteDatabase(db); updater.Commit(); } finally { updater.Dispose(); reader.Dispose(); } }
public static void WatchUser() { using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 1000, true, false)) { session.BeginRead(); session.SubscribeToChanges(typeof(Vertex)); Graph g = Graph.Open(session); session.Commit(); Thread.Sleep(5000); for (int i = 0; i < 50; i++) { List<Oid> changes = session.BeginReadWithEvents(); if (changes.Count == 0) { Console.WriteLine("No changes events at: " + DateTime.Now.ToString("HH:mm:ss:fff")); Thread.Sleep(1000); } foreach (Oid id in changes) { object obj = session.Open(id); Console.WriteLine("Received change event for: " + obj + " at: " + DateTime.Now.ToString("HH:mm:ss:fff")); ; //session.UnsubscribeToChanges(typeof(Person)); } session.Commit(); Thread.Sleep(2000); } } }