private void TryAssertion2Events(EPServiceProvider epService, SupportUpdateListener listener) { SendBeanEvent(epService, 1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 2); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 9); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 2); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 2); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 2); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanEvent(epService, 2); Assert.IsTrue(listener.GetAndClearIsInvoked()); }
private void RunAssertionCount(EPServiceProvider epService) { string statementText = "select count(*) as cnt from " + typeof(SupportMarketDataBean).FullName + "#time(1)"; EPStatement stmt = epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "DELL", 1L); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(1L, listener.LastNewData[0].Get("cnt")); SendEvent(epService, "DELL", 1L); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(2L, listener.LastNewData[0].Get("cnt")); SendEvent(epService, "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"); stmt.Dispose(); }
private void RunAssertionCountPlusStar(EPServiceProvider epService) { // Test for ESPER-118 string statementText = "select *, count(*) as cnt from " + typeof(SupportMarketDataBean).FullName; EPStatement stmt = epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "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(epService, "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(epService, "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")); stmt.Dispose(); }
private void RunAssertionSelectAvgExprGroupBy(EPServiceProvider epService) { string stmtText = "select istream avg(price) as aprice, symbol from " + typeof(SupportMarketDataBean).FullName + "#length(2) group by symbol"; EPStatement statement = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); statement.Events += listener.Update; SendEvent(epService, "A", 1); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1.0, listener.LastNewData[0].Get("aprice")); Assert.AreEqual("A", listener.LastNewData[0].Get("symbol")); SendEvent(epService, "B", 3); //there is no A->1 as we already got it out Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(3.0, listener.LastNewData[0].Get("aprice")); Assert.AreEqual("B", listener.LastNewData[0].Get("symbol")); SendEvent(epService, "B", 5); // there is NOW a A->null entry Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(2, listener.LastNewData.Length); Assert.AreEqual(null, listener.LastNewData[1].Get("aprice")); Assert.AreEqual(4.0, listener.LastNewData[0].Get("aprice")); Assert.AreEqual("B", listener.LastNewData[0].Get("symbol")); SendEvent(epService, "A", 10); SendEvent(epService, "A", 20); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(2, listener.LastNewData.Length); Assert.AreEqual(15.0, listener.LastNewData[0].Get("aprice")); //A Assert.AreEqual(null, listener.LastNewData[1].Get("aprice")); //B statement.Dispose(); }
private void RunAssertionFilterBehavior(EPServiceProvider epService) { epService.EPAdministrator.CreateEPL("create table varaggFB (total count(*))"); epService.EPAdministrator.CreateEPL("into table varaggFB select count(*) as total from SupportBean_S0"); var listener = new SupportUpdateListener(); epService.EPAdministrator.CreateEPL("select * from SupportBean(varaggFB.total = IntPrimitive)").Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(0)); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean_S0(0)); epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("E1", 3)); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPAdministrator.DestroyAllStatements(); }
public void TestIntersectSubselect() { Init(false); var text = "select * from SupportBean_S0 where p00 in (select TheString from SupportBean.win:length(2).std:unique(IntPrimitive) retain-intersection)"; var stmt = _epService.EPAdministrator.CreateEPL(text); stmt.Events += _listener.Update; SendEvent("E1", 1); SendEvent("E2", 2); SendEvent("E3", 3); // throws out E1 SendEvent("E4", 2); // throws out E2 SendEvent("E5", 1); // throws out E3 _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E1")); Assert.IsFalse(_listener.GetAndClearIsInvoked()); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E2")); Assert.IsFalse(_listener.GetAndClearIsInvoked()); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E3")); Assert.IsFalse(_listener.GetAndClearIsInvoked()); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E4")); Assert.IsTrue(_listener.GetAndClearIsInvoked()); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E5")); Assert.IsTrue(_listener.GetAndClearIsInvoked()); }
private void RunAssertionOrderOfEvaluationSubselectFirst(EPServiceProvider epService) { var listener = new SupportUpdateListener(); epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); string epl = "select * from SupportBean(IntPrimitive<10) where IntPrimitive not in (select IntPrimitive from SupportBean#unique(IntPrimitive))"; EPStatement stmtOne = epService.EPAdministrator.CreateEPL(epl); stmtOne.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 5)); Assert.IsFalse(listener.GetAndClearIsInvoked()); stmtOne.Dispose(); string eplTwo = "select * from SupportBean where IntPrimitive not in (select IntPrimitive from SupportBean(IntPrimitive<10)#unique(IntPrimitive))"; EPStatement stmtTwo = epService.EPAdministrator.CreateEPL(eplTwo); stmtTwo.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 5)); Assert.IsFalse(listener.GetAndClearIsInvoked()); stmtTwo.Dispose(); }
private void RunAssertionDiscreteDelivery(EPServiceProvider epService) { SendTimer(epService, 0); EPStatement stmt = epService.EPAdministrator.CreateEPL("select * from SupportBean#time_batch(1) for discrete_delivery"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); epService.EPRuntime.SendEvent(new SupportBean("E3", 1)); SendTimer(epService, 1000); Assert.AreEqual(3, listener.NewDataList.Count); EPAssertionUtil.AssertPropsPerRow(listener.NewDataList[0], "TheString,IntPrimitive".Split(','), new object[][] { new object[] { "E1", 1 } }); EPAssertionUtil.AssertPropsPerRow(listener.NewDataList[1], "TheString,IntPrimitive".Split(','), new object[][] { new object[] { "E2", 2 } }); EPAssertionUtil.AssertPropsPerRow(listener.NewDataList[2], "TheString,IntPrimitive".Split(','), new object[][] { new object[] { "E3", 1 } }); listener.Reset(); // test no-event delivery epService.EPAdministrator.Configuration.AddEventType("ObjectEvent", typeof(Object)); string epl = "SELECT * FROM ObjectEvent OUTPUT ALL EVERY 1 seconds for discrete_delivery"; epService.EPAdministrator.CreateEPL(epl).Events += listener.Update; epService.EPRuntime.SendEvent(new Object()); SendTimer(epService, 2000); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendTimer(epService, 3000); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPAdministrator.DestroyAllStatements(); }
public void TestDiscreteDelivery() { SendTimer(0); EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from SupportBean.win:time_batch(1) for discrete_delivery"); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); _epService.EPRuntime.SendEvent(new SupportBean("E3", 1)); SendTimer(1000); Assert.AreEqual(3, _listener.NewDataList.Count); EPAssertionUtil.AssertPropsPerRow(_listener.NewDataList[0], "TheString,IntPrimitive".Split(','), new Object[][] { new Object[] { "E1", 1 } }); EPAssertionUtil.AssertPropsPerRow(_listener.NewDataList[1], "TheString,IntPrimitive".Split(','), new Object[][] { new Object[] { "E2", 2 } }); EPAssertionUtil.AssertPropsPerRow(_listener.NewDataList[2], "TheString,IntPrimitive".Split(','), new Object[][] { new Object[] { "E3", 1 } }); _listener.Reset(); // test no-event delivery _epService.EPAdministrator.Configuration.AddEventType <object>("ObjectEvent"); String epl = "SELECT * FROM ObjectEvent OUTPUT ALL EVERY 1 seconds for discrete_delivery"; _epService.EPAdministrator.CreateEPL(epl).Events += _listener.Update; _epService.EPRuntime.SendEvent(new Object()); SendTimer(2000); Assert.IsTrue(_listener.GetAndClearIsInvoked()); SendTimer(3000); Assert.IsFalse(_listener.GetAndClearIsInvoked()); }
private void RunAssertion2Events() { SendBeanEvent(1); Assert.IsFalse(_listener.GetAndClearIsInvoked()); SendBeanEvent(2); Assert.IsTrue(_listener.GetAndClearIsInvoked()); SendBeanEvent(9); Assert.IsFalse(_listener.GetAndClearIsInvoked()); SendBeanEvent(1); Assert.IsFalse(_listener.GetAndClearIsInvoked()); SendBeanEvent(1); Assert.IsFalse(_listener.GetAndClearIsInvoked()); SendBeanEvent(2); Assert.IsTrue(_listener.GetAndClearIsInvoked()); SendBeanEvent(1); Assert.IsFalse(_listener.GetAndClearIsInvoked()); SendBeanEvent(2); Assert.IsTrue(_listener.GetAndClearIsInvoked()); SendBeanEvent(2); Assert.IsFalse(_listener.GetAndClearIsInvoked()); SendBeanEvent(2); Assert.IsTrue(_listener.GetAndClearIsInvoked()); }
private void RunAssertionPatternSelect(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean)); epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement stmt = epService.EPAdministrator.CreateEPL("select * from pattern [" + "every r=OrderEvent[books][reviews] -> SupportBean(IntPrimitive = r[0].reviewId)]"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventOne()); epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventFour()); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("E2", -1)); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("E2", 201)); Assert.IsTrue(listener.GetAndClearIsInvoked()); stmt.Dispose(); }
private void RunAssertionPattern(EPServiceProvider epService, long startTime, string patternExpr, params long[] flipTimes) { EPServiceProviderIsolated isolated = epService.GetEPServiceIsolated("iso"); isolated.EPRuntime.SendEvent(new CurrentTimeEvent(startTime)); SupportUpdateListener listener = new SupportUpdateListener(); EPStatement stmt = isolated.EPAdministrator.CreateEPL("select * from pattern[" + patternExpr + "]", "s0", null); stmt.AddListener(listener); int count = 0; foreach (long flipTime in flipTimes) { isolated.EPRuntime.SendEvent(new CurrentTimeEvent(flipTime - 1)); Assert.IsFalse(listener.GetAndClearIsInvoked(), "Failed for flip " + count); isolated.EPRuntime.SendEvent(new CurrentTimeEvent(flipTime)); Assert.IsTrue(listener.GetAndClearIsInvoked(), "Failed for flip " + count); count++; } isolated.EPRuntime.SendEvent(new CurrentTimeEvent(long.MaxValue)); Assert.IsFalse(listener.GetAndClearIsInvoked()); isolated.Dispose(); }
private void RunAssertionUnionSubselect(EPServiceProvider epService) { string text = "select * from SupportBean_S0 where p00 in (select TheString from SupportBean#length(2)#unique(IntPrimitive) retain-union)"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "E1", 1); SendEvent(epService, "E2", 2); SendEvent(epService, "E3", 3); SendEvent(epService, "E4", 2); // throws out E1 SendEvent(epService, "E5", 1); // retains E3 epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E1")); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E2")); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E3")); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E4")); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E5")); Assert.IsTrue(listener.GetAndClearIsInvoked()); stmt.Dispose(); }
private void RunAssertionCount(EPServiceProvider epService) { // Create the EPL statement and add a listener string statementText = "select symbol, sum(volume) from " + EVENT_NAME + "#length(5) output first every 3 events"; EPStatement statement = epService.EPAdministrator.CreateEPL(statementText); var updateListener = new SupportUpdateListener(); statement.Events += updateListener.Update; updateListener.Reset(); // Send the first event of the batch, should be output SendEventLong(epService, 10L); AssertEvent(updateListener, 10L); // Send the second event of the batch, not output, used // for updating the aggregate value only SendEventLong(epService, 20L); Assert.IsFalse(updateListener.GetAndClearIsInvoked()); // Send the third event of the batch, still not output, // but should reset the batch SendEventLong(epService, 30L); Assert.IsFalse(updateListener.GetAndClearIsInvoked()); // First event, next batch, aggregate value should be // 10 + 20 + 30 + 40 = 100 SendEventLong(epService, 40L); AssertEvent(updateListener, 100L); // Next event again not output SendEventLong(epService, 50L); Assert.IsFalse(updateListener.GetAndClearIsInvoked()); statement.Dispose(); }
private void RunAssertionSelectAvgStdGroupByUni(EPServiceProvider epService) { string stmtText = "select istream average as aprice from " + typeof(SupportMarketDataBean).FullName + "#groupwin(symbol)#length(2)#uni(price)"; EPStatement statement = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); statement.Events += listener.Update; SendEvent(epService, "A", 1); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(1.0, listener.LastNewData[0].Get("aprice")); SendEvent(epService, "B", 3); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(3.0, listener.LastNewData[0].Get("aprice")); SendEvent(epService, "A", 3); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(2.0, listener.LastNewData[0].Get("aprice")); SendEvent(epService, "A", 10); SendEvent(epService, "A", 20); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(15.0, listener.LastNewData[0].Get("aprice")); statement.Dispose(); }
private void RunAssertionWithinMayMaxMonthScoped(bool hasMax) { 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 SupportBean) where " + (hasMax ? "timer:withinmax(1 month, 10)" : "timer:within(1 month)") + "]").Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendCurrentTimeWithMinus(epService, "2002-03-01T9:00:00.000", 1); epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendCurrentTime(epService, "2002-03-01T9:00:00.000"); epService.EPRuntime.SendEvent(new SupportBean("E3", 0)); Assert.IsFalse(listener.GetAndClearIsInvoked()); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
private void TryAssertionFirstUniqueAndFirstLength(EPServiceProvider epService, SupportUpdateListener listener, EPStatement stmt) { var fields = new string[] { "TheString", "IntPrimitive" }; SendEvent(epService, "E1", 1); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } }); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 }); SendEvent(epService, "E1", 2); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 } }); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", 2 }); SendEvent(epService, "E2", 1); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 }, new object[] { "E2", 1 } }); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2", 1 }); SendEvent(epService, "E2", 3); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 }, new object[] { "E2", 1 } }); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendEvent(epService, "E3", 3); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 }, new object[] { "E2", 1 }, new object[] { "E3", 3 } }); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 }); SendEvent(epService, "E3", 4); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 }, new object[] { "E2", 1 }, new object[] { "E3", 3 } }); Assert.IsFalse(listener.GetAndClearIsInvoked()); }
public void TestSendMapNative() { var statementText = "select * from MyObjectArrayEvent.win:length(5)"; var statement = _epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); statement.Events += listener.Update; // send event var theEvent = new Object[] { 3, "some string", SupportBeanComplexProps.MakeDefaultBean() }; _epService.EPRuntime.SendEvent(theEvent, "MyObjectArrayEvent"); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreSame(theEvent, listener.LastNewData[0].Underlying); Assert.AreEqual(3, listener.LastNewData[0].Get("myInt")); Assert.AreEqual("some string", listener.LastNewData[0].Get("myString")); // send event theEvent = new Object[] { 4, "string2", null }; _epService.EPRuntime.SendEvent(theEvent, "MyObjectArrayEvent"); Assert.IsTrue(listener.GetAndClearIsInvoked()); Assert.AreEqual(1, listener.LastNewData.Length); Assert.AreEqual(theEvent, listener.LastNewData[0].Underlying); Assert.AreEqual(4, listener.LastNewData[0].Get("myInt")); Assert.AreEqual("string2", listener.LastNewData[0].Get("myString")); }
private void RunAssertionHavingWildcardSelect(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); string epl = "select * " + "from SupportBean#length_batch(2) " + "where IntPrimitive>0 " + "having count(*)=2"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("E3", 1)); epService.EPRuntime.SendEvent(new SupportBean("E4", 1)); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("E3", 0)); epService.EPRuntime.SendEvent(new SupportBean("E4", 1)); Assert.IsFalse(listener.GetAndClearIsInvoked()); stmt.Dispose(); }
private void RunAssertionSubSelect(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean)); epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement stmt = epService.EPAdministrator.CreateEPL("select TheString from SupportBean s0 where " + "exists (select * from OrderEvent[books][reviews]#unique(reviewId) where reviewId = s0.IntPrimitive)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventOne()); epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventFour()); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("E2", -1)); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("E2", 201)); Assert.IsTrue(listener.GetAndClearIsInvoked()); stmt.Dispose(); }
public void TestCount() { // Create the EPL statement and add a listener var statementText = "select Symbol, sum(Volume) from " + EVENT_NAME + ".win:length(5) output first every 3 events"; var statement = _epService.EPAdministrator.CreateEPL(statementText); var updateListener = new SupportUpdateListener(); statement.AddListener(updateListener); updateListener.Reset(); // Send the first event of the batch, should be output SendEventLong(10L); AssertEvent(updateListener, 10L); // Send the second event of the batch, not output, used // for updating the aggregate value only SendEventLong(20L); Assert.IsFalse(updateListener.GetAndClearIsInvoked()); // Send the third event of the batch, still not output, // but should reset the batch SendEventLong(30L); Assert.IsFalse(updateListener.GetAndClearIsInvoked()); // First event, next batch, aggregate value should be // 10 + 20 + 30 + 40 = 100 SendEventLong(40L); AssertEvent(updateListener, 100L); // Next event again not output SendEventLong(50L); Assert.IsFalse(updateListener.GetAndClearIsInvoked()); }
public void TestIsolateFilter() { EPStatement stmt = _epService.EPAdministrator.CreateEPL( "select * from pattern [every a=SupportBean -> b=SupportBean(TheString=a.TheString)]"); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsFalse(_listener.GetAndClearIsInvoked()); EPServiceProviderIsolated unit = _epService.GetEPServiceIsolated("i1"); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "i1" }, _epService.EPServiceIsolatedNames); // send fake to wrong place unit.EPRuntime.SendEvent(new SupportBean("E1", -1)); unit.EPAdministrator.AddStatement(stmt); // send to 'wrong' engine _epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); Assert.IsFalse(_listener.GetAndClearIsInvoked()); // send to 'right' engine unit.EPRuntime.SendEvent(new SupportBean("E1", 3)); EPAssertionUtil.AssertProps( _listener.AssertOneGetNewAndReset(), "a.TheString,a.IntPrimitive,b.IntPrimitive".Split(','), new Object[] { "E1", 1, 3 } ); // send second pair, and a fake to the wrong place unit.EPRuntime.SendEvent(new SupportBean("E2", 4)); _epService.EPRuntime.SendEvent(new SupportBean("E2", -1)); unit.EPAdministrator.RemoveStatement(stmt); // send to 'wrong' engine unit.EPRuntime.SendEvent(new SupportBean("E2", 5)); Assert.IsFalse(_listener.GetAndClearIsInvoked()); // send to 'right' engine _epService.EPRuntime.SendEvent(new SupportBean("E2", 6)); EPAssertionUtil.AssertProps( _listener.AssertOneGetNewAndReset(), "a.TheString,a.IntPrimitive,b.IntPrimitive".Split(','), new Object[] { "E2", 4, 6 } ); _epService.EPAdministrator.DestroyAllStatements(); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "i1" }, _epService.EPServiceIsolatedNames); _epService.GetEPServiceIsolated("i1").Dispose(); EPAssertionUtil.AssertEqualsAnyOrder(new string[0], _epService.EPServiceIsolatedNames); }
private void TryAssertionAnyOf(EPServiceProvider epService, SupportUpdateListener listener) { epService.EPRuntime.SendEvent(MakeContainerEvent("A")); Assert.IsTrue(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(MakeContainerEvent("B")); Assert.IsFalse(listener.GetAndClearIsInvoked()); }
private void RunAssertionTimeToLive(EPServiceProvider epService) { epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); string[] fields = "id".Split(','); string epl = "select irstream * from SupportBeanTimestamp#timetolive(timestamp)"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "E1", 1000); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" } }); SendEvent(epService, "E2", 500); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E2" }, new object[] { "E1" } }); epService.EPRuntime.SendEvent(new CurrentTimeEvent(499)); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new CurrentTimeEvent(500)); EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E2" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" } }); SendEvent(epService, "E3", 200); EPAssertionUtil.AssertProps(listener.AssertPairGetIRAndReset(), fields, new object[] { "E3" }, new object[] { "E3" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" } }); SendEvent(epService, "E4", 1200); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E4" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" }, new object[] { "E4" } }); SendEvent(epService, "E5", 1000); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E5" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" }, new object[] { "E4" }, new object[] { "E5" } }); epService.EPRuntime.SendEvent(new CurrentTimeEvent(999)); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); EPAssertionUtil.AssertPropsPerRowAnyOrder(listener.GetAndResetDataListsFlattened(), fields, null, new object[][] { new object[] { "E1" }, new object[] { "E5" } }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E4" } }); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1199)); Assert.IsFalse(listener.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1200)); EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E4" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, null); SendEvent(epService, "E6", 1200); EPAssertionUtil.AssertProps(listener.AssertPairGetIRAndReset(), fields, new object[] { "E6" }, new object[] { "E6" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, null); epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionSimpleOneParameter(EPServiceProvider epService) { string stmt = "select * from " + typeof(SupportBean).FullName + "(TheString=?)"; EPPreparedStatement prepared = epService.EPAdministrator.PrepareEPL(stmt); prepared.SetObject(1, "e1"); EPStatement statement = epService.EPAdministrator.Create(prepared); var listenerOne = new SupportUpdateListener(); statement.Events += listenerOne.Update; Assert.AreEqual("select * from " + typeof(SupportBean).FullName + "(TheString=\"e1\")", statement.Text); prepared.SetObject(1, "e2"); statement = epService.EPAdministrator.Create(prepared); var listenerTwo = new SupportUpdateListener(); statement.Events += listenerTwo.Update; Assert.AreEqual("select * from com.espertech.esper.supportregression.bean.SupportBean(TheString=\"e2\")", statement.Text); epService.EPRuntime.SendEvent(new SupportBean("e2", 10)); Assert.IsFalse(listenerOne.IsInvoked); Assert.IsTrue(listenerTwo.GetAndClearIsInvoked()); epService.EPRuntime.SendEvent(new SupportBean("e1", 10)); Assert.IsFalse(listenerTwo.IsInvoked); Assert.IsTrue(listenerOne.GetAndClearIsInvoked()); // Test substitution parameter and inheritance in key matching epService.EPAdministrator.Configuration.AddEventType("MyEventOne", typeof(MyEventOne)); string epl = "select * from MyEventOne(key = ?)"; EPPreparedStatement preparedStatement = epService.EPAdministrator.PrepareEPL(epl); var lKey = new MyObjectKeyInterface(); preparedStatement.SetObject(1, lKey); statement = epService.EPAdministrator.Create(preparedStatement); statement.Events += listenerOne.Update; epService.EPRuntime.SendEvent(new MyEventOne(lKey)); Assert.IsTrue(listenerOne.GetAndClearIsInvoked()); // Test substitution parameter and concrete subclass in key matching epService.EPAdministrator.Configuration.AddEventType("MyEventTwo", typeof(MyEventTwo)); epl = "select * from MyEventTwo where key = ?"; preparedStatement = epService.EPAdministrator.PrepareEPL(epl); var cKey = new MyObjectKeyConcrete(); preparedStatement.SetObject(1, cKey); statement = epService.EPAdministrator.Create(preparedStatement); statement.Events += listenerOne.Update; epService.EPRuntime.SendEvent(new MyEventTwo(cKey)); Assert.IsTrue(listenerOne.GetAndClearIsInvoked()); epService.EPAdministrator.DestroyAllStatements(); }
public void TestPatternStartedPatternEnded() { SendTimeEvent("2002-05-1 8:00:00.000"); _epService.EPAdministrator.CreateEPL("create context EveryNowAndThen as " + "start pattern [s0=SupportBean_S0 -> timer:interval(1 sec)] " + "end pattern [s1=SupportBean_S1 -> timer:interval(1 sec)]"); String[] fields = "c1,c2".Split(','); SupportUpdateListener listener = new SupportUpdateListener(); EPStatement statement = _epService.EPAdministrator.CreateEPL("context EveryNowAndThen select context.s0.P00 as c1, sum(IntPrimitive) as c2 " + "from SupportBean.win:keepall()"); statement.Events += listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean_S0(100, "S0_1")); // starts it _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); _epService.EPRuntime.SendEvent(new SupportBean("E3", 3)); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimeEvent("2002-05-1 8:00:01.000"); // 1 second passes _epService.EPRuntime.SendEvent(new SupportBean("E4", 4)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "S0_1", 4 }); _epService.EPRuntime.SendEvent(new SupportBean("E5", 5)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "S0_1", 9 }); _epService.EPRuntime.SendEvent(new SupportBean_S0(101, "S0_2")); // ignored SendTimeEvent("2002-05-1 8:00:03.000"); _epService.EPRuntime.SendEvent(new SupportBean("E6", 6)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "S0_1", 15 }); _epService.EPRuntime.SendEvent(new SupportBean_S1(101, "S1_1")); // ignored _epService.EPRuntime.SendEvent(new SupportBean("E7", 7)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "S0_1", 22 }); SendTimeEvent("2002-05-1 8:00:04.000"); // terminates _epService.EPRuntime.SendEvent(new SupportBean("E8", 8)); _epService.EPRuntime.SendEvent(new SupportBean_S1(102, "S1_2")); // ignored SendTimeEvent("2002-05-1 8:00:10.000"); _epService.EPRuntime.SendEvent(new SupportBean("E9", 9)); Assert.IsFalse(listener.GetAndClearIsInvoked()); _epService.EPRuntime.SendEvent(new SupportBean_S0(103, "S0_3")); // new instance SendTimeEvent("2002-05-1 8:00:11.000"); _epService.EPRuntime.SendEvent(new SupportBean("E10", 10)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "S0_3", 10 }); _epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionLimitSnapshot(EPServiceProvider epService) { var listener = new SupportUpdateListener(); SendTimer(epService, 0); string selectStmt = "select count(*) as cnt from " + typeof(SupportBean).FullName + "#time(10 seconds) where IntPrimitive > 0 output snapshot every 1 seconds"; EPStatement stmt = epService.EPAdministrator.CreateEPL(selectStmt); stmt.Events += listener.Update; SendEvent(epService, "s0", 1); SendTimer(epService, 500); SendEvent(epService, "s1", 1); SendEvent(epService, "s2", -1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 1000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 2L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(epService, 1500); SendEvent(epService, "s4", 2); SendEvent(epService, "s5", 3); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 2000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 4L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendEvent(epService, "s5", 4); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 9000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 5L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(epService, 10000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 4L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(epService, 10999); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 11000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 3L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); stmt.Dispose(); }
public void TestPropertyAndSODAAndTimezone() { var listener = new SupportUpdateListener(); var config = SupportConfigFactory.GetConfiguration(); config.AddEventType("SupportBean", typeof(SupportBean).FullName); var epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } SendTimeEvent("2008-08-03 06:00:00.000", epService); var expression = "select * from pattern [a=SupportBean -> every timer:at(2*a.IntPrimitive,*,*,*,*)]"; var statement = epService.EPAdministrator.CreateEPL(expression); statement.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 20)); SendTimeEvent("2008-08-03 06:39:59.000", epService); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimeEvent("2008-08-03 06:40:00.000", epService); Assert.IsTrue(listener.GetAndClearIsInvoked()); statement.Dispose(); // test SODA var epl = "select * from pattern [every timer:at(*/VFREQ,VMIN:VMAX,1 last,*,[8,2:VMAX,*/VREQ])]"; var model = epService.EPAdministrator.CompileEPL(epl); Assert.AreEqual(epl, model.ToEPL()); // test timezone if (TimeZoneInfo.Local.BaseUtcOffset == TimeSpan.FromHours(-5)) // asserting only in EST timezone, see schedule util tests { SendTimeEvent("2008-01-04 06:50:00.000", epService); epService.EPAdministrator.CreateEPL("select * from pattern [timer:at(0, 5, 4, 1, *, 0, 'PST')]").Events += listener.Update; SendTimeEvent("2008-01-04 07:59:59.999", epService); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimeEvent("2008-01-04 08:00:00.000", epService); Assert.IsTrue(listener.GetAndClearIsInvoked()); } epService.EPAdministrator.CreateEPL("select * from pattern [timer:at(0, 5, 4, 8, *, 0, 'xxx')]").Events += listener.Update; epService.EPAdministrator.CreateEPL("select * from pattern [timer:at(0, 5, 4, 8, *, 0, *)]").Events += listener.Update; if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestEnabledDisableRuntime() { EPStatement[] statements = new EPStatement[5]; Configuration config = GetConfig(10000, 10000, true); _epService = EPServiceProviderManager.GetProvider("MyURI", config); _epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName); } SendTimer(1000); statements[0] = _epService.EPAdministrator.CreateEPL("select * from " + typeof(StatementMetric).FullName, "stmtmetric"); statements[0].Events += _listenerStmtMetric.Update; statements[1] = _epService.EPAdministrator.CreateEPL("select * from " + typeof(EngineMetric).FullName, "enginemetric"); statements[1].Events += _listenerEngineMetric.Update; statements[2] = _epService.EPAdministrator.CreateEPL("select * from SupportBean(IntPrimitive=1).win:keepall() where MyMetricFunctions.TakeCpuTime(LongPrimitive)"); SendEvent("E1", 1, CpuGoalOneNano); SendTimer(11000); Assert.IsTrue(_listenerStmtMetric.GetAndClearIsInvoked()); Assert.IsTrue(_listenerEngineMetric.GetAndClearIsInvoked()); _epService.EPAdministrator.Configuration.SetMetricsReportingDisabled(); SendEvent("E2", 2, CpuGoalOneNano); SendTimer(21000); Assert.IsFalse(_listenerStmtMetric.GetAndClearIsInvoked()); Assert.IsFalse(_listenerEngineMetric.GetAndClearIsInvoked()); SendTimer(31000); SendEvent("E3", 3, CpuGoalOneNano); Assert.IsFalse(_listenerStmtMetric.GetAndClearIsInvoked()); Assert.IsFalse(_listenerEngineMetric.GetAndClearIsInvoked()); _epService.EPAdministrator.Configuration.SetMetricsReportingEnabled(); SendEvent("E4", 4, CpuGoalOneNano); SendTimer(41000); Assert.IsTrue(_listenerStmtMetric.GetAndClearIsInvoked()); Assert.IsTrue(_listenerEngineMetric.GetAndClearIsInvoked()); statements[2].Dispose(); SendTimer(51000); Assert.IsTrue(_listenerStmtMetric.IsInvoked); // metrics statements reported themselves Assert.IsTrue(_listenerEngineMetric.IsInvoked); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestLimitSnapshot() { var listener = new SupportUpdateListener(); SendTimer(0); var selectStmt = "select count(*) as cnt from " + typeof(SupportBean).FullName + ".win:time(10 seconds) where IntPrimitive > 0 output snapshot every 1 seconds"; var stmt = _epService.EPAdministrator.CreateEPL(selectStmt); stmt.Events += listener.Update; SendEvent("s0", 1); SendTimer(500); SendEvent("s1", 1); SendEvent("s2", -1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(1000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 2L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(1500); SendEvent("s4", 2); SendEvent("s5", 3); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(2000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 4L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendEvent("s5", 4); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(9000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 5L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(10000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 4L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(10999); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(11000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 3L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); }