Exemple #1
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <BinaryData>().Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);


            var b = new BinaryData()
            {
                Id   = 2,
                Data = new List <byte>()
                {
                    4, 5, 6
                }.ToArray()
            };
            db.Table <BinaryData>().Save(b);

            d = new SomeData()
            {
                Id         = 2,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "Žtest123"
            };
            db.Table <SomeData>().Save(d);;
            var res = db.Table <SomeData>()
                      .OrderByDescending(f => f.NameSearch)
                      .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 2 || res[0].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #2
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <BinaryData>().Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <UsersItem>().Delete(new HashSet <int>(db.Table <UsersItem>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <Answer>().Delete(new HashSet <int>(db.Table <Answer>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <KaggleClass>().Delete(new HashSet <int>(db.Table <KaggleClass>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var job1 = new ParallelWorkload();
            var job2 = new ParallelWorkload2();
            var job3 = new ParallelSave();
            var job4 = new ParallelBatch();



            var t1 = Task.Run(() =>
            {
                try
                {
                    job1.Do2(db);
                }
                catch (Exception e)
                {
                    ParallelWorkloadAll.errors++;
                }
            });

            var t2 = Task.Run(() =>
            {
                try
                {
                    job2.Do2(db);
                }
                catch (Exception e)
                {
                    ParallelWorkloadAll.errors++;
                }
            });

            var t3 = Task.Run(() =>
            {
                try
                {
                    job3.Do2(db);
                }
                catch (Exception e)
                {
                    ParallelWorkloadAll.errors++;
                }
            });

            var t4 = Task.Run(() =>
            {
                try
                {
                    job4.Do2(db);
                }
                catch (Exception e)
                {
                    ParallelWorkloadAll.errors++;
                }
            });


            t1.Wait();
            t2.Wait();
            t3.Wait();
            t4.Wait();

            if (ParallelWorkloadAll.errors > 0)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
        public void Do2(Db db)
        {
            bool dispose = false;

            if (db == null)
            {
                db      = new Db("DATA");
                dispose = true;
#if (SERVER)
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
                using (var trans = new LinqdbTransaction())
                {
                    db.Table <SomeData>(trans).Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
                    trans.Commit();
                }
#endif
                DoInit = true;
            }
            this.db = db;

            var start_list = new List <SomeData>(JobTrans.start);
            for (int i = 1; i < JobTrans.start; i++)
            {
                start_list.Add(new SomeData()
                {
                    Id         = i,
                    GroupBy    = i % 10,
                    Normalized = Convert.ToDouble("0," + i)
                });
            }
            if (start_list.Any())
            {
                for (int i = 0; ; i++)
                {
                    var list = start_list.Skip(i * 50000).Take(50000).ToList();
                    if (!list.Any())
                    {
                        break;
                    }
                    using (var trans = new LinqdbTransaction())
                    {
                        db.Table <SomeData>(trans).SaveBatch(list);
                        trans.Commit();
                    }
                }
            }


            JobTrans.errors  = 0;
            JobTrans.numbers = new List <int>();
            JobTrans.rg      = new Random();
            var sw = new Stopwatch();
            sw.Start();
            for (int j = 0; j < 5; j++)
            {
                var jobs = new List <JobTrans>();
                for (int i = 0; i < 10000; i++)
                {
                    jobs.Add(new JobTrans());
                }

                Parallel.ForEach(jobs, /*new ParallelOptions { MaxDegreeOfParallelism = 500 },*/ f =>
                {
                    JobTrans.Do(db);
                });
            }

            if (JobTrans.errors > 0)
            {
                throw new Exception("Assert failure, errors " + JobTrans.errors);
            }
            Console.WriteLine("Select: {0} ms", JobTrans.totalms_select / (double)JobTrans.total_select);
            Console.WriteLine("Save: {0} ms", JobTrans.totalms_save / (double)JobTrans.total_save);
            Console.WriteLine("Delete: {0} ms", JobTrans.totalms_delete / (double)JobTrans.total_delete);
            Console.WriteLine("Update: {0} ms", JobTrans.totalms_update / (double)JobTrans.total_update);
            sw.Stop();
            Console.WriteLine("Total jobs 50000, time {0} sec", sw.ElapsedMilliseconds / 1000);
            var ids = db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList();
            for (int i = 0; ; i++)
            {
                var ids_delete = ids.Skip(i * 50000).Take(50000).ToList();
                if (!ids_delete.Any())
                {
                    break;
                }
                using (var trans = new LinqdbTransaction())
                {
                    db.Table <SomeData>().Delete(new HashSet <int>(ids_delete));
                    trans.Commit();
                }
            }
            if (DoInit)
            {
#if (SERVER || SOCKETS)
                if (dispose)
                {
                    Logic.Dispose();
                }
#else
                if (dispose)
                {
                    db.Dispose();
                }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
                if (dispose)
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
#endif
            }
        }
Exemple #4
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var data = Enumerable.Range(1, 10000).Select(f => new SomeData()
            {
                Id    = f,
                Value = f
            }).ToList();
            var bad = Enumerable.Range(1, 1000).Select(f => new SomeData()
            {
                Value = double.NaN
            }).ToList();
            data.AddRange(bad);

            data = data.OrderBy(a => Guid.NewGuid()).ToList();
            int count = 0;
            Parallel.ForEach(data, f =>
            {
                try
                {
                    db.Table <SomeData>().Save(f);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("This error could belong to another entity which happened"))
                    {
                        count++;
                    }
                }
            });

            if (count == 0)
            {
                throw new Exception("Assert failure");
            }


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #5
0
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }

            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new Testing.tables.KaggleClass()
            {
                Id                   = 1,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 1,
                Qid2                 = 2,
                TotalLength          = 5
            };
            db.Table <Testing.tables.KaggleClass>().Save(d);
            var d2 = new Testing.tables.KaggleClass()
            {
                Id                   = 2,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 1,
                Qid2                 = 2,
                TotalLength          = 5,
            };
            db.Table <Testing.tables.KaggleClass>().Save(d2);

#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif

            var ids = db.Table <Testing.tables2.KaggleClass>().Select(f => new { f.Id }).Select(f => f.Id);
            db.Table <Testing.tables2.KaggleClass>().Delete(new HashSet <int>(ids));

            var res = db.Table <Testing.tables2.KaggleClass>().SelectEntity();
            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
Exemple #6
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <BinaryData>().Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new BinaryData()
            {
                Id   = 2,
                Data = new List <byte>()
                {
                    4, 5, 6
                }.ToArray()
            };
            db.Table <BinaryData>().Save(d);
            var res = db.Table <BinaryData>()
                      .Select(f => new
            {
                Id     = f.Id,
                MyData = f.Data
            });
            if (res.Count() != 1 || res[0].MyData.Length != 3 || res[0].MyData[0] != (byte)4)
            {
                throw new Exception("Assert failure");
            }

            var ids = db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList();
            db.Table <BinaryData>().Delete(new HashSet <int>(ids));

            d = new BinaryData()
            {
                Id   = 1,
                Data = new List <byte>()
                {
                    1, 2, 3
                }.ToArray()
            };
            db.Table <BinaryData>().Save(d);
            d = new BinaryData()
            {
                Id   = 2,
                Data = null
            };
            db.Table <BinaryData>().Save(d);
            res = db.Table <BinaryData>()
                  .Where(f => f.Data != null)
                  .Select(f => new
            {
                Id     = f.Id,
                MyData = f.Data
            });
            if (res.Count() != 1 || res[0].Id != 1 || res[0].MyData.Length != 3 || res[0].MyData[0] != (byte)1)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #7
0
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }

            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new Testing.tables.SomeType()
            {
                Name     = "test1",
                PeriodId = 1,
                Value    = 1.1
            };

#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables.SomeType>().Save(d);

            var res = db.Table <Testing.tables.SomeType>()
                      .Where(f => f.Id == d.Id)
                      .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].Id != 1 || res[0].PeriodId != 1)
            {
                throw new Exception("Assert failure");
            }

            //remove double column

            var d_new = new Testing.tables2.SomeType()
            {
                Name     = "test1",
                PeriodId = 1,
            };
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables2.SomeType>().Save(d_new);
#if (INDEXES)
            try
            {
                db.Table <Testing.tables.SomeType>().CreatePropertyMemoryIndex(f => f.Value);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                db.Table <Testing.tables.SomeType>().CreateGroupByMemoryIndex(f => f.Id, f => f.Value);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
#endif
            //add it back
            d.Id = 3;
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables.SomeType>().Save(d);
            var res2 = db.Table <Testing.tables.SomeType>()
                       .Where(f => f.Id == 3)
                       .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId,
                Value    = f.Value
            });
            if (res2.Count() != 1 || res2[0].Id != 3 || res2[0].Value != 1.1)
            {
                throw new Exception("Assert failure");
            }
