public void TestJoinUniquePerId()
        {
            String joinStatement = "select * from " +
                                   typeof(SupportMarketDataBean).FullName + "(Symbol='IBM').win:length(3) s0, " +
                                   typeof(SupportMarketDataBean).FullName + "(Symbol='CSCO').win:length(3) s1" +
                                   " where s0.Volume=s1.Volume";

            EPStatement joinView = _epService.EPAdministrator.CreateEPL(joinStatement, "MyJoin");

            joinView.Events += _updateListener.Update;

            SendEvent(setOne[0]);
            SendEvent(setTwo[0]);
            Assert.NotNull(_updateListener.LastNewData);
            _updateListener.Reset();

            joinView.Stop();
            SendEvent(setOne[1]);
            SendEvent(setTwo[1]);
            Assert.IsFalse(_updateListener.IsInvoked);

            joinView.Start();
            SendEvent(setOne[2]);
            Assert.IsFalse(_updateListener.IsInvoked);

            joinView.Stop();
            SendEvent(setOne[3]);
            SendEvent(setOne[4]);
            SendEvent(setTwo[3]);

            joinView.Start();
            SendEvent(setTwo[4]);
            Assert.IsFalse(_updateListener.IsInvoked);

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

            Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportMarketDataBean).FullName));
            ICollection <String> stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportMarketDataBean).FullName);

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

            joinView.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"));
        }
Beispiel #2
0
        private void RunAssertionBatchWindow(EPServiceProvider epService)
        {
            var fields = new string[] { "TheString" };

            EPStatement stmt     = epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#length_batch(3)#unique(IntPrimitive) retain-union");
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendEvent(epService, "E1", 1);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" });

            SendEvent(epService, "E2", 2);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" });

            SendEvent(epService, "E3", 3);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3" });

            SendEvent(epService, "E4", 4);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E4" });

            SendEvent(epService, "E5", 4);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4", "E5"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E5" });

            SendEvent(epService, "E6", 4);     // remove stream is E1, E2, E3
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4", "E5", "E6"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E6" });

            SendEvent(epService, "E7", 5);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4", "E5", "E6", "E7"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E7" });

            SendEvent(epService, "E8", 6);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E5", "E4", "E6", "E7", "E8"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E8" });

            SendEvent(epService, "E9", 7);     // remove stream is E4, E5, E6; E4 and E5 get removed as their
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E6", "E7", "E8", "E9"));
            EPAssertionUtil.AssertPropsPerRow(listener.LastOldData, fields, new object[][] { new object[] { "E4" }, new object[] { "E5" } });
            EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E9" });
            listener.Reset();

            stmt.Dispose();
        }
Beispiel #3
0
        private void AssertEvents(SupportUpdateListener listener, string symbol, long volume, double sum)
        {
            EventBean[] oldData = listener.LastOldData;
            EventBean[] newData = listener.LastNewData;

            Assert.IsNull(oldData);
            Assert.AreEqual(1, newData.Length);

            Assert.AreEqual(symbol, newData[0].Get("symbol"));
            Assert.AreEqual(volume, newData[0].Get("volume"));
            Assert.AreEqual(sum, newData[0].Get("mySum"));

            listener.Reset();
            Assert.IsFalse(listener.IsInvoked);
        }
Beispiel #4
0
        private void RunAssertionDestroyAll(EPServiceProvider epService)
        {
            EPStatement[] stmts        = CreateStmts(epService, new string[] { "s1", "s2", "s3" });
            var           testListener = new SupportUpdateListener();

            stmts[0].Events += testListener.Update;
            stmts[1].Events += testListener.Update;
            stmts[2].Events += testListener.Update;
            SendEvent(epService);
            Assert.AreEqual(3, testListener.NewDataList.Count);
            testListener.Reset();

            epService.EPAdministrator.DestroyAllStatements();
            AssertDestroyed(epService, stmts, testListener);
        }
Beispiel #5
0
        public void TestBatchOffsetNoOrderOM()
        {
            var model = new EPStatementObjectModel();

            model.SelectClause = SelectClause.CreateWildcard();
            model.SelectClause.StreamSelector = StreamSelector.RSTREAM_ISTREAM_BOTH;
            model.FromClause = FromClause.Create(FilterStream.Create("SupportBean").AddView("win", "length_batch",
                                                                                            Expressions.Constant(3)));
            model.RowLimitClause = RowLimitClause.Create(1);

            String statementString = "select irstream * from SupportBean.win:length_batch(3) limit 1";

            Assert.AreEqual(statementString, model.ToEPL());
            EPStatement stmt = _epService.EPAdministrator.Create(model);

            RunAssertion(stmt);
            stmt.Dispose();
            _listener.Reset();

            model = _epService.EPAdministrator.CompileEPL(statementString);
            Assert.AreEqual(statementString, model.ToEPL());
            stmt = _epService.EPAdministrator.Create(model);
            RunAssertion(stmt);
        }
