Exemplo n.º 1
0
        private void RunAssertionStartStopDeleter(bool namedWindow)
        {
            SupportNamedWindowObserver observer = new SupportNamedWindowObserver();
            NamedWindowLifecycleEvent  theEvent;

            if (namedWindow)
            {
                _epService.NamedWindowService.AddObserver(observer);
            }

            // create window
            string stmtTextCreate = namedWindow ?
                                    "create window MyInfra.win:keepall() as select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName :
                                    "create table MyInfra(a string primary key, b int primary key)";
            EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate);

            Assert.AreEqual(namedWindow ? StatementType.CREATE_WINDOW : StatementType.CREATE_TABLE, ((EPStatementSPI)stmtCreate).StatementMetadata.StatementType);
            stmtCreate.AddListener(_listenerWindow);
            if (namedWindow)
            {
                theEvent = observer.GetFirstAndReset();
                Assert.AreEqual(NamedWindowLifecycleEvent.LifecycleEventType.CREATE, theEvent.EventType);
                Assert.AreEqual("MyInfra", theEvent.Name);
            }

            // stop and start, no consumers or deleters
            stmtCreate.Stop();
            if (namedWindow)
            {
                theEvent = observer.GetFirstAndReset();
                Assert.AreEqual(NamedWindowLifecycleEvent.LifecycleEventType.DESTROY, theEvent.EventType);
                Assert.AreEqual("MyInfra", theEvent.Name);
            }

            stmtCreate.Start();
            if (namedWindow)
            {
                Assert.AreEqual(NamedWindowLifecycleEvent.LifecycleEventType.CREATE, observer.GetFirstAndReset().EventType);
            }

            // create delete stmt
            string      stmtTextDelete = "on " + typeof(SupportBean_A).FullName + " delete from MyInfra";
            EPStatement stmtDelete     = _epService.EPAdministrator.CreateEPL(stmtTextDelete);

            // create insert into
            string stmtTextInsertOne = "insert into MyInfra select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName;

            _epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // create consumer
            string[]    fields         = new string[] { "a", "b" };
            string      stmtTextSelect = "select irstream a, b from MyInfra as s1";
            EPStatement stmtSelect     = _epService.EPAdministrator.CreateEPL(stmtTextSelect);

            stmtSelect.AddListener(_listenerSelect);

            // send 1 event
            SendSupportBean("E1", 1);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
            }
            else
            {
                Assert.IsFalse(_listenerWindow.IsInvoked);
                Assert.IsFalse(_listenerSelect.IsInvoked);
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } });

            // Delete all events, 1 row expected
            SendSupportBean_A("A2");
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E1", 1 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetOldAndReset(), fields, new object[] { "E1", 1 });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null);

            SendSupportBean("E2", 2);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E2", 2 } });

            // Stop the deleting statement
            stmtDelete.Stop();
            SendSupportBean_A("A2");
            Assert.IsFalse(_listenerWindow.IsInvoked);

            // Start the deleting statement
            stmtDelete.Start();

            SendSupportBean_A("A3");
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E2", 2 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetOldAndReset(), fields, new object[] { "E2", 2 });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null);

            SendSupportBean("E3", 3);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 } });

            stmtDelete.Dispose();
            SendSupportBean_A("A3");
            Assert.IsFalse(_listenerWindow.IsInvoked);

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 2
0
        private void RunAssertionJoinUniquePerId(EPServiceProvider epService)
        {
            string joinStatement = "select * from " +
                                   typeof(SupportMarketDataBean).FullName + "(symbol='IBM')#length(3) s0, " +
                                   typeof(SupportMarketDataBean).FullName + "(symbol='CSCO')#length(3) s1" +
                                   " where s0.volume=s1.volume";

            var setOne     = new Object[5];
            var setTwo     = new Object[5];
            var volumesOne = new long[] { 10, 20, 20, 40, 50 };
            var volumesTwo = new long[] { 10, 20, 30, 40, 50 };

            for (int i = 0; i < setOne.Length; i++)
            {
                setOne[i] = new SupportMarketDataBean("IBM", volumesOne[i], (long)i, "");
                setTwo[i] = new SupportMarketDataBean("CSCO", volumesTwo[i], (long)i, "");
            }

            EPStatement stmt     = epService.EPAdministrator.CreateEPL(joinStatement, "MyJoin");
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendEvent(epService, setOne[0]);
            SendEvent(epService, setTwo[0]);
            Assert.IsNotNull(listener.LastNewData);
            listener.Reset();

            stmt.Stop();
            SendEvent(epService, setOne[1]);
            SendEvent(epService, setTwo[1]);
            Assert.IsFalse(listener.IsInvoked);

            stmt.Start();
            SendEvent(epService, setOne[2]);
            Assert.IsFalse(listener.IsInvoked);

            stmt.Stop();
            SendEvent(epService, setOne[3]);
            SendEvent(epService, setOne[4]);
            SendEvent(epService, setTwo[3]);

            stmt.Start();
            SendEvent(epService, setTwo[4]);
            Assert.IsFalse(listener.IsInvoked);

            // assert type-statement reference
            EPServiceProviderSPI spi = (EPServiceProviderSPI)epService;

            Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportMarketDataBean).FullName));
            var stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportMarketDataBean).FullName);

            Assert.IsTrue(stmtNames.Contains("MyJoin"));

            stmt.Dispose();

            Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportMarketDataBean).FullName));
            stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportMarketDataBean).FullName);
            EPAssertionUtil.AssertEqualsAnyOrder(null, stmtNames.ToArray());
            Assert.IsFalse(stmtNames.Contains("MyJoin"));
        }
        private void TryAssertionTwo(EPServiceProvider epService, string expression)
        {
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(expression);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            string[] fields = "id,valh0,valh1".Split(',');
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, null);

            SendBeanInt(epService, "E1", 1, 1);
            EPAssertionUtil.AssertPropsPerRow(
                listener.GetAndResetLastNewData(), fields, new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H011"
                }
            });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                stmt.GetEnumerator(), fields, new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H011"
                }
            });

            SendBeanInt(epService, "E2", 0, 1);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, null);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                stmt.GetEnumerator(), fields, new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H011"
                }
            });

            SendBeanInt(epService, "E3", 1, 0);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, null);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                stmt.GetEnumerator(), fields, new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H011"
                }
            });

            SendBeanInt(epService, "E4", 2, 2);
            object[][] result =
            {
                new object[] {
                    "E4",
                    "H01",
                    "H011"
                }, new object[]{
                    "E4",
                    "H01",
                    "H012"
                }, new object[]{
                    "E4",
                    "H02",
                    "H021"
                }, new object[]{
                    "E4",
                    "H02",
                    "H022"
                }
            };
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, result);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                stmt.GetEnumerator(), fields,
                EPAssertionUtil.ConcatenateArray2Dim(
                    result, new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H011"
                }
            }));

            stmt.Dispose();
        }
Exemplo n.º 4
0
        public void TestUniqueIndexCorrelated()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("S0", typeof(SupportBean_S0));
            String[] fields = "c0,c1".Split(',');

            // test std:unique
            String eplUnique = INDEX_CALLBACK_HOOK + "select id as c0, " +
                               "(select IntPrimitive from SupportBean#unique(TheString) where TheString = s0.p00) as c1 " +
                               "from S0 as s0";
            EPStatement stmtUnique = _epService.EPAdministrator.CreateEPL(eplUnique);

            stmtUnique.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_SINGLE_UNIQUE);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 4));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E2"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 10, 4 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 11, 3 });

            stmtUnique.Dispose();

            // test std:firstunique
            String eplFirstUnique = INDEX_CALLBACK_HOOK + "select id as c0, " +
                                    "(select IntPrimitive from SupportBean#firstunique(TheString) where TheString = s0.p00) as c1 " +
                                    "from S0 as s0";
            EPStatement stmtFirstUnique = _epService.EPAdministrator.CreateEPL(eplFirstUnique);

            stmtFirstUnique.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_SINGLE_UNIQUE);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 4));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E2"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 10, 2 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 11, 1 });

            stmtFirstUnique.Dispose();

            // test intersection std:firstunique
            String eplIntersection = INDEX_CALLBACK_HOOK + "select id as c0, " +
                                     "(select IntPrimitive from SupportBean#time(1)#unique(TheString) where TheString = s0.p00) as c1 " +
                                     "from S0 as s0";
            EPStatement stmtIntersection = _epService.EPAdministrator.CreateEPL(eplIntersection);

            stmtIntersection.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_SINGLE_UNIQUE);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 4));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E2"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 10, 4 });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 11, 3 });

            stmtIntersection.Dispose();

            // test grouped unique
            String eplGrouped = INDEX_CALLBACK_HOOK + "select id as c0, " +
                                "(select LongPrimitive from SupportBean#groupwin(TheString)#unique(IntPrimitive) where TheString = s0.p00 and IntPrimitive = s0.id) as c1 " +
                                "from S0 as s0";
            EPStatement stmtGrouped = _epService.EPAdministrator.CreateEPL(eplGrouped);

            stmtGrouped.Events += _listener.Update;

            SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(0, null, BACKING_MULTI_UNIQUE);

            _epService.EPRuntime.SendEvent(MakeBean("E1", 1, 100));
            _epService.EPRuntime.SendEvent(MakeBean("E1", 2, 101));
            _epService.EPRuntime.SendEvent(MakeBean("E1", 1, 102));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E1"));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 1, 102L });

            stmtGrouped.Dispose();
        }
