private void RunAssertionBlackWhitePercent(EPServiceProvider epService)
        {
            string[]       fields   = "cb,cnb,c,pct".Split(',');
            string         epl      = "select count(*,IsBlack) as cb, count(*,not IsBlack) as cnb, count(*) as c, count(*,IsBlack)/count(*) as pct from BlackWhiteEvent#length(3)";
            EPStatementSPI stmt     = (EPStatementSPI)epService.EPAdministrator.CreateEPL(epl);
            var            listener = new SupportUpdateListener();

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

            epService.EPRuntime.SendEvent(new BlackWhiteEvent(true));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 0L, 1L, 1d });

            epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 1L, 2L, 0.5d });

            epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 2L, 3L, 1 / 3d });

            epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0L, 3L, 3L, 0d });

            SupportModelHelper.CompileCreate(epService, epl);
            SupportModelHelper.CompileCreate(epService, "select count(distinct IsBlack,not IsBlack), count(IsBlack,IsBlack) from BlackWhiteEvent");

            epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertionOM(EPServiceProvider epService)
        {
            var model = new EPStatementObjectModel();

            model.CreateVariable = CreateVariableClause.Create("long", "var1OM", null);
            epService.EPAdministrator.Create(model);
            Assert.AreEqual("create variable long var1OM", model.ToEPL());

            model = new EPStatementObjectModel();
            model.CreateVariable = CreateVariableClause.Create("string", "var2OM", Expressions.Constant("abc"));
            epService.EPAdministrator.Create(model);
            Assert.AreEqual("create variable string var2OM = \"abc\"", model.ToEPL());

            string      stmtTextSelect = "select var1OM, var2OM from " + typeof(SupportBean).FullName;
            EPStatement stmtSelect     = epService.EPAdministrator.CreateEPL(stmtTextSelect);
            var         listener       = new SupportUpdateListener();

            stmtSelect.Events += listener.Update;

            var fieldsVar = new string[] { "var1OM", "var2OM" };

            SendSupportBean(epService, "E1", 10);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsVar, new object[] { null, "abc" });

            SupportModelHelper.CompileCreate(epService, "create variable double[] arrdouble = {1.0d,2.0d}");

            stmtSelect.Dispose();
        }
Beispiel #3
0
        private void RunAssertionEventBeanAnnotation(EventRepresentationChoice rep)
        {
            _epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema MyEvent(col1 string)");
            var listenerInsert = new SupportUpdateListener();
            var eplInsert      = "insert into DStream select " +
                                 "last(*) @eventbean as c0, " +
                                 "window(*) @eventbean as c1, " +
                                 "prevwindow(s0) @eventbean as c2 " +
                                 "from MyEvent#length(2) as s0";
            var stmtInsert = _epService.EPAdministrator.CreateEPL(eplInsert);

            stmtInsert.AddListener(listenerInsert);

            foreach (var prop in "c0,c1,c2".Split(','))
            {
                AssertFragment(prop, stmtInsert.EventType, "MyEvent", prop.Equals("c1") || prop.Equals("c2"));
            }

            // test consuming statement
            var fields        = "f0,f1,f2,f3,f4,f5".Split(',');
            var listenerProps = new SupportUpdateListener();

            _epService.EPAdministrator.CreateEPL("select " +
                                                 "c0 as f0, " +
                                                 "c0.col1 as f1, " +
                                                 "c1 as f2, " +
                                                 "c1.lastOf().col1 as f3, " +
                                                 "c1 as f4, " +
                                                 "c1.lastOf().col1 as f5 " +
                                                 "from DStream").AddListener(listenerProps);

            var eventOne = SendEvent(rep, "E1");

            Assert.IsTrue(((Map)listenerInsert.AssertOneGetNewAndReset().Underlying).Get("c0") is EventBean);
            EPAssertionUtil.AssertProps(listenerProps.AssertOneGetNewAndReset(), fields, new Object[] { eventOne, "E1", new Object[] { eventOne }, "E1", new Object[] { eventOne }, "E1" });

            var eventTwo = SendEvent(rep, "E2");

            EPAssertionUtil.AssertProps(listenerProps.AssertOneGetNewAndReset(), fields, new Object[] { eventTwo, "E2", new Object[] { eventOne, eventTwo }, "E2", new Object[] { eventOne, eventTwo }, "E2" });

            // test SODA
            SupportModelHelper.CompileCreate(_epService, eplInsert);

            // test invalid
            try {
                _epService.EPAdministrator.CreateEPL("select last(*) @xxx from MyEvent");
                Assert.Fail();
            } catch (EPStatementException ex) {
                Assert.AreEqual("Failed to recognize select-expression annotation 'xxx', expected 'eventbean' in text 'last(*) @xxx' [select last(*) @xxx from MyEvent]", ex.Message);
            }

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("DStream", false);
            _epService.EPAdministrator.Configuration.RemoveEventType("MyEvent", false);
        }