Beispiel #6
0
        private void CheckNew(EPStatement statement, long countE, double sumE, double avgE, double stdevpaE, double stdevE, double varianceE, SupportUpdateListener listener)
        {
            IEnumerator <EventBean> iterator = statement.GetEnumerator();

            Assert.IsTrue(iterator.MoveNext());
            CheckValues(iterator.Current, false, false, countE, sumE, avgE, stdevpaE, stdevE, varianceE);
            Assert.IsFalse(iterator.MoveNext());

            Assert.IsTrue(listener.LastNewData.Length == 1);
            EventBean childViewValues = listener.LastNewData[0];

            CheckValues(childViewValues, false, false, countE, sumE, avgE, stdevpaE, stdevE, varianceE);

            listener.Reset();
        }
        private void RunAssertionTimeLengthBatchForceOutputSum(EPServiceProvider epService, SupportMarketDataBean[] events)
        {
            long startTime = 1000;

            SendTimer(epService, startTime);

            EPStatement stmt = epService.EPAdministrator.CreateEPL(
                "select sum(price) from " + typeof(SupportMarketDataBean).FullName +
                "#time_length_batch(10 sec, 3, 'FORCE_UPDATE')");
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            EPRuntime engine = epService.EPRuntime;

            // Send 1 events in batch
            engine.SendEvent(events[10]);
            Assert.IsFalse(listener.IsInvoked);

            SendTimer(epService, startTime + 10000);
            Assert.AreEqual(10.0, listener.LastNewData[0].Get("sum(price)"));
            listener.Reset();

            SendTimer(epService, startTime + 20000);
            Assert.AreEqual(null, listener.LastNewData[0].Get("sum(price)"));
            listener.Reset();

            SendTimer(epService, startTime + 30000);
            Assert.AreEqual(null, listener.LastNewData[0].Get("sum(price)"));
            listener.Reset();

            SendTimer(epService, startTime + 40000);
            Assert.AreEqual(null, listener.LastNewData[0].Get("sum(price)"));
            listener.Reset();

            stmt.Dispose();
        }
Beispiel #8
0
        private void RunAssertionNamedWindowFilter(EPServiceProvider epService)
        {
            string[] fields = "reviewId".Split(',');
            epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));

            epService.EPAdministrator.CreateEPL("create window OrderWindowNWF#lastevent as OrderEvent");
            epService.EPAdministrator.CreateEPL("insert into OrderWindowNWF select * from OrderEvent");

            string      stmtText = "select reviewId from OrderWindowNWF[books][reviews] bookReviews order by reviewId asc";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(stmtText);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, fields, new object[][] { new object[] { 1 }, new object[] { 2 }, new object[] { 10 } });
            listener.Reset();

            epService.EPRuntime.SendEvent(OrderBeanFactory.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, fields, new object[][] { new object[] { 201 } });
            listener.Reset();

            stmt.Dispose();
        }
        private void AssertPrio(SupportUpdateListener listener, string theString, int[] prioValues)
        {
            EventBean[] events = listener.GetNewDataListFlattened();
            Assert.AreEqual(prioValues.Length, events.Length);
            for (int i = 0; i < prioValues.Length; i++)
            {
                Assert.AreEqual(prioValues[i], events[i].Get("prio"));
                if (theString != null)
                {
                    Assert.AreEqual(theString, events[i].Get("TheString"));
                }
            }

            listener.Reset();
        }
        private void RunAssertionIRStreamArrayItem(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));
            string stmtText = "@IterableUnbound select irstream bookId from OrderEvent[books[0]]";

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

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(MakeEventOne());
            EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, "bookId".Split(','), new object[][] { new object[] { "10020" } });
            Assert.IsNull(listener.LastOldData);
            listener.Reset();
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "bookId".Split(','), new object[][] { new object[] { "10020" } });

            epService.EPRuntime.SendEvent(MakeEventFour());
            Assert.IsNull(listener.LastOldData);
            EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, "bookId".Split(','), new object[][] { new object[] { "10031" } });
            listener.Reset();
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "bookId".Split(','), new object[][] { new object[] { "10031" } });

            stmt.Dispose();
        }
