public void TestReluctantZeroToOne()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportRecogBean>("MyEvent");
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            String[] fields = "a_string,b_string".Split(',');
            String   text   = "select * from MyEvent#keepall " +
                              "match_recognize (" +
                              "  measures A.TheString as a_string, B.TheString as b_string " +
                              "  pattern (A?? B?) " +
                              "  define " +
                              "   A as A.Value = 1," +
                              "   B as B.Value = 1" +
                              ")";

            EPStatement stmt     = epService.EPAdministrator.CreateEPL(text);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 1));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new[] { new Object[] { null, "E1" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new[] { new Object[] { null, "E1" } });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#2
0
        public void TestLargeBatch()
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }

            _epService.EPAdministrator.DeploymentAdmin.ParseDeploy(
                "create schema IncomingEvent(id int);\n" +
                "create schema RetainedEvent(id int);\n" +
                "insert into RetainedEvent select * from IncomingEvent.win:expr_batch(current_count >= 10000);\n" +
                "create window RetainedEventWindow.win:keepall() as RetainedEvent;\n" +
                "insert into RetainedEventWindow select * from RetainedEvent;\n");

            var @event = new Dictionary <string, object>();

            @event.Put("id", 1);
            for (int i = 0; i < 10000; i++)
            {
                _epService.EPRuntime.SendEvent(@event, "IncomingEvent");
            }
        }
示例#3
0
        public void TestFollowedOrPermFalse()
        {
            // ESPER-451
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportBean>();
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));

            const string pattern = "every s=SupportBean(TheString='E') -> " +
                                   "(timer:interval(10) and not SupportBean(TheString='C1'))" +
                                   "or" +
                                   "(SupportBean(TheString='C2') and not timer:interval(10))";
            EPStatement statement = epService.EPAdministrator.CreatePattern(pattern);
            var         listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000));
            epService.EPRuntime.SendEvent(new SupportBean("E", 0));

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(10999));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(11000));
            Assert.IsTrue(listener.IsInvoked);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#4
