Inheritance: Person
 public void SingleReaderSingleUpdater1()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     Man man = new Man();
     man.Persist(session, man);
     session.Commit();
   }
   UInt64 id;
   using (SessionNoServer session = new SessionNoServer(systemDir, 5000))
   {
     session.BeginUpdate();
     Man man = new Man();
     man.Persist(session, man);
     id = man.Id;
     using (SessionNoServer session2 = new SessionNoServer(systemDir))
     {
       session2.BeginRead();
       Man man2 = (Man)session2.Open(id);
       Assert.Null(man2);
       session2.Commit();
     }
     session.Commit();
   }
 }
 public void CreateMoreDataWithBackupServer()
 {
   int loops = 1000;
   int j;
   using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly))
   {
     Man aMan = null;
     Woman aWoman = null;
     session.BeginUpdate();
     for (j = 1; j <= loops; j++)
     {
       aMan = new Man(null, aMan, DateTime.Now);
       session.Persist(aMan);
       aWoman = new Woman(aMan, aWoman);
       session.Persist(aWoman);
       aMan.m_spouse = new VelocityDb.WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
       if (j % 1000000 == 0)
         Console.WriteLine("Loop # " + j);
     }
     UInt64 id = aWoman.Id;
     Console.WriteLine("Commit, done Loop # " + j);
     session.FlushUpdates();
     ReadSomeData(); // read some with uncommited cached server data
     session.Commit();
   }
 }
 public void TwoUpdaters1()
 {
   Assert.Throws<OptimisticLockingFailed>(() =>
   {
     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;
       Database db = session.NewDatabase(3567);
       using (SessionNoServer session2 = new SessionNoServer(systemDir))
       {
         session2.BeginUpdate();
         Man man2 = (Man)session2.Open(id);
         Assert.Less(man2.Age, man.Age);
         man2.Age = ++man.Age;
         session2.Commit();
       }
       session.DeleteDatabase(db);
       session.Commit(); // OptimisticLockingFailed here
     }
   });
 }
 public void CreateDataWithBackupServer()
 {
   int loops = 30000;
   int j;
   using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly))
   {
     Man aMan = null;
     Woman aWoman = null;
     const bool isBackupLocation = true;
     session.BeginUpdate();
     // we need to have backup locations special since server is not supposed to do encryption or compression
     DatabaseLocation backupLocation = new DatabaseLocation(backupHost, backupDir, backupLocationStartDbNum, UInt32.MaxValue, session,
       PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.noEncryption, isBackupLocation, session.DatabaseLocations.Default());
     session.NewLocation(backupLocation);
     session.Commit();
     session.BeginUpdate();
     for (j = 1; j <= loops; j++)
     {
       aMan = new Man(null, aMan, DateTime.Now);
       session.Persist(aMan);
       aWoman = new Woman(aMan, aWoman);
       session.Persist(aWoman);
       aMan.m_spouse = new VelocityDb.WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
       if (j % 1000000 == 0)
         Console.WriteLine("Loop # " + j);
     }
     UInt64 id = aWoman.Id;
     Console.WriteLine("Commit, done Loop # " + j);
     session.Commit();
   }
 }
 //[TestCase(true)]
 //[TestCase(false)]
 public void CreateDataWithBackupServerAutoPlacement(bool useServerSession)
 {
   int loops = 100000;
   int j;
   if (Directory.Exists(backupDir))
     Directory.Delete(backupDir, true); // remove systemDir from prior runs and all its databases.
   Directory.CreateDirectory(backupDir);
   using (SessionBase session = useServerSession ? (SessionBase)new ServerClientSession(systemDir) : (SessionBase)new SessionNoServer(systemDir))
   {
     Man aMan = null;
     Woman aWoman = null;
     const bool isBackupLocation = true;
     session.BeginUpdate();
     // we need to have backup locations special since server is not supposed to do encryption or compression
     DatabaseLocation backupLocation = new DatabaseLocation(Dns.GetHostName(), backupDir, backupLocationStartDbNum, UInt32.MaxValue, session,
       PageInfo.compressionKind.None, PageInfo.encryptionKind.noEncryption, isBackupLocation, session.DatabaseLocations.Default());
     session.NewLocation(backupLocation);
     for (j = 1; j <= loops; j++)
     {
       aMan = new Man(null, aMan, DateTime.Now);
       session.Persist(aMan);
       aWoman = new Woman(aMan, aWoman);
       session.Persist(aWoman);
       aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
       if (j % 1000000 == 0)
         Console.WriteLine("Loop # " + j);
     }
     UInt64 id = aWoman.Id;
     Console.WriteLine("Commit, done Loop # " + j);
     session.Commit();
   }
 }
 //[TestCase(false)]
 public void CreateDataWithBackupServer(bool useServerSession)
 {
   int loops = 30000;
   UInt16 objectsPerPage = 300;
   UInt16 pagesPerDatabase = 65000;
   int j;
   if (Directory.Exists(backupDir))
   {
     foreach (string s in Directory.GetFiles(backupDir))
       File.Delete(s);
     foreach (string s in Directory.GetDirectories(backupDir))
       Directory.Delete(s, true);
   }
   else
     Directory.CreateDirectory(systemDir);
   using (SessionBase session = useServerSession ? (SessionBase)new ServerClientSession(systemDir) : (SessionBase)new SessionNoServer(systemDir))
   {
     Placement place = new Placement(11, 1, 1, objectsPerPage, pagesPerDatabase);
     Man aMan = null;
     Woman aWoman = null;
     const bool isBackupLocation = true;
     session.BeginUpdate();
     // we need to have backup locations special since server is not supposed to do encryption or compression
     DatabaseLocation backupLocation = new DatabaseLocation(Dns.GetHostName(), backupDir, backupLocationStartDbNum, UInt32.MaxValue, session,
       PageInfo.compressionKind.None, PageInfo.encryptionKind.noEncryption, isBackupLocation, session.DatabaseLocations.Default());
     session.NewLocation(backupLocation);
     for (j = 1; j <= loops; j++)
     {
       aMan = new Man(null, aMan, DateTime.UtcNow);
       aMan.Persist(place, session);
       aWoman = new Woman(aMan, aWoman);
       aWoman.Persist(place, session);
       aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);               
       if (j % 1000000 == 0)
         Console.WriteLine("Loop # " + j);
     }
     UInt64 id = aWoman.Id;
     Console.WriteLine("Commit, done Loop # " + j);
     session.Commit();
   }
 }
 public void SingleReaderSingleUpdater3()
 {
   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;
     session.FlushUpdates();
     using (SessionNoServer session2 = new SessionNoServer(systemDir))
     {
       session2.BeginRead();
       Man man2 = (Man)session2.Open(id);
       Assert.Less(man2.Age, man.Age);
       session2.Commit();
     }
     session.Commit();
   }
 }