Beispiel #11
0
        private void RunAssertionInnerJoinLateStart(EventRepresentationEnum eventRepresentationEnum)
        {
            var stmtOne = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema Product (product string, size int)");

            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtOne.EventType.UnderlyingType);
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema Portfolio (portfolio string, product string)");
            var stmtTwo = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window ProductWin.win:keepall() as Product");

            Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmtTwo.EventType.UnderlyingType);

            _epService.EPAdministrator.CreateEPL("insert into ProductWin select * from Product");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window PortfolioWin.win:keepall() as Portfolio");
            _epService.EPAdministrator.CreateEPL("insert into PortfolioWin select * from Portfolio");

            SendProduct(eventRepresentationEnum, "productA", 1);
            SendProduct(eventRepresentationEnum, "productB", 2);
            SendPortfolio(eventRepresentationEnum, "Portfolio", "productA");

            var stmtText = "@Name(\"Query2\") select portfolio, ProductWin.product, size " +
                           "from PortfolioWin unidirectional inner join ProductWin on PortfolioWin.product=ProductWin.product";
            var stmt = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listenerStmtOne);

            SendPortfolio(eventRepresentationEnum, "Portfolio", "productB");
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), new string[] { "portfolio", "ProductWin.product", "size" }, new object[] { "Portfolio", "productB", 2 });

            SendPortfolio(eventRepresentationEnum, "Portfolio", "productC");
            _listenerStmtOne.Reset();

            SendProduct(eventRepresentationEnum, "productC", 3);
            SendPortfolio(eventRepresentationEnum, "Portfolio", "productC");
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), new string[] { "portfolio", "ProductWin.product", "size" }, new object[] { "Portfolio", "productC", 3 });

            _epService.Initialize();
        }
        private void CheckValue(EPServiceProvider epService, SupportUpdateListener testListener, EPStatement weightedAvgView, double avgE)
        {
            IEnumerator <EventBean> iterator = weightedAvgView.GetEnumerator();

            Assert.IsTrue(iterator.MoveNext());
            CheckValue(iterator.Current, avgE);
            Assert.IsTrue(!iterator.MoveNext());

            Assert.IsTrue(testListener.LastNewData.Length == 1);
            EventBean listenerValues = testListener.LastNewData[0];

            CheckValue(listenerValues, avgE);

            testListener.Reset();
        }
