Esempio n. 1
0
        public void Bug1Test()
        {
            _count++;
            VelocityDbSchema.Samples.Sample1.Person person;
            var sess = new ServerClientSession(systemDir);

            sess.BeginUpdate();
            var count = 10000;
            var tw    = new Stopwatch();

            tw.Start();
            for (int i = 0; i < count; i++)
            {
                person = new VelocityDbSchema.Samples.Sample1.Person("Bill" + i, "Gates", 56);
                person.Persist(sess, person);
            }
            tw.Stop();
            Console.WriteLine("{0} records in {1} ms., Count is: {2}", _count, tw.ElapsedMilliseconds, _count);
            sess.Commit();
            sess.Dispose();
        }
 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 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();
            }
        }