private void RunAssertion()
        {
            string[] fields = "orderId,bookId,reviewId".Split(',');

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] {
                new object[] { "PO200901", "10020", 1 }, new object[] { "PO200901", "10020", 2 }, new object[] { "PO200901", "10021", 10 }
            });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "PO200904", "10031", 201 } });
            _listener.Reset();
        }
        public void TestSimple()
        {
            string[] fields = "reviewId".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));

            string         stmtText = "select reviewId from OrderEvent[books][reviews] bookReviews order by reviewId asc";
            EPStatementSPI stmt     = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(stmtText);

            Assert.IsTrue(stmt.StatementContext.IsStatelessSelect);
            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 1 }, new object[] { 2 }, new object[] { 10 } });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 201 } });
            _listener.Reset();
        }
        public void TestNamedWindowFilter()
        {
            string[] fields = "reviewId".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));

            _epService.EPAdministrator.CreateEPL("create window OrderWindow.std:lastevent() as OrderEvent");
            _epService.EPAdministrator.CreateEPL("insert into OrderWindow select * from OrderEvent");

            string      stmtText = "select reviewId from OrderWindow[books][reviews] bookReviews order by reviewId asc";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 1 }, new object[] { 2 }, new object[] { 10 } });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 201 } });
            _listener.Reset();
        }
        public void TestUnderlyingSelect()
        {
            string[] fields = "orderId,bookId,reviewId".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));

            string stmtText = "select orderdetail.orderId as orderId, bookFrag.bookId as bookId, reviewFrag.reviewId as reviewId " +
                              //String stmtText = "select * " +
                              "from OrderEvent[books as book][select myorder.*, book.* as bookFrag, review.* as reviewFrag from reviews as review] as myorder";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] {
                new object[] { "PO200901", "10020", 1 }, new object[] { "PO200901", "10020", 2 }, new object[] { "PO200901", "10021", 10 }
            });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "PO200904", "10031", 201 } });
            _listener.Reset();
        }
        public void TestSubSelect()
        {
            _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].std:unique(reviewId) where reviewId = s0.intPrimitive)");

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            _epService.EPRuntime.SendEvent(TestContainedEventSimple.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());
        }
        public void TestPatternSelect()
        {
            _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)]");

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            _epService.EPRuntime.SendEvent(TestContainedEventSimple.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());
        }
        public void TestNamedWindowPremptive()
        {
            string[] fields = "bookId".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));
            _epService.EPAdministrator.Configuration.AddEventType("BookDesc", typeof(BookDesc));

            string      stmtText = "insert into BookStream select * from OrderEvent[books]";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            EPStatement stmtNW = _epService.EPAdministrator.CreateEPL("create window MyWindow.std:lastevent() as BookDesc");

            _epService.EPAdministrator.CreateEPL("insert into MyWindow select * from BookStream bs where not exists (select * from MyWindow mw where mw.price > bs.price)");

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "10020" }, new object[] { "10021" }, new object[] { "10022" } });
            _listener.Reset();

            // higest price (27 is the last value)
            EventBean theEvent = stmtNW.First();

            Assert.AreEqual(35.0, theEvent.Get("price"));
        }
        public void TestNamedWindowSubquery()
        {
            string[] fields = "theString,totalPrice".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            _epService.EPAdministrator.CreateEPL("create window OrderWindow.std:lastevent() as OrderEvent");
            _epService.EPAdministrator.CreateEPL("insert into OrderWindow select * from OrderEvent");

            string      stmtText = "select *, (select sum(price) from OrderWindow[books]) as totalPrice from SupportBean";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "E1", 24d + 35d + 27d } });
            _listener.Reset();

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "E2", 15d + 13d } });
            _listener.Reset();
        }
        public void TestWhere()
        {
            string[] fields = "reviewId".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));

            // try where in root
            string      stmtText = "select reviewId from OrderEvent[books where title = 'Enders Game'][reviews] bookReviews order by reviewId asc";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 1 }, new object[] { 2 } });
            _listener.Reset();

            // try where in different levels
            stmt.Dispose();
            stmtText = "select reviewId from OrderEvent[books where title = 'Enders Game'][reviews where reviewId in (1, 10)] bookReviews order by reviewId asc";
            stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 1 } });
            _listener.Reset();

            // try where in combination
            stmt.Dispose();
            stmtText = "select reviewId from OrderEvent[books as bc][reviews as rw where rw.reviewId in (1, 10) and bc.title = 'Enders Game'] bookReviews order by reviewId asc";
            stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 1 } });
            _listener.Reset();
            Assert.IsFalse(_listener.IsInvoked);
        }
        public void TestNamedWindowOnTrigger()
        {
            string[] fields = "theString,intPrimitive".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            _epService.EPAdministrator.CreateEPL("create window SupportBeanWindow.std:lastevent() as SupportBean");
            _epService.EPAdministrator.CreateEPL("insert into SupportBeanWindow select * from SupportBean");
            _epService.EPAdministrator.CreateEPL("create window OrderWindow.std:lastevent() as OrderEvent");
            _epService.EPAdministrator.CreateEPL("insert into OrderWindow select * from OrderEvent");

            string      stmtText = "on OrderWindow[books] owb select sbw.* from SupportBeanWindow sbw where theString = title";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            Assert.IsFalse(_listener.IsInvoked);

            _epService.EPRuntime.SendEvent(new SupportBean("Foundation 2", 2));
            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { "Foundation 2", 2 } });
        }