0
        public void TestTypeMapped()
        {
            ConfigurationDBRef dbconfig = GetDBConfig();

            dbconfig.ColumnChangeCase = ConfigurationDBRef.ColumnChangeCaseEnum.LOWERCASE;
            dbconfig.AddSqlTypesBinding(java.sql.Types.INTEGER, "string");
            Configuration configuration = GetConfig(dbconfig);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            const string sql = "select myint from mytesttable where ${IntPrimitive} = myint'" +
                               "metadatasql 'select myint from mytesttable'";
            string stmtText = "select myint from " +
                              " sql:MyDB ['" + sql + "] as s0," +
                              typeof(SupportBean).FullName + "#length(100) as s1";

            EPStatement statement = _epService.EPAdministrator.CreateEPL(stmtText);

            _listener         = new SupportUpdateListener();
            statement.Events += _listener.Update;

            Assert.AreEqual(typeof(string), statement.EventType.GetPropertyType("myint"));

            SendSupportBeanEvent(10);
            Assert.AreEqual("10", _listener.AssertOneGetNewAndReset().Get("myint"));

            SendSupportBeanEvent(80);
            Assert.AreEqual("80", _listener.AssertOneGetNewAndReset().Get("myint"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#5
0
        public void TestCaseSensitive()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.CASE_SENSITIVE;

            epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }

            EPStatement           stmt     = epService.EPAdministrator.CreateEPL("select MYPROPERTY, myproperty, myProperty from " + typeof(SupportBeanDupProperty).FullName);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.AddListener(listener);

            var uevent = new SupportBeanDupProperty("lowercamel", "uppercamel", "upper", "lower");

            epService.EPRuntime.SendEvent(uevent);
            EventBean result = listener.AssertOneGetNewAndReset();

            Assert.AreEqual(uevent.MYPROPERTY, result.Get("MYPROPERTY"));
            Assert.AreEqual(uevent.myproperty, result.Get("myproperty"));
            Assert.AreEqual(uevent.myProperty, result.Get("myProperty"));

            try {
                epService.EPAdministrator.CreateEPL("select MyProPerty from " + typeof(SupportBeanDupProperty).FullName);
                Assert.Fail();
            } catch (EPException ex) {
                // expected
            }
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestHasMetaSQLStringParam()
        {
            ConfigurationDBRef dbconfig = GetDBConfig();

            dbconfig.ColumnChangeCase = ConfigurationDBRef.ColumnChangeCaseEnum.UPPERCASE;
            Configuration configuration = GetConfig(dbconfig);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            const string sql = "select myint from mytesttable where ${TheString} = myvarchar'" +
                               "metadatasql 'select myint from mytesttable'";
            String stmtText = "select MYINT from " +
                              " sql:MyDB ['" + sql + "] as s0," +
                              typeof(SupportBean).FullName + ".win:length(100) as s1";

            EPStatement statement = _epService.EPAdministrator.CreateEPL(stmtText);

            _listener         = new SupportUpdateListener();
            statement.Events += _listener.Update;

            Assert.AreEqual(typeof(int?), statement.EventType.GetPropertyType("MYINT"));

            SendSupportBeanEvent("A");
            Assert.AreEqual(10, _listener.AssertOneGetNewAndReset().Get("MYINT"));

            SendSupportBeanEvent("H");
            Assert.AreEqual(80, _listener.AssertOneGetNewAndReset().Get("MYINT"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#7
0
        public void TestConfig()
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.AddEventType("TypeS0", typeof(SupportBean_S0));
            config.AddEventType("TypeS2", typeof(SupportBean_S2));

            config.AddVariable("vars0", "TypeS0", new SupportBean_S0(10));
            config.AddVariable("vars1", typeof(SupportBean_S1).FullName, new SupportBean_S1(20));
            config.AddVariable("varsobj1", typeof(Object).FullName, 123);

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

            Assert.AreEqual(10, ((SupportBean_S0)_epService.EPRuntime.GetVariableValue("vars0")).Id);
            Assert.AreEqual(20, ((SupportBean_S1)_epService.EPRuntime.GetVariableValue("vars1")).Id);
            Assert.AreEqual(123, _epService.EPRuntime.GetVariableValue("varsobj1"));

            _epService.EPAdministrator.Configuration.AddVariable("vars2", "TypeS2", new SupportBean_S2(30));
            _epService.EPAdministrator.Configuration.AddVariable("vars3", typeof(SupportBean_S3), new SupportBean_S3(40));
            _epService.EPAdministrator.Configuration.AddVariable("varsobj2", typeof(Object), "ABC");

            Assert.AreEqual(30, ((SupportBean_S2)_epService.EPRuntime.GetVariableValue("vars2")).Id);
            Assert.AreEqual(40, ((SupportBean_S3)_epService.EPRuntime.GetVariableValue("vars3")).Id);
            Assert.AreEqual("ABC", _epService.EPRuntime.GetVariableValue("varsobj2"));

            _epService.EPAdministrator.CreateEPL("create variable object varsobj3=222");
            Assert.AreEqual(222, _epService.EPRuntime.GetVariableValue("varsobj3"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#8
0
        public void TestCaseDistinctInsensitive()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.EventMeta.ClassPropertyResolutionStyle = PropertyResolutionStyle.DISTINCT_CASE_INSENSITIVE;

            epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }

            EPStatement           stmt     = epService.EPAdministrator.CreateEPL("select MYPROPERTY, myproperty, myProperty from " + typeof(SupportBeanDupProperty).FullName);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.AddListener(listener);

            epService.EPRuntime.SendEvent(new SupportBeanDupProperty("lowercamel", "uppercamel", "upper", "lower"));
            EventBean result = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("upper", result.Get("MYPROPERTY"));
            Assert.AreEqual("lower", result.Get("myproperty"));
            Assert.IsTrue(result.Get("myProperty").Equals("lowercamel") || result.Get("myProperty").Equals("uppercamel"));     // JDK6 versus JDK7 JavaBean inspector

            try {
                epService.EPAdministrator.CreateEPL("select MyProPerty from " + typeof(SupportBeanDupProperty).FullName);
                Assert.Fail();
            } catch (EPException ex) {
                SupportMessageAssertUtil.AssertMessage(ex, "Unexpected exception starting statement: Unable to determine which property to use for \"MyProPerty\" because more than one property matched [");
                // expected
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#9
0
        public void TestOrderOfEvaluationSubselectFirst()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.ExpressionConfig.IsSelfSubselectPreeval = true;
            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }
            _listener = new SupportUpdateListener();

            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            String      viewExpr = "select * from SupportBean(IntPrimitive<10) where IntPrimitive not in (select IntPrimitive from SupportBean.std:unique(IntPrimitive))";
            EPStatement stmtOne  = _epService.EPAdministrator.CreateEPL(viewExpr);

            stmtOne.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 5));
            Assert.IsFalse(_listener.GetAndClearIsInvoked());

            stmtOne.Dispose();

            String      viewExprTwo = "select * from SupportBean where IntPrimitive not in (select IntPrimitive from SupportBean(IntPrimitive<10).std:unique(IntPrimitive))";
            EPStatement stmtTwo     = _epService.EPAdministrator.CreateEPL(viewExprTwo);

            stmtTwo.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 5));
            Assert.IsFalse(_listener.GetAndClearIsInvoked());

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#10
0
        public void TestFollowedNotEvery()
        {
            String expression = "select * from pattern [every A=" + typeof(SupportBean).FullName +
                                " -> (timer:interval(1 seconds) and not " + typeof(SupportBean_A).FullName + ")]";

            Configuration     config    = SupportConfigFactory.GetConfiguration();
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));

            EPStatement statement = epService.EPAdministrator.CreateEPL(expression);
            var         listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            Object eventOne = new SupportBean();

            epService.EPRuntime.SendEvent(eventOne);

            Object eventTwo = new SupportBean();

            epService.EPRuntime.SendEvent(eventTwo);

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000));
            Assert.AreEqual(1, listener.NewDataList.Count);
            Assert.AreEqual(2, listener.NewDataList[0].Length);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#11
