public virtual void TestCacheFunctionality() { RpcCallCache cache = new RpcCallCache("Test", 10); // Add 20 entries to the cache and only last 10 should be retained int size = 0; for (int clientId = 0; clientId < 20; clientId++) { IPAddress clientIp = Extensions.GetAddressByName("1.1.1." + clientId); System.Console.Out.WriteLine("Adding " + clientIp); cache.CheckOrAddToCache(clientIp, 0); size = Math.Min(++size, 10); System.Console.Out.WriteLine("Cache size " + cache.Size()); Assert.Equal(size, cache.Size()); // Ensure the cache size is correct // Ensure the cache entries are correct int startEntry = Math.Max(clientId - 10 + 1, 0); IEnumerator <KeyValuePair <RpcCallCache.ClientRequest, RpcCallCache.CacheEntry> > iterator = cache.Iterator(); for (int i = 0; i < size; i++) { RpcCallCache.ClientRequest key = iterator.Next().Key; System.Console.Out.WriteLine("Entry " + key.GetClientId()); Assert.Equal(Extensions.GetAddressByName("1.1.1." + (startEntry + i)), key.GetClientId()); } // Ensure cache entries are returned as in progress. for (int i_1 = 0; i_1 < size; i_1++) { RpcCallCache.CacheEntry e = cache.CheckOrAddToCache(Extensions.GetAddressByName ("1.1.1." + (startEntry + i_1)), 0); NUnit.Framework.Assert.IsNotNull(e); Assert.True(e.IsInProgress()); NUnit.Framework.Assert.IsFalse(e.IsCompleted()); } } }