コード例 #1
0
        void statisticsTest()
        {
            /* Create Statistics in right and wrong manner */
            StatisticsFactory factory = StatisticsFactory.GetExistingInstance();

            /* Register a type */
            TestStatisticsType testType = new TestStatisticsType();

            createType(factory, testType);
            Util.Log("Statistics Type TestStats Registered");

            /* Create a statistics */
            Statistics testStat1 = factory.CreateStatistics(testType.testStatsType, "TestStatistics");

            Assert.IsNotNull(testStat1, "Test Statistics Creation Failed");

            /* Tests Find Type , Find Statistics */
            Statistics temp = factory.FindFirstStatisticsByType(testType.testStatsType);

            Assert.IsNotNull(temp, "findFirstStatisticsByType Failed");
            Util.Log("Statistics testStat1 Created Successfully.");

            /* Test Set Functions */
            testGetSetIncFunctions(testStat1, testType);
            Util.Log("Get / Set / Inc Functions Tested ");

            /* Close Statistics */
            testStat1.Close();
            Statistics temp2 = factory.FindFirstStatisticsByType(testType.testStatsType);

            Assert.IsNull(temp2, "Statistics close() Failed");

            Util.Log("StatisticsTest Completed");
        }
コード例 #2
0
        void createType(StatisticsFactory statFactory, TestStatisticsType testType)
        {
            StatisticDescriptor[] statDescriptorArr = new StatisticDescriptor[6];

            statDescriptorArr[0] = statFactory.CreateIntCounter("IntCounter",
                                                                "Test Statistic Descriptor int_t Counter.", "TestUnit");

            statDescriptorArr[1] = statFactory.CreateIntGauge("IntGauge",
                                                              "Test Statistic Descriptor int_t Gauge.", "TestUnit");

            statDescriptorArr[2] = statFactory.CreateLongCounter("LongCounter",
                                                                 "Test Statistic Descriptor Long Counter.", "TestUnit");

            statDescriptorArr[3] = statFactory.CreateLongGauge("LongGauge",
                                                               "Test Statistic Descriptor Long Gauge.", "TestUnit");

            statDescriptorArr[4] = statFactory.CreateDoubleCounter("DoubleCounter",
                                                                   "Test Statistic Descriptor Double Counter.", "TestUnit");

            statDescriptorArr[5] = statFactory.CreateDoubleGauge("DoubleGauge",
                                                                 "Test Statistic Descriptor Double Gauge.", "TestUnit");

            StatisticsType statsType = statFactory.CreateType("TestStatsType",
                                                              "Statistics for Unit Test.", statDescriptorArr, 6);

            Assert.IsNotNull(statsType, "Error in creating Stats Type");

            testType.testStatsType       = statsType;
            testType.statIdIntCounter    = statsType.NameToId("IntCounter");
            testType.statIdIntGauge      = statsType.NameToId("IntGauge");
            testType.statIdLongCounter   = statsType.NameToId("LongCounter");
            testType.statIdLongGauge     = statsType.NameToId("LongGauge");
            testType.statIdDoubleCounter = statsType.NameToId("DoubleCounter");
            testType.statIdDoubleGauge   = statsType.NameToId("DoubleGauge");

            StatisticsType statsType1 = statFactory.CreateType("TestStatsType1",
                                                               "Statistics for Unit Test", statDescriptorArr, 6);

            testType.testStatsType = statsType1;

            /* Test Find */
            Assert.IsNotNull(statFactory.FindType("TestStatsType"), "stat not found");
            Assert.IsNotNull(statFactory.FindType("TestStatsType1"), "stat not found");
            Assert.IsNull(statFactory.FindType("TestStatsType2"), "stat not to be found");
        }
コード例 #3
0
 public IncThread(Statistics stat, TestStatisticsType type)
 {
     this.m_stat = stat;
     this.m_type = type;
 }
