Exemplo n.º 1
0
        public void TestSnapshot()
        {
            var path = CleanTestDB();

            using (var db = new LDB(path, new Options {
                CreateIfMissing = true
            }))
            {
                db.Set("Tampa", "green");
                db.Set("London", "red");
                db.Remove("New York");

                using (var snapShot = db.CreateSnapshot())
                {
                    var readOptions = new ReadOptions {
                        Snapshot = snapShot
                    };

                    db.Set("New York", "blue");

                    Assert.Equal((string)db.Get("Tampa", readOptions), "green");
                    Assert.Equal((string)db.Get("London", readOptions), "red");

                    // Snapshot taken before key was updates
                    Assert.Null(db.Get("New York", readOptions));
                }

                // can see the change now
                Assert.Equal((string)db.Get("New York"), "blue");
            }
        }
Exemplo n.º 2
0
 public void Intro()
 {
     using(var database = new LDB(DatabasePath, new Options() { CreateIfMissing = true }))
     {
         database.Set("key1", "value1");
         Assert.Equal("value1", (string)database.Get("key1"));
         Assert.True(database.Get("key1") != null);
         database.Remove("key1");
         Assert.False(database.Get("key1") != null);
         Assert.Null(database.Get("key1"));
     }
 }
Exemplo n.º 3
0
 public void Intro()
 {
     using (var database = new LDB(DatabasePath, new Options()
     {
         CreateIfMissing = true
     }))
     {
         database.Put("key1", "value1");
         Assert.Equal("value1", (string)database.Get("key1"));
         Assert.True(database.Get("key1") != null);
         database.Delete("key1");
         Assert.False(database.Get("key1") != null);
         Assert.Null(database.Get("key1"));
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// get value
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static string Get(string key)
 {
     CheckPath();
     using (var db = new LDB(path))
     {
         return(db.Get(key));
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// exist value
 /// </summary>
 /// <param name="key"></param>
 public static bool Exists(string key)
 {
     CheckPath();
     using (var db = new LDB(path))
     {
         return(db.Get(key) != null);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// get value
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static T Get <T>(string key) where T : class, new()
        {
            CheckPath();
            using (var db = new LDB(path))
            {
                var item = db.Get(key);

                if (item == null)
                {
                    return(new T());
                }
                else
                {
                    return(db.Get(key).ByteArray.ToModel <T>() ?? new T());
                }
            }
        }
Exemplo n.º 7
0
        public void TestCRUD()
        {
            var path = CleanTestDB();

            using(var db = new LDB(path, new Options { CreateIfMissing = true }))
            {
                db.Set("Tampa", "green");
                db.Set("London", "red");
                db.Set("New York", "blue");

                Assert.Equal((string)db.Get("Tampa"), "green");
                Assert.Equal((string)db.Get("London"), "red");
                Assert.Equal((string)db.Get("New York"), "blue");

                db.Remove("New York");

                Assert.Null(db.Get("New York"));

                db.Remove("New York");
            }
        }
Exemplo n.º 8
0
 public void Error()
 {
     Assert.Throws<LevelDBException>(() =>
     {
         var options = new Options()
         {
             CreateIfMissing = false
         };
         var db = new LDB("non-existent", options);
         Assert.True(false);
         db.Get("key1");
     });
 }
Exemplo n.º 9
0
        public void TestCRUD()
        {
            var path = CleanTestDB();

            using (var db = new LDB(path, new Options {
                CreateIfMissing = true
            }))
            {
                db.Set("Tampa", "green");
                db.Set("London", "red");
                db.Set("New York", "blue");

                Assert.Equal((string)db.Get("Tampa"), "green");
                Assert.Equal((string)db.Get("London"), "red");
                Assert.Equal((string)db.Get("New York"), "blue");

                db.Remove("New York");

                Assert.Null(db.Get("New York"));

                db.Remove("New York");
            }
        }
Exemplo n.º 10
0
        public void TestSnapshot()
        {
            var path = CleanTestDB();

            using(var db = new LDB(path, new Options { CreateIfMissing = true }))
            {
                db.Set("Tampa", "green");
                db.Set("London", "red");
                db.Remove("New York");

                using(var snapShot = db.CreateSnapshot())
                {
                    var readOptions = new ReadOptions { Snapshot = snapShot };

                    db.Set("New York", "blue");

                    Assert.Equal((string)db.Get("Tampa", readOptions), "green");
                    Assert.Equal((string)db.Get("London", readOptions), "red");

                    // Snapshot taken before key was updates
                    Assert.Null(db.Get("New York", readOptions));
                }

                // can see the change now
                Assert.Equal((string)db.Get("New York"), "blue");

            }
        }