Пример #1
0
 /// <summary>Mark a request as completed and add corresponding response to the cache</summary>
 public virtual void CallCompleted(IPAddress clientId, int xid, RpcResponse response
                                   )
 {
     RpcCallCache.ClientRequest req = new RpcCallCache.ClientRequest(clientId, xid);
     RpcCallCache.CacheEntry    e;
     lock (map)
     {
         e = map[req];
     }
     e.response = response;
 }
Пример #2
0
 public override bool Equals(object obj)
 {
     if (this == obj)
     {
         return(true);
     }
     if (obj == null || !(obj is RpcCallCache.ClientRequest))
     {
         return(false);
     }
     RpcCallCache.ClientRequest other = (RpcCallCache.ClientRequest)obj;
     return(clientId.Equals(other.clientId) && (xid == other.xid));
 }
Пример #3
0
 /// <summary>Check the cache for an entry.</summary>
 /// <remarks>
 /// Check the cache for an entry. If it does not exist, add the request
 /// as in progress.
 /// </remarks>
 public virtual RpcCallCache.CacheEntry CheckOrAddToCache(IPAddress clientId, int
                                                          xid)
 {
     RpcCallCache.ClientRequest req = new RpcCallCache.ClientRequest(clientId, xid);
     RpcCallCache.CacheEntry    e;
     lock (map)
     {
         e = map[req];
         if (e == null)
         {
             // Add an inprogress cache entry
             map[req] = new RpcCallCache.CacheEntry();
         }
     }
     return(e);
 }
Пример #4
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());
                }
            }
        }