0
        public void TestPrimitivesTypes()
        {
            _properties            = new Properties();
            _properties["MyInt"]   = typeof(int).FullName;
            _properties["byteArr"] = typeof(byte[]).FullName;
            _properties["MyInt2"]  = "int";
            _properties["double"]  = "double";
            _properties["boolean"] = "boolean";
            _properties["long"]    = "long";
            _properties["astring"] = "string";

            Configuration configuration = SupportConfigFactory.GetConfiguration();

            configuration.AddEventType("MyPrimMapEvent", _properties);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            _epService.Dispose();
        }
        public void TestPreConfigStaticTypeResolution()
        {
            Configuration configuration = GetConfiguration();

            configuration.AddPlugInEventType("TestTypeOne", new Uri[] { new Uri("type://properties/test1/testtype") }, "t1");
            configuration.AddPlugInEventType("TestTypeTwo", new Uri[] { new Uri("type://properties/test2") }, "t2");
            configuration.AddPlugInEventType("TestTypeThree", new Uri[] { new Uri("type://properties/test3") }, "t3");
            configuration.AddPlugInEventType("TestTypeFour", new Uri[] { new Uri("type://properties/test2/x"), new Uri("type://properties/test3") }, "t4");

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            RunAssertionCaseStatic(_epService);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#13
0
        public void TestIntervalPrepared()
        {
            Configuration     config    = SupportConfigFactory.GetConfiguration();
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            // External clocking
            SendTimer(0, epService);

            // Set up a timer:within
            EPPreparedStatement prepared = epService.EPAdministrator.PrepareEPL(
                "select * from pattern [(every " + typeof(SupportBean).FullName +
                ") where timer:within(? days ? hours ? minutes ? seconds ? milliseconds)]");

            prepared.SetObject(1, 1);
            prepared.SetObject(2, 2);
            prepared.SetObject(3, 3);
            prepared.SetObject(4, 4);
            prepared.SetObject(5, 5);
            EPStatement statement = epService.EPAdministrator.Create(prepared);

            SupportUpdateListener testListener = new SupportUpdateListener();

            statement.Events += testListener.Update;

            RunAssertion(epService, testListener);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#14
0
        private void RunAssertionLongRunningUnbound(EPServiceProvider epService)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            } // excluded from instrumentation, too much data

            string epl = "select symbol as currSymbol, " +
                         " prior(3, symbol) as prior0Symbol " +
                         "from " + typeof(SupportMarketDataBean).FullName;

            EPStatementSPI stmt     = (EPStatementSPI)epService.EPAdministrator.CreateEPL(epl);
            var            listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            Assert.IsFalse(stmt.StatementContext.IsStatelessSelect);

            var random = new Random();

            // 200000 is a better number for a memory test, however for short unit tests this is 2000
            for (int i = 0; i < 2000; i++)
            {
                if (i % 10000 == 0)
                {
                    //Log.Info(i);
                }

                SendMarketEvent(epService, Convert.ToString(random.Next()), 4);

                if (i % 1000 == 0)
                {
                    listener.Reset();
                }
            }

            stmt.Dispose();
        }
