public void TestSumOneView() { // Every event generates a new row, this time we sum the price by symbol and output volume string viewExpr = "select irstream symbol, sum(distinct volume) as volSum " + "from " + typeof(SupportMarketDataBean).FullName + ".win:length(3) "; EPStatement selectTestView = _epService.EPAdministrator.CreateEPL(viewExpr); selectTestView.AddListener(_testListener); // assert select result type Assert.AreEqual(typeof(string), selectTestView.EventType.GetPropertyType("symbol")); Assert.AreEqual(typeof(long?), selectTestView.EventType.GetPropertyType("volSum")); SendEvent(SYMBOL_DELL, 10000); AssertEvents(SYMBOL_DELL, 10000); SendEvent(SYMBOL_DELL, 10000); AssertEvents(SYMBOL_DELL, 10000); // still 10k since summing distinct volumes SendEvent(SYMBOL_DELL, 20000); AssertEvents(SYMBOL_DELL, 30000); SendEvent(SYMBOL_IBM, 1000); AssertEvents(SYMBOL_DELL, 31000, SYMBOL_IBM, 31000); SendEvent(SYMBOL_IBM, 1000); AssertEvents(SYMBOL_DELL, 21000, SYMBOL_IBM, 21000); SendEvent(SYMBOL_IBM, 1000); AssertEvents(SYMBOL_DELL, 1000, SYMBOL_IBM, 1000); }
private void RunAssertionHaving(EPStatement statement) { var fields = "Symbol,mysum".Split(','); _testListener = new SupportUpdateListener(); statement.AddListener(_testListener); SendEvent("IBM", 3); SendEvent("IBM", 4); SendEvent("CMU", 1); SendEvent("CMU", 2); SendEvent("CAT", 5); SendEvent("CAT", 6); EPAssertionUtil.AssertPropsPerRow(_testListener.LastNewData, fields, new object[][] { new object[] { "CMU", 1.0 }, new object[] { "CMU", 3.0 }, new object[] { "IBM", 3.0 }, new object[] { "CAT", 5.0 }, new object[] { "IBM", 7.0 }, new object[] { "CAT", 11.0 } }); EPAssertionUtil.AssertPropsPerRow(_testListener.LastOldData, fields, new object[][] { new object[] { "CMU", 1.0 }, new object[] { "IBM", 3.0 }, new object[] { "CAT", 5.0 } }); _testListener.Reset(); SendEvent("IBM", 3); SendEvent("IBM", 4); SendEvent("CMU", 5); SendEvent("CMU", 5); SendEvent("DOG", 0); SendEvent("DOG", 1); EPAssertionUtil.AssertPropsPerRow(_testListener.LastNewData, fields, new object[][] { new object[] { "DOG", 1.0 }, new object[] { "CMU", 8.0 }, new object[] { "IBM", 10.0 }, new object[] { "CMU", 13.0 }, new object[] { "IBM", 14.0 } }); EPAssertionUtil.AssertPropsPerRow(_testListener.LastOldData, fields, new object[][] { new object[] { "CMU", 3.0 }, new object[] { "IBM", 7.0 }, new object[] { "CMU", 8.0 }, new object[] { "IBM", 10.0 } }); }
private void RunAssertionExecCtx(bool soda) { _epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); SendTimer(0); string epl = "select " + "current_evaluation_context() as c0, " + "current_evaluation_context(), " + "current_evaluation_context().get_EngineURI() as c2 from SupportBean"; EPStatement stmt = SupportModelHelper.CreateByCompileOrParse(_epService, soda, epl, "my_user_object"); stmt.AddListener(_listener); Assert.AreEqual(typeof(EPLExpressionEvaluationContext), stmt.EventType.GetPropertyType("current_evaluation_context()")); _epService.EPRuntime.SendEvent(new SupportBean()); EventBean @event = _listener.AssertOneGetNewAndReset(); EPLExpressionEvaluationContext ctx = (EPLExpressionEvaluationContext)@event.Get("c0"); Assert.AreEqual(_epService.URI, ctx.EngineURI); Assert.AreEqual(stmt.Name, ctx.StatementName); Assert.AreEqual(-1, ctx.ContextPartitionId); Assert.AreEqual("my_user_object", ctx.StatementUserObject); Assert.AreEqual(_epService.URI, @event.Get("c2")); _epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionUngroupedWHavingWRelOpAllAnySome() { string[] fields = "c0,c1,c2".SplitCsv(); string epl = "select " + "value < all (select sum(intPrimitive) from SupportBean#keepall having last(theString) not in ('E1', 'E3')) as c0, " + "value < any (select sum(intPrimitive) from SupportBean#keepall having last(theString) not in ('E1', 'E3')) as c1, " + "value < some (select sum(intPrimitive) from SupportBean#keepall having last(theString) not in ('E1', 'E3')) as c2 " + "from SupportValueEvent"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); SendVEAndAssert(fields, 10, new object[] { null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean("E1", 19)); SendVEAndAssert(fields, 10, new object[] { null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 11)); SendVEAndAssert(fields, 10, new object[] { true, true, true }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 9)); SendVEAndAssert(fields, 10, new object[] { null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean("E4", -1000)); SendVEAndAssert(fields, 10, new object[] { false, false, false }); stmt.Dispose(); }
private void RunAssertionUngroupedWHavingWIn() { string[] fields = "c0,c1".SplitCsv(); string epl = "select value in (select sum(intPrimitive) from SupportBean#keepall having last(theString) != 'E1') as c0," + "value not in (select sum(intPrimitive) from SupportBean#keepall having last(theString) != 'E1') as c1 " + "from SupportValueEvent"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); SendVEAndAssert(fields, 10, new object[] { null, null }); _epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); SendVEAndAssert(fields, 10, new object[] { null, null }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); SendVEAndAssert(fields, 10, new object[] { true, false }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 1)); SendVEAndAssert(fields, 10, new object[] { false, true }); _epService.EPRuntime.SendEvent(new SupportBean("E4", -1)); SendVEAndAssert(fields, 10, new object[] { true, false }); stmt.Dispose(); }
public void TestJoin() { string[] fields = "book.bookId,item.itemId,amount".Split(','); _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean)); string stmtText = "select book.bookId,item.itemId,amount from " + "OrderEvent[books].std:firstunique(bookId) book, " + "OrderEvent[orderdetail.items].win:keepall() item " + "where book.bookId = item.productId " + "order by book.bookId, item.itemId"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); _epService.EPRuntime.SendEvent(MakeEventOne()); EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "10020", "A001", 10 }, new object[] { "10020", "A003", 30 }, new object[] { "10021", "A002", 25 } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "10020", "A001", 10 }, new object[] { "10020", "A003", 30 }, new object[] { "10021", "A002", 25 } }); _listener.Reset(); _epService.EPRuntime.SendEvent(MakeEventTwo()); EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "10022", "B001", 5 } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "10020", "A001", 10 }, new object[] { "10020", "A003", 30 }, new object[] { "10021", "A002", 25 }, new object[] { "10022", "B001", 5 } }); _listener.Reset(); _epService.EPRuntime.SendEvent(MakeEventThree()); EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "10021", "C001", 50 } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "10020", "A001", 10 }, new object[] { "10020", "A003", 30 }, new object[] { "10021", "A002", 25 }, new object[] { "10021", "C001", 50 }, new object[] { "10022", "B001", 5 } }); _listener.Reset(); _epService.EPRuntime.SendEvent(MakeEventFour()); Assert.IsFalse(_listener.IsInvoked); }
private void RunAssertionGroupedWHavingWEqualsAllAnySome() { string[] fields = "c0,c1,c2".SplitCsv(); string epl = "select " + "value = all (select sum(intPrimitive) from SupportBean#keepall group by theString having first(theString) != 'E1') as c0, " + "value = any (select sum(intPrimitive) from SupportBean#keepall group by theString having first(theString) != 'E1') as c1, " + "value = some (select sum(intPrimitive) from SupportBean#keepall group by theString having first(theString) != 'E1') as c2 " + "from SupportValueEvent"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); SendVEAndAssert(fields, 10, new object[] { true, false, false }); _epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); SendVEAndAssert(fields, 10, new object[] { true, false, false }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 10)); SendVEAndAssert(fields, 10, new object[] { true, true, true }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 11)); SendVEAndAssert(fields, 10, new object[] { false, true, true }); stmt.Dispose(); }
private void RunAssertionOnSelectWindowAgg(object[][] expectedType, object[] rowValues) { EPStatement stmt = _epService.EPAdministrator.CreateEPL("on SupportBean_S2 select " + "window(win.*) as c0," + "last(win.*) as c1, " + "first(win.*) as c2, " + "first(p1) as c3," + "window(p1) as c4," + "sorted(p1) as c5," + "minby(p1) as c6" + " from MyTable as win"); stmt.AddListener(_listener); _epService.EPRuntime.SendEvent(new SupportBean_S2(0)); EventBean @event = _listener.AssertOneGetNewAndReset(); foreach (string col in "c1,c2,c6".Split(',')) { AssertEventUnd(@event.Get(col), rowValues); } foreach (string col in "c0,c5".Split(',')) { AssertEventUnd(((object[][])@event.Get(col))[0], rowValues); } Assert.AreEqual("b", @event.Get("c3")); EPAssertionUtil.AssertEqualsExactOrder(new string[] { "b" }, (string[])@event.Get("c4")); stmt.Dispose(); }
private void RunAssertionSingleRowFunc(object[] rowValues) { // try join passing of params string eplJoin = "select " + this.GetType().FullName + ".MyServiceEventBean(mt) as c0, " + this.GetType().FullName + ".MyServiceObjectArray(mt) as c1 " + "from SupportBean_S2, MyTable as mt"; EPStatement stmtJoin = _epService.EPAdministrator.CreateEPL(eplJoin); stmtJoin.AddListener(_listener); _epService.EPRuntime.SendEvent(new SupportBean_S2(0)); EventBean result = _listener.AssertOneGetNewAndReset(); AssertEventUnd(result.Get("c0"), rowValues); AssertEventUnd(result.Get("c1"), rowValues); stmtJoin.Dispose(); // try subquery _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("pluginServiceEventBean", this.GetType().FullName, "MyServiceEventBean"); string eplSubquery = "select (select pluginServiceEventBean(mt) from MyTable as mt) as c0 " + "from SupportBean_S2"; EPStatement stmtSubquery = _epService.EPAdministrator.CreateEPL(eplSubquery); stmtSubquery.AddListener(_listener); _epService.EPRuntime.SendEvent(new SupportBean_S2(0)); result = _listener.AssertOneGetNewAndReset(); AssertEventUnd(result.Get("c0"), rowValues); stmtSubquery.Dispose(); }
public void TestCountPlusStar() { // Test for ESPER-118 var statementText = "select *, count(*) as cnt from " + typeof(SupportMarketDataBean).FullName; _selectTestView = _epService.EPAdministrator.CreateEPL(statementText); _selectTestView.AddListener(_listener); SendEvent("S0", 1L); Assert.IsTrue(_listener.GetAndClearIsInvoked()); Assert.AreEqual(1, _listener.LastNewData.Length); Assert.AreEqual(1L, _listener.LastNewData[0].Get("cnt")); Assert.AreEqual("S0", _listener.LastNewData[0].Get("symbol")); SendEvent("S1", 1L); Assert.IsTrue(_listener.GetAndClearIsInvoked()); Assert.AreEqual(1, _listener.LastNewData.Length); Assert.AreEqual(2L, _listener.LastNewData[0].Get("cnt")); Assert.AreEqual("S1", _listener.LastNewData[0].Get("symbol")); SendEvent("S2", 1L); Assert.IsTrue(_listener.GetAndClearIsInvoked()); Assert.AreEqual(1, _listener.LastNewData.Length); Assert.AreEqual(3L, _listener.LastNewData[0].Get("cnt")); Assert.AreEqual("S2", _listener.LastNewData[0].Get("symbol")); }
public void TestCountMain() { var statementText = "select count(*) as cnt from " + typeof(SupportMarketDataBean).FullName + ".win:time(1)"; _selectTestView = _epService.EPAdministrator.CreateEPL(statementText); _selectTestView.AddListener(_listener); SendEvent("DELL", 1L); Assert.IsTrue(_listener.GetAndClearIsInvoked()); Assert.AreEqual(1, _listener.LastNewData.Length); Assert.AreEqual(1L, _listener.LastNewData[0].Get("cnt")); SendEvent("DELL", 1L); Assert.IsTrue(_listener.GetAndClearIsInvoked()); Assert.AreEqual(1, _listener.LastNewData.Length); Assert.AreEqual(2L, _listener.LastNewData[0].Get("cnt")); SendEvent("DELL", 1L); Assert.IsTrue(_listener.GetAndClearIsInvoked()); Assert.AreEqual(1, _listener.LastNewData.Length); Assert.AreEqual(3L, _listener.LastNewData[0].Get("cnt")); // test invalid distinct SupportMessageAssertUtil.TryInvalid(_epService, "select count(distinct *) from " + typeof(SupportMarketDataBean).FullName, "Error starting statement: Failed to validate select-clause expression 'count(distinct *)': Invalid use of the 'distinct' keyword with count and wildcard"); }
private void RunAssertionSubSelStar(bool namedWindow) { string eplCreate = namedWindow ? "create window MyInfra.win:keepall() as (c0 string, c1 int)" : "create table MyInfra(c0 string primary key, c1 int)"; epService.EPAdministrator.CreateEPL(eplCreate); // create insert into string eplInsert = "insert into MyInfra select TheString as c0, IntPrimitive as c1 from SupportBean"; epService.EPAdministrator.CreateEPL(eplInsert); // create subquery string eplSubquery = "select p00, (select * from MyInfra) @eventbean as detail from SupportBean_S0"; EPStatement stmtSubquery = epService.EPAdministrator.CreateEPL(eplSubquery); stmtSubquery.AddListener(listener); epService.EPRuntime.SendEvent(new SupportBean_S0(0)); AssertReceived(null); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean_S0(0)); AssertReceived(new object[][] { new object[] { "E1", 1 } }); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); epService.EPRuntime.SendEvent(new SupportBean_S0(0)); AssertReceived(new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } }); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false); }
private void RunAssertionUngroupedUncorrelatedTwoAggStopStart() { string stmtText = "select (select avg(id) + max(id) from S1#length(3)) as value from S0"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); SendEventS0(1); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(100); SendEventS0(2); Assert.AreEqual(200.0, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(200); SendEventS0(3); Assert.AreEqual(350.0, _listener.AssertOneGetNewAndReset().Get("value")); stmt.Stop(); SendEventS1(10000); SendEventS0(4); Assert.IsFalse(_listener.IsInvoked); stmt.Start(); SendEventS1(10); SendEventS0(5); Assert.AreEqual(20.0, _listener.AssertOneGetNewAndReset().Get("value")); stmt.Dispose(); }
private void RunAssertionUngroupedUncorrelatedInSelect() { string stmtText = "select (select max(id) from S1#length(3)) as value from S0"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); SendEventS0(1); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(100); SendEventS0(2); Assert.AreEqual(100, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(200); SendEventS0(3); Assert.AreEqual(200, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(190); SendEventS0(4); Assert.AreEqual(200, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(180); SendEventS0(5); Assert.AreEqual(200, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(170); // note event leaving window SendEventS0(6); Assert.AreEqual(190, _listener.AssertOneGetNewAndReset().Get("value")); stmt.Dispose(); }
public void TestUnidirectionalJoinCount() { _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean)); string stmtText = "select count(*) from " + "OrderEvent orderEvent unidirectional, " + "OrderEvent[books] as book, " + "OrderEvent[orderdetail.items] item " + "where book.bookId = item.productId order by book.bookId asc, item.amount asc"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); _epService.EPRuntime.SendEvent(MakeEventOne()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "count(*)".Split(','), new object[] { 3L }); _epService.EPRuntime.SendEvent(MakeEventTwo()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "count(*)".Split(','), new object[] { 1L }); _epService.EPRuntime.SendEvent(MakeEventThree()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "count(*)".Split(','), new object[] { 1L }); _epService.EPRuntime.SendEvent(MakeEventFour()); Assert.IsFalse(_listener.IsInvoked); }
private void RunAssertionSubquerySelectStar(object[] rowValues) { string eplFiltered = "select (select * from MyTable where key = 'G1') as mt from SupportBean_S2"; RunAssertionSubquerySelectStar(rowValues, eplFiltered); string eplUnfiltered = "select (select * from MyTable) as mt from SupportBean_S2"; RunAssertionSubquerySelectStar(rowValues, eplUnfiltered); // With @eventbean string eplEventBean = "select (select * from MyTable) @eventbean as mt from SupportBean_S2"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(eplEventBean); stmt.AddListener(_listener); Assert.AreEqual(typeof(object[][]), stmt.EventType.GetPropertyType("mt")); Assert.AreSame(GetTablePublicType("MyTable"), stmt.EventType.GetFragmentType("mt").FragmentType); _epService.EPRuntime.SendEvent(new SupportBean_S2(0)); EventBean @event = _listener.AssertOneGetNewAndReset(); object[][] value = (object[][])@event.Get("mt"); AssertEventUnd(value[0], rowValues); Assert.AreSame(GetTablePublicType("MyTable"), ((EventBean[])@event.GetFragment("mt"))[0].EventType); stmt.Dispose(); }
public void TestJoinCount() { string[] fields = "count(*)".Split(','); _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean)); string stmtText = "select count(*) from " + "OrderEvent[books].std:unique(bookId) book, " + "OrderEvent[orderdetail.items].win:keepall() item " + "where book.bookId = item.productId"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); _epService.EPRuntime.SendEvent(MakeEventOne()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 3L }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 3L } }); _epService.EPRuntime.SendEvent(MakeEventTwo()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "count(*)".Split(','), new object[] { 4L }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 4L } }); _epService.EPRuntime.SendEvent(MakeEventThree()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "count(*)".Split(','), new object[] { 5L }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 5L } }); _epService.EPRuntime.SendEvent(MakeEventFour()); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(MakeEventOne()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "count(*)".Split(','), new object[] { 8L }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 8L } }); }
private void RunAssertionDeleteFlow() { SupportUpdateListener listenerDeleteFiltered = new SupportUpdateListener(); SupportUpdateListener listenerDeleteAll = new SupportUpdateListener(); string[] fields = "key,thesum".Split(','); epService.EPAdministrator.CreateEPL("create table varagg as (key string primary key, thesum sum(int))"); epService.EPAdministrator.CreateEPL("into table varagg select sum(IntPrimitive) as thesum from SupportBean group by TheString"); epService.EPAdministrator.CreateEPL("select varagg[p00].thesum as value from SupportBean_S0").AddListener(listener); EPStatement stmtDeleteFiltered = epService.EPAdministrator.CreateEPL("on SupportBean_S1(id = 1) delete from varagg where key = p10"); EPStatement stmtDeleteAll = epService.EPAdministrator.CreateEPL("on SupportBean_S1(id = 2) delete from varagg"); object[][] expectedType = new object[][] { new object[] { "key", typeof(string) }, new object[] { "thesum", typeof(int?) } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedType, stmtDeleteAll.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE); stmtDeleteFiltered.AddListener(listenerDeleteFiltered); stmtDeleteAll.AddListener(listenerDeleteAll); epService.EPRuntime.SendEvent(new SupportBean("G1", 10)); AssertValues(epService, listener, "G1,G2", new int?[] { 10, null }); epService.EPRuntime.SendEvent(new SupportBean("G2", 20)); AssertValues(epService, listener, "G1,G2", new int?[] { 10, 20 }); epService.EPRuntime.SendEvent(new SupportBean_S1(1, "G1")); AssertValues(epService, listener, "G1,G2", new int?[] { null, 20 }); EPAssertionUtil.AssertProps(listenerDeleteFiltered.AssertOneGetNewAndReset(), fields, new object[] { "G1", 10 }); epService.EPRuntime.SendEvent(new SupportBean_S1(2, null)); AssertValues(epService, listener, "G1,G2", new int?[] { null, null }); EPAssertionUtil.AssertProps(listenerDeleteAll.AssertOneGetNewAndReset(), fields, new object[] { "G2", 20 }); epService.EPAdministrator.DestroyAllStatements(); }
public void TestFirstUnique() { _epService.EPAdministrator.Configuration.AddEventType("SupportBean", typeof(SupportBean)); _epService.EPAdministrator.Configuration.AddEventType("SupportBean_A", typeof(SupportBean_A)); string[] fields = new string[] { "TheString", "IntPrimitive" }; string stmtTextCreateOne = "create window MyWindowOne.std:firstunique(TheString) as select * from SupportBean"; EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreateOne); _epService.EPAdministrator.CreateEPL("insert into MyWindowOne select * from SupportBean"); EPStatement stmtDelete = _epService.EPAdministrator.CreateEPL("on SupportBean_A a delete from MyWindowOne where TheString=a.id"); stmtDelete.AddListener(_listenerDelete); _epService.EPRuntime.SendEvent(new SupportBean("A", 1)); _epService.EPRuntime.SendEvent(new SupportBean("A", 2)); _epService.EPRuntime.SendEvent(new SupportBean_A("A")); EPAssertionUtil.AssertProps(_listenerDelete.AssertOneGetNewAndReset(), fields, new object[] { "A", 1 }); _epService.EPRuntime.SendEvent(new SupportBean("A", 3)); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "A", 3 } }); _epService.EPRuntime.SendEvent(new SupportBean_A("A")); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null); }
private void RunAssertionUpdateIStreamSetMapProps(EventRepresentationChoice eventRepresentationEnum) { // test update-istream with map _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyInfraType(simple string, myarray int[], mymap com.espertech.esper.compat.collections.StringMap)"); EPStatement stmtUpdTwo = _epService.EPAdministrator.CreateEPL("update istream MyInfraType set simple='A', mymap('abc') = 1, myarray[2] = 10"); stmtUpdTwo.AddListener(_listener); if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { null, new int[10], new Dictionary <string, Object>() }, "MyInfraType"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyInfraType"); } else if (eventRepresentationEnum.IsAvroEvent()) { GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyInfraType").AsRecordSchema()); theEvent.Put("myarray", Collections.List(0, 0, 0, 0, 0)); theEvent.Put("mymap", new Dictionary <string, object>()); _epService.EPRuntime.SendEventAvro(theEvent, "MyInfraType"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps(_listener.AssertPairGetIRAndReset(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[] { "A", 1, 10 }, new Object[] { null, null, 0 }); _epService.Initialize(); }
private void RunAssertionGroupedWHavingWExists() { EPStatement stmtNamedWindow = _epService.EPAdministrator.CreateEPL("create window MyWindow#keepall as (key string, anint int)"); EPStatement stmtInsert = _epService.EPAdministrator.CreateEPL("insert into MyWindow(key, anint) select id, value from SupportIdAndValueEvent"); string[] fields = "c0,c1".SplitCsv(); string epl = "select exists (select sum(anint) from MyWindow group by key having sum(anint) < 15) as c0," + "not exists (select sum(anint) from MyWindow group by key having sum(anint) < 15) as c1 from SupportValueEvent"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); SendVEAndAssert(fields, new object[] { false, true }); _epService.EPRuntime.SendEvent(new SupportIdAndValueEvent("E1", 19)); SendVEAndAssert(fields, new object[] { false, true }); _epService.EPRuntime.SendEvent(new SupportIdAndValueEvent("E2", 12)); SendVEAndAssert(fields, new object[] { true, false }); _epService.EPRuntime.ExecuteQuery("delete from MyWindow"); SendVEAndAssert(fields, new object[] { false, true }); stmt.Dispose(); stmtNamedWindow.Dispose(); stmtInsert.Dispose(); }
public void TestCreateNamedAfterNamed() { // create window string stmtTextCreateOne = "create window MyWindow#keepall as SupportBean"; EPStatement stmtCreateOne = _epService.EPAdministrator.CreateEPL(stmtTextCreateOne); stmtCreateOne.AddListener(_listeners[0]); // create window string stmtTextCreateTwo = "create window MyWindowTwo#keepall as MyWindow"; EPStatement stmtCreateTwo = _epService.EPAdministrator.CreateEPL(stmtTextCreateTwo); stmtCreateTwo.AddListener(_listeners[1]); // create insert into string stmtTextInsertOne = "insert into MyWindow select * from SupportBean"; _epService.EPAdministrator.CreateEPL(stmtTextInsertOne); // create consumer string stmtTextSelectOne = "select theString from MyWindow"; EPStatement stmtSelectOne = _epService.EPAdministrator.CreateEPL(stmtTextSelectOne); stmtSelectOne.AddListener(_listeners[2]); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); var fields = new string[] { "theString" }; EPAssertionUtil.AssertProps(_listeners[0].AssertOneGetNewAndReset(), fields, new Object[] { "E1" }); EPAssertionUtil.AssertProps(_listeners[2].AssertOneGetNewAndReset(), fields, new Object[] { "E1" }); }
private void RunAssertionInSimple() { string stmtText = "select id from S0 where id in (select max(id) from S1#length(2))"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); SendEventS0(1); Assert.IsFalse(_listener.IsInvoked); SendEventS1(100); SendEventS0(2); Assert.IsFalse(_listener.IsInvoked); SendEventS0(100); Assert.AreEqual(100, _listener.AssertOneGetNewAndReset().Get("id")); SendEventS0(200); Assert.IsFalse(_listener.IsInvoked); SendEventS1(-1); SendEventS1(-1); SendEventS0(-1); Assert.AreEqual(-1, _listener.AssertOneGetNewAndReset().Get("id")); }
private void RunAssertionDynamicDateFormat() { var epl = "select " + "cast(a,date,dateformat:b) as c0," + "cast(a,long,dateformat:b) as c1" + " from SupportBean_StringAlphabetic"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); RunAssertionDynamicDateFormat("20100502", "yyyyMMdd"); RunAssertionDynamicDateFormat("20100502101112", "yyyyMMddhhmmss"); RunAssertionDynamicDateFormat(null, "yyyyMMdd"); // invalid date try { _epService.EPRuntime.SendEvent(new SupportBean_StringAlphabetic("x", "yyyyMMddhhmmss")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Exception parsing date 'x' format 'yyyyMMddhhmmss': String was not recognized as a valid DateTime"); } #if NO_ERROR_IN_CLR // invalid format try { _epService.EPRuntime.SendEvent(new SupportBean_StringAlphabetic("20100502", "UUHHYY")); } catch (EPException ex) { SupportMessageAssertUtil.AssertMessageContains(ex, "Illegal pattern character 'U'"); } #endif stmt.Dispose(); }
public void TestPerformanceOneCriteria() { String stmtText = "select (select P10 from S1#length(100000) where Id = s0.Id) as value from S0 as s0"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); // preload with 10k events for (int i = 0; i < 10000; i++) { _epService.EPRuntime.SendEvent(new SupportBean_S1(i, Convert.ToString(i))); } long startTime = PerformanceObserver.MilliTime; for (int i = 0; i < 10000; i++) { int index = 5000 + i % 1000; _epService.EPRuntime.SendEvent(new SupportBean_S0(index, Convert.ToString(index))); Assert.AreEqual(Convert.ToString(index), _listener.AssertOneGetNewAndReset().Get("value")); } long endTime = PerformanceObserver.MilliTime; long delta = endTime - startTime; Assert.IsTrue(delta < 1000, "Failed perf test, delta=" + delta); }
public void TestOnDelete() { _epService.EPAdministrator.CreateEPL("create window MyWindow#keepall as select * from SupportBean"); _epService.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportBean"); _epService.EPAdministrator.CreateEPL("on SupportBean_A delete from MyWindow where TheString = id"); string[] fields = "firsteverstring,lasteverstring,counteverall".Split(','); string epl = "select firstever(TheString) as firsteverstring, " + "lastever(TheString) as lasteverstring," + "countever(*) as counteverall from MyWindow"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); _epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E1", 1L }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 20)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E2", 2L }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 30)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E3", 3L }); _epService.EPRuntime.SendEvent(new SupportBean_A("E2")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E3", 3L }); _epService.EPRuntime.SendEvent(new SupportBean_A("E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E3", 3L }); _epService.EPRuntime.SendEvent(new SupportBean_A("E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "E3", 3L }); }
public void TestMultipleDataWindowIntersect() { string stmtTextCreate = "create window MyWindow#unique(TheString)#length(2) as select * from SupportBean"; EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate); stmtCreate.AddListener(_listenerWindow); string stmtTextInsertOne = "insert into MyWindow select * from SupportBean"; _epService.EPAdministrator.CreateEPL(stmtTextInsertOne); string stmtTextUpdate = "on SupportBean_A update MyWindow set IntPrimitive=IntPrimitive*100 where TheString=id"; _epService.EPAdministrator.CreateEPL(stmtTextUpdate); _epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 3)); _epService.EPRuntime.SendEvent(new SupportBean_A("E2")); EventBean[] newevents = _listenerWindow.LastNewData; EventBean[] oldevents = _listenerWindow.LastOldData; Assert.AreEqual(1, newevents.Length); EPAssertionUtil.AssertProps(newevents[0], "IntPrimitive".Split(','), new object[] { 300 }); Assert.AreEqual(1, oldevents.Length); oldevents = EPAssertionUtil.Sort(oldevents, "TheString"); EPAssertionUtil.AssertPropsPerRow(oldevents, "TheString,IntPrimitive".Split(','), new object[][] { new object[] { "E2", 3 } }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), "TheString,IntPrimitive".Split(','), new object[][] { new object[] { "E1", 2 }, new object[] { "E2", 300 } }); }
private void RunAssertionFirstLastEver(bool soda) { string[] fields = "firsteverstring,firsteverint,lasteverstring,lasteverint,counteverstar,counteverexpr,counteverexprfilter".Split(','); string epl = "select " + "firstever(TheString) as firsteverstring, " + "lastever(TheString) as lasteverstring, " + "firstever(IntPrimitive) as firsteverint, " + "lastever(IntPrimitive) as lasteverint, " + "countever(*) as counteverstar, " + "countever(IntBoxed) as counteverexpr, " + "countever(IntBoxed,BoolPrimitive) as counteverexprfilter " + "from SupportBean#length(2)"; EPStatement stmt = SupportModelHelper.CreateByCompileOrParse(_epService, soda, epl); stmt.AddListener(_listener); MakeSendBean("E1", 10, 100, true); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", 10, "E1", 10, 1L, 1L, 1L }); MakeSendBean("E2", 11, null, true); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", 10, "E2", 11, 2L, 1L, 1L }); MakeSendBean("E3", 12, 120, false); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", 10, "E3", 12, 3L, 2L, 1L }); stmt.Dispose(); }
public void TestOnUpdateWTypeWiden() { SupportUpdateListener listenerUpdate = new SupportUpdateListener(); string[] fields = "keyOne,keyTwo,p0".Split(','); _epService.EPAdministrator.CreateEPL("create table varagg as (" + "keyOne string primary key, keyTwo int primary key, p0 long)"); _epService.EPAdministrator.CreateEPL("on SupportBean merge varagg where TheString = keyOne and " + "IntPrimitive = keyTwo when not matched then insert select TheString as keyOne, IntPrimitive as keyTwo, 1 as p0"); _epService.EPAdministrator.CreateEPL("select varagg[p00, id].p0 as value from SupportBean_S0").AddListener(_listener); EPStatement stmtUpdate = _epService.EPAdministrator.CreateEPL("on MyUpdateEvent update varagg set p0 = newValue " + "where k1 = keyOne and k2 = keyTwo"); stmtUpdate.AddListener(listenerUpdate); object[][] expectedType = new object[][] { new object[] { "keyOne", typeof(string) }, new object[] { "keyTwo", typeof(int) }, new object[] { "p0", typeof(long) } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedType, stmtUpdate.EventType, EventTypeAssertionEnum.NAME, EventTypeAssertionEnum.TYPE); _epService.EPRuntime.SendEvent(new SupportBean("G1", 10)); AssertValues(new object[][] { new object[] { "G1", 10 } }, new long?[] { 1L }); _epService.EPRuntime.SendEvent(new MyUpdateEvent("G1", 10, 2)); AssertValues(new object[][] { new object[] { "G1", 10 } }, new long?[] { 2L }); EPAssertionUtil.AssertProps(listenerUpdate.LastNewData[0], fields, new object[] { "G1", 10, 2L }); EPAssertionUtil.AssertProps(listenerUpdate.GetAndResetLastOldData()[0], fields, new object[] { "G1", 10, 1L }); // try property method invocation _epService.EPAdministrator.CreateEPL("create table MyTableSuppBean as (sb SupportBean)"); _epService.EPAdministrator.CreateEPL("on SupportBean_S0 update MyTableSuppBean sb set sb.set_LongPrimitive(10)"); }
private void RunAssertion(EPStatement stmt) { var fields = "TheString".Split(','); stmt.AddListener(_listener); SendEvent("E1", 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" } }); SendEvent("E2", 2); Assert.IsFalse(_listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" } }); SendEvent("E3", 3); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E1" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, null); SendEvent("E4", 4); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E4" } }); SendEvent("E5", 5); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E4" } }); SendEvent("E6", 6); EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "E4" } }); EPAssertionUtil.AssertPropsPerRow(_listener.LastOldData, fields, new object[][] { new object[] { "E1" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, null); }