public override void Run(EPServiceProvider epService)
        {
            string[] engineFields = "engineURI,timestamp,inputCount,inputCountDelta,scheduleDepth".Split(',');
            SendTimer(epService, 1000);

            string      text     = "select * from " + typeof(EngineMetric).FullName;
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(text);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean());

            SendTimer(epService, 10999);
            Assert.IsFalse(listener.IsInvoked);

            epService.EPAdministrator.CreateEPL("select * from pattern[timer:interval(5 sec)]");

            SendTimer(epService, 11000);
            EventBean theEvent = listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertProps(theEvent, engineFields, new object[] { "default", 11000L, 1L, 1L, 1L });

            epService.EPRuntime.SendEvent(new SupportBean());
            epService.EPRuntime.SendEvent(new SupportBean());

            SendTimer(epService, 20000);
            SendTimer(epService, 21000);
            theEvent = listener.AssertOneGetNewAndReset();
            EPAssertionUtil.AssertProps(theEvent, engineFields, new object[] { "default", 21000L, 4L, 3L, 0L });

#if false
            // Try MBean
            ThreadMXBean mbean = ManagementFactory.ThreadMXBean;
            if (!mbean.IsThreadCpuTimeEnabled)
            {
                Assert.Fail("ThreadMXBean CPU time reporting is not enabled");
            }

            long msecMultiplier = 1000 * 1000;
            long msecGoal       = 10;
            long cpuGoal        = msecGoal * msecMultiplier;

            long beforeCPU = mbean.CurrentThreadCpuTime;
            MyMetricFunctions.TakeCPUTime(cpuGoal);
            long afterCPU = mbean.CurrentThreadCpuTime;
            Assert.IsTrue((afterCPU - beforeCPU) > cpuGoal);
#endif
        }
示例#2
0
        public void TestTakeCPUTime()
        {
            ThreadMXBean mbean = ManagementFactory.ThreadMXBean;

            if (!mbean.IsThreadCpuTimeEnabled)
            {
                Fail("ThreadMXBean CPU time reporting is not enabled");
            }

            long msecMultiplier = 1000 * 1000;
            long msecGoal       = 10;
            long cpuGoal        = msecGoal * msecMultiplier;

            long beforeCPU = mbean.CurrentThreadCpuTime;

            MyMetricFunctions.TakeCPUTime(cpuGoal);
            long afterCPU = mbean.CurrentThreadCpuTime;

            Assert.IsTrue((afterCPU - beforeCPU) > cpuGoal);
        }