#if (INDEXES)
            try
            {
                db.Table <Testing.tables.SomeType>().CreatePropertyMemoryIndex(f => f.Value);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                db.Table <Testing.tables.SomeType>().CreateGroupByMemoryIndex(f => f.Id, f => f.Value);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
#endif
            //remove string column
            var d_new_no_string = new Testing.tables3.SomeType()
            {
                PeriodId = 1,
            };
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables3.SomeType>().Save(d_new_no_string);

            //add it back
            d.Id = 3;
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables.SomeType>().Save(d);
            var res3 = db.Table <Testing.tables.SomeType>()
                       .Where(f => f.Id == 3)
                       .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId,
                Value    = f.Value,
                Name     = f.Name
            });
            if (res3.Count() != 1 || res3[0].Id != 3 || res3[0].Value != 1.1 || res3[0].Name != "test1")
            {
                throw new Exception("Assert failure");
            }


            //remove int column
            var d_new_no_int = new Testing.tables4.SomeType()
            {
                Name = "4",
            };
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables4.SomeType>().Save(d_new_no_int);
#if (INDEXES)
            try
            {
                db.Table <Testing.tables.SomeType>().CreatePropertyMemoryIndex(f => f.PeriodId);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                db.Table <Testing.tables.SomeType>().CreateGroupByMemoryIndex(f => f.PeriodId, f => f.Id);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                db.Table <Testing.tables.SomeType>().CreateGroupByMemoryIndex(f => f.Id, f => f.PeriodId);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
#endif
            //add it back
            d.Id = 3;
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables.SomeType>().Save(d);
            var res4 = db.Table <Testing.tables.SomeType>()
                       .Where(f => f.Id == 3)
                       .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId,
                Value    = f.Value,
                Name     = f.Name
            });
            if (res3.Count() != 1 || res3[0].Id != 3 || res3[0].Value != 1.1 || res3[0].PeriodId != 1)
            {
                throw new Exception("Assert failure");
            }
#if (INDEXES)
            try
            {
                db.Table <Testing.tables.SomeType>().CreatePropertyMemoryIndex(f => f.PeriodId);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                db.Table <Testing.tables.SomeType>().CreateGroupByMemoryIndex(f => f.PeriodId, f => f.Id);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                db.Table <Testing.tables.SomeType>().CreateGroupByMemoryIndex(f => f.Id, f => f.PeriodId);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("has gaps in data"))
                {
                    throw new Exception("Assert failure");
                }
            }
#endif

#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
Exemple #8
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            try
            {
                db.Table <SomeData>().Search(f => f.NotSearchable, "test").SelectEntity();
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("only string properties named ...Search"))
                {
                    throw new Exception("Assert failure");
                }
            }

            try
            {
                db.Table <SomeData>().SearchPartial(f => f.NotSearchable, "test").SelectEntity();
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("only string properties named ...Search"))
                {
                    throw new Exception("Assert failure");
                }
            }



