Esempio n. 1
0
 public virtual void TestHotItemsAreEvictedLast()
 {
     CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
     if (puppet.cache.GetType().FullName.IndexOf("LRU2QXCache") > 0)
     {
         // LRU2QXCache doesn't meet all the expectations
         return;
     }
     puppet.FillCache();
     puppet.FillCache(0, 2);
     // 0 and 1 are hot now
     puppet.CacheMiss(11);
     // 2 should have been evicted to make room for 11
     puppet.CacheMiss(2);
     puppet.CacheHit(11);
     // 11 is as hot as 0 and 1 now
     puppet.CacheMiss(12);
     puppet.CacheHit(0);
     puppet.CacheHit(1);
     puppet.CacheHit(2);
     puppet.CacheMiss(3);
     puppet.CacheMiss(4);
     puppet.CacheMiss(5);
     puppet.CacheMiss(13);
     puppet.CacheMiss(14);
     puppet.CacheMisses(new int[] { 6, 7, 8, 9 });
     puppet.DumpCache();
     puppet.CacheHits(new int[] { 6, 7, 8, 9, 13, 14 });
     puppet.CacheMiss(15);
     puppet.CacheMiss(11);
     puppet.CacheMiss(0);
     puppet.DumpCache();
 }
Esempio n. 2
0
 public virtual void TestProducerIsNotCalledOnCacheHit()
 {
     CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
     puppet.FillCache();
     puppet.Verify(ApplyCalls(10));
     puppet.FillCache();
     puppet.Verify(ApplyCalls(10));
     Assert.AreEqual("10", puppet.Produce(10));
     puppet.Verify(ApplyCalls(11));
     puppet.Reset();
     Assert.AreEqual("0", puppet.Produce(0));
     puppet.Verify(ApplyCalls(1));
     puppet.FillCache(2, 10);
     puppet.Verify(ApplyCalls(1));
 }
Esempio n. 3
0
		public virtual void TestOnDiscard()
		{
			CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
			puppet.FillCache();
			ByRef discarded = new ByRef();
			puppet.Produce(42, new _IProcedure4_19(discarded));
			Assert.AreEqual("0", ((string)discarded.value));
		}
Esempio n. 4
0
        public virtual void TestOnDiscard()
        {
            CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
            puppet.FillCache();
            ByRef discarded = new ByRef();

            puppet.Produce(42, new _IProcedure4_19(discarded));
            Assert.AreEqual("0", ((string)discarded.value));
        }
Esempio n. 5
0
 public virtual void TestIterable()
 {
     CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
     Iterator4Assert.SameContent(new object[] {  }, puppet.Values());
     puppet.Produce(0);
     Iterator4Assert.SameContent(new object[] { "0" }, puppet.Values());
     puppet.FillCache();
     Iterator4Assert.SameContent(new object[] { "0", "1", "2", "3", "4", "5", "6", "7"
                                                , "8", "9" }, puppet.Values());
 }
Esempio n. 6
0
		public virtual void TestIterable()
		{
			CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
			Iterator4Assert.SameContent(new object[] {  }, puppet.Values());
			puppet.Produce(0);
			Iterator4Assert.SameContent(new object[] { "0" }, puppet.Values());
			puppet.FillCache();
			Iterator4Assert.SameContent(new object[] { "0", "1", "2", "3", "4", "5", "6", "7"
				, "8", "9" }, puppet.Values());
		}
Esempio n. 7
0
		public virtual void TestHotItemsAreEvictedLast()
		{
			CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
			if (puppet.cache.GetType().FullName.IndexOf("LRU2QXCache") > 0)
			{
				// LRU2QXCache doesn't meet all the expectations
				return;
			}
			puppet.FillCache();
			puppet.FillCache(0, 2);
			// 0 and 1 are hot now
			puppet.CacheMiss(11);
			// 2 should have been evicted to make room for 11
			puppet.CacheMiss(2);
			puppet.CacheHit(11);
			// 11 is as hot as 0 and 1 now
			puppet.CacheMiss(12);
			puppet.CacheHit(0);
			puppet.CacheHit(1);
			puppet.CacheHit(2);
			puppet.CacheMiss(3);
			puppet.CacheMiss(4);
			puppet.CacheMiss(5);
			puppet.CacheMiss(13);
			puppet.CacheMiss(14);
			puppet.CacheMisses(new int[] { 6, 7, 8, 9 });
			puppet.DumpCache();
			puppet.CacheHits(new int[] { 6, 7, 8, 9, 13, 14 });
			puppet.CacheMiss(15);
			puppet.CacheMiss(11);
			puppet.CacheMiss(0);
			puppet.DumpCache();
		}
Esempio n. 8
0
		public virtual void TestProducerIsNotCalledOnCacheHit()
		{
			CacheTestUnit.TestPuppet puppet = new CacheTestUnit.TestPuppet();
			puppet.FillCache();
			puppet.Verify(ApplyCalls(10));
			puppet.FillCache();
			puppet.Verify(ApplyCalls(10));
			Assert.AreEqual("10", puppet.Produce(10));
			puppet.Verify(ApplyCalls(11));
			puppet.Reset();
			Assert.AreEqual("0", puppet.Produce(0));
			puppet.Verify(ApplyCalls(1));
			puppet.FillCache(2, 10);
			puppet.Verify(ApplyCalls(1));
		}