示例#15
0
        public void TestIntervalSpecPreparedStmt()
        {
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            // External clocking
            SendTimer(0, epService);

            // Set up a timer:within
            EPPreparedStatement prepared = epService.EPAdministrator.PrepareEPL(
                "select * from pattern [timer:interval(? minute ? seconds)]");

            prepared.SetObject(1, 1);
            prepared.SetObject(2, 2);
            EPStatement statement = epService.EPAdministrator.Create(prepared);

            SupportUpdateListener testListener = new SupportUpdateListener();

            statement.Events += testListener.Update;

            SendTimer(62 * 1000 - 1, epService);
            Assert.IsFalse(testListener.IsInvoked);

            SendTimer(62 * 1000, epService);
            Assert.IsTrue(testListener.IsInvoked);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#16
0
        public void TestClassForNameForbiddenClass()
        {
            EPServiceProvider epService = GetDefaultEngine();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }

            epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean));

            string epl = "select System.Environment.Exit(-1) from SupportBean";

            epService.EPAdministrator.Configuration.TransientConfiguration.Put(ClassForNameProviderConstants.NAME, new MyClassForNameProvider());
            SupportMessageAssertUtil.TryInvalid(epService, epl, "Error starting statement: Failed to validate select-clause expression 'System.Environment.Exit(-1)': Failed to resolve 'System.Environment.Exit' to");

            epService.EPAdministrator.Configuration.TransientConfiguration.Put(ClassForNameProviderConstants.NAME, ClassForNameProviderDefault.INSTANCE);
            epService.EPAdministrator.CreateEPL(epl);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#17
0
        public void TestUDFBuiltin()
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }                                                                       // not instrumented

            _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("udf", typeof(TestViewExpressionWindow.LocalUDF).FullName, "EvaluateExpiryUDF");
            _epService.EPAdministrator.CreateEPL("select * from SupportBean.win:expr_batch(udf(TheString, view_reference, expired_count))");

            TestViewExpressionWindow.LocalUDF.Result = true;
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 0));
            Assert.AreEqual("E1", TestViewExpressionWindow.LocalUDF.Key);
            Assert.AreEqual(0, (int)TestViewExpressionWindow.LocalUDF.ExpiryCount);
            Assert.NotNull(TestViewExpressionWindow.LocalUDF.Viewref);

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 0));

            TestViewExpressionWindow.LocalUDF.Result = false;
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 0));
            Assert.AreEqual("E3", TestViewExpressionWindow.LocalUDF.Key);
            Assert.AreEqual(0, (int)TestViewExpressionWindow.LocalUDF.ExpiryCount);
            Assert.NotNull(TestViewExpressionWindow.LocalUDF.Viewref);
        }
