Beispiel #1
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);
            }
        }
Beispiel #2
0
        public void Comparison()
        {
            var a0 = new ByteArray (new byte[] { 0 });
            var a2 = new ByteArray (new byte[] { 0, 1, 2, 4 });
            var a2B = new ByteArray (new byte[] { 0, 1, 2, 4 });
            var a3 = new ByteArray (new byte[] { 0, 1, 2, 5 });
            var a4 = new ByteArray (new byte[] { 0, 1, 2, 5, 6 });

            // Simple direct comparisons
            Assert.IsTrue (a2.CompareTo (a3) < 0);
            Assert.IsTrue (a3.CompareTo (a2) > 0);
            Assert.IsTrue (a2.CompareTo (a2B) == 0);

            // Length comparisons
            Assert.IsTrue (a4.CompareTo (a0) > 0);
            Assert.IsTrue (a3.CompareTo (a4) < 0);
        }
Beispiel #3
0
 public void TestComparisonSpeed()
 {
     var a = new ByteArray (new byte[] { 0 });
     var b = new ByteArray (new byte[] { 1 });
     Stopwatch timer = new Stopwatch ();
     timer.Start ();
     for (int i = 0; i < 1000000; i++) Assert.True (a.CompareTo (b) < 0);
     timer.Stop ();
     Console.WriteLine ("Elapsed Time (1 byte): {0} ms", timer.ElapsedMilliseconds);
     a = new ByteArray (new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 });
     b = new ByteArray (new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20 });
     timer = new Stopwatch ();
     timer.Start ();
     for (int i = 0; i < 1000000; i++) Assert.True (a.CompareTo (b) < 0);
     timer.Stop ();
     Console.WriteLine ("Elapsed Time (20 byte): {0} ms", timer.ElapsedMilliseconds);
 }
Beispiel #4
0
        public void BulkSetBulkEnumerateWhileMerging()
        {
            string path = Path.GetFullPath("TestData\\BulkSetBulkEnumerateWhileMerging");
            var timer = new Stopwatch();
            int totalSize = 0;
            int readSize = 0;
            int num_items = 100000;

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

                db.Manifest.Logger = (msg) => Console.WriteLine(msg);

                timer.Start();
                for (int i = 0; i < num_items; i++) {
                    var randomKey = ByteArray.Random(40);
                    var randomValue = ByteArray.Random(256);
                    db.Set(randomKey.InternalBytes, randomValue.InternalBytes);

                    readSize += randomKey.Length + randomValue.Length;
                    totalSize += randomKey.Length + randomValue.Length;
                }
                timer.Stop();
                Console.WriteLine("Wrote sorted table at a throughput of {0} MB/s", (double)totalSize / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0));

                timer.Reset();
                Console.WriteLine("Begin enumeration.");
                timer.Start();
                ByteArray lastKey = new ByteArray();
                int ct = 0;
                foreach (var pair in db.Enumerate()) {
                    try {
                        ByteArray k = new ByteArray(pair.Key);
                        Assert.True(lastKey.CompareTo(k) < 0);
                        lastKey = k;
                        ct++;
                    } catch (Exception e) {
                        Console.WriteLine("Key: {0}\n{1}",pair.Key,e);
                        Debugger.Launch();
                        throw;
                    }
                }
                timer.Stop();
                Assert.AreEqual(num_items, ct, num_items.ToString() + " items should be enumerated.");

                Console.WriteLine("Enumerated read throughput of {0} MB/s", (double)readSize / timer.Elapsed.TotalSeconds / (1024.0 * 1024.0));
            }
        }