Exemple #8
0
 public void CreateDefaultCompareFailException()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Man aMan;
     Woman aWoman;
     session.BeginUpdate();
     BTreeSet<Person> bTree = new BTreeSet<Person>(null, session);
     for (int i = 0; i < 1000000; i++)
     {
       aMan = new Man();
       aWoman = new Woman();
       bTree.Add(aMan);
       bTree.Add(aWoman);
     }
     session.Commit();
   }
 }
 [TestCase(false)] // test will fail if pessimistic locking is used
 public void SingleReaderSingleUpdater4(bool useReaderCommit)
 {
   using (SessionNoServer updater = new SessionNoServer(systemDir, 5000)) 
   using (SessionNoServer reader = new SessionNoServer(systemDir, 5000))
   {
     updater.SetTraceAllDbActivity();
     reader.SetTraceAllDbActivity();
     updater.BeginUpdate();
     UInt32 dbNum = updater.DatabaseNumberOf(typeof(Man));
     Database db = updater.OpenDatabase(dbNum, true, false);
     if (db != null)
       updater.DeleteDatabase(db);
     updater.Commit();
     updater.BeginUpdate();
     Man man = new Man();
     for (int i = 0; i < 100; i++)
     {
       man = new Man();
       updater.Persist(man);
     }
     updater.Commit();
     reader.BeginRead();
     updater.BeginUpdate();
     db = reader.OpenDatabase(dbNum);
     foreach (Page page in db)
       Assert.True(page.PageInfo.VersionNumber == 1);
     if (useReaderCommit)
       reader.Commit();
     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 > 1) // skip AutoPlacemnt page
         {
           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 > 1)
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       updater.Commit();
       updater.BeginUpdate();
       db2 = reader.OpenDatabase(dbNum);
       foreach (Page page in db2)
       {
         if (page.PageNumber > 1)
         {
           //Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
         }
       }
       reader.ClearPageCache();
       System.GC.Collect();
     }
     reader.Commit();
     updater.Commit();
   }
 }
 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();
   }
 }
    [Repeat(3)] // remove when propagation of optimistic locking flag is done to slave database locations TO DO (issue caused by CopyAllDatabasdesTo that uses pessimistic locking)
    public void multipleServersOK()
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        foreach (DatabaseLocation loc in session.DatabaseLocations)
          Console.WriteLine(loc.ToStringDetails(session, false));
        session.Commit();
      }

      using (ServerClientSession session = new ServerClientSession(systemDir, systemHost))
      {
        session.SetTraceDbActivity(0);
        DatabaseLocation localLocation = new DatabaseLocation(systemHost, location2Dir, 10000, 20000, session, PageInfo.compressionKind.LZ4, 0);
        Placement place = new Placement(10000, 2);
        session.BeginUpdate();
        foreach (DatabaseLocation loc in session.DatabaseLocations)
          Console.WriteLine(loc.ToStringDetails(session, false));
        Console.WriteLine();
        session.NewLocation(localLocation);
        foreach (DatabaseLocation loc in session.DatabaseLocations)
          Console.WriteLine(loc.ToStringDetails(session, false));
        Man aMan = null;
        Woman aWoman = null;

        for (int j = 1; j <= 5; j++)
        {
          aMan = new Man(null, aMan, DateTime.UtcNow);
          aMan.Persist(place, session);
          aWoman = new Woman(aMan, aWoman);
          aWoman.Persist(place, session);
          aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
          if (j % 1000 == 0)
          {
            session.FlushUpdates();
          }
        }
        localLocation = new DatabaseLocation(systemHost2, systemDir, 20001, 30000, session, PageInfo.compressionKind.LZ4, 0);
        session.NewLocation(localLocation);
        foreach (DatabaseLocation loc in session.DatabaseLocations)
          Console.WriteLine(loc.ToStringDetails(session, false));
        place = new Placement(20001);
        //localDatabase = session.NewDatabase(20001, localLocation);
        for (int j = 1; j <= 5; j++)
        {
          aMan = new Man(null, aMan, DateTime.UtcNow);
          aMan.Persist(place, session);
          aWoman = new Woman(aMan, aWoman);
          aWoman.Persist(place, session);
          aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
          if (j % 1000 == 0)
          {
            session.FlushUpdates();
          }
        }
        DatabaseLocation serverLocation = new DatabaseLocation(systemHost2, location2Dir, 30001, 40000, session, PageInfo.compressionKind.LZ4, 0);
        session.NewLocation(serverLocation);
        foreach (DatabaseLocation loc in session.DatabaseLocations)
          Console.WriteLine(loc.ToStringDetails(session, false));
        place = new Placement(30001);
        for (int j = 1; j <= 5; j++)
        {
          aMan = new Man(null, aMan, DateTime.UtcNow);
          aMan.Persist(place, session);
          aWoman = new Woman(aMan, aWoman);
          aWoman.Persist(place, session);
          aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
          if (j % 1000 == 0)
          {
            session.FlushUpdates();
          }
        }
        localLocation = new DatabaseLocation(systemHost3, systemDir, 40001, 50000, session, PageInfo.compressionKind.None, 0);
        session.NewLocation(localLocation);
        place = new Placement(40001);
        //localDatabase = session.NewDatabase(20001, localLocation);
        for (int j = 1; j <= 5; j++)
        {
          aMan = new Man(null, aMan, DateTime.UtcNow);
          aMan.Persist(place, session);
          aWoman = new Woman(aMan, aWoman);
          aWoman.Persist(place, session);
          aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
          if (j % 1000 == 0)
          {
            session.FlushUpdates();
          }
        }
        session.Commit();
      }

      using (ServerClientSession session = new ServerClientSession(systemDir, systemHost))
      {
        session.CopyAllDatabasesTo(copyDir);
        using (SessionNoServer copySession = new SessionNoServer(copyDir))
        {
          copySession.Verify();
        }
      }

      using (ServerClientSession session = new ServerClientSession(systemDir, systemHost, 2000, false)) // TO DO, change back to use optimistic locking
      {
        //session.SetTraceDbActivity(0);
        session.BeginUpdate();
        Database db = session.OpenDatabase(10000);
        session.DeleteDatabase(db);
        db = session.OpenDatabase(20001);
        session.DeleteDatabase(db);
        db = session.OpenDatabase(30001);
        session.DeleteDatabase(db);
        db = session.OpenDatabase(40001);
        session.DeleteDatabase(db);
        session.Commit();
        Directory.Delete(copyDir, true);
      }

      System.GC.Collect();
      System.GC.WaitForPendingFinalizers();

      using (ServerClientSession session = new ServerClientSession(systemDir, systemHost))
      {
        Assert.True(session.OptimisticLocking);
      }
    }
 public void TwoUpdaters3()
 {
   Assert.Throws<OptimisticLockingFailed>(() =>
   {
     UInt64 id;
     try
     {
       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;
         session.FlushUpdates(); // fStream set for updated databases will cause other write sessions to fail updating these databases
         using (SessionNoServer session2 = new SessionNoServer(systemDir))
         {
           session2.BeginUpdate();
           Man man2 = (Man)session2.Open(id);
           Assert.Less(man2.Age, man.Age);
           man2.Age = ++man.Age;
           session2.Commit(); // OptimisticLockingFailed here
         }
         session.Commit();
       }
     }
     finally
     {
       System.GC.Collect();
     }
   });
 }
 public void CreateMoreDataWithBackupServer()
 {
   int loops = 30000;
   UInt16 objectsPerPage = 350;
   UInt16 pagesPerDatabase = 65000;
   int j;
   using (ServerClientSession session = new ServerClientSession(systemDir, Dns.GetHostName()))
   {
     Placement place = new Placement(11, 1, 1, objectsPerPage, pagesPerDatabase);
     Man aMan = null;
     Woman aWoman = null;
     session.BeginUpdate();
     for (j = 1; j <= loops; j++)
     {
       aMan = new Man(null, aMan, DateTime.UtcNow);
       aMan.Persist(place, session);
       aWoman = new Woman(aMan, aWoman);
       aWoman.Persist(place, session);
       aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);          
       if (j % 1000000 == 0)
         Console.WriteLine("Loop # " + j);
     }
     UInt64 id = aWoman.Id;
     Console.WriteLine("Commit, done Loop # " + j);
     session.Commit();
   }
 }
    public void multipleServersInvalid()
    {
      Assert.Throws<InvalidChangeOfDefaultLocationException>(() =>
      {
        using (ServerClientSession session = new ServerClientSession(systemDir))
        {
          session.SetTraceDbActivity(2);
          try
          {
            DatabaseLocation localLocation = new DatabaseLocation(systemHost, location2Dir, 10000, 20000, session, PageInfo.compressionKind.LZ4, 0);
            Placement place = new Placement(10000, 2);
            session.BeginUpdate();
            session.NewLocation(localLocation);
            Man aMan = null;
            Woman aWoman = null;

            for (int j = 1; j <= 5; j++)
            {
              aMan = new Man(null, aMan, DateTime.UtcNow);
              aMan.Persist(place, session);
              aWoman = new Woman(aMan, aWoman);
              aWoman.Persist(place, session);
              aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
              if (j % 1000 == 0)
              {
                session.FlushUpdates();
              }
            }
            localLocation = new DatabaseLocation(systemHost, systemDir, 20001, 30000, session, PageInfo.compressionKind.None, 0);
            session.NewLocation(localLocation);
            place = new Placement(20001);
            //localDatabase = session.NewDatabase(20001, localLocation);
            for (int j = 1; j <= 5; j++)
            {
              aMan = new Man(null, aMan, DateTime.UtcNow);
              aMan.Persist(place, session);
              aWoman = new Woman(aMan, aWoman);
              aWoman.Persist(place, session);
              aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
              if (j % 1000 == 0)
              {
                session.FlushUpdates();
              }
            }
            DatabaseLocation serverLocation = new DatabaseLocation(systemHost2, location2Dir, 30001, 40000, session, PageInfo.compressionKind.LZ4, 0);
            session.NewLocation(serverLocation);
            place = new Placement(30001);
            for (int j = 1; j <= 5; j++)
            {
              aMan = new Man(null, aMan, DateTime.UtcNow);
              aMan.Persist(place, session);
              aWoman = new Woman(aMan, aWoman);
              aWoman.Persist(place, session);
              aMan.m_spouse = new WeakIOptimizedPersistableReference<VelocityDbSchema.Person>(aWoman);
              if (j % 1000 == 0)
              {
                session.FlushUpdates();
              }
            }
            session.Commit();
          }
          finally
          {
            //session.Close();
          }
        }
      });
    }