示例#18
0
        private void TryCaseInsensitive(Configuration configuration, string stmtText, string propOneName, string propTwoName)
        {
            epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }

            EPStatement           stmt     = epService.EPAdministrator.CreateEPL(stmtText);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.AddListener(listener);

            epService.EPRuntime.SendEvent(new SupportBean("A", 10));
            EventBean result = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("A", result.Get(propOneName));
            Assert.AreEqual(10, result.Get(propTwoName));
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#19
0
        public void TestIndexedFilterProp()
        {
            var testListener = new SupportUpdateListener();
            var epService    = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            var type    = typeof(SupportBeanComplexProps).FullName;
            var pattern = "every a=" + type + "(Indexed[0]=3)";

            var stmt = epService.EPAdministrator.CreatePattern(pattern);

            stmt.Events += testListener.Update;

            Object theEvent = new SupportBeanComplexProps(new int[] { 3, 4 });

            epService.EPRuntime.SendEvent(theEvent);
            Assert.AreSame(theEvent, testListener.AssertOneGetNewAndReset().Get("a"));

            theEvent = new SupportBeanComplexProps(new int[] { 6 });
            epService.EPRuntime.SendEvent(theEvent);
            Assert.IsFalse(testListener.IsInvoked);

            theEvent = new SupportBeanComplexProps(new int[] { 3 });
            epService.EPRuntime.SendEvent(theEvent);
            Assert.AreSame(theEvent, testListener.AssertOneGetNewAndReset().Get("a"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#20
0
        public void TestRouteTimer()
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }                                                                       // excluded

            String      viewExpr    = "every tag=" + typeof(SupportBean).FullName;
            EPStatement patternStmt = _epService.EPAdministrator.CreatePattern(viewExpr);

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));

            // define time-based pattern and listener
            viewExpr = "timer:at(*,*,*,*,*,*)";
            EPStatement atPatternStmt = _epService.EPAdministrator.CreatePattern(viewExpr);
            SingleRouteUpdateListener timeListener = new SingleRouteUpdateListener {
                RouteEvent = RouteEvent
            };

            atPatternStmt.Events += timeListener.Update;

            // register regular listener
            SingleRouteUpdateListener eventListener = new SingleRouteUpdateListener {
                RouteEvent = RouteEvent
            };

            patternStmt.Events += eventListener.Update;

            Assert.AreEqual(0, timeListener.Count);
            Assert.AreEqual(0, eventListener.Count);

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));

            Assert.AreEqual(1, timeListener.Count);
            Assert.AreEqual(1000, eventListener.Count);
        }
        private void RunAssertionExpression(EPServiceProvider epService)
        {
            var expression = "select * from pattern [every timer:at(7+1-8,4+4,*,*,[1,2,3,4,5])]";

            var cal = MakeDateTime(2008, 7, 3, 10, 0, 0, 0); // start on a Sunday at 6am, August 3 2008

            SendTimer(cal.TimeInMillis(), epService);

            var prepared  = epService.EPAdministrator.PrepareEPL(expression);
            var statement = epService.EPAdministrator.Create(prepared);

            var listener = new SupportUpdateListener();

            statement.Events += listener.Update;

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            } // excluding assertion, too many steps

            TryAssertion(epService, listener);

            statement.Dispose();
        }