Exemplo n.º 5
0
        private void RunAssertionStaggered(EventRepresentationEnum outputType)
        {
            string[] fieldsOne = new string[] { "a1", "b1" };
            string[] fieldsTwo = new string[] { "a2", "b2" };

            // create window one
            string      stmtTextCreateOne = outputType.GetAnnotationText() + " create window MyWindowOne.win:keepall() as select TheString as a1, IntPrimitive as b1 from " + typeof(SupportBean).FullName;
            EPStatement stmtCreateOne     = _epService.EPAdministrator.CreateEPL(stmtTextCreateOne);

            stmtCreateOne.AddListener(_listenerWindow);
            Assert.AreEqual(0, GetCount("MyWindowOne"));
            Assert.AreEqual(outputType.GetOutputClass(), stmtCreateOne.EventType.UnderlyingType);

            // create window two
            string      stmtTextCreateTwo = outputType.GetAnnotationText() + " create window MyWindowTwo.win:keepall() as select TheString as a2, IntPrimitive as b2 from " + typeof(SupportBean).FullName;
            EPStatement stmtCreateTwo     = _epService.EPAdministrator.CreateEPL(stmtTextCreateTwo);

            stmtCreateTwo.AddListener(_listenerWindowTwo);
            Assert.AreEqual(0, GetCount("MyWindowTwo"));
            Assert.AreEqual(outputType.GetOutputClass(), stmtCreateTwo.EventType.UnderlyingType);

            // create delete stmt
            string      stmtTextDelete = "on MyWindowOne delete from MyWindowTwo where a1 = a2";
            EPStatement stmtDelete     = _epService.EPAdministrator.CreateEPL(stmtTextDelete);

            stmtDelete.AddListener(_listenerDelete);
            Assert.AreEqual(StatementType.ON_DELETE, ((EPStatementSPI)stmtDelete).StatementMetadata.StatementType);

            // create insert into
            string stmtTextInsert = "insert into MyWindowOne select TheString as a1, IntPrimitive as b1 from " + typeof(SupportBean).FullName + "(IntPrimitive > 0)";

            _epService.EPAdministrator.CreateEPL(stmtTextInsert);
            stmtTextInsert = "insert into MyWindowTwo select TheString as a2, IntPrimitive as b2 from " + typeof(SupportBean).FullName + "(IntPrimitive < 0)";
            _epService.EPAdministrator.CreateEPL(stmtTextInsert);

            SendSupportBean("E1", -10);
            EPAssertionUtil.AssertProps(_listenerWindowTwo.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "E1", -10 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 } });
            Assert.IsFalse(_listenerWindow.IsInvoked);
            Assert.AreEqual(1, GetCount("MyWindowTwo"));

            SendSupportBean("E2", 5);
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fieldsOne, new object[] { "E2", 5 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsOne, new object[][] { new object[] { "E2", 5 } });
            Assert.IsFalse(_listenerWindowTwo.IsInvoked);
            Assert.AreEqual(1, GetCount("MyWindowOne"));

            SendSupportBean("E3", -1);
            EPAssertionUtil.AssertProps(_listenerWindowTwo.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "E3", -1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 }, new object[] { "E3", -1 } });
            Assert.IsFalse(_listenerWindow.IsInvoked);
            Assert.AreEqual(2, GetCount("MyWindowTwo"));

            SendSupportBean("E3", 1);
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fieldsOne, new object[] { "E3", 1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsOne, new object[][] { new object[] { "E2", 5 }, new object[] { "E3", 1 } });
            EPAssertionUtil.AssertProps(_listenerWindowTwo.AssertOneGetOldAndReset(), fieldsTwo, new object[] { "E3", -1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 } });
            Assert.AreEqual(2, GetCount("MyWindowOne"));
            Assert.AreEqual(1, GetCount("MyWindowTwo"));

            stmtDelete.Dispose();
            stmtCreateOne.Dispose();
            stmtCreateTwo.Dispose();
            _listenerDelete.Reset();
            _listenerSelect.Reset();
            _listenerWindow.Reset();
            _listenerWindowTwo.Reset();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindowOne", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindowTwo", true);
        }
Exemplo n.º 6
0
        public void TestManageDependency()
        {
            // single variable
            EPStatement stmtOne = _epService.EPAdministrator.CreateEPL("@Name('S0') create variable boolean var2 = true");
            EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL("@Name('S1') select * from SupportBean(var2)");

            AssertStmtsRef("var2", new String[] { "S0", "S1" });
            Assert.AreEqual(true, _epService.EPRuntime.GetVariableValue("var2"));

            stmtOne.Dispose();
            AssertStmtsRef("var2", new String[] { "S1" });
            Assert.AreEqual(true, _epService.EPRuntime.GetVariableValue("var2"));

            stmtTwo.Dispose();
            AssertStmtsRef("var2", null);
            AssertNotFound("var2");

            // multiple variable
            EPStatement stmt1        = _epService.EPAdministrator.CreateEPL("@Name('T0') create variable boolean v1 = true");
            EPStatement stmt2        = _epService.EPAdministrator.CreateEPL("@Name('T1') create variable long v2 = 1");
            EPStatement stmt3        = _epService.EPAdministrator.CreateEPL("@Name('T2') create variable string v3 = 'a'");
            EPStatement stmtUseOne   = _epService.EPAdministrator.CreateEPL("@Name('TX') select * from SupportBean(v1, v2=1, v3='a')");
            EPStatement stmtUseTwo   = _epService.EPAdministrator.CreateEPL("@Name('TY') select * from SupportBean(v2=2)");
            EPStatement stmtUseThree = _epService.EPAdministrator.CreateEPL("@Name('TZ') select * from SupportBean(v3='A', v1)");

            AssertStmtsRef("v1", new String[] { "T0", "TX", "TZ" });
            AssertStmtsRef("v2", new String[] { "T1", "TX", "TY" });
            AssertStmtsRef("v3", new String[] { "T2", "TX", "TZ" });

            stmt2.Dispose();
            AssertStmtsRef("v2", new String[] { "TX", "TY" });

            stmtUseOne.Dispose();
            AssertStmtsRef("v2", new String[] { "TY" });

            stmtUseTwo.Dispose();
            AssertStmtsRef("v2", null);
            AssertNotFound("v2");

            EPStatement stmt4       = _epService.EPAdministrator.CreateEPL("@Name('T3') create variable boolean v4 = true");
            EPStatement stmtUseFour = _epService.EPAdministrator.CreateEPL("@Name('TQ') select * from SupportBean(v4)");

            AssertStmtsRef("v4", new String[] { "T3", "TQ" });
            Assert.AreEqual(true, _epService.EPRuntime.GetVariableValue("v4"));

            stmt1.Dispose();
            stmtUseThree.Dispose();

            AssertStmtsRef("v1", null);
            AssertNotFound("v1");
            Assert.AreEqual("a", _epService.EPRuntime.GetVariableValue("v3"));
            AssertStmtsRef("v3", new String[] { "T2" });

            stmt3.Dispose();
            AssertNotFound("v3");

            stmt4.Dispose();
            stmtUseFour.Dispose();
            AssertNotFound("v4");

            Assert.AreEqual(1, _epService.EPRuntime.VariableValueAll.Count);
        }
Exemplo n.º 7
0
        public void TestLambda()
        {
            String[] fieldsOne = "a0,a1,a2,b".Split(',');
            String   eplOne    = "select * from SupportBean " +
                                 "match_recognize (" +
                                 " measures A[0].TheString as a0, A[1].TheString as a1, A[2].TheString as a2, B.TheString as b" +
                                 " pattern (A* B)" +
                                 " define" +
                                 " B as (coalesce(A.SumOf(v => v.IntPrimitive), 0) + B.IntPrimitive) > 100" +
                                 ")";

            EPStatement stmt = _epService.EPAdministrator.CreateEPL(eplOne);

            stmt.Events += _listener.Update;
            _listener.Reset();

            SendEvents(new Object[][] { new Object[] { "E1", 50 }, new Object[] { "E2", 49 } });
            Assert.IsFalse(_listener.IsInvoked);

            SendEvents(new Object[][] { new Object[] { "E3", 2 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsOne, new Object[] { "E1", "E2", null, "E3" });

            SendEvents(new Object[][] { new Object[] { "E4", 101 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsOne, new Object[] { null, null, null, "E4" });

            SendEvents(new Object[][] { new Object[] { "E5", 50 }, new Object[] { "E6", 51 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsOne, new Object[] { "E5", null, null, "E6" });

            SendEvents(new Object[][] { new Object[] { "E7", 10 }, new Object[] { "E8", 10 }, new Object[] { "E9", 79 }, new Object[] { "E10", 1 }, new Object[] { "E11", 1 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsOne, new Object[] { "E7", "E8", "E9", "E11" });
            stmt.Dispose();

            String[] fieldsTwo = "a[0].TheString,a[1].TheString,b.TheString".Split(',');
            String   eplTwo    = "select * from SupportBean " +
                                 "match_recognize (" +
                                 " measures A as a, B as b " +
                                 " pattern (A+ B)" +
                                 " define" +
                                 " A as TheString like 'A%', " +
                                 " B as TheString like 'B%' and B.IntPrimitive > A.SumOf(v => v.IntPrimitive)" +
                                 ")";

            EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL(eplTwo);

            stmtTwo.Events += _listener.Update;
            _listener.Reset();

            SendEvents(new Object[][] { new Object[] { "A1", 1 }, new Object[] { "A2", 2 }, new Object[] { "B1", 3 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsTwo, new Object[] { "A2", null, "B1" });

            SendEvents(new Object[][] { new Object[] { "A3", 1 }, new Object[] { "A4", 2 }, new Object[] { "B2", 4 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsTwo, new Object[] { "A3", "A4", "B2" });

            SendEvents(new Object[][] { new Object[] { "A5", -1 }, new Object[] { "B3", 0 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsTwo, new Object[] { "A5", null, "B3" });

            SendEvents(new Object[][] { new Object[] { "A6", 10 }, new Object[] { "B3", 9 }, new Object[] { "B4", 11 } });
            SendEvents(new Object[][] { new Object[] { "A7", 10 }, new Object[] { "A8", 9 }, new Object[] { "A9", 8 } });
            Assert.IsFalse(_listener.IsInvoked);

            SendEvents(new Object[][] { new Object[] { "B5", 18 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsTwo, new Object[] { "A8", "A9", "B5" });

            SendEvents(new Object[][] { new Object[] { "A0", 10 }, new Object[] { "A11", 9 }, new Object[] { "A12", 8 }, new Object[] { "B6", 8 } });
            Assert.IsFalse(_listener.IsInvoked);

            SendEvents(new Object[][] { new Object[] { "A13", 1 }, new Object[] { "A14", 1 }, new Object[] { "A15", 1 }, new Object[] { "A16", 1 }, new Object[] { "B7", 5 } });
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsTwo, new Object[] { "A13", "A14", "B7" });

            SendEvents(new Object[][] { new Object[] { "A17", 1 }, new Object[] { "A18", 1 }, new Object[] { "B8", 1 } });
            Assert.IsFalse(_listener.IsInvoked);
        }
Exemplo n.º 8
0
        public void TestInCollection()
        {
            String stmtText = "select 10 in (arrayProperty) as result from "
                              + typeof(SupportBeanComplexProps).FullName;
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += _listener.Update;
            Assert.AreEqual(typeof(bool?), stmt.EventType.GetPropertyType("result"));

            stmtText = "select 5 in (arrayProperty) as result from "
                       + typeof(SupportBeanComplexProps).FullName;
            EPStatement selectTestCaseTwo = _epService.EPAdministrator.CreateEPL(stmtText);

            selectTestCaseTwo.Events += _testListenerTwo.Update;

            _epService.EPRuntime.SendEvent(
                SupportBeanComplexProps.MakeDefaultBean());
            Assert.AreEqual(true, _listener.AssertOneGetNewAndReset().Get("result"));
            Assert.AreEqual(false, _testListenerTwo.AssertOneGetNewAndReset().Get("result"));

            stmt.Stop();
            selectTestCaseTwo.Stop();

            // Arrays
            stmtText = "select 1 in (IntArr, LongArr) as resOne, 1 not in (IntArr, LongArr) as resTwo from "
                       + typeof(SupportBeanArrayCollMap).FullName;
            stmt         = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            String[] fields = "resOne, resTwo".Split(',');

            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new int[] { 10, 20, 30 }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, true });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new int[] { 10, 1, 30 }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new int[] { 30 }, new long?[] { 20L, 1L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new int[] { }, new long?[] { null, 1L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(null, new long?[] { 1L, 100L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(null, new long?[] { 0L, 100L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, true });
            stmt.Dispose();

            // Collection
            stmtText = "select 1 in (IntCol, LongCol) as resOne, 1 not in (LongCol, IntCol) as resTwo from "
                       + typeof(SupportBeanArrayCollMap).FullName;
            stmt         = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(true, new int[] { 10, 20, 30 }, null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, true });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(true, new int[] { 10, 20, 1 }, null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(true, new int[] { 30 }, new long?[] { 20L, 1L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(true, new int[] { }, new long?[] { null, 1L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(true, null, new long?[] { 1L, 100L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            stmt.Dispose();

            // Maps
            stmtText = "select 1 in (LongMap, IntMap) as resOne, 1 not in (LongMap, IntMap) as resTwo from "
                       + typeof(SupportBeanArrayCollMap).FullName;
            stmt         = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(false, new int[] { 10, 20, 30 }, null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, true });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(false, new int[] { 10, 20, 1 }, null));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(false, new int[] { 30 }, new long?[] { 20L, 1L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(false, new int[] { }, new long?[] { null, 1L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(false, null, new long?[] { 1L, 100L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            stmt.Dispose();

            // Mixed
            stmtText = "select 1 in (LongBoxed, IntArr, LongMap, IntCol) as resOne, 1 not in (LongBoxed, IntArr, LongMap, IntCol) as resTwo from "
                       + typeof(SupportBeanArrayCollMap).FullName;
            stmt         = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(1L, new int[0], new long?[0], new int[0]));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(2L, null, new long?[0], new int[0]));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, true });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(null, null, null, new int[] { 3, 4, 5, 6, 7, 7, 7, 8, 8, 8, 1 }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(-1L, null, new long?[] { 1L }, new int[] { 3, 4, 5, 6, 7, 7, 7, 8, 8 }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false }); // NEsper does type introspection & conversion
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(-1L, new int[] { 1 }, null, new int[] { }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
            stmt.Dispose();

            // Object array
            stmtText = "select 1 in (objectArr) as resOne, 2 in (objectArr) as resTwo from "
                       + typeof(SupportBeanArrayCollMap).FullName;
            stmt         = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new Object[] {}));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new Object[] { 1, 2 }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, true });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new Object[] { 1d, 2L }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false, false });
            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new Object[] { null, 2 }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, true });
            stmt.Dispose();

            // Object array
            stmtText = "select 1 in ({1,2,3}) as resOne, 2 in ({0, 1}) as resTwo from "
                       + typeof(SupportBeanArrayCollMap).FullName;
            stmt         = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBeanArrayCollMap(new Object[] { }));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true, false });
        }
Exemplo n.º 9
0
        public void TestInRange()
        {
            _epService.EPAdministrator.Configuration.AddEventType(
                "SupportBean", typeof(SupportBean));

            String[]    fields = "ro,rc,rho,rhc,nro,nrc,nrho,nrhc".Split(',');
            EPStatement stmt   = _epService.EPAdministrator.CreateEPL(
                "select IntPrimitive in (2:4) as ro, IntPrimitive in [2:4] as rc, IntPrimitive in [2:4) as rho, IntPrimitive in (2:4] as rhc, "
                +
                "IntPrimitive not in (2:4) as nro, IntPrimitive not in [2:4] as nrc, IntPrimitive not in [2:4) as nrho, IntPrimitive not in (2:4] as nrhc "
                + "from SupportBean#lastevent");

            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                false, false, false, false, true, true, true, true
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                false, true, true, false, true, false, false, true
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                true, true, true, true, false, false, false, false
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 4));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                false, true, false, true, true, false, true, false
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 5));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                false, false, false, false, true, true, true, true
            }
                );

            // test range reversed
            stmt.Dispose();
            stmt = _epService.EPAdministrator.CreateEPL(
                "select IntPrimitive between 4 and 2 as r1, IntPrimitive in [4:2] as r2 from SupportBean#lastevent");
            stmt.Events += _listener.Update;

            fields = "r1,r2".Split(',');
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                true, true
            }
                );

            // test string type
            stmt.Dispose();
            fields = "ro".Split(',');
            stmt   = _epService.EPAdministrator.CreateEPL(
                "select TheString in ('a':'d') as ro from SupportBean#lastevent");
            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("a", 5));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                false
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("b", 5));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                true
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("c", 5));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                true
            }
                );

            _epService.EPRuntime.SendEvent(new SupportBean("d", 5));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                false
            }
                );
        }