Beispiel #13
0
        private void TryPriorSortWindow(EPServiceProvider epService, string epl)
        {
            EPStatement statement = epService.EPAdministrator.CreateEPL(epl);
            var         listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            SendMarketEvent(epService, "COX", 30);
            AssertNewEvents(listener, "COX", "COX", 30d, null, null, null, null, null, null);

            SendMarketEvent(epService, "IBM", 45);
            AssertNewEvents(listener, "IBM", "IBM", 45d, "COX", 30d, null, null, null, null);

            SendMarketEvent(epService, "MSFT", 33);
            AssertNewEvents(listener, "MSFT", "MSFT", 33d, "IBM", 45d, "COX", 30d, null, null);

            SendMarketEvent(epService, "XXX", 55);
            EventBean newEvent = listener.LastNewData[0];
            EventBean oldEvent = listener.LastOldData[0];

            AssertEventProps(listener, newEvent, "XXX", "XXX", 55d, "MSFT", 33d, "IBM", 45d, "COX", 30d);
            AssertEventProps(listener, oldEvent, "XXX", "XXX", 55d, "MSFT", 33d, "IBM", 45d, "COX", 30d);

            SendMarketEvent(epService, "BOO", 20);
            newEvent = listener.LastNewData[0];
            oldEvent = listener.LastOldData[0];
            AssertEventProps(listener, newEvent, "BOO", "BOO", 20d, "XXX", 55d, "MSFT", 33d, "IBM", 45d);
            AssertEventProps(listener, oldEvent, "MSFT", "MSFT", 33d, "IBM", 45d, "COX", 30d, null, null);

            SendMarketEvent(epService, "DOR", 1);
            newEvent = listener.LastNewData[0];
            oldEvent = listener.LastOldData[0];
            AssertEventProps(listener, newEvent, "DOR", "DOR", 1d, "BOO", 20d, "XXX", 55d, "MSFT", 33d);
            AssertEventProps(listener, oldEvent, "IBM", "IBM", 45d, "COX", 30d, null, null, null, null);

            SendMarketEvent(epService, "AAA", 2);
            newEvent = listener.LastNewData[0];
            oldEvent = listener.LastOldData[0];
            AssertEventProps(listener, newEvent, "AAA", "AAA", 2d, "DOR", 1d, "BOO", 20d, "XXX", 55d);
            AssertEventProps(listener, oldEvent, "DOR", "DOR", 1d, "BOO", 20d, "XXX", 55d, "MSFT", 33d);

            SendMarketEvent(epService, "AAB", 2);
            oldEvent = listener.LastOldData[0];
            AssertEventProps(listener, oldEvent, "COX", "COX", 30d, null, null, null, null, null, null);
            listener.Reset();

            statement.Stop();
        }
        private void AssertCombinedEvent(TxnEventA expectedA, TxnEventB expectedB, TxnEventC expectedC)
        {
            Assert.AreEqual(1, listener.NewDataList.Count);
            Assert.AreEqual(1, listener.LastNewData.Length);
            EventBean combinedEvent = listener.LastNewData[0];

            Assert.AreSame(expectedC.TransactionId, combinedEvent.Get("transactionId"));
            Assert.AreSame(expectedB.TransactionId, combinedEvent.Get("transactionId"));
            Assert.AreSame(expectedA.TransactionId, combinedEvent.Get("transactionId"));
            Assert.AreSame(expectedA.CustomerId, combinedEvent.Get("customerId"));
            Assert.AreSame(expectedC.SupplierId, combinedEvent.Get("supplierId"));
            Assert.AreEqual(expectedC.Timestamp - expectedA.Timestamp, combinedEvent.Get("latencyAC"));
            Assert.AreEqual(expectedB.Timestamp - expectedA.Timestamp, combinedEvent.Get("latencyAB"));
            Assert.AreEqual(expectedC.Timestamp - expectedB.Timestamp, combinedEvent.Get("latencyBC"));
            listener.Reset();
        }
        private void AssertOldNewSpreadEvent(SupportUpdateListener listener, double oldaprice, double oldbprice, double oldspread,
                                             double newaprice, double newbprice, double newspread)
        {
            Assert.AreEqual(1, listener.OldDataList.Count);
            Assert.AreEqual(1, listener.LastOldData.Length);
            Assert.AreEqual(1, listener.NewDataList.Count);   // since event null is put into the list
            Assert.AreEqual(1, listener.LastNewData.Length);

            EventBean oldEvent = listener.LastOldData[0];
            EventBean newEvent = listener.LastNewData[0];

            CompareSpreadEvent(oldEvent, oldaprice, oldbprice, oldspread);
            CompareSpreadEvent(newEvent, newaprice, newbprice, newspread);

            listener.Reset();
        }
Beispiel #16
0
        private void RunAssertionSelect(EPServiceProvider epService)
        {
            string eplFragment = "select " +
                                 "Contained.selectFrom(x => id) as val0 " +
                                 "from Bean";
            EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment);
            var         listener     = new SupportUpdateListener();

            stmtFragment.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(ICollection <string>) });

            epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,12", "E2,11", "E3,2"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", "E1", "E2", "E3");
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", null);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value());
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", new string[0]);
            listener.Reset();
            stmtFragment.Dispose();

            // test scalar-coll with lambda
            string[] fields = "val0".Split(',');
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractNum", typeof(ExecEnumMinMax.MyService), "ExtractNum");
            string eplLambda = "select " +
                               "Strvals.selectFrom(v => extractNum(v)) as val0 " +
                               "from SupportCollection";
            EPStatement stmtLambda = epService.EPAdministrator.CreateEPL(eplLambda);

            stmtLambda.Events += listener.Update;
            LambdaAssertionUtil.AssertTypes(stmtLambda.EventType, fields, new Type[] {
                typeof(ICollection <int>),
                typeof(ICollection <int>)
            });

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E1,E5,E4"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", 2, 1, 5, 4);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1"));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", 1);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(null));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0", null);
            listener.Reset();

            epService.EPRuntime.SendEvent(SupportCollection.MakeString(""));
            LambdaAssertionUtil.AssertValuesArrayScalar(listener, "val0");

            stmtLambda.Dispose();
        }
