Пример #1
0
        public void Statistics_GetsValue_Correctly()
        {
            var statistics = new CacheStatistics();

            Assert.AreEqual(0, statistics.Cleanings.Value);
            Assert.AreEqual(0, statistics.Evictions.Value);
            Assert.AreEqual(0, statistics.Hits.Value);
            Assert.AreEqual(0, statistics.Misses.Value);
            Assert.AreEqual(0, statistics.Requests.Value);
            Assert.AreEqual(0, statistics.Updates.Value);

            Assert.AreEqual(1, statistics.Cleanings.Increment());
            Assert.AreEqual(1, statistics.Evictions.Increment());
            Assert.AreEqual(1, statistics.Hits.Increment());
            Assert.AreEqual(1, statistics.Misses.Increment());
            Assert.AreEqual(1, statistics.Requests.Increment());
            Assert.AreEqual(1, statistics.Updates.Increment());

            Assert.AreEqual(1, statistics.Cleanings.Value);
            Assert.AreEqual(1, statistics.Evictions.Value);
            Assert.AreEqual(1, statistics.Hits.Value);
            Assert.AreEqual(1, statistics.Misses.Value);
            Assert.AreEqual(1, statistics.Requests.Value);
            Assert.AreEqual(1, statistics.Updates.Value);
        }
Пример #2
0
        public void Statistics_GetRates_Correctly()
        {
            var statistics = new CacheStatistics();

            // when we haven't had any requests yet we always get 1.0
            Assert.AreEqual(1.0, statistics.MissRate());
            Assert.AreEqual(1.0, statistics.HitRate());

            for (int i = 0; i < 10; ++i)
            {
                statistics.Hits.Increment();
                statistics.Requests.Increment();
            }
            Assert.AreEqual(0.0, statistics.MissRate());
            Assert.AreEqual(1.0, statistics.HitRate());

            for (int i = 0; i < 10; ++i)
            {
                statistics.Misses.Increment();
                statistics.Requests.Increment();
            }

            Assert.AreEqual(0.5, statistics.MissRate());
            Assert.AreEqual(0.5, statistics.HitRate());
        }
Пример #3
0
        static private void PrintDetailedCacheInfo(Cache cache, string partId, bool printConf, bool xmlSyntax)
        {
            CacheStatistics s          = cache.Statistics;
            long            MaxSize    = 0;
            string          schemeName = s.ClassName.ToLower(CultureInfo.CurrentCulture);
            bool            running    = cache.IsRunning;

            Console.WriteLine("Cache-ID:       {0}", cache.Name);

            if (partId != null && partId != string.Empty)
            {
                Console.WriteLine("Partition-ID:   {0}", partId);
            }

            Console.WriteLine("Scheme:         {0}", schemeName);
            Console.WriteLine("Status:         {0}", cache.IsRunning ? "Running":"Stopped");
            if (running)
            {
                if (s is ClusterCacheStatistics)
                {
                    System.Text.StringBuilder nodes = new System.Text.StringBuilder();

                    ClusterCacheStatistics cs = s as ClusterCacheStatistics;

                    Console.WriteLine("Cluster size:   {0}", cs.Nodes.Count);

                    MaxSize = (cs.LocalNode.Statistics.MaxSize / 1024) / 1024;


                    foreach (NodeInfo n in cs.Nodes)
                    {
                        nodes.Append("                ").Append(n.Address).Append("\n");
                    }
                    Console.Write("{0}", nodes.ToString());

                    if (partId != null && partId != string.Empty)
                    {
                        if (cs.SubgroupNodes != null && cs.SubgroupNodes.Contains(partId.ToLower()))
                        {
                            nodes = new System.Text.StringBuilder();
                            ArrayList groupNodes = cs.SubgroupNodes[partId.ToLower()] as ArrayList;
                            Console.WriteLine("Partition size: {0}", groupNodes.Count);

                            foreach (Address address in groupNodes)
                            {
                                nodes.Append("                ").Append(address).Append("\n");
                            }
                        }
                        Console.Write("{0}", nodes.ToString());
                    }
                }
                Console.WriteLine("UpTime:         {0}", s.UpTime);

                if (s.MaxSize != 0)
                {
                    Console.WriteLine("Capacity:       {0} MB", ((s.MaxSize / 1024) / 1024));
                }
                else
                {
                    Console.WriteLine("Capacity:       {0} MB", MaxSize);
                }

                Console.WriteLine("Count:          {0}", s.Count);
            }
            if (printConf)
            {
                try
                {
                    if (xmlSyntax)
                    {
                        PropsConfigReader pr = new PropsConfigReader(cache.ConfigString);
                        Console.WriteLine("Configuration:\n{0}", ConfigReader.ToPropertiesXml(pr.Properties, true));
                    }
                    else
                    {
                        Console.WriteLine("Configuration:\n{0}", cache.ConfigString);
                    }
                }
                catch (ConfigurationException) {}
            }
            Console.WriteLine("");
        }
