예제 #1
0
        public void LargeDataEnumerateTest()
        {
            string path      = Path.GetFullPath("TestData\\LargeDataEnumerateTest");
            int    totalSize = 0;
            int    num_items = 500;
            var    timer     = new Stopwatch();

            using (var db = new KeyValueStore(path)) {
                db.Truncate();

                // Generate a data value that is larger than the block size.
                var value = ByteArray.Random(Config.SortedBlockSize + 256);

                // Do it enough times to ensure a roll-over
                for (int i = 0; i < num_items; i++)
                {
                    var key = BitConverter.GetBytes(i).Reverse().ToArray(); // this has to be little endian to sort in an obvious way
                    db.Set(key, value.InternalBytes);
                    totalSize += value.InternalBytes.Length;
                }

                int j = 0;
                timer.Start();
                foreach (var pair in db.Enumerate())
                {
                    var key = BitConverter.GetBytes(j).Reverse().ToArray();
                    Assert.AreEqual(key, pair.Key);
                    Assert.AreEqual(value.InternalBytes, pair.Value);
                    j++;
                }
                timer.Stop();

                Console.WriteLine("Randomized read throughput of {0} MB/s (avg {1} ms per lookup)", (double)totalSize / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0), (double)timer.Elapsed.TotalSeconds / (double)num_items);
            }
        }
예제 #2
0
        public void CrashTestOnMerge()
        {
            string path = Path.GetFullPath("TestData\\CrashTestOnMerge");

            using (var db = new KeyValueStore(path)) db.Truncate();

            var doneSetting = new EventWaitHandle(false, EventResetMode.ManualReset, "CrashTestOnMerge");

            doneSetting.Reset();

            string testPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "RazorTest.exe");
            var    process  = Process.Start(testPath, "CrashTestOnMerge");

            doneSetting.WaitOne(30000);
            process.Kill();
            process.WaitForExit();

            // Open the database created by the other program
            using (var db = new KeyValueStore(path)) {
                db.Manifest.Logger = (msg) => Console.WriteLine(msg);

                Console.WriteLine("Begin enumeration.");
                ByteArray lastKey = new ByteArray();
                int       ct      = 0;
                foreach (var pair in db.Enumerate())
                {
                    ByteArray k = new ByteArray(pair.Key);
                    Assert.True(lastKey.CompareTo(k) < 0);
                    lastKey = k;
                    ct++;
                }
                Assert.AreEqual(50000, ct);
                Console.WriteLine("Found {0} items in the crashed database.", ct);
            }
        }
예제 #3
0
        public IEnumerable <Record> GetRecords(string keyFilter, string valueFilter)
        {
            int index      = 0;
            var collection = _db.Enumerate().Select(pair => new Record(index++, pair, _viz));

            if (!string.IsNullOrWhiteSpace(keyFilter))
            {
                Regex reg = new Regex(keyFilter, RegexOptions.None);
                collection = collection.Where(rec => reg.IsMatch(rec.Key));
            }
            if (!string.IsNullOrWhiteSpace(valueFilter))
            {
                Regex reg = new Regex(valueFilter, RegexOptions.None);
                collection = collection.Where(rec => reg.IsMatch(rec.Value));
            }
            return(collection);
        }
예제 #4
0
        public void IndexClean()
        {
            string path = Path.GetFullPath("TestData\\IndexClean");

            using (var db = new KeyValueStore(path)) {
                db.Truncate();
                db.Manifest.Logger = msg => Console.WriteLine(msg);

                db.Set(Encoding.UTF8.GetBytes("KeyA"), Encoding.UTF8.GetBytes("ValueA:1"), new Dictionary <string, byte[]> {
                    { "Idx", Encoding.UTF8.GetBytes("1") }
                });
                db.Set(Encoding.UTF8.GetBytes("KeyB"), Encoding.UTF8.GetBytes("ValueB:2"), new Dictionary <string, byte[]> {
                    { "Idx", Encoding.UTF8.GetBytes("2") }
                });
                db.Set(Encoding.UTF8.GetBytes("KeyC"), Encoding.UTF8.GetBytes("ValueC:3"), new Dictionary <string, byte[]> {
                    { "Idx", Encoding.UTF8.GetBytes("3") }
                });

                var lookupValue = db.Find("Idx", Encoding.UTF8.GetBytes("3")).Single();
                Assert.AreEqual("ValueC:3", Encoding.UTF8.GetString(lookupValue.Value));
                Assert.AreEqual("KeyC", Encoding.UTF8.GetString(lookupValue.Key));

                db.Delete(Encoding.UTF8.GetBytes("KeyC"));
            }

            // Open the index directly and confirm that the lookup key is still there
            using (var db = new KeyValueStore(Path.Combine(path, "Idx"))) {
                Assert.AreEqual(3, db.Enumerate().Count());
            }

            using (var db = new KeyValueStore(path)) {
                db.CleanIndex("Idx");
            }

            // Open the index directly and confirm that the lookup key is now gone
            using (var db = new KeyValueStore(Path.Combine(path, "Idx"))) {
                Assert.AreEqual(2, db.Enumerate().Count());
            }
        }