Beispiel #17
0
        private void AssertOldEvents(SupportUpdateListener listener, string currSymbol,
                                     string priorSymbol,
                                     double?priorPrice)
        {
            EventBean[] oldData = listener.LastOldData;
            EventBean[] newData = listener.LastNewData;

            Assert.IsNull(newData);
            Assert.AreEqual(1, oldData.Length);

            Assert.AreEqual(currSymbol, oldData[0].Get("currSymbol"));
            Assert.AreEqual(priorSymbol, oldData[0].Get("priorSymbol"));
            Assert.AreEqual(priorPrice, oldData[0].Get("priorPrice"));

            listener.Reset();
        }
        private void AssertOldEvents(SupportUpdateListener listener, string symbol,
                                     double?oldPrice, double?oldAvgPrice
                                     )
        {
            EventBean[] oldData = listener.LastOldData;
            EventBean[] newData = listener.LastNewData;

            Assert.IsNull(newData);
            Assert.AreEqual(1, oldData.Length);

            Assert.AreEqual(symbol, oldData[0].Get("symbol"));
            Assert.AreEqual(oldPrice, oldData[0].Get("price"));
            Assert.AreEqual(oldAvgPrice, oldData[0].Get("avgPrice"));

            listener.Reset();
        }
        private void TryExpr(EPServiceProvider epService, string filterExpr, string fieldName, object[] values, bool[] isInvoked)
        {
            string      expr     = "select * from " + typeof(SupportBean).FullName + filterExpr;
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(expr);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            for (int i = 0; i < values.Length; i++)
            {
                SendBean(epService, fieldName, values[i]);
                Assert.AreEqual(isInvoked[i], listener.IsInvoked, "Listener invocation unexpected for " + filterExpr + " field " + fieldName + "=" + values[i]);
                listener.Reset();
            }

            stmt.Stop();
        }
Beispiel #20
0
        private static void TryOptimizableBoolean(
            RegressionEnvironment env,
            RegressionPath path,
            string epl)
        {
            // test function returns lookup value and "Equals"
            int count = 10;
            for (int i = 0; i < count; i++) {
                EPCompiled compiled = env.Compile("@Name('s" + i + "')" + epl, path);
                EPDeploymentService admin = env.Runtime.DeploymentService;
                try {
                    admin.Deploy(compiled);
                }
                catch (EPDeployException) {
                    Assert.Fail();
                }
            }

            env.Milestone(0);

            SupportUpdateListener listener = new SupportUpdateListener();
            for (int i = 0; i < 10; i++) {
                env.Statement("s" + i).AddListener(listener);
            }

            var loops = 10000;
            var delta = PerformanceObserver.TimeMillis(
                () => {
                    SupportStaticMethodLib.ResetCountInvoked();
                    for (int i = 0; i < loops; i++) {
                        string key = "E_" + i % 100;
                        env.SendEventBean(new SupportBean(key, 0));
                        if (key.Equals("E_1")) {
                            Assert.AreEqual(count, listener.NewDataList.Count);
                            listener.Reset();
                        }
                        else {
                            Assert.IsFalse(listener.IsInvoked);
                        }
                    }
                });
            Assert.AreEqual(loops, SupportStaticMethodLib.CountInvoked);

            Assert.IsTrue(delta < 1000, "Delta is " + delta);
            env.UndeployAll();
        }