#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #9
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <Small>().Delete(new HashSet <int>(db.Table <Small>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <Small2>().Delete(new HashSet <int>(db.Table <Small2>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new Small()
            {
                Id   = 1,
                Some = 5
            };
            db.Table <Small>().Save(d);

            var res = db.Table <Small>()
                      .Select(f => new
            {
                f.Id,
                f.Some
            });
            if (res.Count() != 1 || res[0].Id != 1 || res[0].Some != 5)
            {
                throw new Exception("Assert failure");
            }

            var d2 = new Small2()
            {
                Id = 1,
                A  = 5
            };
            db.Table <Small2>().Save(d2);

            var res2 = db.Table <Small2>()
                       .Select(f => new
            {
                f.Id,
                f.A
            });
            if (res2.Count() != 1 || res2[0].Id != 1 || res2[0].A != 5)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #10
0
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }
            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var list  = new List <SomeData>();
            int total = 150000;
            for (int i = 1; i <= total; i++)
            {
                var d = new SomeData()
                {
                    Normalized = i,
                    PeriodId   = i,
                    Date       = DateTime.Now.AddDays(i),
                    NameSearch = i + "",
                    ObjectId   = i,
                    PersonId   = i,
                    Value      = i
                };
                list.Add(d);
            }

            db.Table <SomeData>().SaveBatch(list.Take(50000).ToList());
            db.Table <SomeData>().SaveBatch(list.Skip(50000).Take(50000).ToList());
            db.Table <SomeData>().SaveBatch(list.Skip(100000).ToList());

            var res = db.Table <SomeData>().SelectEntity();
            if (res.Count() != total)
            {
                throw new Exception("Assert failure");
            }

            foreach (var r in list)
            {
                if (r.Id != r.PeriodId)
                {
                    throw new Exception("Assert failure");
                }
            }

#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
Exemple #11
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "test 123 abc"
            };
            db.Table <SomeData>().Save(d);
            db.Table <SomeData>().Delete(new HashSet <int>()
            {
                1, 2, 3, 4
            });

            //count
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);;

            int count = db.Table <SomeData>().Count();
            if (count != 2)
            {
                throw new Exception("Assert failure");
            }
            count = db.Table <SomeData>().Where(f => f.Id >= 2).Count();
            if (count != 1)
            {
                throw new Exception("Assert failure");
            }


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #12
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "TeSt 123 AbC"
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 0.9,
                PeriodId   = 7,
                NameSearch = "test"
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 0.5,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);;


            var res = db.Table <SomeData>()
                      .Search(f => f.NameSearch, "test")
                      .OrderBy(f => f.Id)
                      .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 2 || res[0].Id != 1 || res[1].Id != 2)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Search(f => f.NameSearch, "test abc")
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].Id != 1)
            {
                throw new Exception("Assert failure");
            }


            d = new SomeData()
            {
                Id            = 1,
                Normalized    = 1.2,
                PeriodId      = 5,
                NameSearch    = "ПриВеТ Как ДелА",
                NotSearchable = "ПриВеТ Как ДелА"
            };
            db.Table <SomeData>().Save(d);

            res = db.Table <SomeData>()
                  .Search(f => f.NameSearch, "привет дела")
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].Id != 1)
            {
                throw new Exception("Assert failure");
            }


            res = db.Table <SomeData>()
                  .Where(f => f.NameSearch == "привет как дела")
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].Id != 1)
            {
                throw new Exception("Assert failure");
            }

            res = db.Table <SomeData>()
                  .Where(f => f.NameSearch == "привет как делаa")
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }

            res = db.Table <SomeData>()
                  .Where(f => f.NameSearch != "привет как дела")
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 2)
            {
                throw new Exception("Assert failure");
            }

            var res2 = db.Table <SomeData>()
                       .Intersect(f => f.NameSearch, new HashSet <string>()
            {
                "привет как дела"
            })
                       .Select(f => new
            {
                f.Id,
                f.PeriodId,
                f.NameSearch,
                f.NotSearchable
            });
            if (res2.Count() != 1 || res2[0].Id != 1 || res2[0].NameSearch != "ПриВеТ Как ДелА" || res2[0].NotSearchable != "ПриВеТ Как ДелА")
            {
                throw new Exception("Assert failure");
            }

            res = db.Table <SomeData>()
                  .SearchPartial(f => f.NameSearch, "ПРИ КА Д")
                  .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].Id != 1)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #13
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var count = db.Table <SomeData>().Count();

            if (count != 0)
            {
                throw new Exception("Assert failure");
            }

            var list  = new List <SomeData>();
            int total = 1000000;
            for (int i = 1; i <= total; i++)
            {
                list.Add(new SomeData()
                {
                    Id         = i,
                    NameSearch = i.ToString() + " " + i.ToString(),
                    Normalized = i,
                    ObjectId   = i,
                    PeriodId   = i,
                    Value      = i
                });
            }
            db.Table <SomeData>().SaveNonAtomically(list);
            count = db.Table <SomeData>().Count();

            if (count != total)
            {
                throw new Exception("Assert failure");
            }

            try
            {
                using (var tran = new LinqdbTransaction())
                {
                    db.Table <SomeData>(tran).SaveNonAtomically(list);
                }
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("can't be used in a transaction"))
                {
                    throw new Exception("Assert failure");
                }
            }

            var updateInfo = list.ToDictionary(f => f.Id, f => f.Id + 1);
            db.Table <SomeData>().UpdateNonAtomically(f => f.PeriodId, updateInfo);

            var res = db.Table <SomeData>().Select(f => new
            {
                f.Id,
                f.ObjectId,
                f.PeriodId
            });

            if (res.Count() == 0 || res.Any(f => f.Id != f.ObjectId || f.Id != f.PeriodId - 1))
            {
                throw new Exception("Assert failure");
            }

            var ids = db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id);
            db.Table <SomeData>().DeleteNonAtomically(new HashSet <int>(ids));

            count = db.Table <SomeData>().Count();
            if (count != 0)
            {
                throw new Exception("Assert failure");
            }

            list = new List <SomeData>();
            for (int i = 1; i <= total; i++)
            {
                list.Add(new SomeData()
                {
                    NameSearch = i.ToString() + " " + i.ToString(),
                    Normalized = i,
                    ObjectId   = i,
                    PeriodId   = i,
                    Value      = i
                });
            }
            db.Table <SomeData>().SaveNonAtomically(list);
            count = db.Table <SomeData>().Count();
            if (count != total)
            {
                throw new Exception("Assert failure");
            }
            var idsList = db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList();
            if (idsList.Distinct().Count() != total)
            {
                throw new Exception("Assert failure");
            }

            ids = db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id);
            db.Table <SomeData>().DeleteNonAtomically(new HashSet <int>(ids));

            count = db.Table <SomeData>().Count();
            if (count != 0)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #14
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var count = db.Table <SomeData>()
                        .Search(f => f.NameSearch, "test")
                        .Count();

            if (count != 0)
            {
                throw new Exception("Assert failure");
            }

            for (int i = 1; i < 1000; i++)
            {
                var d = new SomeData()
                {
                    Id         = i,
                    Normalized = 1.2,
                    PeriodId   = 5,
                    NameSearch = "test"
                };
                db.Table <SomeData>().Save(d);
            }

            using (var tran = new LinqdbTransaction())
            {
                db.Table <SomeData>(tran).Delete(1);
                var d = new SomeData()
                {
                    Id         = 1000,
                    Normalized = 1.2,
                    PeriodId   = 5,
                    NameSearch = "test"
                };
                db.Table <SomeData>(tran).Save(d);
                tran.Commit();
            }

            count = db.Table <SomeData>()
                    .Where(f => f.Id > 999)
                    .Search(f => f.NameSearch, "test")
                    .Count();

            if (count != 1)
            {
                throw new Exception("Assert failure");
            }


            using (var tran = new LinqdbTransaction())
            {
                db.Table <SomeData>(tran).Delete(2);
                var d = new SomeData()
                {
                    Id         = 1001,
                    Normalized = 1.2,
                    PeriodId   = 5,
                    NameSearch = "test"
                };
                db.Table <SomeData>(tran).Save(d);

                tran.Commit();
            }

            count = db.Table <SomeData>()
                    .Where(f => f.Id > 999)
                    .Search(f => f.NameSearch, "test")
                    .Count();

            if (count != 2)
            {
                throw new Exception("Assert failure");
            }

