예제 #1
0
        public void TestJounalVarLength()
        {
            using var ms = new KeepOpenMemoryStream();
            using (var journal = new Journal(ms, new PlaneDBOptions().EnableCompression())) {
                for (var i = 0; i < COUNT; ++i)
                {
                    var v = i.ToString();
                    journal.Put(v, v + v + v);
                    if (i % 10 == 0)
                    {
                        journal.Put("o" + v, v + v + v);
                    }

                    if (i % 30 == 0)
                    {
                        Assert.IsTrue(journal.Update("o" + v, v + v + v + v));
                    }
                    else if (i % 20 == 0)
                    {
                        journal.Remove("o" + v);
                    }
                }
            }

            var table = new MemoryTable(new PlaneDBOptions().EnableCompression());

            Journal.ReplayOnto(ms, new PlaneDBOptions().EnableCompression(), table);

            for (var i = 0; i < COUNT; ++i)
            {
                var v = i.ToString();
                Assert.IsTrue(table.ContainsKey(v, out _));
                Assert.IsFalse(table.ContainsKey($"nope{v}", out _));
                Assert.IsTrue(table.TryGet(v, out var s));
                Assert.AreEqual(v + v + v, s);

                if (i % 30 == 0)
                {
                    Assert.IsTrue(table.ContainsKey("o" + v, out _));
                    Assert.IsTrue(table.TryGet("o" + v, out var val));
                    Assert.AreEqual(v + v + v + v, val);
                }
                else if (i % 20 == 0)
                {
                    Assert.IsTrue(table.ContainsKey("o" + v, out _));
                    Assert.IsTrue(table.TryGet("o" + v, out var val));
                    Assert.IsNull(val);
                }
                else if (i % 10 == 0)
                {
                    Assert.IsTrue(table.ContainsKey("o" + v, out _));
                    Assert.IsTrue(table.TryGet("o" + v, out var val));
                    Assert.AreEqual(v + v + v, val);
                }
            }
        }
예제 #2
0
        public void TestMemoryTable()
        {
            var table = new MemoryTable(new PlaneDBOptions());

            for (var i = 0; i < COUNT; ++i)
            {
                var v = i.ToString();
                if (i % 16 != 0)
                {
                    table.Put(v, v + v + v);
                }

                if (i % 10 == 0)
                {
                    table.Put("o" + v, v + v + v);
                }

                if (i % 30 == 0)
                {
                    Assert.IsTrue(table.Update("o" + v, v + v + v + v));
                }
                else if (i % 20 == 0)
                {
                    table.Remove("o" + v);
                }
            }

            for (var i = 0; i < COUNT; ++i)
            {
                var v = i.ToString();
                if (i % 16 != 0)
                {
                    Assert.IsTrue(table.ContainsKey(v, out _));
                    Assert.IsFalse(table.ContainsKey($"nope{v}", out _));
                    Assert.IsTrue(table.TryGet(v, out var s));
                    Assert.AreEqual(v + v + v, s);
                }
                else
                {
                    Assert.IsFalse(table.ContainsKey(v, out _));
                    Assert.IsFalse(table.ContainsKey($"nope{v}", out _));
                    Assert.IsFalse(table.TryGet(v, out var s));
                    Assert.AreEqual(null, s);
                }

                if (i % 30 == 0)
                {
                    Assert.IsTrue(table.ContainsKey("o" + v, out _));
                    Assert.IsTrue(table.TryGet("o" + v, out var val));
                    Assert.AreEqual(v + v + v + v, val);
                }
                else if (i % 20 == 0)
                {
                    Assert.IsTrue(table.ContainsKey("o" + v, out _));
                    Assert.IsTrue(table.TryGet("o" + v, out var val));
                    Assert.IsNull(val);
                }
                else if (i % 10 == 0)
                {
                    Assert.IsTrue(table.ContainsKey("o" + v, out _));
                    Assert.IsTrue(table.TryGet("o" + v, out var val));
                    Assert.AreEqual(v + v + v, val);
                }
            }
        }