Ejemplo n.º 1
0
        public async Task FirstLastTest()
        {
            IDbStore columnFamilyDbStore = this.rocksDbStoreProvider.GetColumnStoreFamily("firstLastTest");

            string firstKey   = "firstKey";
            string firstValue = "firstValue";
            await columnFamilyDbStore.Put(firstKey.ToBytes(), firstValue.ToBytes());

            for (int i = 0; i < 10; i++)
            {
                string key   = $"key{i}";
                string value = "$value{i}";
                await columnFamilyDbStore.Put(key.ToBytes(), value.ToBytes());
            }

            string lastKey   = "lastKey";
            string lastValue = "lastValue";
            await columnFamilyDbStore.Put(lastKey.ToBytes(), lastValue.ToBytes());

            Option <(byte[], byte[])> firstEntryOption = await columnFamilyDbStore.GetFirstEntry();

            Assert.True(firstEntryOption.HasValue);
            (byte[] key, byte[] value)firstEntry = firstEntryOption.OrDefault();
            Assert.Equal(firstKey, firstEntry.key.FromBytes());
            Assert.Equal(firstValue, firstEntry.value.FromBytes());

            Option <(byte[], byte[])> lastEntryOption = await columnFamilyDbStore.GetLastEntry();

            Assert.True(lastEntryOption.HasValue);
            (byte[] key, byte[] value)lastEntry = lastEntryOption.OrDefault();
            Assert.Equal(lastKey, lastEntry.key.FromBytes());
            Assert.Equal(lastValue, lastEntry.value.FromBytes());
        }