Example #1
0
 private void ValidateCompletedCacheEntry(RpcCallCache.CacheEntry c, RpcResponse response
                                          )
 {
     NUnit.Framework.Assert.IsFalse(c.IsInProgress());
     Assert.True(c.IsCompleted());
     Assert.Equal(response, c.GetResponse());
 }
Example #2
0
        public virtual void TestCacheEntry()
        {
            RpcCallCache.CacheEntry c = new RpcCallCache.CacheEntry();
            ValidateInprogressCacheEntry(c);
            Assert.True(c.IsInProgress());
            NUnit.Framework.Assert.IsFalse(c.IsCompleted());
            NUnit.Framework.Assert.IsNull(c.GetResponse());
            RpcResponse response = Org.Mockito.Mockito.Mock <RpcResponse>();

            c.SetResponse(response);
            ValidateCompletedCacheEntry(c, response);
        }
Example #3
0
        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());
                }
            }
        }
Example #4
0
 private void ValidateInprogressCacheEntry(RpcCallCache.CacheEntry c)
 {
     Assert.True(c.IsInProgress());
     NUnit.Framework.Assert.IsFalse(c.IsCompleted());
     NUnit.Framework.Assert.IsNull(c.GetResponse());
 }