Beispiel #1
0
        public void testDelete()
        {
            // create the ConditionalIndex to be tested
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new LessFilter(extractor, 15);
            var             mapIndex  = new ConditionalIndex(filter, extractor, true, null, true);

            // define the keys and values
            const string oKey       = "key";
            Object       oValue     = 1;
            Object       oExtracted = 1;
            ICacheEntry  entry      = new CacheEntry(oKey, oValue, oValue);

            // begin test

            // verify that the index does not contain a value for the tested keys
            Assert.AreEqual(ObjectUtils.NO_VALUE, mapIndex.Get(oKey));

            // insert into the index
            mapIndex.Insert(entry);

            object extractedValue = mapIndex.Get(oKey);

            Assert.AreEqual(oExtracted, extractedValue,
                            "The index should contain the extracted value for key.");

            mapIndex.Delete(entry);

            Assert.AreEqual(ObjectUtils.NO_VALUE, mapIndex.Get(oKey));
        }
Beispiel #2
0
        public void testDelete_forwardIndexFalse()
        {
            // create the ConditionalIndex to be tested
            IValueExtractor extractor = new IdentityExtractor();
            IFilter         filter    = new LessFilter(extractor, 15);
            var             mapIndex  = new ConditionalIndex(filter, extractor, true, null, false);

            // define the keys and values for the mock entries
            const string oKey       = "key";
            Object       oValue     = 1;
            Object       oExtracted = 1;
            ICacheEntry  entry      = new CacheEntry(oKey, oValue);
            ICacheEntry  delEntry   = new CacheEntry(oKey, oValue, oValue);

            // begin test

            // assert the the inverse map does not contain an entry for the extracted value
            Assert.IsFalse(mapIndex.IndexContents.Contains(oExtracted));

            // insert into the index
            mapIndex.Insert(entry);

            // assert the the inverse map does contain an entry for the extracted value
            Assert.IsTrue(mapIndex.IndexContents.Contains(oExtracted));

            mapIndex.Delete(delEntry);

            // get the inverse map
            var mapInverse = (SynchronizedDictionary)mapIndex.IndexContents;

            // get the set of keys from the inverse map keyed by the extracted
            // value for key
            var set = (HashSet)mapInverse[oExtracted];

            // verify that the set of keys does not contain key
            Assert.IsTrue(set == null || !set.Contains(oKey),
                          "The index's inverse map should not contain the key for the extracted value.");
        }