示例#22
0
        public void TestPerformance()
        {
            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } // exclude test

            String stmtText = "select SimpleProperty?, " +
                              "Indexed[1]? as Indexed, " +
                              "Mapped('keyOne')? as Mapped " +
                              "from " + typeof(SupportBeanComplexProps).FullName;
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            EventType type = stmt.EventType;
            Assert.AreEqual(typeof(Object), type.GetPropertyType("SimpleProperty?"));
            Assert.AreEqual(typeof(Object), type.GetPropertyType("Indexed"));
            Assert.AreEqual(typeof(Object), type.GetPropertyType("Mapped"));

            SupportBeanComplexProps inner = SupportBeanComplexProps.MakeDefaultBean();
            _epService.EPRuntime.SendEvent(inner);
            EventBean theEvent = _listener.AssertOneGetNewAndReset();
            Assert.AreEqual(inner.SimpleProperty, theEvent.Get("SimpleProperty?"));
            Assert.AreEqual(inner.GetIndexed(1), theEvent.Get("Indexed"));
            Assert.AreEqual(inner.GetMapped("keyOne"), theEvent.Get("Mapped"));

            long start = PerformanceObserver.MilliTime;
            for (int i = 0; i < 10000; i++)
            {
                _epService.EPRuntime.SendEvent(inner);
                if (i % 1000 == 0)
                {
                    _listener.Reset();
                }
            }
            long end = PerformanceObserver.MilliTime;
            long delta = end - start;
            Assert.IsTrue(delta < 1000, "delta=" + delta);
        }
        public void TestInvalid()
        {
            Configuration configuration = GetConfiguration();

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            try {
                _epService.EPRuntime.GetEventSender(new Uri[0]);
                Assert.Fail();
            } catch (EventTypeException ex) {
                Assert.AreEqual("Event sender for resolution URIs '[]' did not return at least one event representation's event factory", ex.Message);
            }


            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#24
0
        public void TestPatternNotFollowedBy()
        {
            // test for ESPER-350
            var config = SupportConfigFactory.GetConfiguration();

            config.AddEventType("A", typeof(SupportBean));
            config.AddEventType("B", typeof(SupportMarketDataBean));
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            SendTimer(0, epService);

            var stmtText  = "select * from pattern [ every(A -> (B where timer:within(5 sec))) ]";
            var statement = epService.EPAdministrator.CreateEPL(stmtText);
            var listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            SendTimer(6000, epService);

            epService.EPRuntime.SendEvent(new SupportBean("E4", 1));
            epService.EPRuntime.SendEvent(new SupportMarketDataBean("E5", "M1", 1d));
            Assert.IsTrue(listener.IsInvoked);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#25
0
        public void TestMonthScoped()
        {
            String[]          fields    = "a.TheString,a.IntPrimitive".Split(',');
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(
                SupportConfigFactory.GetConfiguration());

            epService.Initialize();
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            SupportUpdateListener listener = new SupportUpdateListener();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            SendCurrentTime(epService, "2002-02-01T9:00:00.000");
            epService.EPAdministrator.CreateEPL("select * from pattern [every-distinct(TheString, 1 month) a=SupportBean]").Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", 1 });

            epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            SendCurrentTimeWithMinus(epService, "2002-03-01T9:00:00.000", 1);
            epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            Assert.IsFalse(listener.IsInvoked);

            SendCurrentTime(epService, "2002-03-01T9:00:00.000");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 4));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", 4 });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestUnpartitionedKeepAll()
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportRecogBean>("MyEvent");
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            var fields = "a_string".Split(',');
            var text   = "select * from MyEvent#keepall " +
                         "match_recognize (" +
                         "  measures A.TheString as a_string" +
                         "  all matches pattern (A) " +
                         "  define A as (A.Value > PREV(A.Value))" +
                         ") " +
                         "order by a_string";

            var stmt     = epService.EPAdministrator.CreateEPL(text);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 3));
            Assert.IsFalse(listener.IsInvoked);
            Assert.IsFalse(stmt.HasFirst());

            epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 6));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E3" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 4));
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 6));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E5" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" }, new Object[] { "E5" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 10));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E6" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" }, new Object[] { "E5" }, new Object[] { "E6" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 9));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 4));
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" }, new Object[] { "E5" }, new Object[] { "E6" } });

            stmt.Stop();

            text = "select * from MyEvent#keepall " +
                   "match_recognize (" +
                   "  measures A.TheString as a_string" +
                   "  all matches pattern (A) " +
                   "  define A as (PREV(A.Value, 2) = 5)" +
                   ") " +
                   "order by a_string";

            stmt         = epService.EPAdministrator.CreateEPL(text);
            listener     = new SupportUpdateListener();
            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 4));
            Assert.IsFalse(listener.IsInvoked);
            Assert.IsFalse(stmt.HasFirst());

            epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 6));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E3" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 3));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 3));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 5));
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 6));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E7" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" }, new Object[] { "E7" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 6));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E8" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E3" }, new Object[] { "E7" }, new Object[] { "E8" } });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestPartitionBy2FieldsKeepall()
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportRecogBean>("MyEvent");
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            var fields = "a_string,a_cat,a_value,b_value".Split(',');
            var text   = "select * from MyEvent#keepall " +
                         "match_recognize (" +
                         "  partition by TheString, Cat" +
                         "  measures A.TheString as a_string, A.Cat as a_cat, A.Value as a_value, B.Value as b_value " +
                         "  all matches pattern (A B) " +
                         "  define " +
                         "    A as (A.Value > PREV(A.Value))," +
                         "    B as (B.Value > PREV(B.Value))" +
                         ") order by a_string, a_cat";

            var stmt     = epService.EPAdministrator.CreateEPL(text);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T1", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 110));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 21));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T1", 7));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 111));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 20));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 110));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1000));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1001));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", null, 9));
            Assert.IsFalse(listener.IsInvoked);
            Assert.IsFalse(stmt.HasFirst());

            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T1", 9));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "S1", "T1", 7, 9 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "S1", "T1", 7, 9 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1001));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 109));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 25));
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "S1", "T1", 7, 9 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1002));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1003));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "S2", "T2", 1002, 1003 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "S1", "T1", 7, 9 }, new Object[] { "S2", "T2", 1002, 1003 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 28));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "S1", "T2", 25, 28 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "S1", "T1", 7, 9 }, new Object[] { "S1", "T2", 25, 28 }, new Object[] { "S2", "T2", 1002, 1003 } });

            stmt.Dispose();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestTimeWindowPartitionedSimple()
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportRecogBean>("MyEvent");
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            SendTimer(0, epService);
            var fields = "a_string".Split(',');
            var text   = "select * from MyEvent#time(5 sec) " +
                         "match_recognize (" +
                         "  partition by Cat " +
                         "  measures A.Cat as Cat, A.TheString as a_string" +
                         "  all matches pattern (A) " +
                         "  define " +
                         "    A as PREV(A.Value) = (A.Value - 1)" +
                         ") order by a_string";

            var stmt     = epService.EPAdministrator.CreateEPL(text);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendTimer(1000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E1", "S1", 100));

            SendTimer(2000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E2", "S3", 100));

            SendTimer(2500, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E3", "S2", 102));

            SendTimer(6200, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E4", "S1", 101));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E4" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E4" } });

            SendTimer(6500, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E5", "S3", 101));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E5" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E4" }, new Object[] { "E5" } });

            SendTimer(7000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E6", "S1", 102));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E6" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E4" }, new Object[] { "E5" }, new Object[] { "E6" } });

            SendTimer(10000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("E7", "S2", 103));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E7" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E4" }, new Object[] { "E5" }, new Object[] { "E6" }, new Object[] { "E7" } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("E8", "S2", 102));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E8", "S1", 101));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E8", "S2", 104));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E8", "S1", 105));
            Assert.IsFalse(listener.IsInvoked);

            SendTimer(11199, epService);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E4" }, new Object[] { "E5" }, new Object[] { "E6" }, new Object[] { "E7" } });

            SendTimer(11200, epService);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E5" }, new Object[] { "E6" }, new Object[] { "E7" } });

            SendTimer(11600, epService);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E6" }, new Object[] { "E7" } });

            SendTimer(16000, epService);
            Assert.IsFalse(stmt.HasFirst());

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestTimeWindowUnpartitioned()
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportRecogBean>("MyEvent");
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            SendTimer(0, epService);
            var fields = "a_string,b_string".Split(',');
            var text   = "select * from MyEvent#time(5) " +
                         "match_recognize (" +
                         "  measures A.TheString as a_string, B.TheString as b_string" +
                         "  all matches pattern (A B) " +
                         "  define " +
                         "    A as PREV(A.TheString, 3) = 'P3' and PREV(A.TheString, 2) = 'P2' and PREV(A.TheString, 4) = 'P4' and Math.Abs(prev(A.Value, 0)) >= 0," +
                         "    B as B.Value in (PREV(B.Value, 4), PREV(B.Value, 2))" +
                         ")";

            var stmt     = epService.EPAdministrator.CreateEPL(text);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendTimer(1000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 1));
            epService.EPRuntime.SendEvent(new SupportRecogBean("P1", 2));
            epService.EPRuntime.SendEvent(new SupportRecogBean("P3", 3));
            epService.EPRuntime.SendEvent(new SupportRecogBean("P4", 4));
            SendTimer(2000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 1));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 3));
            Assert.IsFalse(listener.IsInvoked);
            Assert.IsFalse(stmt.HasFirst());

            SendTimer(3000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("P4", 11));
            epService.EPRuntime.SendEvent(new SupportRecogBean("P3", 12));
            epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 13));
            SendTimer(4000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("xx", 4));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E2", -1));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 12));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E2", "E3" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E2", "E3" } });

            SendTimer(5000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("P4", 21));
            epService.EPRuntime.SendEvent(new SupportRecogBean("P3", 22));
            SendTimer(6000, epService);
            epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 23));
            epService.EPRuntime.SendEvent(new SupportRecogBean("xx", -2));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E5", -1));
            epService.EPRuntime.SendEvent(new SupportRecogBean("E6", -2));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new [] { new Object[] { "E5", "E6" } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E2", "E3" }, new Object[] { "E5", "E6" } });

            SendTimer(8500, epService);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E2", "E3" }, new Object[] { "E5", "E6" } });

            SendTimer(9500, epService);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E5", "E6" } });

            SendTimer(10500, epService);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new [] { new Object[] { "E5", "E6" } });

            SendTimer(11500, epService);
            Assert.IsFalse(stmt.HasFirst());

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
示例#30
0
        public void TestSimpleXMLXPathProperties()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();

            ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "myevent";
            xmlDOMEventTypeDesc.AddXPathProperty("xpathElement1", "/myevent/element1", XPathResultType.String);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathCountE21", "count(/myevent/element2/element21)", XPathResultType.Number);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrString", "/myevent/element3/@attrString", XPathResultType.String);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrNum", "/myevent/element3/@attrNum", XPathResultType.Number);
            xmlDOMEventTypeDesc.AddXPathProperty("xpathAttrBool", "/myevent/element3/@attrBool", XPathResultType.Boolean);
            xmlDOMEventTypeDesc.AddXPathProperty("stringCastLong", "/myevent/element3/@attrNum", XPathResultType.String, "long");
            xmlDOMEventTypeDesc.AddXPathProperty("stringCastDouble", "/myevent/element3/@attrNum", XPathResultType.String, "double");
            xmlDOMEventTypeDesc.AddXPathProperty("numCastInt", "/myevent/element3/@attrNum", XPathResultType.Number, "int");
            xmlDOMEventTypeDesc.XPathFunctionResolver = typeof(SupportXPathFunctionResolver).FullName;
            xmlDOMEventTypeDesc.XPathVariableResolver = typeof(SupportXPathVariableResolver).FullName;
            configuration.AddEventType("TestXMLNoSchemaType", xmlDOMEventTypeDesc);

            xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();
            xmlDOMEventTypeDesc.RootElementName = "my.event2";
            configuration.AddEventType("TestXMLWithDots", xmlDOMEventTypeDesc);

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _updateListener = new SupportUpdateListener();

            // assert type metadata
            EventTypeSPI type = (EventTypeSPI)((EPServiceProviderSPI)_epService).EventAdapterService.GetEventTypeByName("TestXMLNoSchemaType");

            Assert.AreEqual(ApplicationType.XML, type.Metadata.OptionalApplicationType);
            Assert.AreEqual(null, type.Metadata.OptionalSecondaryNames);
            Assert.AreEqual("TestXMLNoSchemaType", type.Metadata.PrimaryName);
            Assert.AreEqual("TestXMLNoSchemaType", type.Metadata.PublicName);
            Assert.AreEqual("TestXMLNoSchemaType", type.Name);
            Assert.AreEqual(TypeClass.APPLICATION, type.Metadata.TypeClass);
            Assert.AreEqual(true, type.Metadata.IsApplicationConfigured);
            Assert.AreEqual(true, type.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(true, type.Metadata.IsApplicationPreConfiguredStatic);

            EPAssertionUtil.AssertEqualsAnyOrder(new[] {
                new EventPropertyDescriptor("xpathElement1", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("xpathCountE21", typeof(double?), null, false, false, false, false, false),
                new EventPropertyDescriptor("xpathAttrString", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("xpathAttrNum", typeof(double?), null, false, false, false, false, false),
                new EventPropertyDescriptor("xpathAttrBool", typeof(bool?), null, false, false, false, false, false),
                new EventPropertyDescriptor("stringCastLong", typeof(long), null, false, false, false, false, false),
                new EventPropertyDescriptor("stringCastDouble", typeof(double), null, false, false, false, false, false),
                new EventPropertyDescriptor("numCastInt", typeof(int), null, false, false, false, false, false),
            }, type.PropertyDescriptors);

            String stmt =
                "select xpathElement1, xpathCountE21, xpathAttrString, xpathAttrNum, xpathAttrBool," +
                "stringCastLong," +
                "stringCastDouble," +
                "numCastInt " +
                "from TestXMLNoSchemaType.win:length(100)";

            EPStatement joinView = _epService.EPAdministrator.CreateEPL(stmt);

            joinView.Events += _updateListener.Update;

            // Generate document with the specified in element1 to confirm we have independent events
            SendEvent("EventA");
            AssertDataSimpleXPath("EventA");

            SendEvent("EventB");
            AssertDataSimpleXPath("EventB");

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