Exemplo n.º 10
0
        public void TestExampleWithPREV()
        {
            String query = "SELECT * " + "FROM MyEvent#keepall"
                           + "   MATCH_RECOGNIZE ("
                           + "       MEASURES A.TheString AS a_string,"
                           + "         A.value AS a_value,"
                           + "         B.TheString AS b_string,"
                           + "         B.value AS b_value,"
                           + "         C[0].TheString AS c0_string,"
                           + "         C[0].value AS c0_value,"
                           + "         C[1].TheString AS c1_string,"
                           + "         C[1].value AS c1_value,"
                           + "         C[2].TheString AS c2_string,"
                           + "         C[2].value AS c2_value,"
                           + "         D.TheString AS d_string,"
                           + "         D.value AS d_value,"
                           + "         E[0].TheString AS e0_string,"
                           + "         E[0].value AS e0_value,"
                           + "         E[1].TheString AS e1_string,"
                           + "         E[1].value AS e1_value,"
                           + "         F[0].TheString AS f0_string,"
                           + "         F[0].value AS f0_value,"
                           + "         F[1].TheString AS f1_string,"
                           + "         F[1].value AS f1_value" + "       ALL MATCHES"
                           + "       after match skip to current row"
                           + "       PATTERN ( A B C* D E* F+ )"
                           + "       DEFINE /* A is unspecified, defaults to TRUE, matches any row */"
                           + "            B AS (B.value < PREV (B.value)),"
                           + "            C AS (C.value <= PREV (C.value)),"
                           + "            D AS (D.value < PREV (D.value)),"
                           + "            E AS (E.value >= PREV (E.value)),"
                           + "            F AS (F.value >= PREV (F.value) and F.value > A.value)"
                           + ")";

            EPStatement           stmt     = _epService.EPAdministrator.CreateEPL(query);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            Object[][] data = new Object[][] {
                new Object[] {
                    "E1", 100, null
                },
                new Object[] {
                    "E2", 98, null
                },
                new Object[] {
                    "E3", 75, null
                },
                new Object[] {
                    "E4", 61, null
                },
                new Object[] {
                    "E5", 50, null
                },
                new Object[] {
                    "E6", 49, null
                },
                new Object[] {
                    "E7", 64,
                    new String[] {
                        "a_string=E4,a_value=61,b_string=E5,b_value=50,c0_string=null,c0_value=null,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=null,e0_value=null,e1_string=null,e1_value=null,f0_string=E7,f0_value=64,f1_string=null,f1_value=null"
                    }
                },
                new Object[] {
                    "E8", 78,
                    new String[] {
                        "a_string=E3,a_value=75,b_string=E4,b_value=61,c0_string=E5,c0_value=50,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=E7,e0_value=64,e1_string=null,e1_value=null,f0_string=E8,f0_value=78,f1_string=null,f1_value=null",
                        "a_string=E4,a_value=61,b_string=E5,b_value=50,c0_string=null,c0_value=null,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=E7,e0_value=64,e1_string=null,e1_value=null,f0_string=E8,f0_value=78,f1_string=null,f1_value=null",
                        "a_string=E4,a_value=61,b_string=E5,b_value=50,c0_string=null,c0_value=null,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=null,e0_value=null,e1_string=null,e1_value=null,f0_string=E7,f0_value=64,f1_string=E8,f1_value=78"
                    }
                },
                new Object[] {
                    "E9", 84,
                    new String[] {
                        "a_string=E3,a_value=75,b_string=E4,b_value=61,c0_string=E5,c0_value=50,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=E7,e0_value=64,e1_string=null,e1_value=null,f0_string=E8,f0_value=78,f1_string=E9,f1_value=84",
                        "a_string=E3,a_value=75,b_string=E4,b_value=61,c0_string=E5,c0_value=50,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=E7,e0_value=64,e1_string=E8,e1_value=78,f0_string=E9,f0_value=84,f1_string=null,f1_value=null",
                        "a_string=E4,a_value=61,b_string=E5,b_value=50,c0_string=null,c0_value=null,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=E7,e0_value=64,e1_string=E8,e1_value=78,f0_string=E9,f0_value=84,f1_string=null,f1_value=null",
                        "a_string=E4,a_value=61,b_string=E5,b_value=50,c0_string=null,c0_value=null,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=E7,e0_value=64,e1_string=null,e1_value=null,f0_string=E8,f0_value=78,f1_string=E9,f1_value=84",
                        "a_string=E4,a_value=61,b_string=E5,b_value=50,c0_string=null,c0_value=null,c1_string=null,c1_value=null,c2_string=null,c2_value=null,d_string=E6,d_value=49,e0_string=null,e0_value=null,e1_string=null,e1_value=null,f0_string=E7,f0_value=64,f1_string=E8,f1_value=78"
                    }
                },
            };

            int rowCount = 0;

            foreach (Object[] row in data)
            {
                rowCount++;
                SupportRecogBean theEvent = new SupportRecogBean((String)row[0], (int)row[1]);

                _epService.EPRuntime.SendEvent(theEvent);

                Compare(row, rowCount, theEvent, listener);
                rowCount++;
            }

            stmt.Dispose();
        }
