コード例 #1
0
ファイル: EPLOtherSplitStream.cs プロジェクト: lanicon/nesper
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var stmtOrigText = "@Name('split') on SupportBean " +
                                   "insert into AStream2SP select * where IntPrimitive=1 " +
                                   "insert into BStream2SP select * where IntPrimitive=1 or IntPrimitive=2";
                env.CompileDeploy(stmtOrigText, path).AddListener("split");
                TryAssertion(env, path);
                path.Clear();

                // statement object model
                var model = new EPStatementObjectModel();
                model.Annotations = Collections.SingletonList(new AnnotationPart("Audit"));
                model.FromClause = FromClause.Create(FilterStream.Create("SupportBean"));
                model.InsertInto = InsertIntoClause.Create("AStream2SP");
                model.SelectClause = SelectClause.CreateWildcard();
                model.WhereClause = Expressions.Eq("IntPrimitive", 1);
                var clause = OnClause.CreateOnInsertSplitStream();
                model.OnExpr = clause;
                var item = OnInsertSplitStreamItem.Create(
                    InsertIntoClause.Create("BStream2SP"),
                    SelectClause.CreateWildcard(),
                    Expressions.Or(Expressions.Eq("IntPrimitive", 1), Expressions.Eq("IntPrimitive", 2)));
                clause.AddItem(item);
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("split"));
                Assert.AreEqual(stmtOrigText, model.ToEPL());
                env.CompileDeploy(model, path).AddListener("split");
                TryAssertion(env, path);
                path.Clear();

                env.EplToModelCompileDeploy(stmtOrigText, path).AddListener("split");
                TryAssertion(env, path);
            }
コード例 #2
0
ファイル: ContextCategory.cs プロジェクト: lanicon/nesper
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var milestone = new AtomicLong();
                var ctx = "CategorizedContext";
                var eplCtx = "@Name('context') create context " +
                             ctx +
                             " as " +
                             "group IntPrimitive<10 as cat1 " +
                             "from SupportBean";
                env.CompileDeploy(eplCtx, path);

                var eplStmt =
                    "@Name('s0') context CategorizedContext select context.name as c0, context.label as c1, prior(1,IntPrimitive) as c2 from SupportBean";
                env.CompileDeploy(eplStmt, path).AddListener("s0");

                RunAssertion(env, ctx, milestone);

                // test SODA
                path.Clear();
                env.EplToModelCompileDeploy(eplCtx, path);
                env.EplToModelCompileDeploy(eplStmt, path);
                env.AddListener("s0");

                RunAssertion(env, ctx, milestone);
            }
コード例 #3
0
 private void UndeployClearPath(
     RegressionEnvironment env,
     RegressionPath path)
 {
     env.UndeployAll();
     path.Clear();
 }
コード例 #4
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var windowABC = env.Compile("module ABC; create window MyWindow#keepall as SupportBean", path);
                path.Clear();

                env.Compile("module DEF; create window MyWindow#keepall as SupportBean", path);
                var insertDEF = env.Compile("select * from MyWindow", path);
                env.Deploy(windowABC);

                TryInvalidDeploy(env, insertDEF, "dependency named window 'MyWindow' module 'DEF'");

                env.UndeployAll();
            }
コード例 #5
0
ファイル: EPLScriptExpression.cs プロジェクト: lanicon/nesper
            public void Run(RegressionEnvironment env)
            {
                object[][] testData;
                string expression;
                var path = new RegressionPath();

                expression = "function fib(n) {" +
                             "  if(n <= 1) return n; " +
                             "  return fib(n-1) + fib(n-2); " +
                             "};" +
                             "return fib(num);";
                testData = new[] {
                    new object[] {new SupportBean("E1", 20), 6765.0}
                };
                TrySelect(
                    env,
                    path,
                    "expression double js:abc(num) [ " + expression + " ]",
                    "abc(IntPrimitive)",
                    typeof(double?),
                    testData);
                path.Clear();

                testData = new[] {
                    new object[] {new SupportBean("E1", 5), 50.0},
                    new object[] {new SupportBean("E1", 6), 60.0}
                };
                TrySelect(
                    env,
                    path,
                    "expression js:abc(myint) [ return myint * 10; ]",
                    "abc(IntPrimitive)",
                    typeof(object),
                    testData);
                path.Clear();
            }
コード例 #6
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var epl = "create window SimpleWindow#keepall as SupportBean";
                env.CompileDeploy(epl, path);
                TryInvalidDeploy(env, epl, "A named window by name 'SimpleWindow'", MODULE_NAME_UNNAMED);
                env.UndeployAll();
                path.Clear();

                epl = "module ABC; create window SimpleWindow#keepall as SupportBean";
                env.CompileDeploy(epl, path);
                TryInvalidDeploy(env, epl, "A named window by name 'SimpleWindow'", "ABC");

                env.UndeployAll();
            }
コード例 #7
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();

                // single variable
                env.CompileDeploy("@Name('S0') create variable boolean var2vmd = true", path);
                env.CompileDeploy("@Name('S1') select * from SupportBean(var2vmd)", path);
                Assert.AreEqual(true, env.Runtime.VariableService.GetVariableValue(env.DeploymentId("S0"), "var2vmd"));

                try {
                    env.Deployment.Undeploy(env.DeploymentId("S0"));
                    Assert.Fail();
                }
                catch (EPUndeployException) {
                    // expected
                }

                env.UndeployModuleContaining("S1");
                Assert.AreEqual(true, env.Runtime.VariableService.GetVariableValue(env.DeploymentId("S0"), "var2vmd"));

                var deploymentIdS0 = env.DeploymentId("S0");
                env.UndeployModuleContaining("S0");
                AssertNotFound(env, deploymentIdS0, "var2vmd");

                // multiple variable
                path.Clear();
                env.CompileDeploy("@Name('T0') create variable boolean v1 = true", path);
                env.CompileDeploy("@Name('T1') create variable long v2 = 1", path);
                env.CompileDeploy("@Name('T2') create variable string v3 = 'a'", path);
                env.CompileDeploy("@Name('TX') select * from SupportBean(v1, v2=1, v3='a')", path);
                env.CompileDeploy("@Name('TY') select * from SupportBean(v2=2)", path);
                env.CompileDeploy("@Name('TZ') select * from SupportBean(v3='A', v1)", path);

                AssertCannotUndeploy(env, "T0,T1,T2");
                env.UndeployModuleContaining("TX");
                AssertCannotUndeploy(env, "T0,T1,T2");

                env.UndeployModuleContaining("TY");
                env.UndeployModuleContaining("T1");
                AssertCannotUndeploy(env, "T0,T2");

                env.UndeployModuleContaining("TZ");
                env.UndeployModuleContaining("T0");
                env.UndeployModuleContaining("T2");

                env.UndeployAll();
            }
コード例 #8
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var eplOne = "create context CtxSegmentedByTarget partition by TheString from SupportBean;" +
                             "@Name('out') context CtxSegmentedByTarget on SupportBean insert into NewSupportBean select * where IntPrimitive = 100;";
                env.CompileDeploy(eplOne, path);
                env.CompileDeploy("@Name('s0') select * from NewSupportBean", path).AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 1));
                Assert.IsFalse(env.Listener("s0").GetAndClearIsInvoked());

                env.SendEventBean(new SupportBean("E1", 100));
                Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked());
                env.UndeployAll();
                path.Clear();

                // test with subquery
                var fields = new [] { "mymax" };
                var eplTwo = "create context CtxSegmentedByTarget partition by TheString from SupportBean;" +
                             "context CtxSegmentedByTarget create window NewEvent#unique(TheString) as SupportBean;" +
                             "@Name('out') context CtxSegmentedByTarget on SupportBean " +
                             "insert into NewEvent select * where IntPrimitive = 100 " +
                             "insert into NewEventTwo select (select max(IntPrimitive) from NewEvent) as mymax  " +
                             "output all;";
                env.CompileDeploy(eplTwo, path);
                env.CompileDeploy("@Name('s0') select * from NewEventTwo", path).AddListener("s0");
                env.SendEventBean(new SupportBean("E1", 1));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null});

                env.SendEventBean(new SupportBean("E1", 100));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null});

                env.SendEventBean(new SupportBean("E1", 0));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {100});

                env.UndeployAll();
            }
コード例 #9
0
 public void Run(RegressionEnvironment env)
 {
     // assert join
     SupportQueryPlanIndexHook.Reset();
     var epl = "@Name('s0') " +
               INDEX_CALLBACK_HOOK +
               "select * from SupportBean_S0 as S0 unidirectional, SupportBean_S1#keepall as S1 " +
               "where P00 in (P10, P11) and P01 in (P12, P13)";
     env.CompileDeploy(epl).AddListener("s0");
     var items = SupportQueryPlanIndexHook.AssertJoinAndReset().IndexSpecs[1].Items;
     Assert.AreEqual("[\"P10\"][\"P11\"]", SupportQueryPlanIndexHelper.GetIndexedExpressions(items));
     TryAssertionMultiIdx(env);
     env.UndeployAll();
     // assert named window
     var path = new RegressionPath();
     env.CompileDeploy("create window S1Window#keepall as SupportBean_S1", path);
     env.CompileDeploy("insert into S1Window select * from SupportBean_S1", path);
     var eplNamedWindow = "@Name('s0') " +
                          INDEX_CALLBACK_HOOK +
                          "on SupportBean_S0 as S0 select * from S1Window as S1 " +
                          "where P00 in (P10, P11) and P01 in (P12, P13)";
     env.CompileDeploy(eplNamedWindow, path).AddListener("s0");
     var onExprNamedWindow = SupportQueryPlanIndexHook.AssertOnExprAndReset();
     Assert.AreEqual(typeof(SubordInKeywordMultiTableLookupStrategyFactoryForge).Name, onExprNamedWindow.TableLookupStrategy);
     TryAssertionMultiIdx(env);
     // assert table
     path.Clear();
     env.CompileDeploy(
         "create table S1Table(Id int primary key, P10 string primary key, P11 string primary key, P12 string primary key, P13 string primary key)",
         path);
     env.CompileDeploy("insert into S1Table select * from SupportBean_S1", path);
     env.CompileDeploy("create index S1Idx1 on S1Table(P10)", path);
     env.CompileDeploy("create index S1Idx2 on S1Table(P11)", path);
     env.CompileDeploy("create index S1Idx3 on S1Table(P12)", path);
     env.CompileDeploy("create index S1Idx4 on S1Table(P13)", path);
     var eplTable = "@Name('s0') " +
                    INDEX_CALLBACK_HOOK +
                    "on SupportBean_S0 as S0 select * from S1Table as S1 " +
                    "where P00 in (P10, P11) and P01 in (P12, P13)";
     env.CompileDeploy(eplTable, path).AddListener("s0");
     var onExprTable = SupportQueryPlanIndexHook.AssertOnExprAndReset();
     Assert.AreEqual(typeof(SubordInKeywordMultiTableLookupStrategyFactoryForge).Name, onExprTable.TableLookupStrategy);
     TryAssertionMultiIdx(env);
     env.UndeployAll();
 }
コード例 #10
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var stmtTextCreate = namedWindow
                    ? "create window MyInfraCI#keepall as (f1 string, f2 int, f3 string, f4 string)"
                    : "create table MyInfraCI as (f1 string primary key, f2 int, f3 string, f4 string)";
                env.CompileDeploy(stmtTextCreate, path);
                var compiledWindow = path.Compileds[0];
                env.CompileDeploy(
                    "insert into MyInfraCI(f1, f2, f3, f4) select TheString, IntPrimitive, '>'||TheString||'<', '?'||TheString||'?' from SupportBean",
                    path);
                env.CompileDeploy("@Name('indexOne') create index MyInfraCIIndex on MyInfraCI(f2, f3, f1)", path);
                var fields = new [] { "f1","f2","f3","f4" };

                env.SendEventBean(new SupportBean("E1", -2));

                var result = env.CompileExecuteFAF("select * from MyInfraCI where f3='>E1<'", path);
                EPAssertionUtil.AssertPropsPerRow(
                    result.Array,
                    fields,
                    new[] {new object[] {"E1", -2, ">E1<", "?E1?"}});

                result = env.CompileExecuteFAF("select * from MyInfraCI where f3='>E1<' and f2=-2", path);
                EPAssertionUtil.AssertPropsPerRow(
                    result.Array,
                    fields,
                    new[] {new object[] {"E1", -2, ">E1<", "?E1?"}});

                result = env.CompileExecuteFAF("select * from MyInfraCI where f3='>E1<' and f2=-2 and f1='E1'", path);
                EPAssertionUtil.AssertPropsPerRow(
                    result.Array,
                    fields,
                    new[] {new object[] {"E1", -2, ">E1<", "?E1?"}});

                env.UndeployModuleContaining("indexOne");

                // test SODA
                path.Clear();
                path.Add(compiledWindow);
                env.EplToModelCompileDeploy("create index MyInfraCIIndexTwo on MyInfraCI(f2, f3, f1)", path)
                    .UndeployAll();
            }
コード例 #11
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('context') create context NineToFive as start (0, 9, *, *, *) end (0, 17, *, *, *)";
                Assert.AreEqual(0, SupportContextMgmtHelper.GetContextCount(env));
                Assert.AreEqual(0, SupportScheduleHelper.ScheduleCountOverall(env));

                // create and destroy
                env.CompileDeploy(epl);
                Assert.AreEqual(1, SupportContextMgmtHelper.GetContextCount(env));
                Assert.AreEqual(0, SupportScheduleHelper.ScheduleCountOverall(env));

                env.UndeployModuleContaining("context");
                Assert.AreEqual(0, SupportContextMgmtHelper.GetContextCount(env));

                // create context, create statement, destroy statement, destroy context
                var path = new RegressionPath();
                env.CompileDeploy(epl, path);
                Assert.AreEqual(1, SupportContextMgmtHelper.GetContextCount(env));

                env.CompileDeploy("@Name('s0') context NineToFive select * from SupportBean", path);
                Assert.AreEqual(1, SupportScheduleHelper.ScheduleCountOverall(env));

                env.UndeployModuleContaining("s0");
                Assert.AreEqual(0, SupportScheduleHelper.ScheduleCountOverall(env));

                env.UndeployModuleContaining("context");
                Assert.AreEqual(0, SupportContextMgmtHelper.GetContextCount(env));

                // create same context
                path.Clear();
                env.CompileDeploy(epl, path);
                env.CompileDeploy("@Name('C') context NineToFive select * from SupportBean", path);
                env.CompileDeploy("@Name('D') context NineToFive select * from SupportBean", path);

                Assert.AreEqual(1, SupportScheduleHelper.ScheduleCountOverall(env));

                env.UndeployAll();
                Assert.AreEqual(0, SupportContextMgmtHelper.GetContextCount(env));
                Assert.AreEqual(0, SupportScheduleHelper.ScheduleCountOverall(env));

                env.UndeployAll();
            }
コード例 #12
0
        private static void RunAssertion(
            RegressionEnvironment env,
            RegressionPath path,
            EPStage stage,
            string typename,
            object underlying,
            Consumer <EPEventService> sender)
        {
            string epl = "@public @buseventtype create schema TriggerEvent();\n" +
                         "@public @buseventtype @name('schema') create json schema " +
                         JSON_TYPENAME +
                         "();\n" +
                         "@Name('trigger') select * from TriggerEvent;\n" +
                         "@Name('s0') select * from " +
                         typename +
                         ";\n";

            env.CompileDeploy(epl, path).AddListener("s0");
            string deploymentId = env.DeploymentId("s0");

            StageIt(env, "ST", deploymentId);

            // test normal send
            sender.Invoke(stage.EventService);
            AssertUnderlying(env, typename, underlying);

            // test EventSender#send
            EventSender eventSender = stage.EventService.GetEventSender(typename);

            eventSender.SendEvent(underlying);
            AssertUnderlying(env, typename, underlying);

            // test EventSender#route
            GetStatement("trigger", "ST", env.Runtime).Events += (_, args) => { eventSender.RouteEvent(underlying); };
            stage.EventService.SendEventMap(new Dictionary <string, object>(), "TriggerEvent");
            AssertUnderlying(env, typename, underlying);

            UnstageIt(env, "ST", deploymentId);

            path.Clear();
            env.UndeployModuleContaining("s0");
        }
コード例 #13
0
        private static void TryAssertionPriorStreamAndVariable(RegressionEnvironment env, RegressionPath path, string priorIndex, AtomicLong milestone)
        {
            var text = "create constant variable int NUM_PRIOR = 1;\n @name('s0') select prior(" + priorIndex + ", s0) as result from SupportBean_S0#length(2) as s0";

            env.CompileDeploy(text, path).AddListener("s0");

            var e1 = new SupportBean_S0(3);

            env.SendEventBean(e1);
            Assert.AreEqual(null, env.Listener("s0").AssertOneGetNewAndReset().Get("result"));

            env.Milestone(milestone.GetAndIncrement());

            env.SendEventBean(new SupportBean_S0(3));
            Assert.AreEqual(e1, env.Listener("s0").AssertOneGetNewAndReset().Get("result"));
            Assert.AreEqual(typeof(SupportBean_S0), env.Statement("s0").EventType.GetPropertyType("result"));

            env.UndeployAll();
            path.Clear();
        }
コード例 #14
0
        private static void TryAssertionLifecycleAndFilter(
            RegressionEnvironment env,
            string expressionBefore,
            string selector,
            string expressionAfter)
        {
            var path = new RegressionPath();
            env.CompileDeploy("@Name('expr-one') " + expressionBefore, path);
            env.CompileDeploy("@Name('s1') " + selector, path).AddListener("s1");

            env.SendEventBean(new SupportBean("E1", 0));
            Assert.IsFalse(env.Listener("s1").GetAndClearIsInvoked());
            env.SendEventBean(new SupportBean("E2", 1));
            Assert.IsTrue(env.Listener("s1").GetAndClearIsInvoked());

            var listenerS1 = env.Listener("s1");
            path.Clear();
            env.UndeployAll();

            env.CompileDeploy("@Name('expr-two') " + expressionAfter, path);
            env.CompileDeploy("@Name('s2') " + selector, path).AddListener("s2");

            env.SendEventBean(new SupportBean("E3", 0));
            Assert.IsFalse(listenerS1.GetAndClearIsInvoked() || env.Listener("s2").GetAndClearIsInvoked());

            env.Milestone(0);

            env.SendEventBean(new SupportBean("E4", 1));
            Assert.IsFalse(listenerS1.GetAndClearIsInvoked());
            Assert.IsFalse(env.Listener("s2").GetAndClearIsInvoked());
            env.SendEventBean(new SupportBean("E4", 2));
            Assert.IsFalse(listenerS1.GetAndClearIsInvoked());
            Assert.IsTrue(env.Listener("s2").GetAndClearIsInvoked());

            env.UndeployAll();
        }
コード例 #15
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(1);
                var path = new RegressionPath();

                // stream, and test audit callback
                var callback = new SupportAuditCallback();
                AuditPath.AuditCallback = callback.Audit;

                AUDITLOG.Info("*** Stream: ");
                env.CompileDeploy("@Name('ABC') @Audit('stream') select * from SupportBean(TheString = 'E1')");
                env.SendEventBean(new SupportBean("E1", 1));
                Assert.AreEqual(1, callback.Audits.Count);
                var cb = callback.Audits[0];
                Assert.AreEqual("SupportBean(TheString=...) inserted SupportBean[SupportBean(\"E1\", 1)]", cb.Message);
                Assert.AreEqual(env.DeploymentId("ABC"), cb.DeploymentId);
                Assert.AreEqual("ABC", cb.StatementName);
                Assert.AreEqual(DEFAULT_RUNTIME_URI, cb.RuntimeURI);
                Assert.AreEqual(AuditEnum.STREAM, cb.Category);
                Assert.AreEqual(1, cb.RuntimeTime);
                AuditPath.AuditCallback = null;
                env.UndeployAll();

                AUDITLOG.Info("*** Insert-Into: ");
                env.CompileDeploy("@Name('insert') @Audit insert into ABC select * from SupportBean");
                env.SendEventBean(new SupportBean("E1", 1));
                env.UndeployAll();

                AUDITLOG.Info("*** Named Window And Insert-Into: ");
                env.CompileDeploy("@Name('create') @Audit create window WinOne#keepall as SupportBean", path);
                env.CompileDeploy("@Name('insert') @Audit insert into WinOne select * from SupportBean", path);
                env.CompileDeploy("@Name('select') @Audit select * from WinOne", path);
                env.SendEventBean(new SupportBean("E1", 1));
                env.UndeployAll();
                path.Clear();

                AUDITLOG.Info("*** Schedule: ");
                env.AdvanceTime(0);
                env.CompileDeploy("@Name('ABC') @Audit('schedule') select irstream * from SupportBean#time(1 sec)")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 1));
                env.Listener("ABC").Reset();
                log.Info("Sending time");
                env.AdvanceTime(2000);
                Assert.IsTrue(env.Listener("ABC").IsInvoked);
                env.UndeployAll();

                // property
                AUDITLOG.Info("*** Property: ");
                env.CompileDeploy("@Name('ABC') @Audit('property') select IntPrimitive from SupportBean")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 50));
                Assert.AreEqual(50, env.Listener("ABC").AssertOneGetNewAndReset().Get("IntPrimitive"));
                env.UndeployAll();

                // view
                AUDITLOG.Info("*** View: ");
                env.CompileDeploy("@Name('ABC') @Audit('view') select IntPrimitive from SupportBean#lastevent")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 50));
                Assert.AreEqual(50, env.Listener("ABC").AssertOneGetNewAndReset().Get("IntPrimitive"));
                env.UndeployAll();

                env.CompileDeploy("@Name('s0') @Audit Select * From SupportBean#groupwin(TheString)#length(2)")
                    .AddListener("s0");
                env.SendEventBean(new SupportBean("E1", 50));
                env.UndeployAll();

                env.CompileDeploy(
                        "@Name('s0') @Audit Select * From SupportBean#groupwin(TheString)#length(2)#unique(IntPrimitive)")
                    .AddListener("s0");
                env.SendEventBean(new SupportBean("E1", 50));
                env.UndeployAll();
                // expression
                AUDITLOG.Info("*** Expression: ");
                env.CompileDeploy(
                        "@Name('ABC') @Audit('expression') select IntPrimitive*100 as val0, sum(IntPrimitive) as val1 from SupportBean")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 50));
                Assert.AreEqual(5000, env.Listener("ABC").AssertOneGetNew().Get("val0"));
                Assert.AreEqual(50, env.Listener("ABC").AssertOneGetNewAndReset().Get("val1"));
                env.UndeployAll();

                // expression-detail
                AUDITLOG.Info("*** Expression-Nested: ");
                env.CompileDeploy(
                        "@Name('ABC') @Audit('expression-nested') select ('A'||TheString)||'X' as val0 from SupportBean")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 50));
                Assert.AreEqual("AE1X", env.Listener("ABC").AssertOneGetNewAndReset().Get("val0"));
                env.UndeployAll();

                // pattern
                AUDITLOG.Info("*** Pattern: ");
                env.CompileDeploy(
                        "@Name('ABC') @Audit('pattern') select a.IntPrimitive as val0 from pattern [a=SupportBean -> b=SupportBean_ST0]")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean_ST0("E2", 2));
                Assert.AreEqual(1, env.Listener("ABC").AssertOneGetNewAndReset().Get("val0"));
                env.UndeployAll();

                // pattern-instances
                AUDITLOG.Info("*** Pattern-Lifecycle: ");
                env.CompileDeploy(
                        "@Name('ABC') @Audit('pattern-instances') select a.IntPrimitive as val0 from pattern [every a=SupportBean -> (b=SupportBean_ST0 and not SupportBean_ST1)]")
                    .AddListener("ABC");
                log.Info("Sending E1");
                env.SendEventBean(new SupportBean("E1", 1));
                log.Info("Sending E2");
                env.SendEventBean(new SupportBean("E2", 2));
                log.Info("Sending E3");
                env.SendEventBean(new SupportBean_ST1("E3", 3));
                log.Info("Destroy");
                env.UndeployAll();

                // exprdef-instances
                AUDITLOG.Info("*** Expression-Def: ");
                env.CompileDeploy(
                        "@Name('ABC') @Audit('exprdef') " +
                        "expression DEF { 1 } " +
                        "expression INN {  x -> x.TheString }" +
                        "expression OUT { x -> INN(x) } " +
                        "select DEF(), OUT(sb) from SupportBean sb")
                    .AddListener("ABC");
                env.SendEventBean(new SupportBean("E1", 1));
                Assert.AreEqual(1, env.Listener("ABC").AssertOneGetNewAndReset().Get("DEF()"));
                env.UndeployAll();

                // data flow
                env.CompileDeploy(
                    "@Audit @Name('df') create dataflow MyFlow " +
                    "EventBusSource -> a<SupportBean> {filter:TheString like 'I%'} " +
                    "filter(a) -> b {filter: true}" +
                    "LogSink(b) {log:false}");
                var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("df"), "MyFlow");
                df.Start();
                env.SendEventBean(new SupportBean("I1", 1));
                df.Cancel();

                // context partitions
                env.CompileDeploy(
                    "create context WhenEventArrives " +
                    "initiated by SupportBean_ST0 as st0 " +
                    "terminated by SupportBean_ST1(Id=st0.Id);\n" +
                    "@Audit('ContextPartition') context WhenEventArrives select * from SupportBean;\n");
                env.SendEventBean(new SupportBean_ST0("E1", 0));
                env.SendEventBean(new SupportBean_ST1("E1", 0));
                env.UndeployAll();

                // table
                AUDITLOG.Info("*** Table And Insert-Into and Into-table: ");
                env.CompileDeploy(
                    "@Name('create-table') @Audit create table TableOne(c0 string primary key, cnt count(*))",
                    path);
                env.CompileDeploy(
                    "@Name('into-table') @Audit into table TableOne select count(*) as cnt from SupportBean group by TheString",
                    path);
                env.CompileDeploy("@Name('access-table') @Audit select TableOne[Id].cnt from SupportBean_ST0", path)
                    .AddListener("access-table");
                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean_ST0("E1", 0));
                env.UndeployAll();
                path.Clear();

                // int-expression with endpoint-included
                env.CompileDeploy("@Audit select * from SupportBean#keepall where IntPrimitive in (1:3)");
                env.SendEventBean(new SupportBean("E1", 1));
                env.UndeployAll();
            }
コード例 #16
0
            public void Run(RegressionEnvironment env)
            {
                var path         = new RegressionPath();
                var eplVariables = "@Name('create') create variable double[primitive] doublearray;\n" +
                                   "create variable int[primitive] intarray;\n" +
                                   "create variable int notAnArray;";

                env.Compile(eplVariables, path);
                // invalid property
                TryInvalidCompile(
                    env,
                    path,
                    "on SupportBean set xxx[IntPrimitive]=1d",
                    "Failed to validate assignment expression 'xxx[IntPrimitive]=1.0d': Variable by name 'xxx' has not been created or configured");
                // index expression is not Integer
                TryInvalidCompile(
                    env,
                    path,
                    "on SupportBean set doublearray[null]=1d",
                    "Incorrect index expression for array operation, expected an expression returning an integer value but the expression 'null' returns 'null (any type)' for expression 'doublearray'");
                // type incompatible cannot assign
                TryInvalidCompile(
                    env,
                    path,
                    "on SupportBean set intarray[IntPrimitive]='x'",
                    "Failed to validate assignment expression 'intarray[IntPrimitive]=\"x\"': Invalid assignment of column '\"x\"' of type 'System.String' to event property 'intarray' typed as 'System.Int32', column and parameter types mismatch");
                // not-an-array
                TryInvalidCompile(
                    env,
                    path,
                    "on SupportBean set notAnArray[IntPrimitive]=1",
                    "Failed to validate assignment expression 'notAnArray[IntPrimitive]=1': Variable 'notAnArray' is not an array");
                path.Clear();
                // runtime-behavior for index-overflow and null-array and null-index and
                var epl = "@Name('create') create variable double[primitive] doublearray = new double[3];\n" +
                          "on SupportBean set doublearray[IntBoxed]=DoubleBoxed;\n";

                env.CompileDeploy(epl);
                // index returned is too large
                try {
                    var sb = new SupportBean();
                    sb.IntBoxed    = 10;
                    sb.DoubleBoxed = 10d;
                    env.SendEventBean(sb);
                    Assert.Fail();
                }
                catch (Exception ex) {
                    Assert.IsTrue(ex.Message.Contains("Array length 3 less than index 10 for variable 'doublearray'"));
                }

                // index returned null
                var sbIndexNull = new SupportBean();

                sbIndexNull.DoubleBoxed = 10d;
                env.SendEventBean(sbIndexNull);
                // rhs returned null for array-of-primitive
                var sbRHSNull = new SupportBean();

                sbRHSNull.IntBoxed = 1;
                env.SendEventBean(sbRHSNull);
                env.UndeployAll();
            }
コード例 #17
0
ファイル: ExprDTDataSources.cs プロジェクト: lanicon/nesper
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();

                // test Map inheritance via create-schema
                var eplMap =
                    "create schema ParentType as (StartTS long, EndTS long) starttimestamp StartTS endtimestamp EndTS;\n" +
                    "create schema ChildType as (foo string) inherits ParentType;\n";
                env.CompileDeployWBusPublicType(eplMap, path);

                env.CompileDeploy("@Name('s0') select * from ChildType dt where dt.before(current_timestamp())", path);
                Assert.AreEqual("StartTS", env.Statement("s0").EventType.StartTimestampPropertyName);
                Assert.AreEqual("EndTS", env.Statement("s0").EventType.EndTimestampPropertyName);

                env.UndeployAll();

                // test Object-array inheritance via create-schema
                path.Clear();
                var eplObjectArray =
                    "create objectarray schema ParentType as (StartTS long, EndTS long) starttimestamp StartTS endtimestamp EndTS;\n" +
                    "create objectarray schema ChildType as (foo string) inherits ParentType;\n";
                env.CompileDeployWBusPublicType(eplObjectArray, path);

                env.CompileDeploy("@Name('s0') select * from ChildType dt where dt.before(current_timestamp())", path);
                Assert.AreEqual("StartTS", env.Statement("s0").EventType.StartTimestampPropertyName);
                Assert.AreEqual("EndTS", env.Statement("s0").EventType.EndTimestampPropertyName);

                env.UndeployAll();

                // test PONO inheritance via create-schema
                path.Clear();
                var eplPONO = "create schema InterfaceType as " +
                              typeof(SupportStartTSEndTSInterface).FullName +
                              " starttimestamp StartTS endtimestamp EndTS;\n" +
                              "create schema DerivedType as " +
                              typeof(SupportStartTSEndTSImpl).FullName +
                              " inherits InterfaceType";
                env.CompileDeployWBusPublicType(eplPONO, path);

                var compiled = env.Compile(
                    "@Name('s2') select * from DerivedType dt where dt.before(current_timestamp())",
                    path);
                env.Deploy(compiled);
                Assert.AreEqual("StartTS", env.Statement("s2").EventType.StartTimestampPropertyName);
                Assert.AreEqual("EndTS", env.Statement("s2").EventType.EndTimestampPropertyName);

                env.UndeployAll();

                // test PONO inheritance via create-schema
                path.Clear();
                String eplXML = "@XMLSchema(RootElementName='root', SchemaText='') " +
                                "@XMLSchemaField(Name='StartTS', XPath='/abc', Type='string', CastToType='long')" +
                                "@XMLSchemaField(Name='EndTS', XPath='/def', Type='string', CastToType='long')" +
                                "create xml schema MyXMLEvent() starttimestamp StartTS endtimestamp EndTS;\n";
                env.CompileDeployWBusPublicType(eplXML, path);

                compiled = env.Compile("@Name('s2') select * from MyXMLEvent dt where dt.before(current_timestamp())", path);

                env.Deploy(compiled);
                Assert.AreEqual("StartTS", env.Statement("s2").EventType.StartTimestampPropertyName);
                Assert.AreEqual("EndTS", env.Statement("s2").EventType.EndTimestampPropertyName);

                env.UndeployAll();

                // test incompatible
                path.Clear();
                var eplT1T2 =
                    "create schema T1 as (StartTS long, EndTS long) starttimestamp StartTS endtimestamp EndTS;\n" +
                    "create schema T2 as (StartTSOne long, EndTSOne long) starttimestamp StartTSOne endtimestamp EndTSOne;\n";
                env.CompileDeployWBusPublicType(eplT1T2, path);

                TryInvalidCompile(
                    env,
                    path,
                    "create schema T12 as () inherits T1,T2",
                    "Event type declares start timestamp as property 'StartTS' however inherited event type 'T2' declares start timestamp as property 'StartTSOne'");
                TryInvalidCompile(
                    env,
                    path,
                    "create schema T12 as (StartTSOne long, EndTSXXX long) inherits T2 starttimestamp StartTSOne endtimestamp EndTSXXX",
                    "Event type declares end timestamp as property 'EndTSXXX' however inherited event type 'T2' declares end timestamp as property 'EndTSOne'");

                env.UndeployAll();
            }
コード例 #18
0
            public void Run(RegressionEnvironment env)
            {
                // Comment-in to see CRC32 code.
                for (var i = 0; i < 10; i++) {
                    var key = "E" + i;
                    var code = SupportHashCodeFuncGranularCRC32.ComputeCRC32(key) % 4;
                    var hashCode = i.GetHashCode() % 4;
                    //System.out.println(key + " code " + code + " hashCode " + hashCode);
                }

                var path = new RegressionPath();
                var ctx = "HashSegmentedContext";
                var milestone = new AtomicLong();

                // test CRC32 Hash
                var eplCtx = "@Name('context') create context " +
                             ctx +
                             " as " +
                             "coalesce consistent_hash_crc32(TheString) from SupportBean " +
                             "granularity 4 " +
                             "preallocate";
                env.CompileDeploy(eplCtx, path);

                var eplStmt = "@Name('s0') context " +
                              ctx +
                              " " +
                              "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString";
                env.CompileDeploy(eplStmt, path).AddListener("s0");
                Assert.AreEqual(4, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 4, null, null, null);

                TryAssertionHash(env, milestone, "s0", ctx); // equivalent to: SupportHashCodeFuncGranularCRC32(4)
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                path.Clear();

                // test same with SODA
                env.EplToModelCompileDeploy(eplCtx, path);
                env.CompileDeploy(eplStmt, path).AddListener("s0");
                TryAssertionHash(env, milestone, "s0", ctx);
                path.Clear();

                // test with Java-hashCode String hash
                env.CompileDeploy(
                    "@Name('context') create context " +
                    ctx +
                    " " +
                    "coalesce hash_code(TheString) from SupportBean " +
                    "granularity 6 " +
                    "preallocate",
                    path);

                env.CompileDeploy(
                    "@Name('s0') context " +
                    ctx +
                    " " +
                    "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString",
                    path);
                env.AddListener("s0");
                Assert.AreEqual(6, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 6, null, null, null);

                TryAssertionHash(env, milestone, "s0", ctx);
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                path.Clear();

                // test no pre-allocate
                env.CompileDeploy(
                    "@Name('context') create context " +
                    ctx +
                    " " +
                    "coalesce hash_code(TheString) from SupportBean " +
                    "granularity 16",
                    path);

                env.CompileDeploy(
                    "@Name('s0') context " +
                    ctx +
                    " " +
                    "select context.name as c0, TheString as c1, sum(IntPrimitive) as c2 from SupportBean#keepall group by TheString",
                    path);
                env.AddListener("s0");
                Assert.AreEqual(1, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));
                AgentInstanceAssertionUtil.AssertInstanceCounts(env, "s0", 0, null, null, null);

                TryAssertionHash(env, milestone, "s0", ctx);
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));

                env.UndeployAll();
            }