Exemplo n.º 1
0
        public void TestInsertConsume()
        {
            _epService.EPAdministrator.CreateEPL("create window MyVDW.test:vdw() as SupportBean");
            var window      = (SupportVirtualDW)GetFromContext("/virtualdw/MyVDW");
            var supportBean = new SupportBean("S1", 100);

            window.Data = supportBean.AsSingleton();
            _epService.EPAdministrator.CreateEPL("insert into MyVDW select * from SupportBean");

            // test straight consume
            var fields      = "TheString,IntPrimitive".Split(',');
            var stmtConsume = _epService.EPAdministrator.CreateEPL("select irstream * from MyVDW");

            stmtConsume.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 200));
            Assert.IsNull(_listener.LastOldData);
            EPAssertionUtil.AssertProps(_listener.GetAndResetLastNewData()[0], fields, new Object[] { "E1", 200 });
            stmtConsume.Dispose();

            // test aggregated consumer - wherein the virtual data window does not return an iterator that prefills the aggregation state
            fields = "val0".Split(',');
            var stmtAggregate = _epService.EPAdministrator.CreateEPL("select sum(IntPrimitive) as val0 from MyVDW");

            stmtAggregate.Events += _listener.Update;

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

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 150 });
            stmtAggregate.Dispose();
        }
Exemplo n.º 2
0
        public void TestInsertConsume()
        {
            _epService.EPAdministrator.CreateEPL("create window MyVDW.test:vdw() as SupportBean");
            var window      = (SupportVirtualDW)GetFromContext("/virtualdw/MyVDW");
            var supportBean = new SupportBean("S1", 100);

            window.Data = supportBean.AsSingleton();
            _epService.EPAdministrator.CreateEPL("insert into MyVDW select * from SupportBean");

            // test aggregated consumer - wherein the virtual data window does not return an iterator that prefills the aggregation state
            var fields        = "val0".Split(',');
            var stmtAggregate = _epService.EPAdministrator.CreateEPL("@Name('ABC') select sum(IntPrimitive) as val0 from MyVDW");

            stmtAggregate.Events += _listener.Update;
            EPAssertionUtil.AssertProps(stmtAggregate.First(), fields, new Object[] { 100 });

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

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

            // assert events received for add-consumer and remove-consumer
            stmtAggregate.Dispose();
            var addConsumerEvent    = (VirtualDataWindowEventConsumerAdd)window.Events[0];
            var removeConsumerEvent = (VirtualDataWindowEventConsumerRemove)window.Events[1];

            foreach (var @base in new VirtualDataWindowEventConsumerBase[] { addConsumerEvent, removeConsumerEvent })
            {
                Assert.AreEqual(-1, @base.AgentInstanceId);
                Assert.AreEqual("MyVDW", @base.NamedWindowName);
                Assert.AreEqual("ABC", @base.StatementName);
            }
            Assert.AreSame(removeConsumerEvent.ConsumerObject, addConsumerEvent.ConsumerObject);
            window.Events.Clear();

            // test filter criteria passed to event
            var stmtAggregateWFilter = _epService.EPAdministrator.CreateEPL("@Name('ABC') select sum(IntPrimitive) as val0 from MyVDW(TheString = 'A')");
            var eventWithFilter      = (VirtualDataWindowEventConsumerAdd)window.Events[0];

            Assert.AreEqual(1, eventWithFilter.FilterExpressions.Length);
            Assert.IsNotNull(eventWithFilter.ExprEvaluatorContext);
            stmtAggregateWFilter.Dispose();
        }
Exemplo n.º 3
0
        public void TestLimitation()
        {
            var stmtWindow  = _epService.EPAdministrator.CreateEPL("create window MyVDW.test:vdw() as SupportBean");
            var window      = (SupportVirtualDW)GetFromContext("/virtualdw/MyVDW");
            var supportBean = new SupportBean("S1", 100);

            window.Data = supportBean.AsSingleton();
            _epService.EPAdministrator.CreateEPL("insert into MyVDW select * from SupportBean");

            // cannot iterate named window
            Assert.IsFalse(stmtWindow.HasFirst());

            // test data window aggregation (rows not included in aggregation)
            var stmtAggregate = _epService.EPAdministrator.CreateEPL("select Window(TheString) as val0 from MyVDW");

            stmtAggregate.Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 100));
            EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "E1" }, (String[])_listener.AssertOneGetNewAndReset().Get("val0"));
        }