#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            int last_phase = db.Table <SomeData>().LastStep();
            if (last_phase != 1)
            {
                throw new Exception("Assert failure");
            }
#endif



#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #15
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "Admin11",
                Date       = Convert.ToDateTime("2005-01-01")
            };
            db.Table <SomeData>().Save(d);

            var date = Convert.ToDateTime("2005-01-01");
            var res  = db.Table <SomeData>()
                       .Where(f => f.Date == date)
                       .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }

            d.Date = Convert.ToDateTime("2010-01-01");

            db.Table <SomeData>().Save(d);
            date = Convert.ToDateTime("2005-01-01");
            res  = db.Table <SomeData>()
                   .Where(f => f.Date == date)
                   .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }
            date = Convert.ToDateTime("2010-01-01");
            res  = db.Table <SomeData>()
                   .Where(f => f.Date == date)
                   .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }

            db.Table <SomeData>().Delete(1);
            date = Convert.ToDateTime("2010-01-01");
            var date1 = Convert.ToDateTime("2005-01-01");
            res = db.Table <SomeData>()
                  .Where(f => f.Date == date || f.Date == date1)
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #16
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 0.9,
                PeriodId   = 7
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 0.5,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 4,
                Normalized = 4.5,
                PeriodId   = 15
            };
            db.Table <SomeData>().Save(d);

            var all = db.Table <SomeData>().GetIds();
            if (!all.AllIds || all.Ids.Count() != 4)
            {
                throw new Exception("Assert failure");
            }

            all = db.Table <SomeData>().Where(f => f.Id > 0).GetIds();
            if (all.Ids.Count() != 4)
            {
                throw new Exception("Assert failure");
            }

            var ids = db.Table <SomeData>().Where(f => f.Id > 2).GetIds();
            if (ids.Ids.Count(f => f > 2) != 2 || ids.AllIds)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
        public void Do2(Db db)
        {
            bool dispose = false;

            if (db == null)
            {
                dispose = true;
                db      = new Db("DATA");
#if (SERVER)
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
                db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
                using (var trans = new LinqdbTransaction())
                {
                    db.Table <BinaryData>(trans).Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
                    trans.Commit();
                }
#endif
                DoInit = true;
            }
            this.db = db;

            var start_list = new List <BinaryData>(TransJob2.start);
            for (int i = 1; i < TransJob2.start; i++)
            {
                start_list.Add(new BinaryData()
                {
                    Id   = i,
                    Data = new byte[4] {
                        1, 2, 3, 4
                    }
                });
            }
            if (start_list.Any())
            {
                for (int i = 0; ; i++)
                {
                    var list = start_list.Skip(i * 50000).Take(50000).ToList();
                    if (!list.Any())
                    {
                        break;
                    }
                    using (var trans = new LinqdbTransaction())
                    {
                        db.Table <BinaryData>(trans).SaveBatch(list);
                        trans.Commit();
                    }
                }
            }


            TransJob2.errors  = 0;
            TransJob2.numbers = new List <int>();
            TransJob2.rg      = new Random();

            for (int j = 0; j < 5; j++)
            {
                var jobs = new List <TransJob2>();
                for (int i = 0; i < 10000; i++)
                {
                    jobs.Add(new TransJob2());
                }

                Parallel.ForEach(jobs, /*new ParallelOptions { MaxDegreeOfParallelism = 500 },*/ f =>
                {
                    TransJob2.Do(db);
                });
            }

            if (TransJob2.errors > 0)
            {
                throw new Exception("Assert failure 1");
            }
            var ids = db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList();
            for (int i = 0; ; i++)
            {
                var ids_delete = ids.Skip(i * 50000).Take(50000).ToList();
                if (!ids_delete.Any())
                {
                    break;
                }
                using (var trans = new LinqdbTransaction())
                {
                    db.Table <BinaryData>(trans).Delete(new HashSet <int>(ids_delete));
                    trans.Commit();
                }
            }
            if (DoInit)
            {
#if (SERVER || SOCKETS)
                if (dispose)
                {
                    Logic.Dispose();
                }
#else
                if (dispose)
                {
                    db.Dispose();
                }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
                if (dispose)
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
#endif
            }
        }
