Exemple #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);
            }
        }
Exemple #2
0
        public void CrashTestBeforeMerge()
        {
            string path = Path.GetFullPath ("TestData\\CrashTestBeforeMerge");
            using (var db = new KeyValueStore(path)) db.Truncate ();

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

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

            doneSetting.WaitOne (30000);
            if (!process.HasExited) {
                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 (10000, ct);
                Console.WriteLine ("Found {0} items in the crashed database.", ct);
            }
        }
Exemple #3
0
        public void CleanIndex(string indexName)          // Cleans the index.
        {
            KeyValueStore indexStore = GetSecondaryIndex(indexName);

            var allValueStoreItems = new HashSet <ByteArray> (this.Enumerate().Select(item => new ByteArray(item.Key)));

            foreach (var indexItem in indexStore.Enumerate())
            {
                if (!allValueStoreItems.Contains(new ByteArray(indexItem.Value)))
                {
                    indexStore.Delete(indexItem.Key);
                }
            }
        }
Exemple #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 ());
        }
Exemple #5
0
        public int CountIndex(string indexName)
        {
            KeyValueStore indexStore = GetSecondaryIndex(indexName);

            return(indexStore.Enumerate().Count());
        }