public void TestOM() { var fields = new string[] { "key", "value" }; // create window object model var model = new EPStatementObjectModel(); model.CreateWindow = CreateWindowClause.Create("MyWindow").AddView("win", "keepall"); model.SelectClause = SelectClause.Create() .AddWithAsProvidedName("TheString", "key") .AddWithAsProvidedName("LongBoxed", "value"); model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean).FullName)); var stmtCreate = _epService.EPAdministrator.Create(model); stmtCreate.AddListener(_listenerWindow); var stmtTextCreate = "create window MyWindow.win:keepall() as select TheString as key, LongBoxed as value from " + typeof(SupportBean).FullName; Assert.AreEqual(stmtTextCreate, model.ToEPL()); var stmtTextInsert = "insert into MyWindow select TheString as key, LongBoxed as value from " + typeof(SupportBean).FullName; var modelInsert = _epService.EPAdministrator.CompileEPL(stmtTextInsert); var stmtInsert = _epService.EPAdministrator.Create(modelInsert); // Consumer statement object model model = new EPStatementObjectModel(); Expression multi = Expressions.Multiply(Expressions.Property("value"), Expressions.Constant(2)); model.SelectClause = SelectClause.Create().SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH) .Add("key") .Add(multi, "value"); model.FromClause = FromClause.Create(FilterStream.Create("MyWindow", Expressions.IsNotNull("value"))); var stmtSelectOne = _epService.EPAdministrator.Create(model); stmtSelectOne.AddListener(_listenerStmtOne); var stmtTextSelectOne = "select irstream key, value*2 as value from MyWindow(value is not null)"; Assert.AreEqual(stmtTextSelectOne, model.ToEPL()); // send events SendSupportBean("E1", 10L); EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), fields, new object[] { "E1", 20L }); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 10L }); SendSupportBean("E2", 20L); EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), fields, new object[] { "E2", 40L }); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 20L }); // create delete stmt model = new EPStatementObjectModel(); model.OnExpr = OnClause.CreateOnDelete("MyWindow", "s1"); model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportMarketDataBean).FullName, "s0")); model.WhereClause = Expressions.EqProperty("s0.symbol", "s1.key"); _epService.EPAdministrator.Create(model); var stmtTextDelete = "on " + typeof(SupportMarketDataBean).FullName + " as s0 delete from MyWindow as s1 where s0.symbol=s1.key"; Assert.AreEqual(stmtTextDelete, model.ToEPL()); // send delete event SendMarketBean("E1"); EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetOldAndReset(), fields, new object[] { "E1", 20L }); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E1", 10L }); // send delete event again, none deleted now SendMarketBean("E1"); Assert.IsFalse(_listenerStmtOne.IsInvoked); Assert.IsFalse(_listenerWindow.IsInvoked); // send delete event SendMarketBean("E2"); EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetOldAndReset(), fields, new object[] { "E2", 40L }); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E2", 20L }); // On-select object model model = new EPStatementObjectModel(); model.OnExpr = OnClause.CreateOnSelect("MyWindow", "s1"); model.WhereClause = Expressions.EqProperty("s0.id", "s1.key"); model.FromClause = FromClause.Create(FilterStream.Create(typeof(SupportBean_B).FullName, "s0")); model.SelectClause = SelectClause.CreateStreamWildcard("s1"); var statement = _epService.EPAdministrator.Create(model); statement.AddListener(_listenerOnSelect); var stmtTextOnSelect = "on " + typeof(SupportBean_B).FullName + " as s0 select s1.* from MyWindow as s1 where s0.id=s1.key"; Assert.AreEqual(stmtTextOnSelect, model.ToEPL()); // send some more events SendSupportBean("E3", 30L); SendSupportBean("E4", 40L); _epService.EPRuntime.SendEvent(new SupportBean_B("B1")); Assert.IsFalse(_listenerOnSelect.IsInvoked); // trigger on-select _epService.EPRuntime.SendEvent(new SupportBean_B("E3")); EPAssertionUtil.AssertProps(_listenerOnSelect.AssertOneGetNewAndReset(), fields, new object[] { "E3", 30L }); stmtSelectOne.Dispose(); stmtInsert.Dispose(); stmtCreate.Dispose(); }
public void Run(RegressionEnvironment env) { string[] fields = {"key", "value"}; var path = new RegressionPath(); // create window object model var model = new EPStatementObjectModel(); model.CreateWindow = CreateWindowClause .Create("MyWindow") .AddView("keepall") .WithAsEventTypeName("SupportBean"); model.SelectClause = SelectClause.Create() .AddWithAsProvidedName("TheString", "key") .AddWithAsProvidedName("LongBoxed", "value"); var stmtTextCreate = "create window MyWindow#keepall as select TheString as key, LongBoxed as value from SupportBean"; Assert.AreEqual(stmtTextCreate, model.ToEPL()); model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("create")); env.CompileDeploy(model, path).AddListener("create"); var stmtTextInsert = "insert into MyWindow select TheString as key, LongBoxed as value from SupportBean"; env.EplToModelCompileDeploy(stmtTextInsert, path); // Consumer statement object model model = new EPStatementObjectModel(); Expression multi = Expressions.Multiply(Expressions.Property("value"), Expressions.Constant(2)); model.SelectClause = SelectClause.Create() .SetStreamSelector(StreamSelector.RSTREAM_ISTREAM_BOTH) .Add("key") .Add(multi, "value"); model.FromClause = FromClause.Create(FilterStream.Create("MyWindow", Expressions.IsNotNull("value"))); var eplSelect = "select irstream key, value*2 as value from MyWindow(value is not null)"; Assert.AreEqual(eplSelect, model.ToEPL()); model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("select")); env.CompileDeploy(model, path).AddListener("select"); // send events SendSupportBean(env, "E1", 10L); EPAssertionUtil.AssertProps( env.Listener("select").AssertOneGetNewAndReset(), fields, new object[] {"E1", 20L}); EPAssertionUtil.AssertProps( env.Listener("create").AssertOneGetNewAndReset(), fields, new object[] {"E1", 10L}); SendSupportBean(env, "E2", 20L); EPAssertionUtil.AssertProps( env.Listener("select").AssertOneGetNewAndReset(), fields, new object[] {"E2", 40L}); EPAssertionUtil.AssertProps( env.Listener("create").AssertOneGetNewAndReset(), fields, new object[] {"E2", 20L}); // create delete stmt model = new EPStatementObjectModel(); model.OnExpr = OnClause.CreateOnDelete("MyWindow", "S1"); model.FromClause = FromClause.Create(FilterStream.Create("SupportMarketDataBean", "S0")); model.WhereClause = Expressions.EqProperty("S0.Symbol", "S1.key"); var stmtTextDelete = "on SupportMarketDataBean as S0 delete from MyWindow as S1 where S0.Symbol=S1.key"; Assert.AreEqual(stmtTextDelete, model.ToEPL()); model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("ondelete")); env.CompileDeploy(model, path).AddListener("ondelete"); // send delete event SendMarketBean(env, "E1"); EPAssertionUtil.AssertProps( env.Listener("select").AssertOneGetOldAndReset(), fields, new object[] {"E1", 20L}); EPAssertionUtil.AssertProps( env.Listener("create").AssertOneGetOldAndReset(), fields, new object[] {"E1", 10L}); // send delete event again, none deleted now SendMarketBean(env, "E1"); Assert.IsFalse(env.Listener("select").IsInvoked); Assert.IsFalse(env.Listener("create").IsInvoked); // send delete event SendMarketBean(env, "E2"); EPAssertionUtil.AssertProps( env.Listener("select").AssertOneGetOldAndReset(), fields, new object[] {"E2", 40L}); EPAssertionUtil.AssertProps( env.Listener("create").AssertOneGetOldAndReset(), fields, new object[] {"E2", 20L}); // On-select object model model = new EPStatementObjectModel(); model.OnExpr = OnClause.CreateOnSelect("MyWindow", "S1"); model.WhereClause = Expressions.EqProperty("S0.Id", "S1.key"); model.FromClause = FromClause.Create(FilterStream.Create("SupportBean_B", "S0")); model.SelectClause = SelectClause.CreateStreamWildcard("S1"); var stmtTextOnSelect = "on SupportBean_B as S0 select S1.* from MyWindow as S1 where S0.Id=S1.key"; Assert.AreEqual(stmtTextOnSelect, model.ToEPL()); model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("onselect")); env.CompileDeploy(model, path).AddListener("onselect"); // send some more events SendSupportBean(env, "E3", 30L); SendSupportBean(env, "E4", 40L); env.SendEventBean(new SupportBean_B("B1")); Assert.IsFalse(env.Listener("onselect").IsInvoked); // trigger on-select env.SendEventBean(new SupportBean_B("E3")); EPAssertionUtil.AssertProps( env.Listener("onselect").AssertOneGetNewAndReset(), fields, new object[] {"E3", 30L}); env.UndeployAll(); }