Exemple #18
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = BitConverter.ToDouble(new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 128
                }, 0),
            };
            db.Table <SomeData>().Save(d);
            var res = db.Table <SomeData>().SelectEntity();
            var bs  = BitConverter.GetBytes((double)res.First().Normalized);
            if (bs[0] != 0 || bs[1] != 0 || bs[2] != 0 || bs[3] != 0 || bs[4] != 0 || bs[5] != 0 || bs[6] != 0 || bs[7] != 0)
            {
                throw new Exception("Assert failure");
            }

            try
            {
                d = new SomeData()
                {
                    Id         = 1,
                    Normalized = double.NaN,
                };
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("double with value NaN is not supported"))
                {
                    throw new Exception("Assert failure");
                }
            }

            try
            {
                d = new SomeData()
                {
                    Id         = 1,
                    Normalized = double.PositiveInfinity,
                };
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("double with value PositiveInfinity is not supported"))
                {
                    throw new Exception("Assert failure");
                }
            }

            try
            {
                d = new SomeData()
                {
                    Id         = 1,
                    Normalized = double.NegativeInfinity,
                };
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("double with value NegativeInfinity is not supported"))
                {
                    throw new Exception("Assert failure");
                }
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "test"
            };
            db.Table <SomeData>().Save(d);

            d = new SomeData()
            {
                Id         = 2,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "test"
            };
            db.Table <SomeData>().Save(d);

            string ex_msg = "";
            try
            {
                using (var tran = new LinqdbTransaction())
                {
                    db.Table <SomeData>(tran).Update(f => f.NameSearch, 1, "hohoho");
                    db.Table <SomeData>(tran).Update(f => f.NameSearch, 2, "hohoho");
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                ex_msg = ex.Message;
            }

            if (!string.IsNullOrEmpty(ex_msg))
            {
                throw new Exception("Assert failure");
            }

            ex_msg = "";
            try
            {
                using (var tran = new LinqdbTransaction())
                {
                    d = new SomeData()
                    {
                        Id         = 1,
                        Normalized = 1.2,
                        PeriodId   = 5,
                        NameSearch = "test"
                    };
                    db.Table <SomeData>(tran).Save(d);
                    db.Table <SomeData>(tran).Update(f => f.NameSearch, 1, "hohoho");
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                ex_msg = ex.Message;
            }
            if (!ex_msg.Contains("Linqdb: same entity cannot be modified twice in a transaction."))
            {
                throw new Exception("Assert failure");
            }

            ex_msg = "";
            try
            {
                using (var tran = new LinqdbTransaction())
                {
                    db.Table <SomeData>(tran).Update(f => f.NameSearch, 1, "hohoho");
                    db.Table <SomeData>(tran).Update(f => f.NameSearch, 1, "hohoha");
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                ex_msg = ex.Message;
            }

            if (!ex_msg.Contains("Linqdb: same entity's field cannot be updated twice in a transaction."))
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #20
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var a = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5,
                NameSearch = "test"
            };
            db.Table <SomeData>().Save(a);

            int count = db.Table <SomeData>().Search(f => f.NameSearch, "test").Count();

            if (count != 1)
            {
                throw new Exception("Assert failure");
            }

            using (var tran = new LinqdbTransaction())
            {
                var d = new SomeData()
                {
                    Id         = 2,
                    Normalized = 1.2,
                    PeriodId   = 5,
                    NameSearch = "test"
                };
                db.Table <SomeData>(tran).Save(d);

                d = new SomeData()
                {
                    Id         = 3,
                    Normalized = 1.2,
                    PeriodId   = 5,
                    NameSearch = "test"
                };
                db.Table <SomeData>(tran).Save(d);

                db.Table <SomeData>(tran).Update(f => f.NameSearch, 1, "hohoho");

                tran.Commit();
            }

            count = db.Table <SomeData>().Count();

            if (count != 3)
            {
                throw new Exception("Assert failure");
            }

            var res = db.Table <SomeData>().Search(f => f.NameSearch, "test").SelectEntity();
            count = db.Table <SomeData>().Search(f => f.NameSearch, "test").Count();
            if (res.Count() != 2 || count != 2 || res[0].NameSearch != "test")
            {
                throw new Exception("Assert failure");
            }

            res   = db.Table <SomeData>().Search(f => f.NameSearch, "hohoho").SelectEntity();
            count = db.Table <SomeData>().Search(f => f.NameSearch, "hohoho").Count();
            if (count != 1 || res.Count() != 1 || res[0].NameSearch != "hohoho")
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #21
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <BinaryData>().Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            // empty string and empty array is the same as null

            var d = new SomeData()
            {
                Id         = 1,
                NameSearch = ""
            };
            db.Table <SomeData>().Save(d);

            var res = db.Table <SomeData>()
                      .Where(f => f.NameSearch == "")
                      .Select(f => new
            {
                Name = f.NameSearch
            });
            if (res.Count() != 1 || res[0].Name != null)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Where(f => f.NameSearch == null)
                  .Select(f => new
            {
                Name = f.NameSearch
            });
            if (res.Count() != 1 || res[0].Name != null)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Where(f => f.NameSearch != "")
                  .Select(f => new
            {
                Name = f.NameSearch
            });
            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Where(f => f.NameSearch != null)
                  .Select(f => new
            {
                Name = f.NameSearch
            });
            if (res.Count() != 0)
            {
                throw new Exception("Assert failure");
            }

            var b = new BinaryData()
            {
                Id   = 1,
                Data = new byte[0]
            };
            db.Table <BinaryData>().Save(b);

            var res2 = db.Table <BinaryData>()
                       .Where(f => f.Data == null)
                       .Select(f => new
            {
                Data = f.Data
            });
            if (res2.Count() != 1 || res2[0].Data != null)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #22
0
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }

            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 2.3,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 4.5,
                PeriodId   = 15
            };
            db.Table <SomeData>().Save(d);;

            var res = db.Table <SomeData>()
                      .Where(f => f.Id == 1)
                      .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }

            d = new SomeData()
            {
                Normalized = 1.2,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);
            res = db.Table <SomeData>()
                  .Where(f => f.Id == 1)
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>()
                  .Where(f => f.Id == 4)
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].PeriodId != 10)
            {
                throw new Exception("Assert failure");
            }

            d = new SomeData()
            {
                Normalized = 1.2,
                PeriodId   = 21
            };
            db.Table <SomeData>().Save(d);
            res = db.Table <SomeData>()
                  .Where(f => f.Id == 5)
                  .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 1 || res[0].PeriodId != 21)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id         = 1,
                Normalized = -1.2,
                PeriodId   = -5
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 2,
                Normalized = 2.3,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 3,
                Normalized = -4.5,
                PeriodId   = -15
            };
            db.Table <SomeData>().Save(d);;

            var res = db.Table <SomeData>()
                      .Where(f => f.Normalized >= -1.2)
                      .Select(f => new
            {
                PeriodId = f.PeriodId
            });
            if (res.Count() != 2 || res[0].PeriodId + res[1].PeriodId != 5)
            {
                throw new Exception("Assert failure");
            }
