public void TestMoq()
        {
            Mock <AverageTimer32PerformanceCounter>         averageTimer32PerformanceCounterMock;
            Mock <NumberOfItems64PerformanceCounter>        numberofItems64PerformanceCounterMock;
            Mock <PercentageRatePerformanceCounter>         percentageRatePerformanceCounterMock;
            Mock <RatePerSecond32PerformanceCounter>        ratePerSecond32PerformanceCounterMock;
            Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock;
            const string counterName  = "counterName";
            const string instanceName = "instanceName";

            averageTimer32PerformanceCounterMock = new Mock <AverageTimer32PerformanceCounter>();
            averageTimer32PerformanceCounterMock.Setup(pc => pc.AddTiming(It.IsAny <Stopwatch>()));
            averageTimer32PerformanceCounterMock.Setup(pc => pc.Dispose());

            numberofItems64PerformanceCounterMock = new Mock <NumberOfItems64PerformanceCounter>();
            numberofItems64PerformanceCounterMock.Setup(pc => pc.Increment());
            numberofItems64PerformanceCounterMock.Setup(pc => pc.IncrementBy(It.IsAny <long>()));
            numberofItems64PerformanceCounterMock.Setup(pc => pc.Dispose());

            percentageRatePerformanceCounterMock = new Mock <PercentageRatePerformanceCounter>();
            percentageRatePerformanceCounterMock.Setup(pc => pc.AddHit());
            percentageRatePerformanceCounterMock.Setup(pc => pc.AddMiss());
            percentageRatePerformanceCounterMock.Setup(pc => pc.Dispose());

            ratePerSecond32PerformanceCounterMock = new Mock <RatePerSecond32PerformanceCounter>();
            ratePerSecond32PerformanceCounterMock.Setup(pc => pc.Increment());
            ratePerSecond32PerformanceCounterMock.Setup(pc => pc.Dispose());

            multiInstancePerformanceCounterCategoryMock = new Mock <IMultiInstancePerformanceCounterCategory>();
            multiInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <AverageTimer32PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => averageTimer32PerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => numberofItems64PerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <PercentageRatePerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => percentageRatePerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(() => ratePerSecond32PerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(pcc => pcc.Dispose());

            using (IMultiInstancePerformanceCounterCategory multiInstancePerformanceCounterCategory =
                       multiInstancePerformanceCounterCategoryMock.Object)
            {
                multiInstancePerformanceCounterCategory.GetPerformanceCounter <AverageTimer32PerformanceCounter>(
                    counterName, instanceName).AddTiming(new Stopwatch());
                multiInstancePerformanceCounterCategory.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(
                    counterName, instanceName).Increment();
                multiInstancePerformanceCounterCategory.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(
                    counterName, instanceName).IncrementBy(0);
                multiInstancePerformanceCounterCategory.GetPerformanceCounter <PercentageRatePerformanceCounter>(
                    counterName, instanceName).AddHit();
                multiInstancePerformanceCounterCategory.GetPerformanceCounter <PercentageRatePerformanceCounter>(
                    counterName, instanceName).AddMiss();
                multiInstancePerformanceCounterCategory.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(
                    counterName, instanceName).Increment();
            }
        }
 /// <summary>
 /// Create a new <see cref="AsynchronousLoggingCacheMetricReporter"/> using the given <see cref="IMultiInstancePerformanceCounterCategory"/>.
 /// </summary>
 /// <param name="category">
 /// The performance counter category. This cannot be null.
 /// </param>
 /// <param name="startThread">
 /// True if the background thread should be started, false if not. This option is only used for testing.
 /// </param>
 /// <param name="logHitRates">
 /// True if hit rates should be logged, false otherwise.
 /// </param>
 public AsynchronousLoggingCacheMetricReporter(IMultiInstancePerformanceCounterCategory category, bool startThread = true, bool logHitRates = false)
     : base(category)
 {
     Stopping         = false;
     ThreadSyncObject = new object();
     BackgroundThread = new Thread(ThreadStart);
     LogHitRates      = logHitRates;
     if (startThread)
     {
         BackgroundThread.IsBackground = true;
         BackgroundThread.Start(this);
     }
 }
        /// <summary>
        /// Create a new <see cref="PerformanceCounterLoggingCacheMetricReporter"/> using the given category.
        /// </summary>
        /// <param name="category">
        /// The performance counter category. This cannot be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="category"/> cannot be null.
        /// </exception>
        public PerformanceCounterLoggingCacheMetricReporter(IMultiInstancePerformanceCounterCategory category)
        {
            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            Category               = category;
            SizeCounters           = new ConcurrentDictionary <string, NumberOfItems64PerformanceCounter>();
            HitRateCounters        = new ConcurrentDictionary <string, PercentageRatePerformanceCounter>();
            TotalHitsCounters      = new ConcurrentDictionary <string, NumberOfItems64PerformanceCounter>();
            TotalMissesCounters    = new ConcurrentDictionary <string, NumberOfItems64PerformanceCounter>();
            SizeCallbacks          = new ConcurrentDictionary <string, Func <long> >();
            HitsAndMissesCallbacks = new ConcurrentDictionary <string, Func <HitsAndMisses> >();
        }
Beispiel #4
0
        /// <summary>
        /// Create a new <see cref="EntityAccessControlCacheInvalidator"/>.
        /// </summary>
        /// <param name="platformTrace">
        /// The <see cref="PlatformTrace"/> to use for ETW tracing. This cannot be null.
        /// </param>
        /// <param name="accessControlCacheInvalidationCounters">
        /// Performance counters for the cache. This cannot be null.
        /// </param>
        /// <param name="caches">
        /// Access control caches to invalidate at the appropriate time. None can be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        internal EntityAccessControlCacheInvalidator(PlatformTrace platformTrace,
                                                     IMultiInstancePerformanceCounterCategory accessControlCacheInvalidationCounters,
                                                     params ICacheService[] caches)
        {
            if (platformTrace == null)
            {
                throw new ArgumentNullException("platformTrace");
            }
            if (accessControlCacheInvalidationCounters == null)
            {
                throw new ArgumentNullException("accessControlCacheInvalidationCounters");
            }
            if (caches == null || caches.Any(c => c == null))
            {
                throw new ArgumentNullException("caches");
            }

            Trace = platformTrace;
            AccessControlCacheInvalidationCounters = accessControlCacheInvalidationCounters;
            Caches = new List <ICacheService>(caches).AsReadOnly();
        }
        /// <summary>
        /// Create a new <see cref="CounterEntityAccessControlChecker"/>.
        /// </summary>
        /// <param name="checker">
        /// The <see cref="IEntityAccessControlChecker"/> to actually perform the check. This cannot be null.
        /// </param>
        /// <param name="accessControlCounters">
        /// The <see cref="ISingleInstancePerformanceCounterCategory"/> used to update/set access control performance counters.
        /// </param>
        /// <param name="accessControlPermissionCounters">
        /// The <see cref="IMultiInstancePerformanceCounterCategory"/> used to update/set access control permission performance counters.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        internal CounterEntityAccessControlChecker(
            IEntityAccessControlChecker checker,
            ISingleInstancePerformanceCounterCategory accessControlCounters,
            IMultiInstancePerformanceCounterCategory accessControlPermissionCounters)
        {
            if (checker == null)
            {
                throw new ArgumentNullException("checker");
            }
            if (accessControlCounters == null)
            {
                throw new ArgumentNullException("accessControlCounters");
            }
            if (accessControlPermissionCounters == null)
            {
                throw new ArgumentNullException("accessControlPermissionCounters");
            }

            Checker = checker;
            AccessControlCounters           = accessControlCounters;
            AccessControlPermissionCounters = accessControlPermissionCounters;
        }
Beispiel #6
0
 /// <summary>
 /// Create a new <see cref="SynchronousLoggingCacheMetricReporter"/> using the given category.
 /// </summary>
 /// <param name="category"></param>
 public SynchronousLoggingCacheMetricReporter(IMultiInstancePerformanceCounterCategory category)
     : base(category)
 {
     // Do nothing
 }