Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 2
0
        private void SkipListPutWorking(MemoryTable memoryTable)
        {
            var string1 = Encoding.UTF8.GetBytes("This is the first test string");
            var string2 = Encoding.UTF8.GetBytes("This is the second test string");
            var string3 = Encoding.UTF8.GetBytes("This is the missing test string");
            var value1  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var value2  = new byte[] { 10, 11, 12, 13, 14, 15 };

            _ = new byte[] { 16, 17, 18, 19, 20 };

            memoryTable.Put(string1, value1);
            memoryTable.Put(string2, value2);
            var result = memoryTable.TryGet(string1, out var valueResult);

            Assert.Equal(SearchResult.Found, result);
            Assert.Equal(value1, valueResult.ToArray());

            var result2 = memoryTable.TryGet(string2, out _);

            Assert.Equal(SearchResult.Found, result2);
            var result3 = memoryTable.TryGet(string3, out _);

            Assert.Equal(SearchResult.NotFound, result3);
        }
Exemplo n.º 3
0
        private async Task CanPutInOrder(MemoryTable memoryTable)
        {
            var loadedWords = CommonData.Words;

            foreach (var word in loadedWords)
            {
                var utf8   = Encoding.UTF8.GetBytes(word);
                var value  = Encoding.UTF8.GetBytes($"VALUE={word}");
                var result = memoryTable.Put(utf8, value);
                Assert.True(result);
            }

            foreach (var word in loadedWords)
            {
                var utf8   = Encoding.UTF8.GetBytes(word);
                var value  = Encoding.UTF8.GetBytes($"VALUE={word}");
                var result = memoryTable.TryGet(utf8, out _);
                Assert.Equal(SearchResult.Found, result);
            }
        }
Exemplo n.º 4
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);
                }
            }
        }