#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #24
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var list = new List <SomeData>();
            for (int i = 0; i < 500000; i++)
            {
                list.Add(new SomeData());
            }
            try
            {
                db.Table <SomeData>().SaveBatch(list);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("modification batch is too large"))
                {
                    throw new Exception("Assert failure");
                }
            }
            list = new List <SomeData>();
            for (int i = 0; i < 500000; i++)
            {
                list.Add(new SomeData());
                if (list.Count() > 100000)
                {
                    db.Table <SomeData>().SaveBatch(list);
                    list = new List <SomeData>();
                }
            }
            if (list.Any())
            {
                db.Table <SomeData>().SaveBatch(list);
            }
            var ids = db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList();
            try
            {
                db.Table <SomeData>().Delete(new HashSet <int>(ids));
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("modification batch is too large"))
                {
                    throw new Exception("Assert failure");
                }
            }
            for (int i = 0; ; i++)
            {
                var part = ids.Skip(i * 100000).Take(100000).ToList();
                if (!part.Any())
                {
                    break;
                }
                db.Table <SomeData>().Delete(new HashSet <int>(part));
            }


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }

            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new Testing.tables2.KaggleClass()
            {
                Id                   = 1,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 1,
                Qid2                 = 2,
                TotalLength          = 5,
                SomeNameSearch       = "abc def1"
            };
            db.Table <Testing.tables2.KaggleClass>().Save(d);
            var d2 = new Testing.tables2.KaggleClass()
            {
                Id                   = 2,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 1,
                Qid2                 = 2,
                TotalLength          = 5,
                SomeNameSearch       = "abc def2"
            };
            db.Table <Testing.tables2.KaggleClass>().Save(d2);

#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif

            //delete changed type
            var ids = db.Table <Testing.tables.KaggleClass>().Select(f => new { f.Id }).Select(f => f.Id);
            db.Table <Testing.tables.KaggleClass>().Delete(new HashSet <int>(ids));

            //back to first type
            d = new Testing.tables2.KaggleClass()
            {
                Id                   = 3,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 1,
                Qid2                 = 2,
                TotalLength          = 5,
                SomeNameSearch       = "abc def3"
            };
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables2.KaggleClass>().Save(d);
            d2 = new Testing.tables2.KaggleClass()
            {
                Id                   = 4,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 1,
                Qid2                 = 2,
                TotalLength          = 5,
                SomeNameSearch       = "abc def4"
            };
            db.Table <Testing.tables2.KaggleClass>().Save(d2);

            var total = db.Table <Testing.tables2.KaggleClass>().Count();


            var res = db.Table <Testing.tables2.KaggleClass>().Search(f => f.SomeNameSearch, "abc").SelectEntity();
            if (res.Count() != total || total != 2 || res.First(f => f.Id == 4).CommonCount != 1 || res.First(f => f.Id == 4).SomeNameSearch != "abc def4")
            {
                throw new Exception("Assert failure");
            }

            res = db.Table <Testing.tables2.KaggleClass>().SelectEntity();
            if (res.Count() != total || res.First(f => f.Id == 4).CommonCount != 1 || res.First(f => f.Id == 4).SomeNameSearch != "abc def4")
            {
                throw new Exception("Assert failure");
            }

            //back to second type
            var d_ = new Testing.tables.KaggleClass()
            {
                Id                   = 5,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 5,
                Qid2                 = 5,
                TotalLength          = 5
            };
#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            db.Table <Testing.tables.KaggleClass>().Save(d_);
            var d2_ = new Testing.tables.KaggleClass()
            {
                Id                   = 6,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 6,
                Qid2                 = 6,
                TotalLength          = 6
            };
            db.Table <Testing.tables.KaggleClass>().Save(d2_);

#if (SERVER)
            db.Table <Testing.tables.SomeType>()._internal._db._InternalClearCache();