コード例 #4
0
        void testGetSetIncFunctions(Statistics stat, TestStatisticsType type)
        {
            /* Set a initial value =  10 */
            stat.SetInt(type.statIdIntCounter, 10);
            stat.SetInt(type.statIdIntGauge, 10);
            stat.SetLong(type.statIdLongCounter, 10);
            stat.SetLong(type.statIdLongGauge, 10);
            stat.SetDouble(type.statIdDoubleCounter, 10.0);
            stat.SetDouble(type.statIdDoubleGauge, 10.0);
            Util.Log(" Setting Initial Value Complete");

            /* Check Initial Value = 10*/
            Assert.AreEqual(10, stat.GetInt(type.statIdIntCounter), " Check1 1 Failed ");
            Assert.AreEqual(10, stat.GetInt(type.statIdIntGauge), " Check1 2 Failed ");
            Assert.AreEqual(10, stat.GetLong(type.statIdLongCounter), " Check1 3 Failed ");
            Assert.AreEqual(10, stat.GetLong(type.statIdLongGauge), " Check1 4 Failed ");
            Assert.AreEqual(10.0, stat.GetDouble(type.statIdDoubleCounter), " Check1 5 Failed ");
            Assert.AreEqual(10.0, stat.GetDouble(type.statIdDoubleGauge), " Check1 6 Failed ");
            Util.Log(" All Set() were correct.");

            /* Increment single thread for 100 times */
            for (int incIdx = 0; incIdx < 100; incIdx++)
            {
                stat.IncInt(type.statIdIntCounter, 1);
                stat.IncInt(type.statIdIntGauge, 1);
                stat.IncLong(type.statIdLongCounter, 1);
                stat.IncLong(type.statIdLongGauge, 1);
                stat.IncDouble(type.statIdDoubleCounter, 1.0);
                stat.IncDouble(type.statIdDoubleGauge, 1.0);
                Thread.Sleep(10);
            }
            Util.Log(" Incremented 100 times by 1.");

            /* Check Incremented Value = 110 */
            Assert.AreEqual(110, stat.GetInt(type.statIdIntCounter), " Check2 1 Failed ");
            Assert.AreEqual(110, stat.GetInt(type.statIdIntGauge), " Check2 2 Failed ");
            Assert.AreEqual(110, stat.GetLong(type.statIdLongCounter), " Check2 3 Failed ");
            Assert.AreEqual(110, stat.GetLong(type.statIdLongGauge), " Check2 4 Failed ");
            Assert.AreEqual(110.0, stat.GetDouble(type.statIdDoubleCounter), " Check2 5 Failed ");
            Assert.AreEqual(110.0, stat.GetDouble(type.statIdDoubleGauge), " Check2 6 Failed ");
            Util.Log(" Single thread Inc() Passed.");

            IncThread[] myThreads = new IncThread[10];
            Thread[]    thread    = new Thread[10];

            for (int i = 0; i < 10; i++)
            {
                myThreads[i] = new IncThread(stat, type);
                thread[i]    = new Thread(new ThreadStart(myThreads[i].ThreadOperation));
                thread[i].Start();
            }
            Thread.Sleep(1000);
            for (int i = 0; i < 10; i++)
            {
                thread[i].Join();
            }

            /* Check Final Value = 10,110 */
            Assert.AreEqual(10110, stat.GetInt(type.statIdIntCounter), " Check2 1 Failed ");
            Assert.AreEqual(10110, stat.GetInt(type.statIdIntGauge), " Check2 2 Failed ");
            Assert.AreEqual(10110, stat.GetLong(type.statIdLongCounter), " Check2 3 Failed ");
            Assert.AreEqual(10110, stat.GetLong(type.statIdLongGauge), " Check2 4 Failed ");
            Assert.AreEqual(10110.0, stat.GetDouble(type.statIdDoubleCounter), " Check2 5 Failed ");
            Assert.AreEqual(10110.0, stat.GetDouble(type.statIdDoubleGauge), " Check2 6 Failed ");
            Util.Log(" Parallel Inc() Passed.");

            /* Check value of Gauge type */
            stat.SetInt(type.statIdIntGauge, 50);
            stat.SetDouble(type.statIdDoubleGauge, 50.0);
            stat.SetLong(type.statIdLongGauge, 50);

            Assert.AreEqual(50, stat.GetInt(type.statIdIntGauge), " Check3 1 Failed");
            Assert.AreEqual(50, stat.GetLong(type.statIdLongGauge), "Check3 2 Failed");
            Assert.AreEqual(50.0, stat.GetDouble(type.statIdDoubleGauge), "Check3 3 Failed");
        }