示例#1
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
            }
        }
示例#2
0
        /// <summary>
        /// Tests the caching and re using of sessiosn to increase perfomance by avoding
        /// creating new sessions for each client request
        /// </summary>
        // [Test]
        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";
            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 therad and kill after timeout
            ReturnSessionToCache(lSession);
            Thread lThread = new Thread(new ThreadStart(() =>
            {
                lSession = GetCachedSession();
                counter  = lSession.AllObjects <TestClass>(true, false).Count();
                ReturnSessionToCache(lSession);
            }));

            lThread.Start();
            lEvent.WaitOne(5000);
            if (lThread.IsAlive)
            {
                lThread.Abort();
            }
            Assert.AreNotEqual(0, counter, "Invalid nr of objects retreived");
        }
示例#3
0
 public void OneMillionFindSingleRecordInTheMiddleServer()
 {
     using (ServerClientSession session = new ServerClientSession(systemDir))
     {
         session.BeginRead();
         var result = (from ComputerFileData computerFileData in session.AllObjects <ComputerFileData>()
                       where computerFileData.FileID == 500000
                       select computerFileData).First();
         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
      }
    }
示例#5
0
 public void OneMillionFindSingleRecordInTheMiddleServer()
 {
   using (ServerClientSession session = new ServerClientSession(systemDir))
   {
     session.BeginRead();
     var result = (from ComputerFileData computerFileData in session.AllObjects<ComputerFileData>()
                   where computerFileData.FileID == 500000
                   select computerFileData).First();
     session.Commit();
   }
 }
示例#6
0
        public void ReadSomeData()
        {
            int ct = 0;

            using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly))
            {
                session.BeginRead();
                foreach (Man man in session.AllObjects <Man>())
                {
                    ct++;
                }
                Console.WriteLine("Commit, number of Men found: " + ct);
                session.Commit();
            }
        }
示例#7
0
        public void HighAvalailabiltyByReplication()
        {
            var alternateSystemBoot = new List <ReplicaInfo> {
                new ReplicaInfo {
                    Path = "Replica1"
                }, new ReplicaInfo {
                    Path = "Replica2"
                }
            };
            var p1       = SessionBase.BaseDatabasePath + "/Replica1";
            var p2       = SessionBase.BaseDatabasePath + "/Replica2";
            var p3       = SessionBase.BaseDatabasePath + "/Replica3";
            var p3remote = $"\\{s_systemHost2}/databases/Replica3";

            if (Directory.Exists(p1))
            {
                Directory.Delete(p1, true);
            }
            if (Directory.Exists(p2))
            {
                Directory.Delete(p2, true);
            }
            if (Directory.Exists(p3))
            {
                Directory.Delete(p3, true);
            }
            if (Directory.Exists(p3remote))
            {
                Directory.Delete(p3remote, true);
            }

            using (var session = new ServerClientSession(alternateSystemBoot))
            {
                session.BeginUpdate();
                for (int i = 0; i < 100; i++)
                {
                    var s = i.ToString();
                    session.Persist(s);
                }
                session.Commit();
            }

            alternateSystemBoot = new List <ReplicaInfo> {
                new ReplicaInfo {
                    Path = "Replica1"
                }, new ReplicaInfo {
                    Path = "Replica2"
                }, new ReplicaInfo {
                    Path = "Replica3", Host = s_systemHost2
                }
            };
            using (var session = new ServerClientSession(alternateSystemBoot))
            {
                session.BeginUpdate();
                for (int i = 0; i < 100; i++)
                {
                    var s = i.ToString();
                    session.Persist(s);
                }
                session.Commit();
            }

            using (var session = new ServerClientSession(alternateSystemBoot))
            {
                session.BeginUpdate();
                for (int i = 0; i < 10; i++)
                {
                    var s = i.ToString();
                    session.Persist(s);
                }
                if (Directory.Exists(p2))
                {
                    Directory.Delete(p2, true);
                }
                session.Commit();
            }

            using (var session = new ServerClientSession(alternateSystemBoot))
            {
                session.BeginRead();
                foreach (var s in session.AllObjects <string>())
                {
                    Console.WriteLine(s);
                }
                session.Commit();
            }

            using (var session = new ServerClientSession(alternateSystemBoot))
            {
                session.BeginUpdate();
                for (int i = 0; i < 10; i++)
                {
                    var s = i.ToString();
                    session.Persist(s);
                    if (Directory.Exists(p2))
                    {
                        Directory.Delete(p2, true);
                    }
                }
                session.Commit();
            }

            using (var session = new ServerClientSession(alternateSystemBoot))
            {
                session.BeginRead();
                foreach (var s in session.AllObjects <string>())
                {
                    Console.WriteLine(s);
                }
                session.Commit();
            }

            using (var session = new SessionNoServer("Replica1"))
            {
                session.Verify();
            }
            using (var session = new SessionNoServer("Replica2"))
            {
                session.Verify();
            }
            using (var session = new ServerClientSession("Replica3", s_systemHost2))
            {
                session.Verify();
            }
        }
示例#8
0
        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");
        }
示例#9
0
 public void ReadSomeData()
 {
   int ct = 0;
   using (ServerClientSession session = new ServerClientSession(s_systemDir, systemHost, 1000, true, inMemoryOnly))
   {
     session.BeginRead();
     foreach (Man man in session.AllObjects<Man>())
     {
       ct++;
     }
     Console.WriteLine("Commit, number of Men found: " + ct);
     session.Commit();
   }
 }