Exemplo n.º 4
0
        private void RunAssertionVirtualDw(CaseEnum caseEnum, String uniqueFields, String whereClause, bool unique, IndexAssertionEventSend assertion)
        {
            SupportVirtualDWFactory.UniqueKeys = new HashSet <String>(uniqueFields.SplitCsv());
            _epService.EPAdministrator.CreateEPL("create window MyVDW.test:vdw() as SupportBean");
            var window      = (SupportVirtualDW)GetFromContext("/virtualdw/MyVDW");
            var supportBean = new SupportBean("S1", 101);

            supportBean.DoublePrimitive = 102;
            supportBean.LongPrimitive   = 103;
            window.Data = supportBean.AsSingleton();

            var eplUnique = IndexBackingTableInfo.INDEX_CALLBACK_HOOK + "select * from ";

            if (caseEnum == CaseEnum.UNIDIRECTIONAL)
            {
                eplUnique += "SSB1 as ssb1 unidirectional ";
            }
            else
            {
                eplUnique += "SSB1.std:lastevent() as ssb1 ";
            }
            eplUnique += ", MyVDW as vdw ";
            eplUnique += whereClause;

            var stmtUnique = _epService.EPAdministrator.CreateEPL(eplUnique);

            stmtUnique.Events += _listener.Update;

            // assert query plan
            SupportQueryPlanIndexHook.AssertJoinOneStreamAndReset(unique);

            // run assertion
            assertion.Invoke();

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemplo n.º 5
0
        public void TestJoinAndLifecyle()
        {
            var stmt = _epService.EPAdministrator.CreateEPL("create window MyVDW.test:vdw(1, 'abc') as SupportBean");

            // define some test data to return, via lookup
            var window      = (SupportVirtualDW)GetFromContext("/virtualdw/MyVDW");
            var supportBean = new SupportBean("S1", 100);

            supportBean.LongPrimitive = 50;
            window.Data = supportBean.AsSingleton();

            Assert.NotNull(window.Context.EventFactory);
            Assert.AreEqual("MyVDW", window.Context.EventType.Name);
            Assert.NotNull(window.Context.StatementContext);
            Assert.AreEqual(2, window.Context.Parameters.Length);
            Assert.AreEqual(1, window.Context.Parameters[0]);
            Assert.AreEqual("abc", window.Context.Parameters[1]);
            Assert.AreEqual("MyVDW", window.Context.NamedWindowName);

            // test no-criteria join
            var fields      = "st0.id,vdw.TheString,vdw.IntPrimitive".Split(',');
            var stmtJoinAll = _epService.EPAdministrator.CreateEPL("select * from MyVDW vdw, SupportBean_ST0.std:lastevent() st0");

            stmtJoinAll.Events += _listener.Update;
            AssertIndexSpec(window.LastRequestedIndex, "", "");

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", "S1", 100 });
            EPAssertionUtil.AssertEqualsExactOrder(new Object[] { }, window.LastAccessKeys);
            stmtJoinAll.Dispose();

            // test single-criteria join
            var stmtJoinSingle = _epService.EPAdministrator.CreateEPL("select * from MyVDW vdw, SupportBean_ST0.std:lastevent() st0 where vdw.TheString = st0.id");

            stmtJoinSingle.Events += _listener.Update;
            AssertIndexSpec(window.LastRequestedIndex, "TheString=(String)", "");

            _epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0));
            EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "E1" }, window.LastAccessKeys);
            Assert.IsFalse(_listener.IsInvoked);
            _epService.EPRuntime.SendEvent(new SupportBean_ST0("S1", 0));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "S1", "S1", 100 });
            EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "S1" }, window.LastAccessKeys);
            stmtJoinSingle.Dispose();

            // test multi-criteria join
            var stmtJoinMulti = _epService.EPAdministrator.CreateEPL("select vdw.TheString from MyVDW vdw, SupportBeanRange.std:lastevent() st0 " +
                                                                     "where vdw.TheString = st0.id and LongPrimitive = keyLong and IntPrimitive between rangeStart and rangeEnd");

            stmtJoinMulti.Events += _listener.Update;
            AssertIndexSpec(window.LastRequestedIndex, "TheString=(String)|LongPrimitive=(Nullable<Int64>)", "IntPrimitive[,](Nullable<Int32>)");

            _epService.EPRuntime.SendEvent(SupportBeanRange.MakeKeyLong("S1", 50L, 80, 120));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "vdw.TheString".Split(','), new Object[] { "S1" });
            EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "S1", 50L, new VirtualDataWindowKeyRange(80, 120) }, window.LastAccessKeys);

            // destroy
            stmt.Dispose();
            Assert.IsNull(GetFromContext("/virtualdw/MyVDW"));
            Assert.IsTrue(window.IsDestroyed);
        }