Exemplo n.º 11
0
        public void TestExampleFinancialWPattern()
        {
            String text = "select * " + "from SupportBean " + "match_recognize ("
                          + " measures A.TheString as beginA, last(Z.TheString) as lastZ"
                          + " all matches" + " after match skip to current row"
                          + " pattern (A W+ X+ Y+ Z+)" + " define"
                          + " W as W.IntPrimitive<prev(W.IntPrimitive),"
                          + " X as X.IntPrimitive>prev(X.IntPrimitive),"
                          + " Y as Y.IntPrimitive<prev(Y.IntPrimitive),"
                          + " Z as Z.IntPrimitive>prev(Z.IntPrimitive)" + ")";

            EPStatement           stmt     = _epService.EPAdministrator.CreateEPL(text);
            SupportUpdateListener listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            Object[][] data = new Object[][] {
                new Object[] {
                    "E1", 8
                }, // 0
                new Object[] {
                    "E2", 8
                },
                new Object[] {
                    "E3", 8
                }, // A
                new Object[] {
                    "E4", 6
                }, // W
                new Object[] {
                    "E5", 3
                }, // W
                new Object[] {
                    "E6", 7
                },
                new Object[] {
                    "E7", 6
                },
                new Object[] {
                    "E8", 2
                },
                new Object[] {
                    "E9", 6, // Z
                    new String[] {
                        "beginA=E3,lastZ=E9", "beginA=E4,lastZ=E9"
                    }
                },
                new Object[] {
                    "E10", 2
                },
                new Object[] {
                    "E11", 9, // 10
                    new String[] {
                        "beginA=E6,lastZ=E11", "beginA=E7,lastZ=E11"
                    }
                },
                new Object[] {
                    "E12", 9
                },
                new Object[] {
                    "E13", 8
                },
                new Object[] {
                    "E14", 5
                },
                new Object[] {
                    "E15", 0
                },
                new Object[] {
                    "E16", 9
                },
                new Object[] {
                    "E17", 2
                },
                new Object[] {
                    "E18", 0
                },
                new Object[] {
                    "E19", 2,
                    new String[] {
                        "beginA=E12,lastZ=E19", "beginA=E13,lastZ=E19",
                        "beginA=E14,lastZ=E19"
                    }
                },
                new Object[] {
                    "E20", 3,
                    new String[] {
                        "beginA=E12,lastZ=E20", "beginA=E13,lastZ=E20",
                        "beginA=E14,lastZ=E20"
                    }
                },
                new Object[] {
                    "E21", 8,
                    new String[] {
                        "beginA=E12,lastZ=E21", "beginA=E13,lastZ=E21",
                        "beginA=E14,lastZ=E21"
                    }
                },
                new Object[] {
                    "E22", 5
                },
                new Object[] {
                    "E23", 9, new String[] {
                        "beginA=E16,lastZ=E23", "beginA=E17,lastZ=E23"
                    }
                },
                new Object[] {
                    "E24", 9
                },
                new Object[] {
                    "E25", 4
                },
                new Object[] {
                    "E26", 7
                },
                new Object[] {
                    "E27", 2
                },
                new Object[] {
                    "E28", 8, new String[] {
                        "beginA=E24,lastZ=E28"
                    }
                },
                new Object[] {
                    "E29", 0
                },
                new Object[] {
                    "E30", 4, new String[] {
                        "beginA=E26,lastZ=E30"
                    }
                },
                new Object[] {
                    "E31", 4
                },
                new Object[] {
                    "E32", 7
                },
                new Object[] {
                    "E33", 8
                },
                new Object[] {
                    "E34", 6
                },
                new Object[] {
                    "E35", 4
                },
                new Object[] {
                    "E36", 5
                },
                new Object[] {
                    "E37", 1
                },
                new Object[] {
                    "E38", 7, new String[] {
                        "beginA=E33,lastZ=E38", "beginA=E34,lastZ=E38"
                    }
                },
                new Object[] {
                    "E39", 5
                },
                new Object[] {
                    "E40", 8, new String[] {
                        "beginA=E36,lastZ=E40"
                    }
                },
                new Object[] {
                    "E41", 6
                },
                new Object[] {
                    "E42", 6
                },
                new Object[] {
                    "E43", 0
                },
                new Object[] {
                    "E44", 6
                },
                new Object[] {
                    "E45", 8
                },
                new Object[] {
                    "E46", 4
                },
                new Object[] {
                    "E47", 3
                },
                new Object[] {
                    "E48", 8, new String[] {
                        "beginA=E42,lastZ=E48"
                    }
                },
                new Object[] {
                    "E49", 2
                },
                new Object[] {
                    "E50", 5, new String[] {
                        "beginA=E45,lastZ=E50", "beginA=E46,lastZ=E50"
                    }
                },
                new Object[] {
                    "E51", 3
                },
                new Object[] {
                    "E52", 3
                },
                new Object[] {
                    "E53", 9
                },
                new Object[] {
                    "E54", 8
                },
                new Object[] {
                    "E55", 5
                },
                new Object[] {
                    "E56", 5
                },
                new Object[] {
                    "E57", 9
                },
                new Object[] {
                    "E58", 7
                },
                new Object[] {
                    "E59", 3
                },
                new Object[] {
                    "E60", 3
                }
            };

            int rowCount = 0;

            foreach (Object[] row in data)
            {
                SupportBean theEvent = new SupportBean((String)row[0], (int)row[1]);

                _epService.EPRuntime.SendEvent(theEvent);

                Compare(row, rowCount, theEvent, listener);
                rowCount++;
            }

            stmt.Dispose();
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(
                text);

            Assert.AreEqual(text, model.ToEPL());
            stmt         = _epService.EPAdministrator.Create(model);
            stmt.Events += listener.Update;
            Assert.AreEqual(text, stmt.Text);

            foreach (Object[] row in data)
            {
                SupportBean theEvent = new SupportBean((String)row[0], (int)row[1]);
                _epService.EPRuntime.SendEvent(theEvent);
                Compare(row, rowCount, theEvent, listener);
                rowCount++;
            }
        }
Exemplo n.º 12
0
        private void RunAssertionDeletePattern(bool isNamedWindow)
        {
            // create infra
            string stmtTextCreate = isNamedWindow ?
                                    "create window MyInfra#keepall as select TheString as a, IntPrimitive as b from SupportBean" :
                                    "create table MyInfra(a string primary key, b int)";
            EPStatement stmtCreate = epService.EPAdministrator.CreateEPL(stmtTextCreate);

            stmtCreate.AddListener(listenerInfra);

            // create delete stmt
            string      stmtTextDelete = "on pattern [every ea=" + typeof(SupportBean_A).FullName + " or every eb=" + typeof(SupportBean_B).FullName + "] " + " delete from MyInfra";
            EPStatement stmtDelete     = epService.EPAdministrator.CreateEPL(stmtTextDelete);

            stmtDelete.AddListener(listenerDelete);

            // create insert into
            string stmtTextInsertOne = "insert into MyInfra select TheString as a, IntPrimitive as b from SupportBean";

            epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // send 1 event
            string[] fields = new string[] { "a", "b" };
            SendSupportBean("E1", 1);
            if (isNamedWindow)
            {
                EPAssertionUtil.AssertProps(listenerInfra.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
                EPAssertionUtil.AssertPropsPerRow(stmtDelete.GetEnumerator(), fields, null);
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } });
            Assert.AreEqual(1, GetCount("MyInfra"));

            // Delete all events using A, 1 row expected
            SendSupportBean_A("A1");
            if (isNamedWindow)
            {
                EPAssertionUtil.AssertProps(listenerInfra.AssertOneGetOldAndReset(), fields, new object[] { "E1", 1 });
                EPAssertionUtil.AssertPropsPerRow(stmtDelete.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null);
            EPAssertionUtil.AssertProps(listenerDelete.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
            Assert.AreEqual(0, GetCount("MyInfra"));

            // send 1 event
            SendSupportBean("E2", 2);
            if (isNamedWindow)
            {
                EPAssertionUtil.AssertProps(listenerInfra.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E2", 2 } });
            Assert.AreEqual(1, GetCount("MyInfra"));

            // Delete all events using B, 1 row expected
            SendSupportBean_B("B1");
            if (isNamedWindow)
            {
                EPAssertionUtil.AssertProps(listenerInfra.AssertOneGetOldAndReset(), fields, new object[] { "E2", 2 });
                EPAssertionUtil.AssertPropsPerRow(stmtDelete.GetEnumerator(), fields, new object[][] { new object[] { "E2", 2 } });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null);
            EPAssertionUtil.AssertProps(listenerDelete.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 });
            Assert.AreEqual(0, GetCount("MyInfra"));

            stmtDelete.Dispose();
            stmtCreate.Dispose();
            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 13
0
        public void TestAddRemoveType()
        {
            // test remove type with statement used (no force)
            ConfigurationOperations configOps = _epService.EPAdministrator.Configuration;
            EPStatement             stmt      = _epService.EPAdministrator.CreateEPL("select MyInt from MyMapEvent", "stmtOne");

            EPAssertionUtil.AssertEqualsExactOrder(configOps.GetEventTypeNameUsedBy("MyMapEvent").ToArray(),
                                                   new String[] { "stmtOne" });

            Assert.AreEqual(1, _epService.EPAdministrator.Configuration.EventTypes.Count);
            Assert.AreEqual("MyMapEvent", _epService.EPAdministrator.Configuration.GetEventType("MyMapEvent").Name);

            try
            {
                configOps.RemoveEventType("MyMapEvent", false);
            }
            catch (ConfigurationException ex)
            {
                Assert.IsTrue(ex.Message.Contains("MyMapEvent"));
            }

            // destroy statement and type
            stmt.Dispose();
            Assert.IsTrue(configOps.GetEventTypeNameUsedBy("MyMapEvent").IsEmpty());
            Assert.IsTrue(configOps.IsEventTypeExists("MyMapEvent"));
            Assert.IsTrue(configOps.RemoveEventType("MyMapEvent", false));
            Assert.IsFalse(configOps.RemoveEventType("MyMapEvent", false)); // try double-remove
            Assert.IsFalse(configOps.IsEventTypeExists("MyMapEvent"));
            Assert.AreEqual(0, _epService.EPAdministrator.Configuration.EventTypes.Count);
            Assert.AreEqual(null, _epService.EPAdministrator.Configuration.GetEventType("MyMapEvent"));
            try
            {
                _epService.EPAdministrator.CreateEPL("select MyInt from MyMapEvent");
                Assert.Fail();
            }
            catch (EPException ex)
            {
                // expected
            }

            // add back the type
            var properties = new Properties();

            properties["p01"] = "string";
            configOps.AddEventType("MyMapEvent", properties);
            Assert.IsTrue(configOps.IsEventTypeExists("MyMapEvent"));
            Assert.IsTrue(configOps.GetEventTypeNameUsedBy("MyMapEvent").IsEmpty());
            Assert.AreEqual(1, _epService.EPAdministrator.Configuration.EventTypes.Count);
            Assert.AreEqual("MyMapEvent", _epService.EPAdministrator.Configuration.GetEventType("MyMapEvent").Name);

            // compile
            _epService.EPAdministrator.CreateEPL("select p01 from MyMapEvent", "stmtTwo");
            EPAssertionUtil.AssertEqualsExactOrder(configOps.GetEventTypeNameUsedBy("MyMapEvent").ToArray(),
                                                   new String[] { "stmtTwo" });
            try
            {
                _epService.EPAdministrator.CreateEPL("select MyInt from MyMapEvent");
                Assert.Fail();
            }
            catch (EPException ex)
            {
                // expected
            }

            // remove with force
            try
            {
                configOps.RemoveEventType("MyMapEvent", false);
            }
            catch (ConfigurationException ex)
            {
                Assert.IsTrue(ex.Message.Contains("MyMapEvent"));
            }
            Assert.IsTrue(configOps.RemoveEventType("MyMapEvent", true));
            Assert.IsFalse(configOps.IsEventTypeExists("MyMapEvent"));
            Assert.IsTrue(configOps.GetEventTypeNameUsedBy("MyMapEvent").IsEmpty());

            // add back the type
            properties            = new Properties();
            properties["newprop"] = "string";
            configOps.AddEventType("MyMapEvent", properties);
            Assert.IsTrue(configOps.IsEventTypeExists("MyMapEvent"));

            // compile
            _epService.EPAdministrator.CreateEPL("select newprop from MyMapEvent");
            try
            {
                _epService.EPAdministrator.CreateEPL("select p01 from MyMapEvent");
                Assert.Fail();
            }
            catch (EPException ex)
            {
                // expected
            }
        }
Exemplo n.º 14
0
        private void RunAssertion(bool namedWindow, bool enableIndexShareCreate, bool disableIndexShareConsumer, bool createExplicitIndex)
        {
            _epService.EPAdministrator.CreateEPL("create schema EventSchema(e0 string, e1 int, e2 string)");
            _epService.EPAdministrator.CreateEPL("create schema WindowSchema(col0 string, col1 long, col2 string)");

            string createEpl = namedWindow ?
                               "create window MyInfra#keepall as WindowSchema" :
                               "create table MyInfra (col0 string primary key, col1 long, col2 string)";

            if (enableIndexShareCreate)
            {
                createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl;
            }
            _epService.EPAdministrator.CreateEPL(createEpl);
            _epService.EPAdministrator.CreateEPL("insert into MyInfra select * from WindowSchema");

            EPStatement stmtIndex = null;

            if (createExplicitIndex)
            {
                stmtIndex = _epService.EPAdministrator.CreateEPL("create index MyIndex on MyInfra (col2, col1)");
            }

            string[] fields     = "e0,val".Split(',');
            string   consumeEpl = "select e0, (select col0 from MyInfra where col2 = es.e2 and col1 = es.e1) as val from EventSchema es";

            if (disableIndexShareConsumer)
            {
                consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl;
            }
            EPStatement consumeStmt = _epService.EPAdministrator.CreateEPL(consumeEpl);

            consumeStmt.AddListener(_listener);

            SendWindow("W1", 10L, "c31");
            SendEvent("E1", 10, "c31");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "W1" });

            SendEvent("E2", 11, "c32");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E2", null });

            SendWindow("W2", 11L, "c32");
            SendEvent("E3", 11, "c32");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E3", "W2" });

            SendWindow("W3", 11L, "c31");
            SendWindow("W4", 10L, "c32");

            SendEvent("E4", 11, "c31");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E4", "W3" });

            SendEvent("E5", 10, "c31");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E5", "W1" });

            SendEvent("E6", 10, "c32");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E6", "W4" });

            // test late start
            consumeStmt.Dispose();
            consumeStmt = _epService.EPAdministrator.CreateEPL(consumeEpl);
            consumeStmt.AddListener(_listener);

            SendEvent("E6", 10, "c32");
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "E6", "W4" });

            if (stmtIndex != null)
            {
                stmtIndex.Dispose();
            }
            consumeStmt.Dispose();

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 15
0
        private void RunAssertion(bool namedWindow, bool enableIndexShareCreate, bool disableIndexShareConsumer, bool createExplicitIndex)
        {
            SupportUpdateListener listener = new SupportUpdateListener();

            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddEventType("S0", typeof(SupportBean_S0));

            string createEpl = namedWindow ?
                               "create window MyInfra.win:keepall() as select * from SupportBean" :
                               "create table MyInfra (TheString string primary key, IntPrimitive int primary key)";

            if (enableIndexShareCreate)
            {
                createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl;
            }
            epService.EPAdministrator.CreateEPL(createEpl);
            epService.EPAdministrator.CreateEPL("insert into MyInfra select TheString, IntPrimitive from SupportBean");

            EPStatement indexStmt = null;

            if (createExplicitIndex)
            {
                indexStmt = epService.EPAdministrator.CreateEPL("create index MyIndex on MyInfra(TheString)");
            }

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean("E2", -2));

            string consumeEpl = "select (select IntPrimitive from MyInfra(IntPrimitive<0) sw where s0.p00=sw.TheString) as val from S0 s0";

            if (disableIndexShareConsumer)
            {
                consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl;
            }
            EPStatement consumeStmt = epService.EPAdministrator.CreateEPL(consumeEpl);

            consumeStmt.AddListener(listener);

            epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E1"));
            Assert.AreEqual(null, listener.AssertOneGetNewAndReset().Get("val"));

            epService.EPRuntime.SendEvent(new SupportBean_S0(20, "E2"));
            Assert.AreEqual(-2, listener.AssertOneGetNewAndReset().Get("val"));

            epService.EPRuntime.SendEvent(new SupportBean("E3", -3));
            epService.EPRuntime.SendEvent(new SupportBean("E4", 4));

            epService.EPRuntime.SendEvent(new SupportBean_S0(-3, "E3"));
            Assert.AreEqual(-3, listener.AssertOneGetNewAndReset().Get("val"));

            epService.EPRuntime.SendEvent(new SupportBean_S0(20, "E4"));
            Assert.AreEqual(null, listener.AssertOneGetNewAndReset().Get("val"));

            consumeStmt.Stop();
            if (indexStmt != null)
            {
                indexStmt.Stop();
            }
            consumeStmt.Dispose();
            if (indexStmt != null)
            {
                indexStmt.Dispose();
            }
            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }
Exemplo n.º 16
0
        private void RunAssertionWithRefTime(String epl)
        {
            String[]    fields = "id".Split(',');
            EPStatement stmt   = _epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E1", "08:00:00.000"));
            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E2", "08:00:04.999"));
            Assert.IsFalse(_listener.IsInvoked);

            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E3", "08:00:05.000"));
            EPAssertionUtil.AssertPropsPerRow(
                _listener.AssertInvokedAndReset(), fields,
                new Object[][]
            {
                new Object[]
                {
                    "E1"
                }, new Object[]
                {
                    "E2"
                }
            }, null);

            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E4", "08:00:04.000"));
            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E5", "07:00:00.000"));
            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E6", "08:01:04.999"));
            Assert.IsFalse(_listener.IsInvoked);

            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E7", "08:01:05.000"));
            EPAssertionUtil.AssertPropsPerRow(
                _listener.AssertInvokedAndReset(), fields,
                new Object[][]
            {
                new Object[] { "E3" },
                new Object[] { "E4" },
                new Object[] { "E5" },
                new Object[] { "E6" }
            },
                new Object[][]
            {
                new Object[] { "E1" },
                new Object[] { "E2" }
            });

            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E8", "08:03:55.000"));
            EPAssertionUtil.AssertPropsPerRow(
                _listener.AssertInvokedAndReset(), fields,
                new Object[][]
            {
                new Object[] { "E7" }
            },
                new Object[][]
            {
                new Object[] { "E3" },
                new Object[] { "E4" },
                new Object[] { "E5" },
                new Object[] { "E6" }
            });

            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E9", "00:00:00.000"));
            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E10", "08:04:04.999"));
            _epService.EPRuntime.SendEvent(MyEvent.MakeTime("E11", "08:04:05.000"));
            EPAssertionUtil.AssertPropsPerRow(
                _listener.AssertInvokedAndReset(), fields,
                new Object[][]
            {
                new Object[] { "E8" },
                new Object[] { "E9" },
                new Object[] { "E10" }
            },
                new Object[][]
            {
                new Object[] { "E7" }
            });

            stmt.Dispose();
        }
Exemplo n.º 17
0
        private void RunAssertionAggregation(EPServiceProvider epService)
        {
            // Test ungrouped
            var         fields        = new[] { "TheString" };
            EPStatement stmtUngrouped = epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#expr(sum(IntPrimitive) < 10)");
            var         listener      = new SupportUpdateListener();

            stmtUngrouped.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E1" } });
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" });

            epService.EPRuntime.SendEvent(new SupportBean("E2", 9));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E2" } });
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E2" } }, new[] { new object[] { "E1" } });

            epService.EPRuntime.SendEvent(new SupportBean("E3", 11));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, null);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E3" } }, new[] { new object[] { "E2" }, new object[] { "E3" } });

            epService.EPRuntime.SendEvent(new SupportBean("E4", 12));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, null);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E4" } }, new[] { new object[] { "E4" } });

            epService.EPRuntime.SendEvent(new SupportBean("E5", 1));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E5" } });
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E5" } }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E6", 2));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E5" }, new object[] { "E6" } });
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E6" } }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E7", 3));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E5" }, new object[] { "E6" }, new object[] { "E7" } });
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E7" } }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E8", 6));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E7" }, new object[] { "E8" } });
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E8" } }, new[] { new object[] { "E5" }, new object[] { "E6" } });

            epService.EPRuntime.SendEvent(new SupportBean("E9", 9));
            EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new[] { new object[] { "E9" } });
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E9" } }, new[] { new object[] { "E7" }, new object[] { "E8" } });

            stmtUngrouped.Dispose();

            // Test grouped
            EPStatement stmtGrouped = epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#groupwin(IntPrimitive)#expr(sum(LongPrimitive) < 10)");

            stmtGrouped.Events += listener.Update;

            SendEvent(epService, "E1", 1, 5);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E1" } }, null);

            SendEvent(epService, "E2", 2, 2);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E2" } }, null);

            SendEvent(epService, "E3", 1, 3);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E3" } }, null);

            SendEvent(epService, "E4", 2, 4);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E4" } }, null);

            SendEvent(epService, "E5", 2, 6);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E5" } }, new[] { new object[] { "E2" }, new object[] { "E4" } });

            SendEvent(epService, "E6", 1, 2);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E6" } }, new[] { new object[] { "E1" } });

            stmtGrouped.Dispose();

            // Test on-delete
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_A", typeof(SupportBean_A));
            EPStatement stmt = epService.EPAdministrator.CreateEPL("create window NW#expr(sum(IntPrimitive) < 10) as SupportBean");

            stmt.Events += listener.Update;
            epService.EPAdministrator.CreateEPL("insert into NW select * from SupportBean");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E1" } }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E2", 8));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E2" } }, null);

            epService.EPAdministrator.CreateEPL("on SupportBean_A delete from NW where TheString = id");
            epService.EPRuntime.SendEvent(new SupportBean_A("E2"));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, null, new[] { new object[] { "E2" } });

            epService.EPRuntime.SendEvent(new SupportBean("E3", 7));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E3" } }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E4", 2));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new[] { new object[] { "E4" } }, new[] { new object[] { "E1" } });

            stmt.Dispose();
        }