#endif
            total = db.Table <Testing.tables2.KaggleClass>().Count();
            res   = db.Table <Testing.tables2.KaggleClass>().SelectEntity();
            if (res.Count() != total || total != 4 || res.First(f => f.Id == 4).CommonCount != 1 || res.First(f => f.Id == 4).SomeNameSearch != "abc def4" ||
                res.First(f => f.Id == 5).SomeNameSearch != null || res.First(f => f.Id == 5).Qid1 != 5 ||
                res.First(f => f.Id == 6).SomeNameSearch != null || res.First(f => f.Id == 6).Qid1 != 6)
            {
                throw new Exception("Assert failure");
            }

            d2 = new Testing.tables2.KaggleClass()
            {
                Id                   = 7,
                CommonCount          = 1,
                CommonPercentage     = 0.5,
                Is_duplicate         = 1,
                NormalizedPercentage = 1,
                Q1                   = "sadasd",
                Q2                   = "dsfdjfkldf",
                Qid1                 = 7,
                Qid2                 = 7,
                TotalLength          = 5,
                SomeNameSearch       = "abc def7"
            };
            db.Table <Testing.tables2.KaggleClass>().Save(d2);

            total = db.Table <Testing.tables2.KaggleClass>().Count();
            res   = db.Table <Testing.tables2.KaggleClass>().SelectEntity();
            if (res.Count() != total || total != 5 || res.First(f => f.Id == 4).CommonCount != 1 || res.First(f => f.Id == 4).SomeNameSearch != "abc def4" ||
                res.First(f => f.Id == 5).SomeNameSearch != null || res.First(f => f.Id == 5).Qid1 != 5 ||
                res.First(f => f.Id == 6).SomeNameSearch != null || res.First(f => f.Id == 6).Qid1 != 6 ||
                res.First(f => f.Id == 7).Qid1 != 7 || res.First(f => f.Id == 7).SomeNameSearch != "abc def7")
            {
                throw new Exception("Assert failure");
            }


#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
Exemple #26
0
        public void Do(Db db_unused)
        {
            if (db_unused != null)
            {
#if (SERVER)
                Logic.Dispose();
#else
                db_unused.Dispose();
#endif
                if (Directory.Exists("DATA"))
                {
                    ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
                }
            }
            var db = new Db("DATA");

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif

            var d = new Testing.tables5.SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                PeriodId   = 5
            };
            db.Table <Testing.tables5.SomeData>().Save(d);
            d = new Testing.tables5.SomeData()
            {
                Id         = 2,
                Normalized = 1.3,
                PeriodId   = 5
            };
            db.Table <Testing.tables5.SomeData>().Save(d);
            d = new Testing.tables5.SomeData()
            {
                Id         = 3,
                Normalized = 1.4,
                PeriodId   = 5
            };
            db.Table <Testing.tables5.SomeData>().Save(d);

#if (SERVER)
            db.Table <Testing.tables5.SomeData>()._internal._db._InternalClearCache();
#endif

            var dic = new Dictionary <int, int>()
            {
                { 2, 1 }
            };
            db.Table <Testing.tables.SomeData>().Update(f => f.GroupBy, dic);

            var res = db.Table <Testing.tables.SomeData>()
                      .Where(f => f.Normalized > 1.1 && f.Normalized < 1.35)
                      .SelectEntity();
            if (res.Count() != 2 || res[0].GroupBy != 0 || res[1].GroupBy != 1)
            {
                throw new Exception("Assert failure");
            }


#if (SERVER)
            Logic.Dispose();
#else
            db.Dispose();
#endif
            ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
        }
Exemple #27
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            int id1 = 0;
            int id2 = 0;
            using (var transaction = new LinqdbTransaction())
            {
                var d = new SomeData()
                {
                    NameSearch = "test",
                    Normalized = 1
                };
                db.Table <SomeData>(transaction).Save(d);
                if (d.Id == 0)
                {
                    throw new Exception("Assert failure");
                }
                id1 = d.Id;

                d = new SomeData()
                {
                    NameSearch = "test",
                    Normalized = 1
                };
                db.Table <SomeData>(transaction).Save(d);
                if (d.Id == 0)
                {
                    throw new Exception("Assert failure");
                }
                id2 = d.Id;
                if (id1 == id2)
                {
                    throw new Exception("Assert failure");
                }
                transaction.Commit();
            }

            var res = db.Table <SomeData>().Where(f => f.Id == id1).SelectEntity();
            if (res.Count() != 1)
            {
                throw new Exception("Assert failure");
            }
            res = db.Table <SomeData>().Where(f => f.Id == id2).SelectEntity();
            if (res.Count() != 1)
            {
                throw new Exception("Assert failure");
            }

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #28
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif

            var d = new SomeData()
            {
                Id         = 1,
                Normalized = 1.2,
                GroupBy    = 5,
                NameSearch = "a"
            };
            db.Table <SomeData>().Save(d);

            d = new SomeData()
            {
                Id         = 2,
                Normalized = 7,
                GroupBy    = 3,
                NameSearch = "a"
            };
            db.Table <SomeData>().Save(d);

            d = new SomeData()
            {
                Id         = 3,
                Normalized = 2.3,
                GroupBy    = 10,
                NameSearch = "a"
            };
            db.Table <SomeData>().Save(d);
            d = new SomeData()
            {
                Id         = 4,
                Normalized = 4.5,
                GroupBy    = 10,
                NameSearch = "b"
            };
            db.Table <SomeData>().Save(d);


            try
            {
                db.Table <SomeData>().CreateGroupByMemoryIndex(f => f.NameSearch, z => z.Id);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("type is not supported as group by column"))
                {
                    throw new Exception("Assert failure");
                }
            }

            try
            {
                db.Table <SomeData>().CreateGroupByMemoryIndex(f => f.Value, z => z.Id);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("type is not supported as group by column"))
                {
                    throw new Exception("Assert failure");
                }
            }

            try
            {
                db.Table <SomeData>().CreateGroupByMemoryIndex(f => f.Date, z => z.Id);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("type is not supported as group by column"))
                {
                    throw new Exception("Assert failure");
                }
            }


            db.Table <SomeData>().CreateGroupByMemoryIndex(f => f.GroupBy, z => z.Normalized);
            try
            {
                db.Table <SomeData>().GroupBy(f => f.PeriodId).Select(f => new { f.Key });
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("does not exist."))
                {
                    throw new Exception("Assert failure");
                }
            }
            db.Table <SomeData>().RemovePropertyMemoryIndex(f => f.Value);
            try
            {
                var res = db.Table <SomeData>().GroupBy(f => f.GroupBy).Select(f => new { f.Key, Sum = f.Sum(z => z.Value) });
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("does not exist."))
                {
                    throw new Exception("Assert failure");
                }
            }
            try
            {
                var res = db.Table <SomeData>().GroupBy(f => f.GroupBy2).Select(f => new { f.Key, Sum = f.Sum(z => z.Normalized) });
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("does not exist."))
                {
                    throw new Exception("Assert failure");
                }
            }

            db.Table <SomeData>().RemoveGroupByMemoryIndex(f => f.GroupBy, z => z.Normalized);