Beispiel #4
0
        public void TestEventAggregationAndPrevWindow()
        {
            _epService.EPAdministrator.CreateEPL("create objectarray schema MyEvent(col1 string)");
            var eplInsert = "insert into DStream select " +
                            "last(*) @eventbean as c0, " +
                            "window(*) @eventbean as c1, " +
                            "prevwindow(s0) @eventbean as c2 " +
                            "from MyEvent.win:length(2) as s0";
            var stmtInsert = _epService.EPAdministrator.CreateEPL(eplInsert);

            foreach (var prop in "c0,c1,c2".Split(','))
            {
                AssertFragment(prop, stmtInsert.EventType, "MyEvent", prop.Equals("c1") || prop.Equals("c2"));
            }

            // test consuming statement
            var fields = "f0,f1,f2,f3,f4,f5".Split(',');

            _epService.EPAdministrator.CreateEPL("select " +
                                                 "c0 as f0, " +
                                                 "c0.col1 as f1, " +
                                                 "c1 as f2, " +
                                                 "c1.LastOf().col1 as f3, " +
                                                 "c1 as f4, " +
                                                 "c1.LastOf().col1 as f5 " +
                                                 "from DStream").Events += _listener.Update;

            var eventOne = new Object[] { "E1" };

            _epService.EPRuntime.SendEvent(eventOne, "MyEvent");
            var @out = _listener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertProps(@out, fields, new Object[] { eventOne, "E1", new Object[] { eventOne }, "E1", new Object[] { eventOne }, "E1" });

            var eventTwo = new Object[] { "E2" };

            _epService.EPRuntime.SendEvent(eventTwo, "MyEvent");
            @out = _listener.AssertOneGetNewAndReset();
            EPAssertionUtil.AssertProps(@out, fields, new Object[] { eventTwo, "E2", new Object[] { eventOne, eventTwo }, "E2", new Object[] { eventOne, eventTwo }, "E2" });

            // test SODA
            SupportModelHelper.CompileCreate(_epService, eplInsert);

            // test invalid
            try {
                _epService.EPAdministrator.CreateEPL("select last(*) @xxx from MyEvent");
                Assert.Fail();
            }
            catch (EPStatementException ex) {
                Assert.AreEqual("Failed to recognize select-expression annotation 'xxx', expected 'eventbean' in text 'last(*) @xxx' [select last(*) @xxx from MyEvent]", ex.Message);
            }
        }
Beispiel #5
0
        private void RunAssertion_A_parenthesisBstar(EPServiceProvider epService)
        {
            EPServiceProviderIsolated isolated = epService.GetEPServiceIsolated("I1");

            SendTimer(isolated, 0);

            string[] fields = "a,b0,b1,b2".Split(',');
            string   text   = "select * from MyEvent#keepall " +
                              "match_recognize (" +
                              " measures A.TheString as a, B[0].TheString as b0, B[1].TheString as b1, B[2].TheString as b2" +
                              " pattern (A (B)*)" +
                              " interval 10 seconds or terminated" +
                              " define" +
                              " A as A.TheString like \"A%\"," +
                              " B as B.TheString like \"B%\"" +
                              ")";

            EPStatement stmt     = isolated.EPAdministrator.CreateEPL(text, "stmt1", null);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            // test output by terminated because of misfit event
            isolated.EPRuntime.SendEvent(new SupportRecogBean("A1"));
            isolated.EPRuntime.SendEvent(new SupportRecogBean("B1"));
            Assert.IsFalse(listener.IsInvoked);
            isolated.EPRuntime.SendEvent(new SupportRecogBean("X1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "A1", "B1", null, null });

            SendTimer(isolated, 20000);
            Assert.IsFalse(listener.IsInvoked);

            // test output by timer expiry
            isolated.EPRuntime.SendEvent(new SupportRecogBean("A2"));
            isolated.EPRuntime.SendEvent(new SupportRecogBean("B2"));
            Assert.IsFalse(listener.IsInvoked);
            SendTimer(isolated, 29999);

            SendTimer(isolated, 30000);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "A2", "B2", null, null });

            // destroy
            stmt.Dispose();
            isolated.Dispose();

            EPStatement stmtFromModel = SupportModelHelper.CompileCreate(epService, text);

            stmtFromModel.Dispose();
        }