Beispiel #21
0
        private void RunAssertionAggregationOverGroupedProps(EPServiceProvider epService)
        {
            // test for ESPER-185
            string[] fields = "volume,symbol,price,mycount".Split(',');
            string   epl    = "select irstream volume,symbol,price,count(price) as mycount " +
                              "from " + typeof(SupportMarketDataBean).FullName + "#length(5) " +
                              "group by symbol, price";

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

            stmt.Events += listener.Update;

            SendEvent(epService, SYMBOL_DELL, 1000, 10);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1000L, "DELL", 10.0, 1L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 1000L, "DELL", 10.0, 1L } });

            SendEvent(epService, SYMBOL_DELL, 900, 11);
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { 900L, "DELL", 11.0, 1L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 1000L, "DELL", 10.0, 1L }, new object[] { 900L, "DELL", 11.0, 1L } });
            listener.Reset();

            SendEvent(epService, SYMBOL_DELL, 1500, 10);
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { 1500L, "DELL", 10.0, 2L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 1000L, "DELL", 10.0, 2L }, new object[] { 900L, "DELL", 11.0, 1L }, new object[] { 1500L, "DELL", 10.0, 2L } });
            listener.Reset();

            SendEvent(epService, SYMBOL_IBM, 500, 5);
            Assert.AreEqual(1, listener.NewDataList.Count);
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { 500L, "IBM", 5.0, 1L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 1000L, "DELL", 10.0, 2L }, new object[] { 900L, "DELL", 11.0, 1L }, new object[] { 1500L, "DELL", 10.0, 2L }, new object[] { 500L, "IBM", 5.0, 1L } });
            listener.Reset();

            SendEvent(epService, SYMBOL_IBM, 600, 5);
            Assert.AreEqual(1, listener.LastNewData.Length);
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { 600L, "IBM", 5.0, 2L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 1000L, "DELL", 10.0, 2L }, new object[] { 900L, "DELL", 11.0, 1L }, new object[] { 1500L, "DELL", 10.0, 2L }, new object[] { 500L, "IBM", 5.0, 2L }, new object[] { 600L, "IBM", 5.0, 2L } });
            listener.Reset();

            SendEvent(epService, SYMBOL_IBM, 500, 5);
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { 500L, "IBM", 5.0, 3L });
            EPAssertionUtil.AssertProps(listener.LastOldData[0], fields, new object[] { 1000L, "DELL", 10.0, 1L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 900L, "DELL", 11.0, 1L }, new object[] { 1500L, "DELL", 10.0, 1L }, new object[] { 500L, "IBM", 5.0, 3L }, new object[] { 600L, "IBM", 5.0, 3L }, new object[] { 500L, "IBM", 5.0, 3L } });
            listener.Reset();

            SendEvent(epService, SYMBOL_IBM, 600, 5);
            EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { 600L, "IBM", 5.0, 4L });
            EPAssertionUtil.AssertProps(listener.LastOldData[0], fields, new object[] { 900L, "DELL", 11.0, 0L });
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 1500L, "DELL", 10.0, 1L }, new object[] { 500L, "IBM", 5.0, 4L }, new object[] { 600L, "IBM", 5.0, 4L }, new object[] { 500L, "IBM", 5.0, 4L }, new object[] { 600L, "IBM", 5.0, 4L } });
            listener.Reset();

            stmt.Dispose();
        }
Beispiel #22
0
        private void RunAssertionPriorTimeBatchWindowJoin(EPServiceProvider epService)
        {
            string epl = "select TheString as currSymbol, " +
                         "prior(2, symbol) as priorSymbol, " +
                         "prior(1, price) as priorPrice " +
                         "from " + typeof(SupportBean).FullName + "#keepall, " +
                         typeof(SupportMarketDataBean).FullName + "#time_batch(1 min)";

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

            stmt.Events += listener.Update;

            // assert select result type
            Assert.AreEqual(typeof(string), stmt.EventType.GetPropertyType("priorSymbol"));
            Assert.AreEqual(typeof(double), stmt.EventType.GetPropertyType("priorPrice"));

            SendTimer(epService, 0);
            Assert.IsFalse(listener.IsInvoked);

            SendMarketEvent(epService, "A", 1);
            SendMarketEvent(epService, "B", 2);
            SendBeanEvent(epService, "X1");
            Assert.IsFalse(listener.IsInvoked);

            SendTimer(epService, 60000);
            Assert.AreEqual(2, listener.LastNewData.Length);
            AssertEvent(listener.LastNewData[0], "X1", null, null);
            AssertEvent(listener.LastNewData[1], "X1", null, 1d);
            Assert.IsNull(listener.LastOldData);
            listener.Reset();

            SendMarketEvent(epService, "C1", 11);
            SendMarketEvent(epService, "C2", 12);
            SendMarketEvent(epService, "C3", 13);
            Assert.IsFalse(listener.IsInvoked);

            SendTimer(epService, 120000);
            Assert.AreEqual(3, listener.LastNewData.Length);
            AssertEvent(listener.LastNewData[0], "X1", "A", 2d);
            AssertEvent(listener.LastNewData[1], "X1", "B", 11d);
            AssertEvent(listener.LastNewData[2], "X1", "C1", 12d);

            stmt.Dispose();
        }