Пример #4
0
 public MemoryCacheResultsCache(IMemoryCache cache)
 {
     _cache     = cache ?? throw new ArgumentNullException(nameof(cache));
     _ownsCache = false;
     _stats     = default;
 }
Пример #5
0
 public MemoryCacheResultsCache()
 {
     _cache     = new MemoryCache(new MemoryCacheOptions());
     _ownsCache = true;
     _stats     = default;
 }
Пример #6
0
        protected void AssertNoAccessTime(CacheStatistics statistics, string statisticName)
        {
            var actual = statistics.SafeGetValue <DateTimeOffset?>(statisticName);

            Assert.That(actual, Is.Null);
        }
Пример #7
0
        protected void AssertAccessTime(CacheStatistics statistics, string statisticName, DateTimeOffset expected)
        {
            var actual = statistics.SafeGetValue <DateTimeOffset?>(statisticName);

            AssertAccessTime(actual, expected);
        }
Пример #8
0
 public void Statistics_Initializes_Correctly()
 {
     var statistics = new CacheStatistics();
     Assert.IsNotNull(statistics);
 }
Пример #9
0
 public FileEntry(long pos, long len, CacheStatistics stats)
 {
     Segment = new FileSegment(pos, len);
     Stats   = stats;
 }
Пример #10
0
        private void PrintDetailedCacheInfo(CacheStatistics s, string topology, string partId, bool isRunning, string cacheName, string configString, string pid)
        {
            long   MaxSize    = 0;
            string schemeName = topology;
            bool   running    = isRunning;

            OutputProvider.WriteLine("Cache-Name:\t\t{0}", cacheName);
            OutputProvider.WriteLine("Scheme:\t\t\t{0}    ", schemeName);
            OutputProvider.WriteLine("Status:\t\t\t{0}", isRunning ? "Running" : "Stopped");
            if (running)
            {
                OutputProvider.WriteLine("Process-ID:\t\t{0}", pid);
                if (s is ClusterCacheStatistics)
                {
                    System.Text.StringBuilder nodes = new System.Text.StringBuilder();

                    ClusterCacheStatistics cs = s as ClusterCacheStatistics;

                    OutputProvider.WriteLine("Cluster-size:           " + cs.Nodes.Count);

                    if (cs.LocalNode != null)
                    {
                        MaxSize = (cs.LocalNode.Statistics.MaxSize / 1024) / 1024;
                    }

                    foreach (NodeInfo n in cs.Nodes)
                    {
                        if (schemeName.Equals(Common.Enum.CacheTopology.Mirror.ToString()) && n.IsActive)
                        {
                            nodes.Append("                        ").Append(n.Address).Append(" (Active)\n");
                        }
                        else
                        {
                            nodes.Append("                        ").Append(n.Address).Append("\n");
                        }
                    }
                    OutputProvider.WriteLine("{0}", nodes.ToString());

                    if (partId != null && partId != string.Empty)
                    {
                        if (cs.SubgroupNodes != null && cs.SubgroupNodes.Contains(partId.ToLower()))
                        {
                            nodes = new System.Text.StringBuilder();
                            ArrayList groupNodes = cs.SubgroupNodes[partId.ToLower()] as ArrayList;
                            OutputProvider.WriteLine("Partition-size: " + groupNodes.Count);
                            foreach (Address address in groupNodes)
                            {
                                nodes.Append("                ").Append(address).Append("\n");
                            }
                        }
                        OutputProvider.WriteLine("{0}", nodes.ToString());
                    }
                }
                OutputProvider.WriteLine("UpTime:                 " + s.UpTime);

                if (s.MaxSize != 0)
                {
                    OutputProvider.WriteLine("Capacity:               " + ((s.MaxSize / 1024) / 1024) + " MB");
                }
                else
                {
                    OutputProvider.WriteLine("Capacity:               " + MaxSize + "MB");
                }

                OutputProvider.WriteLine("Count:                  " + s.Count);
            }

            OutputProvider.WriteLine("");
        }