예제 #1
0
        public async Task Should_fill_up_a_bunch_of_buckets()
        {
            var addedObserver   = new NodeAddedCountObserver(100);
            var removedObserver = new NodeRemovedCountObserver <SimpleValue>(40);

            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60));

            var cache = new GreenCache <SimpleValue>(settings);

            IIndex <string, SimpleValue> index = cache.AddIndex("id", x => x.Id);

            cache.Connect(addedObserver);
            cache.Connect(removedObserver);

            for (var i = 0; i < 100; i++)
            {
                var simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);

                settings.CurrentTime += TimeSpan.FromSeconds(1);
            }

            await addedObserver.Completed;
            await removedObserver.Completed;

            Assert.That(cache.Statistics.Count, Is.EqualTo(60));

            Task <SimpleValue>[] values = cache.GetAll().ToArray();

            Assert.That(values.Length, Is.EqualTo(60));
        }
예제 #2
0
        public async Task Should_fill_up_the_buckets_over_time_and_remove_old_entries()
        {
            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(300));

            var cache = new GreenCache <SimpleValue>(settings);

            IIndex <string, SimpleValue> index = cache.AddIndex("id", x => x.Id);

            var observer = new NodeAddedCountObserver(200);

            cache.Connect(observer);

            var removed = new NodeRemovedCountObserver <SimpleValue>(100);

            cache.Connect(removed);

            for (var i = 0; i < 200; i++)
            {
                var simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);

                settings.CurrentTime += TimeSpan.FromSeconds(1);
            }

            await observer.Completed;
            await removed.Completed;

            Assert.That(cache.Statistics.Count, Is.EqualTo(100));
        }
예제 #3
0
        public async Task Should_fill_up_the_buckets()
        {
            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60));

            var cache = new GreenCache <SimpleValue>(settings);

            var index = cache.AddIndex("id", x => x.Id);

            var observer = new NodeAddedCountObserver(100);

            cache.Connect(observer);

            for (int i = 0; i < 100; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);
            }

            await observer.Completed;

            Assert.That(cache.Statistics.Count, Is.EqualTo(100));
        }
예제 #4
0
        public async Task Should_fill_them_even_fuller()
        {
            var settings = new TestCacheSettings(100, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(60));

            var cache = new GreenCache <SimpleValue>(settings);

            var index = cache.AddIndex("id", x => x.Id);


            var addedObserver = new NodeAddedCountObserver(200);

            cache.Connect(addedObserver);

            var removedObserver = new NodeRemovedCountObserver <SimpleValue>(99);

            cache.Connect(removedObserver);

            for (int i = 0; i < 200; i++)
            {
                SimpleValue simpleValue = await index.Get($"key{i}", SimpleValueFactory.Healthy);

                if (i % 2 == 0)
                {
                    settings.CurrentTime += TimeSpan.FromSeconds(1);
                }
            }

            await addedObserver.Completed;
            await removedObserver.Completed;

            Assert.That(cache.Statistics.Count, Is.EqualTo(101));

            var values = cache.GetAll().ToArray();

            Assert.That(values.Length, Is.EqualTo(101));
        }