Beispiel #23
0
        private void RunAssertionCrontab(int days, EPStatement statement)
        {
            var fields = "Symbol".Split(',');

            SendEvent("S1", 0);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimeEvent(days, 17, 14, 59, 0);
            SendEvent("S2", 0);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimeEvent(days, 17, 15, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S1" }, new object[] { "S2" } });

            SendTimeEvent(days, 17, 18, 0, 00);
            SendEvent("S3", 0);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimeEvent(days, 17, 30, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S3" } });

            SendTimeEvent(days, 17, 35, 0, 0);
            SendTimeEvent(days, 17, 45, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, null);

            SendEvent("S4", 0);
            SendEvent("S5", 0);
            SendTimeEvent(days, 18, 0, 0, 0);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimeEvent(days, 18, 1, 0, 0);
            SendEvent("S6", 0);

            SendTimeEvent(days, 18, 15, 0, 0);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimeEvent(days + 1, 7, 59, 59, 0);
            Assert.IsFalse(_listener.IsInvoked);

            SendTimeEvent(days + 1, 8, 0, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S4" }, new object[] { "S5" }, new object[] { "S6" } });

            statement.Dispose();
            _listener.Reset();
        }
        public override void Run(EPServiceProvider epService)
        {
            // Set up a 1 second time window
            EPStatement weightedAvgView = epService.EPAdministrator.CreateEPL(
                "select * from " + typeof(SupportMarketDataBean).FullName +
                "(symbol='" + SYMBOL + "')#time(3.0)#weighted_avg(price, volume, symbol, feed)");
            var testListener = new SupportUpdateListener();

            weightedAvgView.Events += testListener.Update;

            Assert.AreEqual(typeof(double?), weightedAvgView.EventType.GetPropertyType("average"));
            testListener.Reset();

            // Send 2 events, E1 and E2 at +0sec
            epService.EPRuntime.SendEvent(MakeBean(SYMBOL, 10, 500));
            CheckValue(epService, testListener, weightedAvgView, 10);

            epService.EPRuntime.SendEvent(MakeBean(SYMBOL, 11, 500));
            CheckValue(epService, testListener, weightedAvgView, 10.5);

            // Sleep for 1.5 seconds
            Sleep(1500);

            // Send 2 more events, E3 and E4 at +1.5sec
            epService.EPRuntime.SendEvent(MakeBean(SYMBOL, 10, 1000));
            CheckValue(epService, testListener, weightedAvgView, 10.25);
            epService.EPRuntime.SendEvent(MakeBean(SYMBOL, 10.5, 2000));
            CheckValue(epService, testListener, weightedAvgView, 10.375);

            // Sleep for 2 seconds, E1 and E2 should have left the window
            Sleep(2000);
            CheckValue(epService, testListener, weightedAvgView, 10.333333333);

            // Send another event, E5 at +3.5sec
            epService.EPRuntime.SendEvent(MakeBean(SYMBOL, 10.2, 1000));
            CheckValue(epService, testListener, weightedAvgView, 10.3);

            // Sleep for 2.5 seconds, E3 and E4 should expire
            Sleep(2500);
            CheckValue(epService, testListener, weightedAvgView, 10.2);

            // Sleep for 1 seconds, E5 should have expired
            Sleep(1000);
            CheckValue(epService, testListener, weightedAvgView, Double.NaN);
        }
Beispiel #25
0
        public void TestSchemaXMLWSchemaWithRestriction()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();
            ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "order";

            var schemaStream = ResourceManager.GetResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);

            Assert.NotNull(schemaStream);

            var schemaReader = new StreamReader(schemaStream);
            var schemaText   = schemaReader.ReadToEnd();

            schemaReader.Close();
            schemaStream.Close();

            eventTypeMeta.SchemaText = schemaText;
            config.AddEventType("OrderEvent", eventTypeMeta);

            _epService = EPServiceProviderManager.GetProvider("TestSchemaXML", config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _updateListener = new SupportUpdateListener();

            String      text = "select order_amount from OrderEvent";
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(text);

            stmt.Events += _updateListener.Update;

            SupportXML.SendEvent(_epService.EPRuntime,
                                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                                 "<order>\n" +
                                 "<order_amount>202.1</order_amount>" +
                                 "</order>");
            EventBean theEvent = _updateListener.LastNewData[0];

            Assert.AreEqual(typeof(double), theEvent.Get("order_amount").GetType());
            Assert.AreEqual(202.1d, theEvent.Get("order_amount"));
            _updateListener.Reset();
        }
        public void TestPerformance()
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }                                                                       // exclude test

            String stmtText = "select SimpleProperty?, " +
                              "Indexed[1]? as Indexed, " +
                              "Mapped('keyOne')? as Mapped " +
                              "from " + typeof(SupportBeanComplexProps).FullName;
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += _listener.Update;

            EventType type = stmt.EventType;

            Assert.AreEqual(typeof(Object), type.GetPropertyType("SimpleProperty?"));
            Assert.AreEqual(typeof(Object), type.GetPropertyType("Indexed"));
            Assert.AreEqual(typeof(Object), type.GetPropertyType("Mapped"));

            SupportBeanComplexProps inner = SupportBeanComplexProps.MakeDefaultBean();

            _epService.EPRuntime.SendEvent(inner);
            EventBean theEvent = _listener.AssertOneGetNewAndReset();

            Assert.AreEqual(inner.SimpleProperty, theEvent.Get("SimpleProperty?"));
            Assert.AreEqual(inner.GetIndexed(1), theEvent.Get("Indexed"));
            Assert.AreEqual(inner.GetMapped("keyOne"), theEvent.Get("Mapped"));

            long start = PerformanceObserver.MilliTime;

            for (int i = 0; i < 10000; i++)
            {
                _epService.EPRuntime.SendEvent(inner);
                if (i % 1000 == 0)
                {
                    _listener.Reset();
                }
            }
            long end   = PerformanceObserver.MilliTime;
            long delta = end - start;

            Assert.IsTrue(delta < 1000, "delta=" + delta);
        }
        private void AssertEvents(SupportUpdateListener listener, string symbolOld, long volSumOld,
                                  string symbolNew, long volSumNew)
        {
            EventBean[] oldData = listener.LastOldData;
            EventBean[] newData = listener.LastNewData;

            Assert.AreEqual(1, oldData.Length);
            Assert.AreEqual(1, newData.Length);

            Assert.AreEqual(symbolOld, oldData[0].Get("symbol"));
            Assert.AreEqual(volSumOld, oldData[0].Get("volSum"));

            Assert.AreEqual(symbolNew, newData[0].Get("symbol"));
            Assert.AreEqual(volSumNew, newData[0].Get("volSum"));

            listener.Reset();
            Assert.IsFalse(listener.IsInvoked);
        }
        private void TryTimeWindow(String intervalSpec)
        {
            // Set up a time window with a unique view attached
            EPStatement view = _epService.EPAdministrator.CreateEPL(
                "select irstream * from " + typeof(SupportBean).FullName
                + ".win:time(" + intervalSpec + ")");

            _testListener = new SupportUpdateListener();
            view.Events  += _testListener.Update;

            SendTimer(0);

            SendEvent();
            _testListener.Reset();

            SendTimerAssertNotInvoked(29999 * 1000);
            SendTimerAssertInvoked(30000 * 1000);
        }
        public void TestTimeBatchRefPoint()
        {
            // Set up a time window with a unique view attached
            EPStatement view = _epService.EPAdministrator.CreateEPL(
                "select * from " + typeof(SupportBean).FullName
                + ".win:time_batch(10 minutes, 10L)");

            _testListener = new SupportUpdateListener();
            view.Events  += _testListener.Update;

            SendTimer(10);

            SendEvent();
            _testListener.Reset();

            SendTimerAssertNotInvoked(10 * 60 * 1000 - 1 + 10);
            SendTimerAssertInvoked(10 * 60 * 1000 + 10);
        }