Exemplo n.º 18
0
        private void RunAssertionSkipToNextRowPartitioned(EPServiceProvider epService)
        {
            string[] fields = "a_string,a_value,b_value".Split(',');
            string   text   = "select * from MyEvent#keepall " +
                              "match_recognize (" +
                              "  partition by TheString" +
                              "  measures A.TheString as a_string, A.value as a_value, B.value as b_value " +
                              "  all matches " +
                              "  after match skip to next row " +
                              "  pattern (A B) " +
                              "  define B as (B.value > A.value)" +
                              ")" +
                              " order by a_string";

            EPStatement stmt     = epService.EPAdministrator.CreateEPL(text);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 6));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S3", 3));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 4));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 5));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 4));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", -1));
            Assert.IsFalse(listener.IsInvoked);
            Assert.IsFalse(stmt.HasFirst());

            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 6));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 10));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new object[][] { new object[] { "S4", -1, 10 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 }, new object[] { "S4", -1, 10 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 11));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new object[][] { new object[] { "S4", 10, 11 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 }, new object[] { "S4", -1, 10 }, new object[] { "S4", 10, 11 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S3", 3));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", -1));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S3", 2));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 4));
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 }, new object[] { "S4", -1, 10 }, new object[] { "S4", 10, 11 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 7));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new object[][] { new object[] { "S1", 4, 7 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 }, new object[] { "S1", 4, 7 }, new object[] { "S4", -1, 10 }, new object[] { "S4", 10, 11 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 12));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new object[][] { new object[] { "S4", -1, 12 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 }, new object[] { "S1", 4, 7 }, new object[] { "S4", -1, 10 }, new object[] { "S4", 10, 11 }, new object[] { "S4", -1, 12 } });

            epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 12));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 7));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 4));
            epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 5));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 5));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields,
                                              new object[][] { new object[] { "S2", 4, 5 } });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields,
                                              new object[][] { new object[] { "S1", 4, 6 }, new object[] { "S1", 4, 7 }, new object[] { "S2", 4, 5 }, new object[] { "S4", -1, 10 }, new object[] { "S4", 10, 11 }, new object[] { "S4", -1, 12 } });

            stmt.Dispose();
        }
        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();
        }
        private void RunConstantValueAssertion(EPServiceProvider epService, bool indexShare, bool buildIndex)
        {
            string createEpl = "create window MyWindow#keepall as select * from SupportBean";

            if (indexShare)
            {
                createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl;
            }
            epService.EPAdministrator.CreateEPL(createEpl);

            if (buildIndex)
            {
                epService.EPAdministrator.CreateEPL("create index idx1 on MyWindow(TheString hash, IntPrimitive btree)");
            }
            epService.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportBean");

            // preload
            for (int i = 0; i < 10000; i++)
            {
                var bean = new SupportBean("E" + i, i);
                bean.DoublePrimitive = i;
                epService.EPRuntime.SendEvent(bean);
            }

            // single-field compare
            string[]    fields     = "val".Split(',');
            string      eplSingle  = "select (select IntPrimitive from MyWindow where TheString = 'E9734') as val from SupportBeanRange sbr";
            EPStatement stmtSingle = epService.EPAdministrator.CreateEPL(eplSingle);
            var         listener   = new SupportUpdateListener();

            stmtSingle.Events += listener.Update;

            long startTime = DateTimeHelper.CurrentTimeMillis;

            for (int i = 0; i < 1000; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBeanRange("R", "", -1, -1));
                EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 9734 });
            }
            long delta = DateTimeHelper.CurrentTimeMillis - startTime;

            Assert.IsTrue(delta < 500, "delta=" + delta);
            stmtSingle.Dispose();

            // two-field compare
            string      eplTwoHash  = "select (select IntPrimitive from MyWindow where TheString = 'E9736' and IntPrimitive = 9736) as val from SupportBeanRange sbr";
            EPStatement stmtTwoHash = epService.EPAdministrator.CreateEPL(eplTwoHash);

            stmtTwoHash.Events += listener.Update;

            startTime = DateTimeHelper.CurrentTimeMillis;
            for (int i = 0; i < 1000; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBeanRange("R", "", -1, -1));
                EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 9736 });
            }
            delta = DateTimeHelper.CurrentTimeMillis - startTime;
            Assert.IsTrue(delta < 500, "delta=" + delta);
            stmtTwoHash.Dispose();

            // range compare single
            if (buildIndex)
            {
                epService.EPAdministrator.CreateEPL("create index idx2 on MyWindow(IntPrimitive btree)");
            }
            string      eplSingleBTree  = "select (select IntPrimitive from MyWindow where IntPrimitive between 9735 and 9735) as val from SupportBeanRange sbr";
            EPStatement stmtSingleBtree = epService.EPAdministrator.CreateEPL(eplSingleBTree);

            stmtSingleBtree.Events += listener.Update;

            startTime = DateTimeHelper.CurrentTimeMillis;
            for (int i = 0; i < 1000; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBeanRange("R", "", -1, -1));
                EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 9735 });
            }
            delta = DateTimeHelper.CurrentTimeMillis - startTime;
            Assert.IsTrue(delta < 500, "delta=" + delta);
            stmtSingleBtree.Dispose();

            // range compare composite
            string      eplComposite  = "select (select IntPrimitive from MyWindow where TheString = 'E9738' and IntPrimitive between 9738 and 9738) as val from SupportBeanRange sbr";
            EPStatement stmtComposite = epService.EPAdministrator.CreateEPL(eplComposite);

            stmtComposite.Events += listener.Update;

            startTime = DateTimeHelper.CurrentTimeMillis;
            for (int i = 0; i < 1000; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBeanRange("R", "", -1, -1));
                EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 9738 });
            }
            delta = DateTimeHelper.CurrentTimeMillis - startTime;
            Assert.IsTrue(delta < 500, "delta=" + delta);
            stmtComposite.Dispose();

            // destroy all
            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 21
