Exemplo n.º 1
0
 /// <summary>
 /// A server method implemented using
 /// <see cref="RetryCache"/>
 /// .
 /// </summary>
 /// <param name="input">
 /// is returned back in echo, if
 /// <paramref name="success"/>
 /// is true.
 /// </param>
 /// <param name="failureOuput">
 /// returned on failure, if
 /// <paramref name="success"/>
 /// is false.
 /// </param>
 /// <param name="methodTime">
 /// time taken by the operation. By passing smaller/larger
 /// value one can simulate an operation that takes short/long time.
 /// </param>
 /// <param name="success">whether this operation completes successfully or not</param>
 /// <returns>
 /// return the input parameter
 /// <paramref name="input"/>
 /// , if
 /// <paramref name="success"/>
 /// is
 /// true, else return
 /// <paramref name="failureOutput"/>
 /// .
 /// </returns>
 /// <exception cref="System.Exception"/>
 internal virtual int Echo(int input, int failureOutput, long methodTime, bool success
                           )
 {
     RetryCache.CacheEntryWithPayload entry = RetryCache.WaitForCompletion(retryCache,
                                                                           null);
     if (entry != null && entry.IsSuccess())
     {
         System.Console.Out.WriteLine("retryCount incremented " + retryCount.Get());
         retryCount.IncrementAndGet();
         return((int)entry.GetPayload());
     }
     try
     {
         operationCount.IncrementAndGet();
         if (methodTime > 0)
         {
             Thread.Sleep(methodTime);
         }
     }
     finally
     {
         RetryCache.SetState(entry, success, input);
     }
     return(success ? input : failureOutput);
 }
Exemplo n.º 2
0
 public static void Clear(RetryCache cache)
 {
     if (cache != null)
     {
         cache.set.Clear();
         cache.IncrCacheClearedCounter();
     }
 }
Exemplo n.º 3
0
 /// <summary>Static method that provides null check for retryCache</summary>
 public static RetryCache.CacheEntry WaitForCompletion(RetryCache cache)
 {
     if (SkipRetryCache())
     {
         return(null);
     }
     return(cache != null?cache.WaitForCompletion(NewEntry(cache.expirationTime)) :
                null);
 }
Exemplo n.º 4
0
 /// <summary>Static method that provides null check for retryCache</summary>
 public static RetryCache.CacheEntryWithPayload WaitForCompletion(RetryCache cache
                                                                  , object payload)
 {
     if (SkipRetryCache())
     {
         return(null);
     }
     return((RetryCache.CacheEntryWithPayload)(cache != null ? cache.WaitForCompletion
                                                   (NewEntry(payload, cache.expirationTime)) : null));
 }
Exemplo n.º 5
0
        public virtual void TestNames()
        {
            RetryCache cache = Org.Mockito.Mockito.Mock <RetryCache>();

            Org.Mockito.Mockito.When(cache.GetCacheName()).ThenReturn(cacheName);
            RetryCacheMetrics metrics = RetryCacheMetrics.Create(cache);

            metrics.IncrCacheHit();
            metrics.IncrCacheCleared();
            metrics.IncrCacheCleared();
            metrics.IncrCacheUpdated();
            metrics.IncrCacheUpdated();
            metrics.IncrCacheUpdated();
            CheckMetrics(1, 2, 3);
        }