Beispiel #1
0
        public void TestLargeish()
        {
            var di = new DirectoryInfo("testdb");

            using (var db = new PlaneSet(di, FileMode.CreateNew, planeDBOptions)) {
                for (var i = 0; i < 10000; ++i)
                {
                    Assert.IsTrue(db.TryAdd(BitConverter.GetBytes(i)));
                }
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions)) {
                for (var i = 0; i < 10000; ++i)
                {
                    Assert.IsTrue(db.Contains(BitConverter.GetBytes(i)));
                }
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions)) {
                Assert.AreEqual(db.Count, 10000);
                Assert.IsTrue(db.Remove(BitConverter.GetBytes(1000)));
                Assert.AreEqual(db.Count, 9999);
                Assert.IsFalse(db.Remove(BitConverter.GetBytes(1000)));
                var read = db.Select((e, i) => new KeyValuePair <byte[], int>(e, i)).Count();

                Assert.AreEqual(db.Count, read);
                db.Clear();
                Assert.AreEqual(db.Count, 0);
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions)) {
                Assert.AreEqual(db.Count, 0);
            }
        }
Beispiel #2
0
        public void TestBasicIterators()
        {
            var di = new DirectoryInfo("testdb");

            using (var db = new PlaneSet(di, FileMode.CreateNew, planeDBOptions.DisableJournal())) {
                for (var i = 0; i < 10000; ++i)
                {
                    Assert.IsTrue(db.TryAdd(BitConverter.GetBytes(i)));
                }
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions.DisableJournal())) {
                db.Compact();
            }

            int read;

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions.DisableJournal())) {
                Assert.AreEqual(db.Count, 10000);
                Assert.IsTrue(db.Remove(BitConverter.GetBytes(1000)));
                Assert.AreEqual(db.Count, 9999);
                Assert.IsFalse(db.Remove(BitConverter.GetBytes(1000)));
                read = db.Select(e => e).Count();

                Assert.AreEqual(db.Count, read);
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions.DisableJournal())) {
                Assert.AreEqual(db.Count, 9999);
                Assert.IsFalse(db.Remove(BitConverter.GetBytes(1000)));
                Assert.AreEqual(db.Count, 9999);
                read = db.Select((e, i) => new KeyValuePair <byte[], int>(e, i)).Count();

                Assert.AreEqual(db.Count, read);
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions.DisableJournal())) {
                Assert.AreEqual(db.Count, 9999);
                Assert.IsFalse(db.Remove(BitConverter.GetBytes(1000)));
                Assert.AreEqual(db.Count, 9999);
                read = db.Select((e, i) => new KeyValuePair <byte[], int>(e, i)).Count();

                Assert.AreEqual(db.Count, read);
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions.DisableJournal())) {
                Assert.AreEqual(db.Count, read);
                db.Clear();
                Assert.AreEqual(db.Count, 0);
            }

            using (var db = new PlaneSet(di, FileMode.Open, planeDBOptions.DisableJournal())) {
                Assert.AreEqual(db.Count, 0);
            }
        }