Example #1
0
        private static async Task WriteToDB(short threadId, KeyValueGenerator generator, int numberOfIterations, TrimDatabase trimDB)
        {
            await Task.Yield();

            var keyMemory   = new byte[_keySize];
            var valueMemory = new byte[_valueSize];

            for (var i = 0; i < numberOfIterations; i++)
            {
                generator.GetKeyValue(keyMemory.AsSpan(), valueMemory.AsSpan(), threadId, numberOfIterations);
                await trimDB.PutAsync(keyMemory, valueMemory);
            }
        }
Example #2
0
        public async Task TestSkipListOverflow()
        {
            var loadedWords = CommonData.Words;
            var folder      = "D:\\Database";

            foreach (var f in System.IO.Directory.GetFiles(folder))
            {
                System.IO.File.Delete(f);
            }

            using var blocks = new MMapBlockCache();
            var dbOptions = new TrimDatabaseOptions()
            {
                DatabaseFolder = folder
            };
            var db = new TrimDatabase(dbOptions);

            await db.LoadAsync();

            foreach (var word in loadedWords)
            {
                var utf8  = Encoding.UTF8.GetBytes(word);
                var value = Encoding.UTF8.GetBytes($"VALUE={word}");
                await db.PutAsync(utf8, value);
            }

            var key           = Encoding.UTF8.GetBytes(loadedWords[0]);
            var expectedValue = Encoding.UTF8.GetBytes($"VALUE={loadedWords[0]}");

            var result = await db.GetAsync(key);

            Assert.Equal(expectedValue.ToArray(), result.ToArray());

            key           = Encoding.UTF8.GetBytes(loadedWords[loadedWords.Length / 2]);
            expectedValue = Encoding.UTF8.GetBytes($"VALUE={loadedWords[loadedWords.Length / 2]}");
            result        = await db.GetAsync(key);

            Assert.Equal(expectedValue.ToArray(), result.ToArray());

            key           = Encoding.UTF8.GetBytes(loadedWords[^ 1]);