Inheritance: Person
示例#1
0
 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();
   }
 }
示例#2
0
 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();
   }
 }
示例#4
0
    static void UpdaterThread()
    {
      using (ServerClientSession session = new ServerClientSession(s_systemDir))
      {
        session.BeginUpdate();
        Person Mats = new Person("Mats", "Persson", 22, 1234, null, null);
        session.Persist(Mats);
        Woman Kinga = new Woman("Kinga", "Persson", 56, 234, null, Mats);
        foreach (Person p in session.AllObjects<Person>(true))
        {
          p.Age = (ushort) (p.Age + 1); 
        }
        session.Persist(Kinga);
        session.Commit();
// 5 events
        Thread.Sleep(5000);

        session.BeginUpdate();
        Woman Lidia = new Woman("Lidia", "Persson", 22, 1234, null, null);
        session.Persist(Lidia);
        session.Commit();
// 0 events 
        Thread.Sleep(500);

        session.BeginUpdate();
        Woman Margareta = new Woman("Margareta", "Persson", 98, 1234, null, null);
        session.Persist(Margareta);
        session.Commit();
// 1 event
        Thread.Sleep(500);

        session.BeginUpdate();
        Woman Oliwia = new Woman("Oliwia", "Persson", 50, 1234, null, null);
        session.Persist(Oliwia);
        session.Commit();
// 0 events
        Thread.Sleep(500);

        session.BeginUpdate();
        foreach (Woman p in session.AllObjects<Woman>())
        {
          p.Age = (ushort) (p.Age + 1); 
        }
        session.Commit();
// 3 events
        session.BeginUpdate();
        foreach (Woman p in session.AllObjects<Woman>())
        {
          p.Age = (ushort)(p.Age + 1);
        }
        session.Commit();
// 3 events
      }
    }
 //[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();
   }
 }
示例#6
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;
   }
 }
示例#7
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();
   }
 }
示例#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();
   }
 }
示例#9
0
 public void test()
 {
   ServerClientSession VelocityServerSession = new ServerClientSession(systemDir, "localhost");
   Woman TmpSynchronizationData = new Woman();//APSSynchData TmpSynchronizationData = default(APSSynchData);     
    // APSSynchData();
   //TmpSynchronizationData.SyncedElections = new VelocityDbList<Man>();
   VelocityServerSession.BeginUpdate();
   TmpSynchronizationData.Persist(VelocityServerSession, TmpSynchronizationData);
   VelocityServerSession.Commit();
   //SaveToDisk("4.odb", DatabasePath + "\\4.odb");
   VelocityServerSession.BeginUpdate();
 }
示例#10
0
 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();
   }
 }
示例#11
0
    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();
          }
        }
      });
    }
示例#12
0
    [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);
      }
    }