public void MultipleTagInvalidationTest()
        {
            const int MAX_TAG = 10;
            const int MAX_TAG_LIST_LENGTH = 4;

            Random random = new Random();

            for (int iter = 0; iter < 2; iter++)
            {
                TaggedScavengedExpirableCacheStore cacheStore = new TaggedScavengedExpirableCacheStore(new CacheOptions());
                object data = new object();

                for (int i = 0; i < 100000; i++)
                {
                    cacheStore.Set(new CacheItem(Convert.ToString(i), data, 0, TagCacheTestUtil.GetRandomTagsExpirationSpecifier(cacheStore, random, random.Next(1, MAX_TAG_LIST_LENGTH), MAX_TAG)));
                }

                Thread.Sleep(1000);

                for (int j = 0; j < 1000; j++)
                {
                    List<string> tagListToInvalidate = TagCacheTestUtil.GetRandomTagList(random, random.Next(1, MAX_TAG_LIST_LENGTH), MAX_TAG);
                    cacheStore.Invalidate(new List<List<string>> { tagListToInvalidate });
                    _EnsureCacheItemsDontMatch(cacheStore, tagListToInvalidate);
                }
            }
        }
        public void SingleTagMultiThreadedBombardTest()
        {
            TaggedScavengedExpirableCacheStore cacheStore = new TaggedScavengedExpirableCacheStore(new CacheOptions());

            Parallel.For(0, 5, (i) => _CacheBombard(cacheStore, new Random(i)));

            // invalidate a few tags in order to ensure purge queue has some value
            Random random = new Random();
            for (int i = 0; i < TagCacheTestUtil.MAX_TAG / 3; i++)
            {
                cacheStore.Invalidate(new List<List<string>> { new List<string> { TagCacheTestUtil.GetRandomTag(random) } });
            }

            _ValidateCacheConsistency(cacheStore);
        }
        public void TestTagInfoGarbageCollection()
        {
            TaggedScavengedExpirableCacheStore cacheStore = new TaggedScavengedExpirableCacheStore(new CacheOptions());
            Random random = new Random();

            HashSet<string> usedTagSet = new HashSet<string>();

            for (int i = 0; i < 200000; i++)
            {
                string key = TagCacheTestUtil.GetRandomKey(random);
                List<string> tagList = TagCacheTestUtil.GetRandomTagList(random, random.Next(1, 1));

                cacheStore.Set(new CacheItem(key, null, 0, TagCacheTestUtil.GetTagExpirationSpecifier(cacheStore, tagList)));
                usedTagSet.UnionWith(tagList);
            }

            HashSet<string> invalidatedTagSet = new HashSet<string>();

            for (int i = 0; i < TagCacheTestUtil.MAX_TAG * 3 / 4; i++)
            {
                string tag = TagCacheTestUtil.GetRandomTag(random);
                cacheStore.Invalidate(new List<List<string>> { new List<string> { tag } });
                invalidatedTagSet.Add(tag);
            }

            usedTagSet.ExceptWith(invalidatedTagSet);

            List<string> validTagList = new List<string>(usedTagSet);
            _EnsureTags(cacheStore, validTagList);
        }
        public void TestMultipleTagInvalidation()
        {
            //10C4 + 10C3 + 10C2 + 10C1 = 385 combinations
            const int MAX_TAG = 10;
            const int MAX_TAG_LIST_LENGTH = 4;

            TaggedScavengedExpirableCacheStore cacheStore = new TaggedScavengedExpirableCacheStore(new CacheOptions());

            Random random = new Random();

            for (int i = 0; i < 500; i++)
            {
                for (int j = 0; j < 1000; j++)
                {
                    cacheStore.Set(new CacheItem(j.ToString(), null, 0, TagCacheTestUtil.GetRandomTagsExpirationSpecifier(cacheStore, random, random.Next(1, MAX_TAG_LIST_LENGTH), MAX_TAG)));
                }

                for (int j = 0; j < 5; j++)
                {
                    List<string> tagListToInvalidate = TagCacheTestUtil.GetRandomTagList(random, random.Next(1, MAX_TAG_LIST_LENGTH), MAX_TAG);
                    cacheStore.Invalidate(new List<List<string>> { tagListToInvalidate });
                    _EnsureCacheItemsDontMatch(cacheStore, tagListToInvalidate);
                }
            }
        }
        private void _CacheBombard(TaggedScavengedExpirableCacheStore cacheStore, Random random)
        {
            object data = new object();

            try
            {
                for (int i = 0; i < 100000; i++)
                {
                    double dice = random.NextDouble();

                    if (dice <= 0.3)
                    {
                        cacheStore.Set(new CacheItem(TagCacheTestUtil.GetRandomKey(random), data, 0, TagCacheTestUtil.GetTagExpirationSpecifier(cacheStore, TagCacheTestUtil.GetRandomTagList(random, random.Next(1, 4)))));
                    }
                    else if (dice <= 0.8)
                    {
                        cacheStore.Get(TagCacheTestUtil.GetRandomKey(random));
                    }
                    else if (dice <= 0.9)
                    {
                        cacheStore.Invalidate(new List<List<string>> { new List<string> { TagCacheTestUtil.GetRandomTag(random) } });
                    }
                    else
                    {
                        cacheStore.Remove(TagCacheTestUtil.GetRandomKey(random));
                    }
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }