Ejemplo n.º 1
0
        public static void DeleteTest()
        {
            var  rdb = new RaptorDBGuid(_Path + "deleted");
            Guid g   = Guid.NewGuid();

            rdb.Set(g, "for delete");
            for (int i = 0; i < 100; i++)
            {
                rdb.Set(Guid.NewGuid(), "test " + i);
            }
            rdb.SaveIndex();
            string str = "";

            rdb.Get(g, out str);
            Assert.AreEqual("for delete", str);
            rdb.RemoveKey(g);
            int j = rdb.Count();

            Assert.AreEqual(100, j);
        }
Ejemplo n.º 2
0
        private static void Optimized_GUID(int count)
        {
            Console.WriteLine("testing : " + count.ToString("#,#"));
            var db = new RaptorDBGuid("c:\\RaptorDbTest\\" + count);

            var guids = new List <Guid>();

            Console.Write("Building guid list...");
            for (int i = 0; i < count; i++)
            {
                guids.Add(Guid.NewGuid());
            }
            Console.WriteLine("done");
            FileStream fs = new FileStream("c:\\RaptorDbTest\\guids", FileMode.Create);

            for (int i = 0; i < count; i++)
            {
                fs.Write(guids[i].ToByteArray(), 0, 16);
            }
            fs.Flush();
            fs.Close();
            DateTime dt = DateTime.Now;
            int      c  = 0;

            foreach (Guid g in guids)
            {
                string s = "" + g;
                db.Set(g, Encoding.Unicode.GetBytes(s));
                c++;
                if (c % 10000 == 0)
                {
                    Console.Write(".");
                }
                if (c % 100000 == 0)
                {
                    Console.WriteLine("time = " + DateTime.Now.Subtract(dt).TotalSeconds);
                }
            }
            Console.WriteLine("Flushing index...");
            db.SaveIndex();
            Console.WriteLine(count.ToString("#,#") + " save total time = " + DateTime.Now.Subtract(dt).TotalSeconds);
            dt = DateTime.Now;
            GC.Collect(2);
            int notfound = 0;

            c = 0;
            foreach (Guid g in guids)
            {
                byte[] val;
                if (db.Get(g, out val))
                {
                    string s = Encoding.Unicode.GetString(val);
                    if (s.Equals("" + g) == false)
                    {
                        Assert.Fail("data does not match " + g);
                    }
                }
                else
                {
                    notfound++;
                    //Assert.Fail("item not found " + g);
                }
                c++;
                if (c % 100000 == 0)
                {
                    Console.Write(".");
                }
            }
            Console.WriteLine("\r\nfetch total time = " + DateTime.Now.Subtract(dt).TotalSeconds);
            if (notfound > 0)
            {
                Console.WriteLine("items not found  = " + notfound);
                Assert.Fail("items not found");
            }
            Console.WriteLine("ALL DONE OK");
            db.Shutdown();
            db = null;
        }