#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #29
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            var d = new SomeData()
            {
                Id          = 1,
                Normalized  = 1.2,
                PeriodId    = 5,
                NameSearchS = "professor programming pro1 pro0 pro1 pro2 pro3 pro4 pro5 pro6 pro7 pro8 pro9 pro10 pro11 pro12 pro13 pro14 pro15 pro16 pro17 pro18 pro19 pro20 pro21 pro22 pro23 pro24 pro25 pro26 pro27 pro28 pro29 pro30 pro31 pro32 pro33 pro34 pro35 pro36 pro37 pro38 pro39 pro40 pro41 pro42 pro43 pro44 pro45 pro46 pro47 pro48 pro49 pro50 pro51 pro52 pro53 pro54 pro55 pro56 pro57 pro58 pro59 pro60 pro61 pro62 pro63 pro64 pro65 pro66 pro67 pro68 pro69 pro70 pro71 pro72 pro73 pro74 pro75 pro76 pro77 pro78 pro79 pro80 pro81 pro82 pro83 pro84 pro85 pro86 pro87 pro88 pro89 pro90 pro91 pro92 pro93 pro94 pro95 pro96 pro97 pro98 pro99"
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id          = 2,
                Normalized  = 0.9,
                PeriodId    = 7,
                NameSearchS = "programmming"
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id         = 3,
                Normalized = 0.5,
                PeriodId   = 10
            };
            db.Table <SomeData>().Save(d);;
            d = new SomeData()
            {
                Id          = 4,
                Normalized  = 0.9,
                PeriodId    = 7,
                NameSearchS = "привет"
            };
            db.Table <SomeData>().Save(d);;

            var stats = new LinqdbSelectStatistics();
            var res   = db.Table <SomeData>()
                        .SearchPartial(f => f.NameSearchS, "pro")
                        .OrderBy(f => f.Id)
                        .Select(f => new
            {
                Id       = f.Id,
                PeriodId = f.PeriodId
            }, stats);
            if (res.Count() != 2 || res[0].Id != 1 || res[1].Id != 2)
            {
                throw new Exception("Assert failure");
            }

            if (stats.Total != 2)
            {
                throw new Exception("Assert failure");
            }


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }
Exemple #30
0
        public void Do(Db db)
        {
            bool dispose = false; if (db == null)

            {
                db = new Db("DATA"); dispose = true;
            }

#if (SERVER)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f)); };
#endif
#if (SOCKETS)
            db._db_internal.CallServer = (byte[] f) => { return(SocketTesting.CallServer(f, db)); };
#endif
#if (SOCKETS || SAMEDB || INDEXES || SERVER)
            db.Table <SomeData>().Delete(new HashSet <int>(db.Table <SomeData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
            db.Table <BinaryData>().Delete(new HashSet <int>(db.Table <BinaryData>().Select(f => new { f.Id }).Select(f => f.Id).ToList()));
#endif
            StringBuilder sb = new StringBuilder(1024 * 1024 + 10);
            for (int i = 0; i < 1024 * 1024 + 5; i++)
            {
                sb.Append("a");
            }

            var d = new SomeData()
            {
                NameSearch = sb.ToString()
            };
            try
            {
                db.Table <SomeData>().Save(d);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("max size is 1Mb"))
                {
                    throw new Exception("Assert failure");
                }
            }

            d = new SomeData()
            {
                Id = 1
            };
            db.Table <SomeData>().Save(d);
            try
            {
                db.Table <SomeData>().Update(f => f.NameSearch, 1, sb.ToString());
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("max size is 1Mb"))
                {
                    throw new Exception("Assert failure");
                }
            }

            var list = new List <byte>(1024 * 1024 + 10);
            for (int i = 0; i < 1024 * 1024 + 5; i++)
            {
                list.Add((byte)1);
            }
            var b = new BinaryData()
            {
                Data = list.ToArray()
            };
            try
            {
                db.Table <BinaryData>().Save(b);
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("max size is 1Mb"))
                {
                    throw new Exception("Assert failure");
                }
            }

            b = new BinaryData()
            {
                Id = 1
            };
            db.Table <BinaryData>().Save(b);
            try
            {
                db.Table <BinaryData>().Update(f => f.Data, 1, list.ToArray());
                throw new Exception("Assert failure");
            }
            catch (Exception ex)
            {
                if (!ex.Message.Contains("max size is 1Mb"))
                {
                    throw new Exception("Assert failure");
                }
            }


#if (SERVER || SOCKETS)
            if (dispose)
            {
                Logic.Dispose();
            }
#else
            if (dispose)
            {
                db.Dispose();
            }
#endif
#if (!SOCKETS && !SAMEDB && !INDEXES && !SERVER)
            if (dispose)
            {
                ServerSharedData.SharedUtils.DeleteFilesAndFoldersRecursively("DATA");
            }
#endif
        }