0
        public void TestInsertIntoWildcardUndType()
        {
            string[] fields = new string[] { "TheString", "IntPrimitive" };

            // create window
            string      stmtTextCreate = "create window MyWindow.win:keepall() as select * from " + typeof(SupportBean).FullName;
            EPStatement stmtCreate     = _epService.EPAdministrator.CreateEPL(stmtTextCreate);

            // create insert into
            string stmtTextInsertOne = "insert into MyWindow select * from " + typeof(SupportBean).FullName + "(TheString like 'E%')";

            _epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // create on-select stmt
            string      stmtTextSelect = "on " + typeof(SupportBean_A).FullName + " insert into MyStream select mywin.* from MyWindow as mywin order by TheString asc";
            EPStatement stmtSelect     = _epService.EPAdministrator.CreateEPL(stmtTextSelect);

            stmtSelect.AddListener(_listenerSelect);
            Assert.AreEqual(StatementType.ON_INSERT, ((EPStatementSPI)stmtSelect).StatementMetadata.StatementType);

            // create consuming statement
            string      stmtTextConsumer = "select * from default.MyStream";
            EPStatement stmtConsumer     = _epService.EPAdministrator.CreateEPL(stmtTextConsumer);

            stmtConsumer.AddListener(_listenerConsumer);

            // create second inserting statement
            string stmtTextInsertTwo = "insert into MyStream select * from " + typeof(SupportBean).FullName + "(TheString like 'I%')";

            _epService.EPAdministrator.CreateEPL(stmtTextInsertTwo);

            // send event
            SendSupportBean("E1", 1);
            Assert.IsFalse(_listenerSelect.IsInvoked);
            Assert.IsFalse(_listenerConsumer.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } });

            // fire trigger
            SendSupportBean_A("A1");
            EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
            EPAssertionUtil.AssertProps(_listenerConsumer.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });

            // insert via 2nd insert into
            SendSupportBean("I2", 2);
            Assert.IsFalse(_listenerSelect.IsInvoked);
            EPAssertionUtil.AssertProps(_listenerConsumer.AssertOneGetNewAndReset(), fields, new object[] { "I2", 2 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } });

            // send event
            SendSupportBean("E3", 3);
            Assert.IsFalse(_listenerSelect.IsInvoked);
            Assert.IsFalse(_listenerConsumer.IsInvoked);
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E3", 3 } });

            // fire trigger
            SendSupportBean_A("A2");
            Assert.AreEqual(1, _listenerSelect.NewDataList.Count);
            EPAssertionUtil.AssertPropsPerRow(_listenerSelect.LastNewData, fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E3", 3 } });
            _listenerSelect.Reset();
            Assert.AreEqual(2, _listenerConsumer.NewDataList.Count);
            EPAssertionUtil.AssertPropsPerRow(_listenerConsumer.GetNewDataListFlattened(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E3", 3 } });
            _listenerConsumer.Reset();

            // check type
            EventType consumerType = stmtConsumer.EventType;

            Assert.AreEqual(typeof(string), consumerType.GetPropertyType("TheString"));
            Assert.IsTrue(consumerType.PropertyNames.Length > 10);
            Assert.AreEqual(typeof(SupportBean), consumerType.UnderlyingType);

            // check type
            EventType onSelectType = stmtSelect.EventType;

            Assert.AreEqual(typeof(string), onSelectType.GetPropertyType("TheString"));
            Assert.IsTrue(onSelectType.PropertyNames.Length > 10);
            Assert.AreEqual(typeof(SupportBean), onSelectType.UnderlyingType);

            // delete all from named window
            string stmtTextDelete = "on " + typeof(SupportBean_B).FullName + " delete from MyWindow";

            _epService.EPAdministrator.CreateEPL(stmtTextDelete);
            SendSupportBean_B("B1");

            // fire trigger - nothing to insert
            SendSupportBean_A("A3");

            stmtConsumer.Dispose();
            stmtSelect.Dispose();
            stmtCreate.Dispose();
        }
        private void RunAssertionGroupByEventPerGroupBatchContextProp(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL(
                "@Name('context') create context SegmentedByString partition by TheString from SupportBean");

            string[]    fieldsOne = "IntPrimitive,count(*)".Split(',');
            EPStatement stmtOne   = epService.EPAdministrator.CreateEPL(
                "@Name('A') context SegmentedByString select IntPrimitive, count(*) from SupportBean#length_batch(2) group by IntPrimitive order by IntPrimitive asc");
            var listener = new SupportUpdateListener();

            stmtOne.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("G1", 10));
            epService.EPRuntime.SendEvent(new SupportBean("G2", 200));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean("G1", 11));
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fieldsOne, new object[] { 10, 1L });
            EPAssertionUtil.AssertProps(listener.GetAndResetLastNewData()[1], fieldsOne, new object[] { 11, 1L });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 10));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean("G2", 200));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsOne, new object[] { 200, 2L });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 10));
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fieldsOne, new object[] { 10, 2L });
            EPAssertionUtil.AssertProps(listener.GetAndResetLastNewData()[1], fieldsOne, new object[] { 11, 0L });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 10));
            epService.EPRuntime.SendEvent(new SupportBean("G2", 10));
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fieldsOne, new object[] { 10, 2L });
            EPAssertionUtil.AssertProps(listener.GetAndResetLastNewData()[1], fieldsOne, new object[] { 200, 0L });

            stmtOne.Dispose();

            // add "string" : add context property
            string[]    fieldsTwo = "TheString,IntPrimitive,count(*)".Split(',');
            EPStatement stmtTwo   = epService.EPAdministrator.CreateEPL(
                "@Name('B') context SegmentedByString select TheString, IntPrimitive, count(*) from SupportBean#length_batch(2) group by IntPrimitive order by TheString, IntPrimitive asc");

            stmtTwo.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("G1", 10));
            epService.EPRuntime.SendEvent(new SupportBean("G2", 200));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean("G1", 11));
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fieldsTwo, new object[] { "G1", 10, 1L });
            EPAssertionUtil.AssertProps(listener.GetAndResetLastNewData()[1], fieldsTwo, new object[] { "G1", 11, 1L });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 10));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean("G2", 200));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "G2", 200, 2L });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 10));
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fieldsTwo, new object[] { "G1", 10, 2L });
            EPAssertionUtil.AssertProps(listener.GetAndResetLastNewData()[1], fieldsTwo, new object[] { "G1", 11, 0L });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 10));
            epService.EPRuntime.SendEvent(new SupportBean("G2", 10));
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fieldsTwo, new object[] { "G2", 10, 2L });
            EPAssertionUtil.AssertProps(listener.GetAndResetLastNewData()[1], fieldsTwo, new object[] { "G2", 200, 0L });

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 23
0
        private void RunAssertionCustomProps(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(MyOperatorOne));
            epService.EPAdministrator.Configuration.AddImport(typeof(MyOperatorTwo));

            // test simple properties
            MyOperatorOne.Operators.Clear();
            EPStatement stmtGraph = epService.EPAdministrator.CreateEPL(
                "create dataflow MyGraph " + typeof(MyOperatorOne).Name + " {" +
                "  TheString = 'a'," +
                "  TheInt: 1," +
                "  TheBool: true," +
                "  TheLongOne: 1L," +
                "  TheLongTwo: 2," +
                "  TheLongThree: null," +
                "  TheDoubleOne: 1d," +
                "  TheDoubleTwo: 2," +
                "  TheFloatOne: 1f," +
                "  TheFloatTwo: 2," +
                "  TheStringWithSetter: 'b'," +
                "  TheSystemProperty: systemProperties('Path')" +
                "}");

            epService.EPRuntime.DataFlowRuntime.Instantiate("MyGraph");
            Assert.AreEqual(1, MyOperatorOne.Operators.Count);
            MyOperatorOne instanceOne = MyOperatorOne.Operators[0];

            Assert.AreEqual("a", instanceOne.TheString);
            Assert.AreEqual(null, instanceOne.TheNotSetString);
            Assert.AreEqual(1, instanceOne.TheInt);
            Assert.AreEqual(true, instanceOne.TheBool);
            Assert.AreEqual(1L, (long)instanceOne.TheLongOne);
            Assert.AreEqual(2, instanceOne.TheLongTwo);
            Assert.AreEqual(null, instanceOne.TheLongThree);
            Assert.AreEqual(1.0, instanceOne.TheDoubleOne);
            Assert.AreEqual(2.0, instanceOne.TheDoubleTwo);
            Assert.AreEqual(1f, instanceOne.TheFloatOne);
            Assert.AreEqual(2f, instanceOne.TheFloatTwo);
            Assert.AreEqual(">b<", instanceOne.TheStringWithSetter);
            Assert.NotNull(instanceOne.TheSystemProperty);
            stmtGraph.Dispose();

            // test array etc. properties
            MyOperatorTwo.Operators.Clear();
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyGraph " + typeof(MyOperatorTwo).Name + " {\n" +
                "  theStringArray: ['a', \"b\"],\n" +
                "  theIntArray: [1, 2, 3],\n" +
                "  theObjectArray: ['a', 1],\n" +
                "  theMap: {\n" +
                "    a : 10,\n" +
                "    b : 'xyz'\n" +
                "  },\n" +
                "  theInnerOp: {\n" +
                "    fieldOne: 'x',\n" +
                "    fieldTwo: 2\n" +
                "  },\n" +
                "  theInnerOpInterface: {\n" +
                "    class: '" + typeof(MyOperatorTwoInterfaceImplTwo).FullName + "'\n" +
                "  },\n" + // NOTE the last comma here, it's acceptable
                "}");
            epService.EPRuntime.DataFlowRuntime.Instantiate("MyGraph");
            Assert.AreEqual(1, MyOperatorTwo.Operators.Count);
            MyOperatorTwo instanceTwo = MyOperatorTwo.Operators[0];

            EPAssertionUtil.AssertEqualsExactOrder(new string[] { "a", "b" }, instanceTwo.TheStringArray);
            EPAssertionUtil.AssertEqualsExactOrder(new int[] { 1, 2, 3 }, instanceTwo.TheIntArray);
            EPAssertionUtil.AssertEqualsExactOrder(new object[] { "a", 1 }, instanceTwo.TheObjectArray);
            EPAssertionUtil.AssertPropsMap(instanceTwo.TheMap, "a,b".SplitCsv(), new object[] { 10, "xyz" });
            Assert.AreEqual("x", instanceTwo.TheInnerOp.FieldOne);
            Assert.AreEqual(2, instanceTwo.TheInnerOp.FieldTwo);
            Assert.IsTrue(instanceTwo.TheInnerOpInterface is MyOperatorTwoInterfaceImplTwo);
        }
        private void RunAssertionGroupByEventForAll(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL(
                "@Name('context') create context SegmentedByString partition by TheString from SupportBean");

            // test aggregation-only (no access)
            string[]    fieldsOne = "col1".Split(',');
            EPStatement stmtOne   = epService.EPAdministrator.CreateEPL(
                "@Name('A') context SegmentedByString " +
                "select sum(IntPrimitive) as col1 " +
                "from SupportBean");
            var listener = new SupportUpdateListener();

            stmtOne.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("G1", 3));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsOne, new object[] { 3 });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 2));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsOne, new object[] { 2 });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 4));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsOne, new object[] { 7 });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsOne, new object[] { 3 });

            epService.EPRuntime.SendEvent(new SupportBean("G3", -1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fieldsOne, new object[] { -1 });

            stmtOne.Dispose();

            // test mixed with access
            string[]    fieldsTwo = "col1,col2".Split(',');
            EPStatement stmtTwo   = epService.EPAdministrator.CreateEPL(
                "@Name('A') context SegmentedByString " +
                "select sum(IntPrimitive) as col1, toArray(window(*).selectFrom(v=>v.IntPrimitive)) as col2 " +
                "from SupportBean#keepall");

            stmtTwo.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("G1", 8));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsTwo, new object[] { 8, new object[] { 8 } });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 5));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsTwo, new object[] { 5, new object[] { 5 } });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 1));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsTwo, new object[] { 9, new object[] { 8, 1 } });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 2));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsTwo, new object[] { 7, new object[] { 5, 2 } });

            stmtTwo.Dispose();

            // test only access
            string[]    fieldsThree = "col1".Split(',');
            EPStatement stmtThree   = epService.EPAdministrator.CreateEPL(
                "@Name('A') context SegmentedByString " +
                "select toArray(window(*).selectFrom(v=>v.IntPrimitive)) as col1 " +
                "from SupportBean#keepall");

            stmtThree.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("G1", 8));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsThree, new object[] { new object[] { 8 } });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 5));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsThree, new object[] { new object[] { 5 } });

            epService.EPRuntime.SendEvent(new SupportBean("G1", 1));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsThree, new object[] { new object[] { 8, 1 } });

            epService.EPRuntime.SendEvent(new SupportBean("G2", 2));
            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(), fieldsThree, new object[] { new object[] { 5, 2 } });

            stmtThree.Dispose();

            // test subscriber
            EPStatement stmtFour = epService.EPAdministrator.CreateEPL(
                "@Name('A') context SegmentedByString " +
                "select count(*) as col1 " +
                "from SupportBean");
            var subs = new SupportSubscriber();

            stmtFour.Subscriber = subs;

            epService.EPRuntime.SendEvent(new SupportBean("G1", 1));
            Assert.AreEqual(1L, subs.AssertOneGetNewAndReset());

            epService.EPRuntime.SendEvent(new SupportBean("G1", 1));
            Assert.AreEqual(2L, subs.AssertOneGetNewAndReset());

            epService.EPRuntime.SendEvent(new SupportBean("G2", 2));
            Assert.AreEqual(1L, subs.AssertOneGetNewAndReset());

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 25
0
        public void TestAddRemoveStmts()
        {
            String      stmtSelectText = "insert into ABCStream select * from SupportBean";
            EPStatement stmtSelect     = epService.EPAdministrator.CreateEPL(stmtSelectText);

            stmtSelect.Events += listener.Update;

            String      stmtOneText  = "@Drop select * from SupportBean where IntPrimitive = 1";
            EPStatement statementOne = epService.EPAdministrator.CreateEPL(stmtOneText);

            statementOne.Events += listeners[0].Update;

            String      stmtTwoText  = "@Drop select * from SupportBean where IntPrimitive = 2";
            EPStatement statementTwo = epService.EPAdministrator.CreateEPL(stmtTwoText);

            statementTwo.Events += listeners[1].Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(0, "E1");

            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(1, "E2");

            epService.EPRuntime.SendEvent(new SupportBean("E3", 1));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(0, "E3");

            epService.EPRuntime.SendEvent(new SupportBean("E4", 3));
            Assert.AreEqual("E4", listener.AssertOneGetNewAndReset().Get("TheString"));
            AssertReceivedNone();

            String      stmtThreeText  = "@Drop select * from SupportBean where IntPrimitive = 3";
            EPStatement statementThree = epService.EPAdministrator.CreateEPL(stmtThreeText);

            statementThree.Events += listeners[2].Update;

            epService.EPRuntime.SendEvent(new SupportBean("E5", 3));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(2, "E5");

            epService.EPRuntime.SendEvent(new SupportBean("E6", 1));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(0, "E6");

            statementOne.Dispose();
            epService.EPRuntime.SendEvent(new SupportBean("E7", 1));
            Assert.AreEqual("E7", listener.AssertOneGetNewAndReset().Get("TheString"));
            AssertReceivedNone();

            String      stmtSelectTextTwo = "@Priority(50) select * from SupportBean";
            EPStatement stmtSelectTwo     = epService.EPAdministrator.CreateEPL(stmtSelectTextTwo);

            stmtSelectTwo.Events += listenerTwo.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E8", 1));
            Assert.AreEqual("E8", listener.AssertOneGetNewAndReset().Get("TheString"));
            Assert.AreEqual("E8", listenerTwo.AssertOneGetNewAndReset().Get("TheString"));
            AssertReceivedNone();

            epService.EPRuntime.SendEvent(new SupportBean("E9", 2));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(1, "E9");
        }
