Exemplo n.º 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();
            }
        }
Exemplo n.º 2
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();
   }
 }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
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();
   }
 }
Exemplo n.º 5
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
      }
    }
Exemplo n.º 6
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
            }
        }
Exemplo n.º 7
0
 static void Main(string[] args)
 {
   SessionBase.DoWindowsAuthentication = false; // Make sure to use the same setting when starting VelocityDBServer, see http://www.velocitydb.com/UserGuide.aspx
   try
   {                                                           // initial DatabaseLocation directory and hostname
     using (ServerClientSession session = new ServerClientSession(systemDir, System.Net.Dns.GetHostName()))
     {
       session.BeginUpdate();
       // your code here
       Person robinHood = new Person("Robin", "Hood", 30);
       Person billGates = new Person("Bill", "Gates", 56, robinHood);
       Person steveJobs = new Person("Steve", "Jobs", 56, billGates);
       robinHood.BestFriend = billGates;
       session.Persist(steveJobs);
       steveJobs.Friends.Add(billGates);
       steveJobs.Friends.Add(robinHood);
       billGates.Friends.Add(billGates);
       robinHood.Friends.Add(steveJobs);
       session.Commit();
     }
   }
   catch (Exception ex)
   {
     Console.WriteLine(ex.ToString());
   }
 }
Exemplo n.º 8
0
 static void Main(string[] args)
 {
     SessionBase.s_serverTcpIpPortNumber = 7032;
     SessionBase.DoWindowsAuthentication = false; // Make sure to use the same setting when starting VelocityDBServer, see http://www.velocitydb.com/UserGuide.aspx
     try
     {                                            // initial DatabaseLocation directory and hostname
         using (ServerClientSession session = new ServerClientSession(systemDir, System.Net.Dns.GetHostName()))
         {
             session.BeginUpdate();
             // your code here
             Person robinHood = new Person("Robin", "Hood", 30);
             Person billGates = new Person("Bill", "Gates", 56, robinHood);
             Person steveJobs = new Person("Steve", "Jobs", 56, billGates);
             robinHood.BestFriend = billGates;
             session.Persist(steveJobs);
             steveJobs.Friends.Add(billGates);
             steveJobs.Friends.Add(robinHood);
             billGates.Friends.Add(billGates);
             robinHood.Friends.Add(steveJobs);
             session.Commit();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Exemplo n.º 9
0
 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();
   }
 }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
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");
        }