Exemple #16
0
 public void CreateDefaultCompare()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Man aMan = new Man();
     Woman aWoman = new Woman();
     session.BeginUpdate();
     BTreeSet<Person> bTree = new BTreeSet<Person>(null, session);
     session.Persist(bTree);
     for (int i = 0; i < 50000; i++)
     {
       aMan = new Man();
       aMan.Persist(session, aMan);
       aWoman = new Woman();
       aWoman.Persist(session, aWoman);
       bTree.Add(aMan);
       Assert.AreEqual(bTree.GetKeyId(aMan), aMan.Id);
       bTree.Add(aWoman);
     }
     session.Commit();
   }
 }
Exemple #17
0
 public void CreateCompareFields(int numberOfLoops, int comparisonByteArraySize)
 {
   GCLatencyMode gcLatencyMode = GCSettings.LatencyMode; 
   Person.s_randGen = new Random(5);
   try
   {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
       //session.ClientCache.MinimumAvailableMegaBytes = 1100;
       //session.SetTraceAllDbActivity();
       Man aMan;
       Woman aWoman;
       session.BeginUpdate();
       CompareByField<Person> compareByField = new CompareByField<Person>("m_firstName", session, false);
       compareByField.AddFieldToCompare("m_lastName");
       compareByField.AddFieldToCompare("m_age");
       BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, 2000, (ushort)comparisonByteArraySize);
       Placement place = new Placement((UInt32)numberOfLoops);
       bTree.Persist(place, session);
       for (int i = 0; i < numberOfLoops; i++)
       {
         aMan = new Man();
         aWoman = new Woman();
         bTree.AddFast(aMan);
         bTree.AddFast(aWoman);
         if (i % 5000 == 0)
           bTree.FlushTransients();    
       }
       session.Commit();
     }
   }
   finally
   {
     GCSettings.LatencyMode = gcLatencyMode;
   }
 }
 public void TwoUpdaters2()
 {
   Assert.Throws<OpenDatabaseException>(() =>
   {
     UInt64 id;
     try
     {
       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;
         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();
       }
     }
     finally
     {
       System.GC.Collect();
     }
   });
 }