Beispiel #6
0
        private void RunAssertionOverlappingWithPattern(EPServiceProvider epService)
        {
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            string contextExpr = "create context MyContext " +
                                 "initiated by @Now and pattern [every timer:interval(10)] terminated after 10 sec";

            epService.EPAdministrator.CreateEPL(contextExpr);

            var    fields     = new string[] { "cnt" };
            string streamExpr = "context MyContext " +
                                "select count(*) as cnt from SupportBean output last when terminated";
            EPStatement stream   = epService.EPAdministrator.CreateEPL(streamExpr);
            var         listener = new SupportUpdateListener();

            stream.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(8000));
            epService.EPRuntime.SendEvent(new SupportBean("E3", 3));

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(9999));
            Assert.IsFalse(listener.IsInvoked);
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3L });

            epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(10100));
            epService.EPRuntime.SendEvent(new SupportBean("E5", 5));
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(19999));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(20000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2L });

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(30000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0L });

            epService.EPRuntime.SendEvent(new SupportBean("E6", 6));

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(40000));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1L });

            SupportModelHelper.CompileCreate(epService, streamExpr);

            epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertion2SplitNoDefaultOutputFirst(EPServiceProvider epService)
        {
            var stmtOrigText = "@Audit on SupportBean " +
                               "insert into AStream2SP select * where IntPrimitive=1 " +
                               "insert into BStream2SP select * where IntPrimitive=1 or IntPrimitive=2";
            var stmtOrig = epService.EPAdministrator.CreateEPL(stmtOrigText);

            TryAssertion(epService, stmtOrig);

            // statement object model
            var model = new EPStatementObjectModel();

            model.Annotations  = Collections.SingletonList(new AnnotationPart("Audit"));
            model.FromClause   = FromClause.Create(FilterStream.Create("SupportBean"));
            model.InsertInto   = InsertIntoClause.Create("AStream2SP");
            model.SelectClause = SelectClause.CreateWildcard();
            model.WhereClause  = Expressions.Eq("IntPrimitive", 1);
            var clause = OnClause.CreateOnInsertSplitStream();

            model.OnExpr = clause;
            var item = OnInsertSplitStreamItem.Create(
                InsertIntoClause.Create("BStream2SP"),
                SelectClause.CreateWildcard(),
                Expressions.Or(Expressions.Eq("IntPrimitive", 1), Expressions.Eq("IntPrimitive", 2)));

            clause.AddItem(item);
            Assert.AreEqual(stmtOrigText, model.ToEPL());
            stmtOrig = epService.EPAdministrator.Create(model);
            TryAssertion(epService, stmtOrig);

            var newModel = epService.EPAdministrator.CompileEPL(stmtOrigText);

            stmtOrig = epService.EPAdministrator.Create(newModel);
            Assert.AreEqual(stmtOrigText, newModel.ToEPL());
            TryAssertion(epService, stmtOrig);

            SupportModelHelper.CompileCreate(epService, stmtOrigText + " output all");

            epService.EPAdministrator.DestroyAllStatements();
        }
Beispiel #8
0
        public void TestNonOverlapping()
        {
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            var contextExpr = "create context MyContext " +
                              "as start @now end after 10 seconds";

            _epService.EPAdministrator.CreateEPL(contextExpr);

            var fields     = new string[] { "cnt" };
            var streamExpr = "context MyContext " +
                             "select count(*) as cnt from SupportBean output last when terminated";
            var stream = _epService.EPAdministrator.CreateEPL(streamExpr);

            stream.AddListener(_listener);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(8000));
            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 3L });

            _epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(19999));
            Assert.IsFalse(_listener.IsInvoked);
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(20000));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L });

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(30000));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 0L });

            SupportModelHelper.CompileCreate(_epService, streamExpr);

            _epService.EPAdministrator.DestroyAllStatements();

            SupportModelHelper.CompileCreate(_epService, contextExpr);
            _epService.EPAdministrator.DestroyAllStatements();
        }
