Ejemplo n.º 1
0
        public async Task AddUpdateGet(int loops, int step)
        {
            FasterDictionary <int, string> .ReadResult result;
            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), GetOptions($"{nameof(AddGet)}-{loops}")))
            {
                for (var i = 0; i < loops; i++)
                {
                    dictionary.Upsert(i, (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                for (var i = 0; i < loops; i++)
                {
                    dictionary.Upsert(i, (i + 10).ToString()).Dismiss();
                }

                await dictionary.Ping();

                for (var i = 0; i < loops; i += step)
                {
                    result = await dictionary.TryGet(i);

                    Assert.True(result.Found);
                    Assert.Equal((i + 10).ToString(), result.Value);
                }

                await dictionary.Ping();


                result = await dictionary.TryGet(loops);

                Assert.False(result.Found);
            }
        }
Ejemplo n.º 2
0
        public async Task AddIterate(int loops)
        {
            FasterDictionary <string[], string> .ReadResult result;
            using (var dictionary = new FasterDictionary <string[], string>(TestHelper.GetKeyComparer <string[]>(), GetOptions($"{nameof(AddIterate)}-{loops}")))
            {
                var keys = new List <string[]>();

                for (var i = 0; i < loops; i++)
                {
                    keys.Add(new[] { "A", i.ToString() });
                    dictionary.Upsert(keys[i], (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                var count = 0;
                await foreach (var entry in dictionary)
                {
                    count++;
                    Assert.Equal((int.Parse(entry.Key[1]) + 1).ToString(), entry.Value);
                }

                result = await dictionary.TryGet(new[] { "A", loops.ToString() });

                Assert.False(result.Found);

                Assert.Equal(loops, count);
            }
        }
Ejemplo n.º 3
0
        //[InlineData(2_000_000, 31)]
        public async Task AddGet(int loops, int step)
        {
            FasterDictionary <string[], string> .ReadResult result;
            using (var dictionary = new FasterDictionary <string[], string>(TestHelper.GetKeyComparer <string[]>(), GetOptions($"{nameof(AddGet)}-{loops}")))
            {
                var keys = new List <string[]>();

                for (var i = 0; i < loops; i++)
                {
                    keys.Add(new[] { "A", i.ToString() });
                    dictionary.Upsert(keys[i], (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                for (var i = 0; i < loops; i += step)
                {
                    result = await dictionary.TryGet(keys[i]);

                    Assert.True(result.Found);
                    Assert.Equal((i + 1).ToString(), result.Value);
                }

                result = await dictionary.TryGet(new[] { "A", loops.ToString() });

                Assert.False(result.Found);
            }
        }
Ejemplo n.º 4
0
        //        [InlineData(5_000_000)]
        public async Task AddIterate(int loops)
        {
            FasterDictionary <int, string> .ReadResult result;
            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), GetOptions($"{nameof(AddIterate)}-{loops}")))
            {
                for (var i = 0; i < loops; i++)
                {
                    dictionary.Upsert(i, (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                var count = 0;
                await foreach (var entry in dictionary)
                {
                    count++;
                    Assert.Equal((entry.Key + 1).ToString(), entry.Value);
                }

                result = await dictionary.TryGet(loops);

                Assert.False(result.Found);

                Assert.Equal(loops, count);
            }
        }
Ejemplo n.º 5
0
        [InlineData(50_000, 1, CheckpointType.Snapshot)] //OK
        public async Task AddRestartColdRead(int loops, int step, CheckpointType checkpointType)
        {
            var options = GetOptions($"{nameof(AddRestartGetValues)}-{loops}");

            options.CheckPointType = checkpointType;
            options.DeleteOnClose  = false;

            Stopwatch watch = new Stopwatch();

            watch.Reset();

            FasterDictionary <int, string> .ReadResult result;
            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < loops; i++)
                {
                    var guid = GetGuid(i);
                    dictionary.Upsert(i, guid).Dismiss();
                }

                await dictionary.Ping();

                for (var i = 0; i < loops; i += step)
                {
                    var guid = GetGuid(loops - 1);
                    result = await dictionary.TryGet(loops - 1);

                    Assert.True(result.Found);
                    Assert.Equal(guid.ToString(), result.Value);
                }

                await dictionary.Save();
            }

            for (var k = 0; k < 3; k++)
            {
                using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
                {
                    await dictionary.Ping();

                    for (var i = 0; i < loops; i += step)
                    {
                        var guid = GetGuid(loops - 1);
                        result = await dictionary.TryGet(loops - 1);

                        Assert.True(result.Found);
                        Assert.Equal(guid.ToString(), result.Value);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public async Task AddRestartIterateMany(int loops, int rcovrCount, int iteratCnt, CheckpointType checkType)
        {
            var options = GetOptions($"{nameof(AddRestartIterateMany)}-{loops}");

            options.CheckPointType = checkType;
            options.DeleteOnClose  = false;

            var keys = new List <string[]>();

            FasterDictionary <string[], string> .ReadResult result;
            using (var dictionary = new FasterDictionary <string[], string>(TestHelper.GetKeyComparer <string[]>(), options))
            {
                for (var i = 0; i < loops; i++)
                {
                    keys.Add(new[] { "A", i.ToString() });
                    dictionary.Upsert(keys[i], (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                await dictionary.Save();
            }

            for (var j = 0; j < rcovrCount; j++)
            {
                if (j == rcovrCount - 1)
                {
                    options.DeleteOnClose = true;
                }

                using (var dictionary = new FasterDictionary <string[], string>(TestHelper.GetKeyComparer <string[]>(), options))
                {
                    for (var k = 0; k < iteratCnt; k++)
                    {
                        var count = 0;
                        await foreach (var entry in dictionary)
                        {
                            count++;
                            Assert.Equal((int.Parse(entry.Key[1]) + 1).ToString(), entry.Value);
                        }

                        result = await dictionary.TryGet(new[] { "A", loops.ToString() });

                        Assert.False(result.Found);

                        Assert.Equal(loops, count);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        //[InlineData(5_000_000)]
        public async Task AddRestartIterateOnce(int loops, CheckpointType checkpointType)
        {
            var options = GetOptions($"{nameof(AddRestartIterateOnce)}-{loops}");

            options.CheckPointType = checkpointType;
            options.DeleteOnClose  = false;

            FasterDictionary <int, string> .ReadResult result;
            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < loops; i++)
                {
                    dictionary.Upsert(i, (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                await dictionary.Save();
            }

            options.DeleteOnClose = true;

            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < 100; i++)
                {
                    var guid = GetGuid(i);
                    result = await dictionary.TryGet(i);

                    Assert.True(result.Found);
                    Assert.Equal((result.Key + 1).ToString(), result.Value);
                }

                var count = 0;
                await foreach (var entry in dictionary)
                {
                    count++;
                    Assert.Equal((entry.Key + 1).ToString(), entry.Value);
                }

                result = await dictionary.TryGet(loops);

                Assert.False(result.Found);

                Assert.Equal(loops, count);
            }
        }
Ejemplo n.º 8
0
        //[InlineData(5_000_000)]
        public async Task AddIterateUpdateIterateKeys(int loops, CheckpointType checkpointType)
        {
            var options = GetOptions($"{nameof(AddIterateUpdateIterate)}-{loops}");

            options.CheckPointType = checkpointType;
            options.DeleteOnClose  = false;

            FasterDictionary <int, string> .ReadResult result;
            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < loops; i++)
                {
                    dictionary.Upsert(i, (i + 1).ToString()).Dismiss();
                }

                await dictionary.Ping();

                await dictionary.Save();
            }

            var count = 0;

            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < 100; i++)
                {
                    result = await dictionary.TryGet(i);

                    Assert.True(result.Found);
                    Assert.Equal((result.Key + 1).ToString(), result.Value);
                }

                await foreach (var entry in dictionary.AsKeysIterator())
                {
                    count++;
                }

                result = await dictionary.TryGet(loops);

                Assert.False(result.Found);

                Assert.Equal(loops, count);
            }

            count = 0;
            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < loops; i++)
                {
                    if (i % 4 == 0)
                    {
                        dictionary.Remove(i).Dismiss();
                    }
                    else
                    {
                        count++;
                        dictionary.Upsert(i, (i + 2).ToString()).Dismiss();
                    }
                }

                await dictionary.Ping();

                await dictionary.Save();
            }

            options.DeleteOnClose = true;

            using (var dictionary = new FasterDictionary <int, string>(TestHelper.GetKeyComparer <int>(), options))
            {
                for (var i = 0; i < 100; i++)
                {
                    result = await dictionary.TryGet(i);

                    if (i % 4 == 0)
                    {
                        Assert.False(result.Found);
                    }
                    else
                    {
                        Assert.True(result.Found);
                        Assert.Equal((result.Key + 2).ToString(), result.Value);
                    }
                }

                var loopCount = 0;

                await foreach (var entry in dictionary.AsKeysIterator())
                {
                    loopCount++;
                    Assert.False(entry % 4 == 0);
                }

                result = await dictionary.TryGet(loops);

                Assert.False(result.Found);

                Assert.Equal(loopCount, count);
            }
        }