Exemplo n.º 26
0
        private void TryAssertionStaggered(EPServiceProvider epService, EventRepresentationChoice outputType)
        {
            var fieldsOne = new string[] { "a1", "b1" };
            var fieldsTwo = new string[] { "a2", "b2" };

            // create window one
            string      stmtTextCreateOne = outputType.GetAnnotationText() + " create window MyWindowSTAG#keepall as select TheString as a1, IntPrimitive as b1 from " + typeof(SupportBean).FullName;
            EPStatement stmtCreateOne     = epService.EPAdministrator.CreateEPL(stmtTextCreateOne);
            var         listenerWindow    = new SupportUpdateListener();

            stmtCreateOne.Events += listenerWindow.Update;
            Assert.AreEqual(0, GetCount(epService, "MyWindowSTAG"));
            Assert.IsTrue(outputType.MatchesClass(stmtCreateOne.EventType.UnderlyingType));

            // create window two
            string      stmtTextCreateTwo = outputType.GetAnnotationText() + " create window MyWindowSTAGTwo#keepall as select TheString as a2, IntPrimitive as b2 from " + typeof(SupportBean).FullName;
            EPStatement stmtCreateTwo     = epService.EPAdministrator.CreateEPL(stmtTextCreateTwo);
            var         listenerWindowTwo = new SupportUpdateListener();

            stmtCreateTwo.Events += listenerWindowTwo.Update;
            Assert.AreEqual(0, GetCount(epService, "MyWindowSTAGTwo"));
            Assert.IsTrue(outputType.MatchesClass(stmtCreateTwo.EventType.UnderlyingType));

            // create delete stmt
            string      stmtTextDelete = "on MyWindowSTAG delete from MyWindowSTAGTwo where a1 = a2";
            EPStatement stmtDelete     = epService.EPAdministrator.CreateEPL(stmtTextDelete);
            var         listenerDelete = new SupportUpdateListener();

            stmtDelete.Events += listenerDelete.Update;
            Assert.AreEqual(StatementType.ON_DELETE, ((EPStatementSPI)stmtDelete).StatementMetadata.StatementType);

            // create insert into
            string stmtTextInsert = "insert into MyWindowSTAG select TheString as a1, IntPrimitive as b1 from " + typeof(SupportBean).FullName + "(IntPrimitive > 0)";

            epService.EPAdministrator.CreateEPL(stmtTextInsert);
            stmtTextInsert = "insert into MyWindowSTAGTwo select TheString as a2, IntPrimitive as b2 from " + typeof(SupportBean).FullName + "(IntPrimitive < 0)";
            epService.EPAdministrator.CreateEPL(stmtTextInsert);

            SendSupportBean(epService, "E1", -10);
            EPAssertionUtil.AssertProps(listenerWindowTwo.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "E1", -10 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 } });
            Assert.IsFalse(listenerWindow.IsInvoked);
            Assert.AreEqual(1, GetCount(epService, "MyWindowSTAGTwo"));

            SendSupportBean(epService, "E2", 5);
            EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), fieldsOne, new object[] { "E2", 5 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsOne, new object[][] { new object[] { "E2", 5 } });
            Assert.IsFalse(listenerWindowTwo.IsInvoked);
            Assert.AreEqual(1, GetCount(epService, "MyWindowSTAG"));

            SendSupportBean(epService, "E3", -1);
            EPAssertionUtil.AssertProps(listenerWindowTwo.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "E3", -1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 }, new object[] { "E3", -1 } });
            Assert.IsFalse(listenerWindow.IsInvoked);
            Assert.AreEqual(2, GetCount(epService, "MyWindowSTAGTwo"));

            SendSupportBean(epService, "E3", 1);
            EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), fieldsOne, new object[] { "E3", 1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsOne, new object[][] { new object[] { "E2", 5 }, new object[] { "E3", 1 } });
            EPAssertionUtil.AssertProps(listenerWindowTwo.AssertOneGetOldAndReset(), fieldsTwo, new object[] { "E3", -1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 } });
            Assert.AreEqual(2, GetCount(epService, "MyWindowSTAG"));
            Assert.AreEqual(1, GetCount(epService, "MyWindowSTAGTwo"));

            stmtDelete.Dispose();
            stmtCreateOne.Dispose();
            stmtCreateTwo.Dispose();
            listenerDelete.Reset();
            listenerWindow.Reset();
            listenerWindowTwo.Reset();
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowSTAG", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowSTAGTwo", true);
        }
        private void RunAssertionAddRemoveStmts(EPServiceProvider epService)
        {
            string      stmtSelectText = "insert into ABCStream select * from SupportBean";
            EPStatement stmtSelect     = epService.EPAdministrator.CreateEPL(stmtSelectText);
            var         listener       = new SupportUpdateListener();

            stmtSelect.Events += listener.Update;

            string      stmtOneText  = "@Drop select * from SupportBean where IntPrimitive = 1";
            EPStatement statementOne = epService.EPAdministrator.CreateEPL(stmtOneText);

            SupportUpdateListener[] listeners = SupportUpdateListener.MakeListeners(10);
            statementOne.Events += listeners[0].Update;

            string      stmtTwoText  = "@Drop select * from SupportBean where IntPrimitive = 2";
            EPStatement statementTwo = epService.EPAdministrator.CreateEPL(stmtTwoText);

            statementTwo.Events += listeners[1].Update;

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(listeners, 0, "E1");

            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(listeners, 1, "E2");

            epService.EPRuntime.SendEvent(new SupportBean("E3", 1));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(listeners, 0, "E3");

            epService.EPRuntime.SendEvent(new SupportBean("E4", 3));
            Assert.AreEqual("E4", listener.AssertOneGetNewAndReset().Get("TheString"));
            AssertReceivedNone(listeners);

            string      stmtThreeText  = "@Drop select * from SupportBean where IntPrimitive = 3";
            EPStatement statementThree = epService.EPAdministrator.CreateEPL(stmtThreeText);

            statementThree.Events += listeners[2].Update;

            epService.EPRuntime.SendEvent(new SupportBean("E5", 3));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(listeners, 2, "E5");

            epService.EPRuntime.SendEvent(new SupportBean("E6", 1));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(listeners, 0, "E6");

            statementOne.Dispose();
            epService.EPRuntime.SendEvent(new SupportBean("E7", 1));
            Assert.AreEqual("E7", listener.AssertOneGetNewAndReset().Get("TheString"));
            AssertReceivedNone(listeners);

            string      stmtSelectTextTwo = "@Priority(50) select * from SupportBean";
            EPStatement stmtSelectTwo     = epService.EPAdministrator.CreateEPL(stmtSelectTextTwo);
            var         listenerTwo       = new SupportUpdateListener();

            stmtSelectTwo.Events += listenerTwo.Update;

            epService.EPRuntime.SendEvent(new SupportBean("E8", 1));
            Assert.AreEqual("E8", listener.AssertOneGetNewAndReset().Get("TheString"));
            Assert.AreEqual("E8", listenerTwo.AssertOneGetNewAndReset().Get("TheString"));
            AssertReceivedNone(listeners);

            epService.EPRuntime.SendEvent(new SupportBean("E9", 2));
            Assert.IsFalse(listener.IsInvoked);
            AssertReceivedSingle(listeners, 1, "E9");

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 28
0
        public void TestCurrentTimestamp()
        {
            SendTimerUnisolated(5000);
            var fields = new String[]
            {
                "ct"
            };
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(
                "select Current_timestamp() as ct from SupportBean");

            stmt.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                5000L
            }
                );

            EPServiceProviderIsolated unit = _epService.GetEPServiceIsolated("i1");

            SendTimerIso(100000, unit);
            unit.EPAdministrator.AddStatement(new EPStatement[]
            {
                stmt
            }
                                              );

            unit.EPRuntime.SendEvent(new SupportBean());
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                100000L
            }
                );

            _epService.EPAdministrator.DestroyAllStatements();

            stmt = _epService.EPAdministrator.CreateEPL(
                "select TheString as ct from SupportBean where Current_timestamp() >= 10000");
            stmt.Events += _listener.Update;

            unit.EPRuntime.SendEvent(new SupportBean());
            Assert.IsFalse(_listener.IsInvoked);

            SendTimerUnisolated(10000);
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                "E1"
            }
                );

            unit.EPAdministrator.AddStatement(stmt);

            unit.EPRuntime.SendEvent(new SupportBean("E2", 1));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                "E2"
            }
                );

            stmt.Dispose();
            stmt = _epService.EPAdministrator.CreateEPL(
                "select TheString as ct from SupportBean where Current_timestamp() >= 120000");
            stmt.Events += _listener.Update;
            unit.EPAdministrator.AddStatement(new EPStatement[]
            {
                stmt
            }
                                              );

            unit.EPRuntime.SendEvent(new SupportBean("E3", 1));
            Assert.IsFalse(_listener.IsInvoked);

            SendTimerIso(120000, unit);

            unit.EPRuntime.SendEvent(new SupportBean("E4", 1));
            EPAssertionUtil.AssertProps(
                _listener.AssertOneGetNewAndReset(), fields,
                new Object[]
            {
                "E4"
            }
                );
        }
        private void TryAssertionFour(EPServiceProvider epService, string expression)
        {
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(expression);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            string[] fields = "id,valh0,valh1,valh2".Split(',');
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, null);

            SendBeanInt(epService, "E1", 2, 2, 2, 1);
            EPAssertionUtil.AssertPropsPerRow(
                listener.GetAndResetLastNewData(), fields,
                new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H11",
                    "H01H21"
                }
            });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                stmt.GetEnumerator(), fields, new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H11",
                    "H01H21"
                }
            });

            SendBeanInt(epService, "E2", 4, 4, 4, 3);
            EPAssertionUtil.AssertPropsPerRow(
                listener.GetAndResetLastNewData(), fields,
                new object[][] {
                new object[] {
                    "E2",
                    "H03",
                    "H13",
                    "H03H23"
                }
            });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                stmt.GetEnumerator(), fields,
                new object[][] {
                new object[] {
                    "E1",
                    "H01",
                    "H11",
                    "H01H21"
                },
                new object[] {
                    "E2",
                    "H03",
                    "H13",
                    "H03H23"
                }
            });

            stmt.Dispose();
        }
Exemplo n.º 30
0
        private void RunAssertionStartStopConsumer(bool namedWindow)
        {
            // create window
            string stmtTextCreate = namedWindow ?
                                    "create window MyInfra.win:keepall() as select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName :
                                    "create table MyInfra(a string primary key, b int primary key)";
            EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate);

            stmtCreate.AddListener(_listenerWindow);

            // create insert into
            string stmtTextInsertOne = "insert into MyInfra select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName;

            _epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // create consumer
            string[]    fields         = new string[] { "a", "b" };
            string      stmtTextSelect = "select a, b from MyInfra as s1";
            EPStatement stmtSelect     = _epService.EPAdministrator.CreateEPL(stmtTextSelect);

            stmtSelect.AddListener(_listenerSelect);

            // send 1 event
            SendSupportBean("E1", 1);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 });
            }
            EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } });

            // stop consumer
            stmtSelect.Stop();
            SendSupportBean("E2", 2);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 });
            }
            Assert.IsFalse(_listenerSelect.IsInvoked);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } });

            // start consumer: the consumer has the last event even though he missed it
            stmtSelect.Start();
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } });

            // consumer receives the next event
            SendSupportBean("E3", 3);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 });
                EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 });
                EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 }, new object[] { "E3", 3 } });
            }
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 }, new object[] { "E3", 3 } });

            // destroy consumer
            stmtSelect.Dispose();
            SendSupportBean("E4", 4);
            if (namedWindow)
            {
                EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E4", 4 });
            }
            Assert.IsFalse(_listenerSelect.IsInvoked);

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false);
        }