Beispiel #1
0
        public void TestStatementMetrics()
        {
            Configuration config = GetConfig(-1, -1, true);

            // report on all statements every 10 seconds
            MetricsReportingConfig.StmtGroupMetrics configOne = new MetricsReportingConfig.StmtGroupMetrics();
            configOne.Interval = 10000;
            configOne.AddIncludeLike("%cpuStmt%");
            configOne.AddIncludeLike("%wallStmt%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("nonmetrics", configOne);

            // exclude metrics themselves from reporting
            MetricsReportingConfig.StmtGroupMetrics configTwo = new MetricsReportingConfig.StmtGroupMetrics();
            configTwo.Interval = -1;
            configOne.AddExcludeLike("%metrics%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("metrics", configTwo);

            _epService = EPServiceProviderManager.GetProvider("MyURI", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            SendTimer(1000);

            EPStatement[] statements = new EPStatement[5];
            statements[0]         = _epService.EPAdministrator.CreateEPL("select * from " + typeof(StatementMetric).FullName, "stmt_metrics");
            statements[0].Events += _listener.Update;

            statements[1]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=1)#keepall where MyMetricFunctions.TakeCpuTime(LongPrimitive)", "cpuStmtOne");
            statements[1].Events += _listenerTwo.Update;
            statements[2]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=2)#keepall where MyMetricFunctions.TakeCpuTime(LongPrimitive)", "cpuStmtTwo");
            statements[2].Events += _listenerTwo.Update;
            statements[3]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=3)#keepall where MyMetricFunctions.TakeWallTime(LongPrimitive)", "wallStmtThree");
            statements[3].Events += _listenerTwo.Update;
            statements[4]         = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=4)#keepall where MyMetricFunctions.TakeWallTime(LongPrimitive)", "wallStmtFour");
            statements[4].Events += _listenerTwo.Update;

            SendEvent("E1", 1, CpuGoalOneNano);
            SendEvent("E2", 2, CpuGoalTwoNano);
            SendEvent("E3", 3, WallGoalOneMsec);
            SendEvent("E4", 4, WallGoalTwoMsec);

            SendTimer(10999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(11000);
            RunAssertion(11000);

            SendEvent("E1", 1, CpuGoalOneNano);
            SendEvent("E2", 2, CpuGoalTwoNano);
            SendEvent("E3", 3, WallGoalOneMsec);
            SendEvent("E4", 4, WallGoalTwoMsec);

            SendTimer(21000);
            RunAssertion(21000);

            // destroy all application stmts
            for (int i = 1; i < 5; i++)
            {
                statements[i].Dispose();
            }
            SendTimer(31000);
            Assert.IsFalse(_listener.IsInvoked);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Beispiel #2
0
        public void TestStatementGroups()
        {
            Configuration config = GetConfig(-1, 7000, true);

            MetricsReportingConfig.StmtGroupMetrics groupOne = new MetricsReportingConfig.StmtGroupMetrics();
            groupOne.Interval = 8000;
            groupOne.AddIncludeLike("%GroupOne%");
            groupOne.IsReportInactive = true;
            config.EngineDefaults.MetricsReporting.AddStmtGroup("GroupOneStatements", groupOne);

            MetricsReportingConfig.StmtGroupMetrics groupTwo = new MetricsReportingConfig.StmtGroupMetrics();
            groupTwo.Interval         = 6000;
            groupTwo.IsDefaultInclude = true;
            groupTwo.AddExcludeLike("%Default%");
            groupTwo.AddExcludeLike("%Metrics%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("GroupTwoNonDefaultStatements", groupTwo);

            MetricsReportingConfig.StmtGroupMetrics groupThree = new MetricsReportingConfig.StmtGroupMetrics();
            groupThree.Interval = -1;
            groupThree.AddIncludeLike("%Metrics%");
            config.EngineDefaults.MetricsReporting.AddStmtGroup("MetricsStatements", groupThree);

            _epService = EPServiceProviderManager.GetProvider("MyURI", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            SendTimer(0);

            _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive = 1)#keepall", "GroupOne");
            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive = 2)#keepall", "GroupTwo");

            stmt.Subscriber = new SupportSubscriber();
            _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive = 3)#keepall", "Default");   // no listener

            stmt         = _epService.EPAdministrator.CreateEPL("select * from " + typeof(StatementMetric).FullName, "StmtMetrics");
            stmt.Events += _listener.Update;

            SendTimer(6000);
            SendTimer(7000);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(8000);
            String[] fields = "StatementName,OutputIStreamCount,NumInput".Split(',');
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupOne", 0L, 0L });

            SendTimer(12000);
            SendTimer(14000);
            SendTimer(15999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(16000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupOne", 0L, 0L });

            // should report as groupTwo
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            SendTimer(17999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(18000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupTwo", 1L, 1L });

            // should report as groupTwo
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            SendTimer(20999);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(21000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "Default", 0L, 1L });

            // turn off group 1
            _epService.EPAdministrator.Configuration.SetMetricsReportingInterval("GroupOneStatements", -1);
            SendTimer(24000);
            Assert.IsFalse(_listener.IsInvoked);

            // turn on group 1
            _epService.EPAdministrator.Configuration.SetMetricsReportingInterval("GroupOneStatements", 1000);
            SendTimer(25000);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "GroupOne", 0L, 0L });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }