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

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

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

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

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

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

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

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #2
0
        public void TestLongRunningUnbound()
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }                                                                       // excluded from instrumentation, too much data

            String viewExpr = "select symbol as currSymbol, " +
                              " prior(3, symbol) as prior0Symbol " +
                              "from " + typeof(SupportMarketDataBean).FullName;

            EPStatementSPI selectTestView = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(viewExpr);

            selectTestView.Events += _listener.Update;
            Assert.IsFalse(selectTestView.StatementContext.IsStatelessSelect);

            Random random = new Random();

            // 200000 is a better number for a memory test, however for short unit tests this is 2000
            for (int i = 0; i < 2000; i++)
            {
                if (i % 10000 == 0)
                {
                    //Console.Out.WriteLine(i);
                }

                SendMarketEvent(Convert.ToString(random.Next()), 4);

                if (i % 1000 == 0)
                {
                    _listener.Reset();
                }
            }
        }
コード例 #3
0
        private void RunAssertionStartedDestroy(EPServiceProvider epService)
        {
            SendTimer(epService, 1000);

            string         text = "select * from " + typeof(SupportBean).FullName;
            EPStatementSPI stmt = (EPStatementSPI)epService.EPAdministrator.CreateEPL(text, "s1");

            Assert.IsTrue(stmt.StatementContext.IsStatelessSelect);
            Assert.AreEqual(1000L, stmt.TimeLastStateChange);
            Assert.AreEqual(false, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(true, stmt.IsStarted);

            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            SendEvent(epService);
            listener.AssertOneGetNewAndReset();

            SendTimer(epService, 2000);
            stmt.Dispose();
            Assert.AreEqual(2000L, stmt.TimeLastStateChange);
            Assert.AreEqual(true, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(false, stmt.IsStarted);

            SendEvent(epService);
            Assert.IsFalse(listener.IsInvoked);

            AssertStmtDestroyed(epService, stmt, text);
        }
コード例 #4
0
        private void TryHash(EPServiceProvider epService, string hashFunc)
        {
            string eplCtxCRC32 = "@Name('context') create context Ctx1 as coalesce " +
                                 hashFunc + " from SupportBean " +
                                 "granularity 1000000";

            epService.EPAdministrator.CreateEPL(eplCtxCRC32);

            string[] fields  = "c1,c2,c3,c4,c5".Split(',');
            string   eplStmt = "context Ctx1 select IntPrimitive as c1, " +
                               "sum(LongPrimitive) as c2, prev(1, LongPrimitive) as c3, prior(1, LongPrimitive) as c4," +
                               "(select p00 from SupportBean_S0#length(2)) as c5 " +
                               "from SupportBean#length(3)";
            EPStatementSPI statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            var            listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            epService.EPRuntime.SendEvent(MakeBean("E1", 100, 20L));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 100, 20L, null, null, null });

            epService.EPRuntime.SendEvent(MakeBean("E1", 100, 21L));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 100, 41L, 20L, 20L, null });

            epService.EPRuntime.SendEvent(new SupportBean_S0(1000, "S0"));
            epService.EPRuntime.SendEvent(MakeBean("E1", 100, 22L));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 100, 63L, 21L, 21L, "S0" });

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #5
0
        private void RunAssertion3Stream(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddEventType <SupportBeanTwo>();

            string stmtText = "select * from SupportBean#lastevent sb, SupportBeanTwo#lastevent sbt, " +
                              "sql:MyDB ['select myint from mytesttable'] as s1 " +
                              "  where sb.TheString = sbt.stringTwo and s1.myint = sbt.IntPrimitiveTwo";

            EPStatementSPI statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL(stmtText);

            Assert.IsFalse(statement.StatementContext.IsStatelessSelect);
            var listener = new SupportUpdateListener();

            statement.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBeanTwo("T1", 2));
            epService.EPRuntime.SendEvent(new SupportBean("T1", -1));

            epService.EPRuntime.SendEvent(new SupportBeanTwo("T2", 30));
            epService.EPRuntime.SendEvent(new SupportBean("T2", -1));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "sb.TheString,sbt.stringTwo,s1.myint".Split(','), new object[] { "T2", "T2", 30 });

            epService.EPRuntime.SendEvent(new SupportBean("T3", -1));
            epService.EPRuntime.SendEvent(new SupportBeanTwo("T3", 40));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "sb.TheString,sbt.stringTwo,s1.myint".Split(','), new object[] { "T3", "T3", 40 });

            statement.Dispose();
        }
コード例 #6
0
ファイル: EPStageImpl.cs プロジェクト: lanicon/nesper
 private void TraverseContextPartitions(
     DeploymentInternal deployment,
     Consumer <StatementResourceHolder> consumer)
 {
     foreach (EPStatement statement in deployment.Statements)
     {
         EPStatementSPI spi = (EPStatementSPI)statement;
         if (spi.StatementContext.ContextName == null)
         {
             StatementResourceHolder holder = spi.StatementContext.StatementCPCacheService.MakeOrGetEntryCanNull(-1, spi.StatementContext);
             consumer.Invoke(holder);
         }
         else
         {
             ContextRuntimeDescriptor contextDesc    = spi.StatementContext.ContextRuntimeDescriptor;
             ContextManager           contextManager = _servicesContext.ContextManagementService.GetContextManager(
                 contextDesc.ContextDeploymentId,
                 contextDesc.ContextName);
             ICollection <int> agentInstanceIds = contextManager.Realization.GetAgentInstanceIds(ContextPartitionSelectorAll.INSTANCE);
             foreach (int agentInstanceId in agentInstanceIds)
             {
                 StatementResourceHolder holder =
                     spi.StatementContext.StatementCPCacheService.MakeOrGetEntryCanNull(agentInstanceId, spi.StatementContext);
                 consumer.Invoke(holder);
             }
         }
     }
 }
コード例 #7
0
        private void RunAssertionHashSegmentedBySingleRowFunc(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("myHash", GetType(), "MyHashFunc");
            epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("mySecond", GetType(), "MySecondFunc");
            epService.EPAdministrator.Configuration.AddImport(GetType().FullName);

            string eplCtx = "@Name('context') create context HashSegmentedContext as " +
                            "coalesce MyHash(*) from SupportBean " +
                            "granularity 4 " +
                            "preallocate";

            epService.EPAdministrator.CreateEPL(eplCtx);

            string eplStmt = "context HashSegmentedContext select context.id as c1, MyHash(*) as c2, MySecond(*, TheString) as c3, "
                             + this.GetType().Name + ".MySecondFunc(*, TheString) as c4 from SupportBean";
            EPStatementSPI statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            var            listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            string[] fields = "c1,c2,c3, c4".Split(',');

            epService.EPRuntime.SendEvent(new SupportBean("E1", 3));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3, 3, "E1", "E1" });    // context id matches the number returned by myHashFunc

            epService.EPRuntime.SendEvent(new SupportBean("E2", 0));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0, 0, "E2", "E2" });

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

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #8
0
        public void TestStartedDestroy()
        {
            SendTimer(1000);

            String         text = "select * from " + typeof(SupportBean).FullName;
            EPStatementSPI stmt = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(text, "s1");

            Assert.IsTrue(stmt.StatementContext.IsStatelessSelect);
            Assert.AreEqual(1000l, stmt.TimeLastStateChange);
            Assert.AreEqual(false, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(true, stmt.IsStarted);

            stmt.Events += _listener.Update;
            SendEvent();
            _listener.AssertOneGetNewAndReset();

            SendTimer(2000);
            stmt.Dispose();
            Assert.AreEqual(2000l, stmt.TimeLastStateChange);
            Assert.AreEqual(true, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(false, stmt.IsStarted);

            SendEvent();
            Assert.IsFalse(_listener.IsInvoked);

            AssertStmtDestroyed(stmt, text);
        }
コード例 #9
0
        private FilterValueSetParam GetFilterSingle(EPStatementSPI statementSPI)
        {
            var @params = GetFilterMulti(statementSPI);

            Assert.AreEqual(1, @params.Length);
            return(@params[0]);
        }
コード例 #10
0
 public void SetContext(
     EPStatementSPI epStatement,
     EPRuntimeSPI runtime)
 {
     _epStatement = epStatement;
     _runtime = runtime;
     _statementMetricHandle = epStatement.StatementContext.EpStatementHandle.MetricsHandle;
 }
コード例 #11
0
        private void AssertResourcesOutputRate(EPStatement stmt, int numExpectedChangeset)
        {
            EPStatementSPI          spi                   = (EPStatementSPI)stmt;
            StatementResourceHolder resources             = spi.StatementContext.StatementExtensionServicesContext.StmtResources.ResourcesUnpartitioned;
            OutputProcessViewBase   outputProcessViewBase = (OutputProcessViewBase)resources.EventStreamViewables[0].Views[0].Views[0];

            Assert.AreEqual(numExpectedChangeset, outputProcessViewBase.NumChangesetRows);
        }
コード例 #12
0
        private void AssertIterator(EPStatementSPI statement, string[] fields, object[][] expected)
        {
            EventBean[] rows = EPAssertionUtil.EnumeratorToArray(statement.GetEnumerator());
            AssertIterator(rows, fields, expected);

            rows = EPAssertionUtil.EnumeratorToArray(statement.GetSafeEnumerator());
            AssertIterator(rows, fields, expected);
        }
コード例 #13
0
 public void AddStatement(EPStatementSPI stmt)
 {
     int statementId = stmt.StatementId;
     if (statementsById.ContainsKey(statementId))
     {
         throw new ArgumentException("Statement id " + stmt.StatementId + " already assigned");
     }
     statementsById.Put(statementId, stmt);
 }
コード例 #14
0
        private FilterValueSetParam[] GetFilterMulti(EPStatementSPI statementSPI)
        {
            var filterServiceSPI = (FilterServiceSPI)statementSPI.StatementContext.FilterService;
            var set = filterServiceSPI.Take(Collections.SingletonList(statementSPI.StatementId));

            Assert.AreEqual(1, set.Filters.Count);
            FilterValueSet valueSet = set.Filters[0].FilterValueSet;

            return(valueSet.Parameters[0]);
        }
コード例 #15
0
        public static EPStatement AssertFilterMulti(EPServiceProvider epService, string epl, string eventTypeName, SupportFilterItem[][] expected)
        {
            EPStatementSPI statementSPI = (EPStatementSPI)epService.EPAdministrator.CreateEPL(epl);

            if (!((FilterServiceSPI)statementSPI.StatementContext.FilterService).IsSupportsTakeApply)
            {
                return(statementSPI);
            }
            AssertFilterMulti(statementSPI, eventTypeName, expected);
            return(statementSPI);
        }
コード例 #16
0
        public void TestInSelect()
        {
            String stmtText = "select id in (select id from S1#length(1000)) as value from S0";

            EPStatementSPI stmt = (EPStatementSPI)_epService.EPAdministrator.CreateEPL(stmtText);

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

            RunTestInSelect();
        }
コード例 #17
0
        private void RunAssertionStopDestroy(EPServiceProvider epService)
        {
            SendTimer(epService, 5000);
            string      text = "select * from " + typeof(SupportBean).FullName;
            EPStatement stmt = epService.EPAdministrator.CreateEPL(text, "s1");

            Assert.AreEqual(false, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(true, stmt.IsStarted);
            Assert.AreEqual(5000L, stmt.TimeLastStateChange);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;
            SendEvent(epService);
            listener.AssertOneGetNewAndReset();

            SendTimer(epService, 6000);
            stmt.Stop();
            Assert.AreEqual(6000L, stmt.TimeLastStateChange);
            Assert.AreEqual(false, stmt.IsDisposed);
            Assert.AreEqual(true, stmt.IsStopped);
            Assert.AreEqual(false, stmt.IsStarted);

            SendEvent(epService);
            Assert.IsFalse(listener.IsInvoked);

            SendTimer(epService, 7000);
            stmt.Dispose();
            Assert.AreEqual(true, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(false, stmt.IsStarted);
            Assert.AreEqual(7000L, stmt.TimeLastStateChange);
            SendEvent(epService);
            Assert.IsFalse(listener.IsInvoked);

            AssertStmtDestroyed(epService, stmt, text);

            // test fire-stop service
            EPStatementSPI spiOne      = (EPStatementSPI)epService.EPAdministrator.CreateEPL("select * from System.Object");
            var            callbackOne = new StopCallbackImpl();

            spiOne.StatementContext.StatementStopService.StatementStopped += callbackOne.StatementStopped;
            spiOne.Dispose();
            Assert.IsTrue(callbackOne.IsStopped);

            EPStatementSPI spiTwo      = (EPStatementSPI)epService.EPAdministrator.CreateEPL("select * from System.Object");
            var            callbackTwo = new StopCallbackImpl();

            spiTwo.StatementContext.StatementStopService.StatementStopped += callbackTwo.StatementStopped;
            spiTwo.Stop();
            Assert.IsTrue(callbackTwo.IsStopped);

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #18
0
        public void TestSubselect()
        {
            FilterServiceSPI filterSPI = (FilterServiceSPI)_spi.FilterService;

            SendTimeEvent("2002-05-1 8:00:00.000");
            _epService.EPAdministrator.CreateEPL("create context NineToFive as start (0, 9, *, *, *) end (0, 17, *, *, *)");

            String[] fields = "TheString,col".Split(',');
            SupportUpdateListener listener  = new SupportUpdateListener();
            EPStatementSPI        statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context NineToFive select TheString, (select p00 from SupportBean_S0.std:lastevent()) as col from SupportBean");

            statement.Events += listener.Update;
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            // now started
            SendTimeEvent("2002-05-1 9:00:00.000");
            Assert.AreEqual(2, filterSPI.FilterCountApprox);   // from the context

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

            _epService.EPRuntime.SendEvent(new SupportBean_S0(11, "S01"));
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E2", "S01" });

            // now gone
            SendTimeEvent("2002-05-1 17:00:00.000");
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            _epService.EPRuntime.SendEvent(new SupportBean("Ex", 0));
            Assert.IsFalse(listener.IsInvoked);

            // now started
            SendTimeEvent("2002-05-2 9:00:00.000");
            Assert.AreEqual(2, filterSPI.FilterCountApprox);   // from the context
            Assert.IsFalse(listener.IsInvoked);

            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E3", null });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(12, "S02"));
            _epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E4", "S02" });
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 1, 1, 0, 0);

            // now gone
            SendTimeEvent("2002-05-2 17:00:00.000");
            Assert.AreEqual(0, filterSPI.FilterCountApprox);   // from the context

            _epService.EPRuntime.SendEvent(new SupportBean("Ey", 0));
            Assert.IsFalse(listener.IsInvoked);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);
        }
コード例 #19
0
ファイル: EPStageImpl.cs プロジェクト: lanicon/nesper
 private void TraverseStatements(
     DeploymentInternal deployment,
     Consumer <StatementContext> consumer,
     ISet <int> statementIds)
 {
     foreach (EPStatement statement in deployment.Statements)
     {
         EPStatementSPI spi = (EPStatementSPI)statement;
         consumer.Invoke(spi.StatementContext);
         statementIds.Add(spi.StatementId);
     }
 }
コード例 #20
0
        private void RunAssertionInSelect(EPServiceProvider epService)
        {
            string stmtText = "select id in (select id from S1#length(1000)) as value from S0";

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

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

            RunTestInSelect(epService, listener);

            stmt.Dispose();
        }
コード例 #21
0
        public static void AssertFilterTwo(EPServiceProvider epService, string epl, string expressionOne, FilterOperator opOne, string expressionTwo, FilterOperator opTwo)
        {
            EPStatementSPI statementSPI = (EPStatementSPI)epService.EPAdministrator.CreateEPL(epl);

            if (((FilterServiceSPI)statementSPI.StatementContext.FilterService).IsSupportsTakeApply)
            {
                FilterValueSetParam[] multi = GetFilterMulti(statementSPI);
                Assert.AreEqual(2, multi.Length);
                Assert.AreEqual(opOne, multi[0].FilterOperator);
                Assert.AreEqual(expressionOne, multi[0].Lookupable.Expression);
                Assert.AreEqual(opTwo, multi[1].FilterOperator);
                Assert.AreEqual(expressionTwo, multi[1].Lookupable.Expression);
            }
        }
コード例 #22
0
        public void TestStopDestroy()
        {
            SendTimer(5000);
            String      text = "select * from " + typeof(SupportBean).FullName;
            EPStatement stmt = _epService.EPAdministrator.CreateEPL(text, "s1");

            Assert.AreEqual(false, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(true, stmt.IsStarted);
            Assert.AreEqual(5000l, stmt.TimeLastStateChange);
            stmt.Events += _listener.Update;
            SendEvent();
            _listener.AssertOneGetNewAndReset();

            SendTimer(6000);
            stmt.Stop();
            Assert.AreEqual(6000l, stmt.TimeLastStateChange);
            Assert.AreEqual(false, stmt.IsDisposed);
            Assert.AreEqual(true, stmt.IsStopped);
            Assert.AreEqual(false, stmt.IsStarted);

            SendEvent();
            Assert.IsFalse(_listener.IsInvoked);

            SendTimer(7000);
            stmt.Dispose();
            Assert.AreEqual(true, stmt.IsDisposed);
            Assert.AreEqual(false, stmt.IsStopped);
            Assert.AreEqual(false, stmt.IsStarted);
            Assert.AreEqual(7000l, stmt.TimeLastStateChange);
            SendEvent();
            Assert.IsFalse(_listener.IsInvoked);

            AssertStmtDestroyed(stmt, text);

            // test fire-stop service
            EPStatementSPI   spiOne      = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("select * from System.Object");
            StopCallbackImpl callbackOne = new StopCallbackImpl();

            spiOne.StatementContext.StatementStopService.StatementStopped += callbackOne.StatementStopped;
            spiOne.Dispose();
            Assert.IsTrue(callbackOne.IsStopped);

            EPStatementSPI   spiTwo      = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("select * from System.Object");
            StopCallbackImpl callbackTwo = new StopCallbackImpl();

            spiTwo.StatementContext.StatementStopService.StatementStopped += callbackTwo.StatementStopped;
            spiTwo.Stop();
            Assert.IsTrue(callbackTwo.IsStopped);
        }
コード例 #23
0
        public void TestPrevPriorAndAggregation()
        {
            SendTimeEvent("2002-05-1 8:00:00.000");
            _epService.EPAdministrator.CreateEPL("create context NineToFive as start (0, 9, *, *, *) end (0, 17, *, *, *)");

            String[] fields = "col1,col2,col3,col4,col5".Split(',');
            SupportUpdateListener listener  = new SupportUpdateListener();
            EPStatementSPI        statement = (EPStatementSPI)_epService.EPAdministrator.CreateEPL("context NineToFive " +
                                                                                                   "select prev(TheString) as col1, prevwindow(sb) as col2, prevtail(TheString) as col3, prior(1, TheString) as col4, sum(IntPrimitive) as col5 " +
                                                                                                   "from SupportBean.win:keepall() as sb");

            statement.Events += listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean());
            Assert.IsFalse(listener.IsInvoked);

            // now started
            SendTimeEvent("2002-05-1 9:00:00.000");
            SupportBean event1 = new SupportBean("E1", 1);

            _epService.EPRuntime.SendEvent(event1);
            Object[][] expected = new Object[][] { new Object[] { null, new SupportBean[] { event1 }, "E1", null, 1 } };
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, expected);
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, expected);

            SupportBean event2 = new SupportBean("E2", 2);

            _epService.EPRuntime.SendEvent(event2);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", new SupportBean[] { event2, event1 }, "E1", "E1", 3 });

            // now gone
            SendTimeEvent("2002-05-1 17:00:00.000");
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, null);

            _epService.EPRuntime.SendEvent(new SupportBean());
            Assert.IsFalse(listener.IsInvoked);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 0, 0, 0, 0);

            // now started
            SendTimeEvent("2002-05-2 9:00:00.000");

            SupportBean event3 = new SupportBean("E3", 9);

            _epService.EPRuntime.SendEvent(event3);
            expected = new Object[][] { new Object[] { null, new SupportBean[] { event3 }, "E3", null, 9 } };
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, expected);
            EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), statement.GetSafeEnumerator(), fields, expected);
            AgentInstanceAssertionUtil.AssertInstanceCounts(statement.StatementContext, 1, 0, 3, 1);
        }
コード例 #24
0
        private void ApplyFilterVersion(EPStatementSPI stmtSpi, long filtersVersion)
        {
            var resources = stmtSpi.StatementContext.StatementExtensionServicesContext.StmtResources;

            if (resources.Unpartitioned != null)
            {
                ApplyFilterVersion(resources.Unpartitioned, filtersVersion);
            }
            else
            {
                foreach (var entry in resources.ResourcesPartitioned)
                {
                    ApplyFilterVersion(entry.Value, filtersVersion);
                }
            }
        }
コード例 #25
0
 /// <summary>
 /// For initialization of the service to provide statement context.
 /// </summary>
 /// <param name="epStatement">the statement</param>
 /// <param name="epServiceProvider">the engine instance</param>
 /// <param name="isInsertInto">true if this is insert into</param>
 /// <param name="isPattern">true if this is a pattern statement</param>
 /// <param name="isDistinct">true if using distinct</param>
 /// <param name="isForClause">if set to <c>true</c> [is for clause].</param>
 /// <param name="statementMetricHandle">handle for metrics reporting</param>
 public void SetContext(EPStatementSPI epStatement,
                        EPServiceProviderSPI epServiceProvider,
                        bool isInsertInto,
                        bool isPattern,
                        bool isDistinct,
                        bool isForClause,
                        StatementMetricHandle statementMetricHandle)
 {
     _epStatement           = epStatement;
     _epServiceProvider     = epServiceProvider;
     _isInsertInto          = isInsertInto;
     _isPattern             = isPattern;
     _isDistinct            = isDistinct;
     _isForClause           = isForClause;
     _isMakeSynthetic       = isInsertInto || isPattern || isDistinct || isForClause;
     _statementMetricHandle = statementMetricHandle;
 }
コード例 #26
0
        private void TryAssertionEPL(EPServiceProvider epService, string epl, string patternText, string expectedIfDifferent)
        {
            EPStatementObjectModel    model   = epService.EPAdministrator.CompileEPL(epl);
            EPStatementSPI            spi     = (EPStatementSPI)epService.EPAdministrator.Create(model);
            StatementSpecCompiled     spec    = ((EPServiceProviderSPI)epService).StatementLifecycleSvc.GetStatementSpec(spi.StatementId);
            PatternStreamSpecCompiled pattern = (PatternStreamSpecCompiled)spec.StreamSpecs[0];
            var writer = new StringWriter();

            pattern.EvalFactoryNode.ToEPL(writer, PatternExpressionPrecedenceEnum.MINIMUM);
            if (expectedIfDifferent == null)
            {
                Assert.AreEqual(patternText, writer.ToString());
            }
            else
            {
                Assert.AreEqual(expectedIfDifferent, writer.ToString());
            }
            spi.Dispose();
        }
コード例 #27
0
        public void TestSimple()
        {
            string[] fields = "reviewId".Split(',');
            _epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean));

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

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

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

            _epService.EPRuntime.SendEvent(TestContainedEventSimple.MakeEventFour());
            EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new object[][] { new object[] { 201 } });
            _listener.Reset();
        }
コード例 #28
0
        private void TrySend(EPServiceProvider epService, int numThreads, int numRepeats)
        {
            epService.EPAdministrator.Configuration.AddEventType(typeof(SentenceEvent));
            EPStatementSPI spi =
                (EPStatementSPI)epService.EPAdministrator.CreateEPL("select * from SentenceEvent[words]");

            Assert.IsTrue(spi.StatementContext.IsStatelessSelect);

            var runnables = new StatelessRunnable[numThreads];

            for (int i = 0; i < runnables.Length; i++)
            {
                runnables[i] = new StatelessRunnable(epService, numRepeats);
            }

            var threads = new Thread[numThreads];

            for (int i = 0; i < runnables.Length; i++)
            {
                threads[i] = new Thread(runnables[i].Run);
            }

            long start = PerformanceObserver.MilliTime;

            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            long delta = DateTimeHelper.CurrentTimeMillis - start;

            Log.Info("Delta=" + delta + " for " + numThreads * numRepeats + " events");

            foreach (StatelessRunnable r in runnables)
            {
                Assert.IsNull(r.Exception);
            }
        }
コード例 #29
0
        private void RunAssertionExpressionPoll(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.CreateEPL("create variable bool queryvar_bool");
            epService.EPAdministrator.CreateEPL("create variable int queryvar_int");
            epService.EPAdministrator.CreateEPL("create variable int lower");
            epService.EPAdministrator.CreateEPL("create variable int upper");
            epService.EPAdministrator.CreateEPL("on SupportBean set queryvar_int=IntPrimitive, queryvar_bool=BoolPrimitive, lower=IntPrimitive,upper=IntBoxed");

            // Test int and singlerow
            string         stmtText = "select myint from sql:MyDB ['select myint from mytesttable where ${queryvar_int -2} = mytesttable.mybigint']";
            EPStatementSPI stmt     = (EPStatementSPI)epService.EPAdministrator.CreateEPL(stmtText);

            Assert.IsFalse(stmt.StatementContext.IsStatelessSelect);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), new string[] { "myint" }, null);

            SendSupportBeanEvent(epService, 5);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), new string[] { "myint" }, new object[][] { new object[] { 30 } });

            stmt.Dispose();
            Assert.IsFalse(listener.IsInvoked);

            // Test multi-parameter and multi-row
            stmtText = "select myint from sql:MyDB ['select myint from mytesttable where mytesttable.mybigint between ${queryvar_int-2} and ${queryvar_int+2}'] order by myint";
            stmt     = (EPStatementSPI)epService.EPAdministrator.CreateEPL(stmtText);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), new string[] { "myint" }, new object[][] { new object[] { 30 }, new object[] { 40 }, new object[] { 50 }, new object[] { 60 }, new object[] { 70 } });
            stmt.Dispose();

            // Test substitution parameters
            try {
                stmtText = "select myint from sql:MyDB ['select myint from mytesttable where mytesttable.mybigint between ${?} and ${queryvar_int+?}'] order by myint";
                epService.EPAdministrator.PrepareEPL(stmtText);
                Assert.Fail();
            } catch (EPStatementException ex) {
                Assert.AreEqual("EPL substitution parameters are not allowed in SQL ${...} expressions, consider using a variable instead [select myint from sql:MyDB ['select myint from mytesttable where mytesttable.mybigint between ${?} and ${queryvar_int+?}'] order by myint]", ex.Message);
            }

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #30
0
        private void RunAssertionHashSegmentedMulti(EPServiceProvider epService)
        {
            string ctx    = "HashSegmentedContext";
            string eplCtx = "@Name('context') create context " + ctx + " as " +
                            "coalesce " +
                            " consistent_hash_crc32(TheString) from SupportBean, " +
                            " consistent_hash_crc32(p00) from SupportBean_S0 " +
                            "granularity 4 " +
                            "preallocate";

            epService.EPAdministrator.CreateEPL(eplCtx);
            // comment-me-in: var codeFunc = new SupportHashCodeFuncGranularCRC32(4);

            string eplStmt = "context " + ctx + " " +
                             "select context.name as c0, IntPrimitive as c1, id as c2 from SupportBean#keepall as t1, SupportBean_S0#keepall as t2 where t1.TheString = t2.p00";
            EPStatementSPI statement = (EPStatementSPI)epService.EPAdministrator.CreateEPL(eplStmt);
            var            listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            string[] fields = "c0,c1,c2".Split(',');

            epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E2"));
            epService.EPRuntime.SendEvent(new SupportBean("E3", 11));
            epService.EPRuntime.SendEvent(new SupportBean_S0(2, "E4"));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean_S0(3, "E1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, 10, 3 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, 10, 3 } });

            epService.EPRuntime.SendEvent(new SupportBean_S0(4, "E4"));
            epService.EPRuntime.SendEvent(new SupportBean_S0(5, "E5"));
            Assert.IsFalse(listener.IsInvoked);

            epService.EPRuntime.SendEvent(new SupportBean("E2", 12));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { ctx, 12, 1 });
            AssertIterator(statement, fields, new[] { new object[] { ctx, 10, 3 }, new object[] { ctx, 12, 1 } });

            epService.EPAdministrator.DestroyAllStatements();
        }