Beispiel #9
0
        public void TestOM()
        {
            var model = new EPStatementObjectModel();

            model.CreateVariable = CreateVariableClause.Create("long", "var1", null);
            _epService.EPAdministrator.Create(model);
            Assert.AreEqual("create variable long var1", model.ToEPL());

            model = new EPStatementObjectModel();
            model.CreateVariable = CreateVariableClause.Create("string", "var2", Expressions.Constant("abc"));
            _epService.EPAdministrator.Create(model);
            Assert.AreEqual("create variable string var2 = \"abc\"", model.ToEPL());

            String      stmtTextSelect = "select var1, var2 from " + typeof(SupportBean).FullName;
            EPStatement stmtSelect     = _epService.EPAdministrator.CreateEPL(stmtTextSelect);

            stmtSelect.Events += _listener.Update;

            String[] fieldsVar = new String[] { "var1", "var2" };
            SendSupportBean("E1", 10);
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsVar, new Object[] { null, "abc" });

            SupportModelHelper.CompileCreate(_epService, "create variable double[] arrdouble = {1.0d,2.0d}");
        }
Beispiel #10
0
        public void TestBlackWhitePercent()
        {
            var fields = "cb,cnb,c,pct".Split(',');
            var epl    = "select count(*,black) as cb, count(*,not black) as cnb, count(*) as c, count(*,black)/count(*) as pct from BlackWhiteEvent#length(3)";
            var stmt   = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(epl);

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

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(true));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 0L, 1L, 1d });

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 1L, 2L, 0.5d });

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 1L, 2L, 3L, 1 / 3d });

            _epService.EPRuntime.SendEvent(new BlackWhiteEvent(false));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { 0L, 3L, 3L, 0d });

            SupportModelHelper.CompileCreate(_epService, epl);
            SupportModelHelper.CompileCreate(_epService, "select count(distinct black,not black), count(black,black) from BlackWhiteEvent");
        }
        private void RunAssertion_A_Bstar(bool allMatches)
        {
            EPServiceProviderIsolated isolated = _epService.GetEPServiceIsolated("I1");

            SendTimer(isolated, 0);

            String[] fields = "a,b0,b1,b2".Split(',');
            String   text   = "select * from MyEvent.win:keepall() " +
                              "match_recognize (" +
                              " measures A.TheString as a, B[0].TheString as b0, B[1].TheString as b1, B[2].TheString as b2" +
                              (allMatches ? " all matches" : "") +
                              " pattern (A B*)" +
                              " interval 10 seconds or terminated" +
                              " define" +
                              " A as A.TheString like \"A%\"," +
                              " B as B.TheString like \"B%\"" +
                              ")";

            EPStatement stmt = isolated.EPAdministrator.CreateEPL(text, "stmt1", null);

            stmt.Events += _listener.Update;

            // test output by terminated because of misfit event
            isolated.EPRuntime.SendEvent(new SupportRecogBean("A1"));
            isolated.EPRuntime.SendEvent(new SupportRecogBean("B1"));
            Assert.IsFalse(_listener.IsInvoked);
            isolated.EPRuntime.SendEvent(new SupportRecogBean("X1"));
            if (!allMatches)
            {
                EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "A1", "B1", null, null });
            }
            else
            {
                EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields,
                                                          new Object[][] { new Object[] { "A1", "B1", null, null }, new Object[] { "A1", null, null, null } });
            }

            SendTimer(isolated, 20000);
            Assert.IsFalse(_listener.IsInvoked);

            // test output by timer expiry
            isolated.EPRuntime.SendEvent(new SupportRecogBean("A2"));
            isolated.EPRuntime.SendEvent(new SupportRecogBean("B2"));
            Assert.IsFalse(_listener.IsInvoked);
            SendTimer(isolated, 29999);

            SendTimer(isolated, 30000);
            if (!allMatches)
            {
                EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "A2", "B2", null, null });
            }
            else
            {
                EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields,
                                                          new Object[][] { new Object[] { "A2", "B2", null, null }, new Object[] { "A2", null, null, null } });
            }

            // destroy
            stmt.Dispose();
            isolated.Dispose();

            EPStatement stmtFromModel = SupportModelHelper.CompileCreate(_epService, text);

            stmtFromModel.Dispose();
        }