Beispiel #30
0
        private void TryAssertionCrontab(EPServiceProvider epService, int days, EPStatement statement, SupportUpdateListener listener)
        {
            string[] fields = "symbol".Split(',');
            SendEvent(epService, "S1", 0);
            Assert.IsFalse(listener.IsInvoked);

            SendTimeEvent(epService, days, 17, 14, 59, 0);
            SendEvent(epService, "S2", 0);
            Assert.IsFalse(listener.IsInvoked);

            SendTimeEvent(epService, days, 17, 15, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S1" }, new object[] { "S2" } });

            SendTimeEvent(epService, days, 17, 18, 0, 0);
            SendEvent(epService, "S3", 0);
            Assert.IsFalse(listener.IsInvoked);

            SendTimeEvent(epService, days, 17, 30, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S3" } });

            SendTimeEvent(epService, days, 17, 35, 0, 0);
            SendTimeEvent(epService, days, 17, 45, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, null);

            SendEvent(epService, "S4", 0);
            SendEvent(epService, "S5", 0);
            SendTimeEvent(epService, days, 18, 0, 0, 0);
            Assert.IsFalse(listener.IsInvoked);

            SendTimeEvent(epService, days, 18, 1, 0, 0);
            SendEvent(epService, "S6", 0);

            SendTimeEvent(epService, days, 18, 15, 0, 0);
            Assert.IsFalse(listener.IsInvoked);

            SendTimeEvent(epService, days + 1, 7, 59, 59, 0);
            Assert.IsFalse(listener.IsInvoked);

            SendTimeEvent(epService, days + 1, 8, 0, 0, 0);
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S4" }, new object[] { "S5" }, new object[] { "S6" } });

            statement.Dispose();
            listener.Reset();
        }