示例#1
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create expression int js:abc(p1, p2) [return p1*p2*10]", path);
                env.CompileDeploy("create expression int js:abc(p1) [return p1*10]", path);

                var epl =
                    "@Name('s0') select abc(IntPrimitive, DoublePrimitive) as c0, abc(IntPrimitive) as c1 from SupportBean";
                env.CompileDeploy(epl, path).AddListener("s0");

                env.SendEventBean(MakeBean("E1", 10, 3.5));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"c0", "c1"},
                    new object[] {350, 100});

                env.UndeployAll();

                // test SODA
                var eplExpr = "@Name('expr') create expression somescript(i1) ['a']";
                var modelExpr = env.EplToModel(eplExpr);
                Assert.AreEqual(eplExpr, modelExpr.ToEPL());
                env.CompileDeploy(modelExpr, path);
                Assert.AreEqual(eplExpr, env.Statement("expr").GetProperty(StatementProperty.EPL));

                var eplSelect = "@Name('select') select somescript(1) from SupportBean";
                var modelSelect = env.EplToModel(eplSelect);
                Assert.AreEqual(eplSelect, modelSelect.ToEPL());
                env.CompileDeploy(modelSelect, path);
                Assert.AreEqual(eplSelect, env.Statement("select").GetProperty(StatementProperty.EPL));

                env.UndeployAll();
            }
示例#2
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create expression TwoPi {Math.PI * 2}", path);
                env.CompileDeploy("create expression factorPi {sb => Math.PI * IntPrimitive}", path);

                var fields = new[] {"c0", "c1", "c2"};
                var epl = "@Name('s0') select " +
                          "TwoPi() as c0," +
                          "(select TwoPi() from SupportBean_S0#lastevent) as c1," +
                          "factorPi(sb) as c2 " +
                          "from SupportBean sb";
                env.CompileDeploy(epl, path).AddListener("s0");

                env.SendEventBean(new SupportBean_S0(10));
                env.SendEventBean(new SupportBean("E1", 3)); // factor is 3
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {Math.PI * 2, Math.PI * 2, Math.PI * 3});

                env.UndeployModuleContaining("s0");

                // test local expression override
                env.CompileDeploy(
                        "@Name('s0') expression TwoPi {Math.PI * 10} select TwoPi() as c0 from SupportBean",
                        path)
                    .AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 0));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"c0"},
                    new object[] {Math.PI * 10});

                // test SODA
                var eplExpr = "@Name('expr') create expression JoinMultiplication {(s1,s2) => s1.IntPrimitive*s2.Id}";
                var modelExpr = env.EplToModel(eplExpr);
                Assert.AreEqual(eplExpr, modelExpr.ToEPL());
                env.CompileDeploy(modelExpr, path);
                Assert.AreEqual(eplExpr, env.Statement("expr").GetProperty(StatementProperty.EPL));

                // test SODA and join and 2-stream parameter
                var eplJoin =
                    "@Name('join') select JoinMultiplication(sb,s0) from SupportBean#lastevent as sb, SupportBean_S0#lastevent as s0";
                var modelJoin = env.EplToModel(eplJoin);
                Assert.AreEqual(eplJoin, modelJoin.ToEPL());
                env.CompileDeploy(modelJoin, path);
                Assert.AreEqual(eplJoin, env.Statement("join").GetProperty(StatementProperty.EPL));
                env.UndeployAll();

                // test subquery against named window and table defined in declared expression
                TryAssertionTestExpressionUse(env, true);
                TryAssertionTestExpressionUse(env, false);

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                SendTimer(env, 0);

                var epl = "@Name('s0') select irstream max(Price) as maxVol" +
                          " from SupportMarketDataBean#sort(1,Volume desc) as S0, " +
                          "SupportBean#keepall as S1 where S1.TheString=S0.Symbol " +
                          "output every 1.0d seconds";
                env.CompileDeploy(epl).AddListener("s0");

                env.SendEventBean(new SupportBean("JOIN_KEY", -1));

                SendEvent(env, "JOIN_KEY", 1d);
                SendEvent(env, "JOIN_KEY", 2d);
                env.Listener("s0").Reset();

                // moves all events out of the window,
                SendTimer(env, 1000); // newdata is 2 eventa, old data is the same 2 events, therefore the sum is null
                var result = env.Listener("s0").DataListsFlattened;
                Assert.AreEqual(2, result.First.Length);
                Assert.AreEqual(1.0, result.First[0].Get("maxVol"));
                Assert.AreEqual(2.0, result.First[1].Get("maxVol"));
                Assert.AreEqual(2, result.Second.Length);
                Assert.AreEqual(null, result.Second[0].Get("maxVol"));
                Assert.AreEqual(1.0, result.Second[1].Get("maxVol"));

                // statement object model test
                var model = env.EplToModel(epl);
                env.CopyMayFail(model);
                Assert.AreEqual(epl, model.ToEPL());

                env.UndeployAll();
            }
示例#4
0
        private static void TryString(
            RegressionEnvironment env,
            EPStatementObjectModel model,
            string epl,
            string[] input,
            bool?[] result)
        {
            var compiled = env.Compile(model, new CompilerArguments(env.Configuration));

            Assert.AreEqual(epl, model.ToEPL());

            var objectmodel = env.EplToModel(epl);

            objectmodel = SerializableObjectCopier.GetInstance(env.Container).Copy(objectmodel);
            Assert.AreEqual(epl, objectmodel.ToEPL());

            env.Deploy(compiled).AddListener("s0");

            Assert.AreEqual(typeof(bool?), env.Statement("s0").EventType.GetPropertyType("result"));

            for (var i = 0; i < input.Length; i++)
            {
                SendSupportBeanEvent(env, input[i]);
                var theEvent = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.AreEqual(result[i], theEvent.Get("result"), "Wrong result for " + input[i]);
            }

            env.UndeployAll();
        }
 private static void AssertCompileSODA(
     RegressionEnvironment env,
     string epl)
 {
     var model = env.EplToModel(epl);
     Assert.AreEqual(epl, model.ToEPL());
 }
        private static void Validate(
            RegressionEnvironment env,
            string selectClause,
            string groupByClause,
            string[] expectedCSV)
        {
            var epl = PLAN_CALLBACK_HOOK +
                      " select " +
                      selectClause +
                      ", count(*) from SupportEventABCProp group by " +
                      groupByClause;
            SupportGroupRollupPlanHook.Reset();

            env.Compile(epl);
            ComparePlan(expectedCSV);
            env.UndeployAll();

            var model = env.EplToModel(epl);
            Assert.AreEqual(epl, model.ToEPL());
            SupportGroupRollupPlanHook.Reset();

            model.Annotations.Add(AnnotationPart.NameAnnotation("s0"));
            env.CompileDeploy(model).AddListener("s0");
            ComparePlan(expectedCSV);

            env.UndeployAll();
        }
示例#7
0
            public void Run(RegressionEnvironment env)
            {
                env.AdvanceTime(0);

                var stmtText = "@Name('s0') select mychar from " +
                               " sql:MyDBWithRetain ['select mychar from mytesttable where mytesttable.myBigint = 2'] as S0," +
                               " pattern [every timer:interval(5 sec) ]";
                env.CompileDeploy(stmtText).AddListener("s0");

                env.AdvanceTime(5000);
                Assert.AreEqual("Y", env.Listener("s0").AssertOneGetNewAndReset().Get("mychar"));

                env.AdvanceTime(9999);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.AdvanceTime(10000);
                Assert.AreEqual("Y", env.Listener("s0").AssertOneGetNewAndReset().Get("mychar"));

                // with variable
                var path = new RegressionPath();
                env.CompileDeploy("create variable long VarLastTimestamp = 0", path);
                var epl = "@Name('Poll every 5 seconds') insert into PollStream" +
                          " select * from pattern[every timer:interval(5 sec)]," +
                          " sql:MyDBWithRetain ['select mychar from mytesttable where mytesttable.myBigint > ${VarLastTimestamp}'] as S0";
                var model = env.EplToModel(epl);
                env.CompileDeploy(model, path);
                env.UndeployAll();
            }
        private static void RunQuery(
            RegressionEnvironment env,
            RegressionPath path,
            string epl,
            string fields,
            object[][] expected,
            ContextPartitionSelector[] selectors)
        {
            // try FAF without prepare
            var compiled = env.CompileFAF(epl, path);
            var result = env.Runtime.FireAndForgetService.ExecuteQuery(compiled, selectors);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.SplitCsv(), expected);

            // test unparameterized prepare and execute
            var preparedQuery = env.Runtime.FireAndForgetService.PrepareQuery(compiled);
            var resultPrepared = preparedQuery.Execute(selectors);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPrepared.Array, fields.SplitCsv(), expected);

            // test unparameterized prepare and execute
            var preparedParameterizedQuery = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(compiled);
            var resultPreparedParameterized =
                env.Runtime.FireAndForgetService.ExecuteQuery(preparedParameterizedQuery, selectors);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPreparedParameterized.Array, fields.SplitCsv(), expected);

            // test SODA prepare and execute
            var model = env.EplToModel(epl);
            var compiledFromModel = env.CompileFAF(model, path);
            var preparedQueryModel = env.Runtime.FireAndForgetService.PrepareQuery(compiledFromModel);
            var resultPreparedModel = preparedQueryModel.Execute(selectors);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPreparedModel.Array, fields.SplitCsv(), expected);

            // test model query
            result = env.Runtime.FireAndForgetService.ExecuteQuery(compiledFromModel, selectors);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.SplitCsv(), expected);
        }
示例#9
0
			public void Run(RegressionEnvironment env)
			{
				string textOne = "@Name('s0') select irstream CONCATSTRING(TheString) as val from SupportBean#length(10) group by IntPrimitive";
				TryGrouped(env, textOne, null);

				string textTwo = "@Name('s0') select irstream concatstring(TheString) as val from SupportBean#win:length(10) group by IntPrimitive";
				TryGrouped(env, textTwo, null);

				string textThree = "@Name('s0') select irstream concatstring(TheString) as val from SupportBean#length(10) group by IntPrimitive";
				EPStatementObjectModel model = env.EplToModel(textThree);
				SerializableObjectCopier.CopyMayFail(env.Container, model);
				Assert.AreEqual(textThree, model.ToEPL());
				TryGrouped(env, null, model);

				string textFour = "select irstream concatstring(TheString) as val from SupportBean#length(10) group by IntPrimitive";
				EPStatementObjectModel modelTwo = new EPStatementObjectModel();
				modelTwo.SelectClause = SelectClause
					.Create(StreamSelector.RSTREAM_ISTREAM_BOTH)
					.Add(Expressions.PlugInAggregation("concatstring", Expressions.Property("TheString")), "val");
				modelTwo.FromClause = FromClause.Create(FilterStream.Create("SupportBean").AddView(null, "length", Expressions.Constant(10)));
				modelTwo.GroupByClause = GroupByClause.Create("IntPrimitive");
				Assert.AreEqual(textFour, modelTwo.ToEPL());
				SerializableObjectCopier.CopyMayFail(env.Container, modelTwo);
				modelTwo.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
				TryGrouped(env, null, modelTwo);

				env.UndeployAll();
			}
示例#10
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "@Name('s0') select S0.Id as idS0, S1.Id as idS1 " +
                               "from pattern [every S0=SupportBean_S0" +
                               " or every S1=SupportBean_S1] " +
                               "where S0.Id is not null and S0.Id<100 or S1.Id is not null and S1.Id>=100";
                var model = env.EplToModel(stmtText);
                model = env.CopyMayFail(model);

                var reverse = model.ToEPL();
                Assert.AreEqual(stmtText, reverse);

                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                env.CompileDeploy(model).AddListener("s0");

                SendEventS0(env, 1);
                AssertEventIds(env, 1, null);

                SendEventS0(env, 101);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                SendEventS1(env, 1);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                SendEventS1(env, 100);
                AssertEventIds(env, null, 100);

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var model = new EPStatementObjectModel();
                model.SelectClause = SelectClause.Create()
                    .AddStreamWildcard("S0")
                    .AddStreamWildcard("S1", "S1stream")
                    .AddWithAsProvidedName("TheString", "sym");
                model.FromClause = FromClause.Create()
                    .Add(FilterStream.Create("SupportBean", "S0").AddView("keepall"))
                    .Add(FilterStream.Create("SupportMarketDataBean", "S1").AddView("keepall"));
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                env.CompileDeploy(model).AddListener("s0");

                var epl =
                    "@Name('s0') select S0.*, S1.* as S1stream, TheString as sym from SupportBean#keepall as S0, " +
                    "SupportMarketDataBean#keepall as S1";
                Assert.AreEqual(epl, model.ToEPL());
                var modelReverse = env.EplToModel(model.ToEPL());
                Assert.AreEqual(epl, modelReverse.ToEPL());

                var type = env.Statement("s0").EventType;
                Assert.AreEqual(typeof(SupportMarketDataBean), type.GetPropertyType("S1stream"));
                Assert.AreEqual(typeof(Pair<object, IDictionary<string, object>>), type.UnderlyingType);

                SendBeanEvent(env, "E1");
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                object theEvent = SendMarketEvent(env, "E1");
                var outevent = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.AreSame(theEvent, outevent.Get("S1stream"));

                env.UndeployAll();
            }
示例#12
0
            public void Run(RegressionEnvironment env)
            {
                string[][] testdata = {
                    new[] {"A or B and C", null, "PatternOrExpr"},
                    new[] {"(A or B) and C", null, "PatternAndExpr"},
                    new[] {"(A or B) and C", null, "PatternAndExpr"},
                    new[] {"every A or every B", null, "PatternOrExpr"},
                    new[] {"B -> D or A", null, "PatternFollowedByExpr"},
                    new[] {"every A and not B", null, "PatternAndExpr"},
                    new[] {"every A and not B", null, "PatternAndExpr"},
                    new[] {"every A -> B", null, "PatternFollowedByExpr"},
                    new[] {"A where timer:within(10)", null, "PatternGuardExpr"},
                    new[] {"every (A and B)", null, "PatternEveryExpr"},
                    new[] {"every A where timer:within(10)", null, "PatternEveryExpr"},
                    new[] {"A or B until C", null, "PatternOrExpr"},
                    new[] {"A or (B until C)", "A or B until C", "PatternOrExpr"},
                    new[] {"every (every A)", null, "PatternEveryExpr"},
                    new[] {"(A until B) until C", null, "PatternMatchUntilExpr"},
                };

                foreach (var aTestdata in testdata) {
                    var epl = "select * from pattern [" + aTestdata[0] + "]";
                    var expected = aTestdata[1];
                    var expressionLowestPrecedenceClass = aTestdata[2];
                    var failText = "Failed for [" + aTestdata[0] + "]";

                    var modelBefore = env.EplToModel(epl);
                    var eplAfter = modelBefore.ToEPL();

                    if (expected == null) {
                        Assert.AreEqual(epl, eplAfter, failText);
                    }
                    else {
                        var expectedEPL = "select * from pattern [" + expected + "]";
                        Assert.AreEqual(expectedEPL, eplAfter, failText);
                    }

                    // get where clause root expression of both models
                    var modelAfter = env.EplToModel(eplAfter);
                    Assert.AreEqual(GetPatternRootExpr(modelAfter).GetType(), GetPatternRootExpr(modelBefore).GetType(), failText);
                    Assert.AreEqual(expressionLowestPrecedenceClass, GetPatternRootExpr(modelAfter).GetType().Name, failText);
                }

                env.UndeployAll();
            }
            private void TryAssertionInsertWhereOMStaggered(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                var path = new RegressionPath();
                var stmtTextCreateOne = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyWindowIWOM>() +
                                        " @Name('window') create window MyWindowIWOM#keepall as select a, b from MyMapAB";
                env.CompileDeploy(stmtTextCreateOne, path);
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("window").EventType.UnderlyingType));
                env.AddListener("window");

                // create insert into
                var stmtTextInsertOne = "insert into MyWindowIWOM select a, b from MyMapAB";
                env.CompileDeploy(stmtTextInsertOne, path);

                // populate some data
                env.SendEventMap(BuildMap(new[] {new object[] {"a", "E1"}, new object[] {"b", 2}}), "MyMapAB");
                env.SendEventMap(BuildMap(new[] {new object[] {"a", "E2"}, new object[] {"b", 10}}), "MyMapAB");
                env.SendEventMap(BuildMap(new[] {new object[] {"a", "E3"}, new object[] {"b", 10}}), "MyMapAB");

                // create window with keep-all using OM
                var model = new EPStatementObjectModel();
                eventRepresentationEnum.AddAnnotationForNonMap(model);
                Expression where = Expressions.Eq("b", 10);
                model.CreateWindow =
                    CreateWindowClause.Create("MyWindowIWOMTwo", View.Create("keepall"))
                        .WithInsert(true)
                        .WithInsertWhereClause(where)
                        .WithAsEventTypeName("MyWindowIWOM");
                model.SelectClause = SelectClause.CreateWildcard();
                var text = eventRepresentationEnum.GetAnnotationTextForNonMap() +
                           " create window MyWindowIWOMTwo#keepall as select * from MyWindowIWOM insert where b=10";
                Assert.AreEqual(text.Trim(), model.ToEPL());

                var modelTwo = env.EplToModel(text);
                Assert.AreEqual(text.Trim(), modelTwo.ToEPL());
                modelTwo.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("windowTwo"));
                env.CompileDeploy(modelTwo, path).AddListener("windowTwo");

                EPAssertionUtil.AssertPropsPerRow(
                    env.GetEnumerator("windowTwo"),
                    new[] {"a", "b"},
                    new[] {new object[] {"E2", 10}, new object[] {"E3", 10}});

                // test select individual fields and from an insert-from named window
                env.CompileDeploy(
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyWindowIWOMThree>() +
                    " @Name('windowThree') create window MyWindowIWOMThree#keepall as select a from MyWindowIWOMTwo insert where a = 'E2'",
                    path);
                EPAssertionUtil.AssertPropsPerRow(
                    env.GetEnumerator("windowThree"),
                    new[] {"a"},
                    new[] {new object[] {"E2"}});

                env.UndeployAll();
            }
示例#14
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') select " +
                          "?:a0:int[] as c0, " +
                          "?:a1:int[primitive] as c1, " +
                          "?:a2:System.Object[] as c2, " +
                          "?:a3:string[][] as c3, " +
                          "?:a4:System.Object[][] as c4 " +
                          "from SupportBean";

                EPCompiled compiled;
                if (soda) {
                    var copy = env.EplToModel(epl);
                    Assert.AreEqual(epl.Trim(), copy.ToEPL());
                    compiled = env.Compile(copy, new CompilerArguments(env.Configuration));
                }
                else {
                    compiled = env.Compile(epl);
                }

                var options = new DeploymentOptions().WithStatementSubstitutionParameter(
                    _ => {
                        _.SetObject("a0", new int?[] {1, 2});
                        _.SetObject("a1", new[] {3, 4});
                        _.SetObject("a2", new object[] {"a", "b"});
                        _.SetObject("a3", new[] {new[] {"A"}});
                        _.SetObject("a4", new[] {new object[] {5, 6}});
                    });

                try {
                    env.Deployment.Deploy(compiled, options);
                }
                catch (EPDeployException e) {
                    throw new EPRuntimeException(e);
                }

                env.AddListener("s0");

                var eventType = env.Statement("s0").EventType;
                Assert.AreEqual(typeof(int?[]), eventType.GetPropertyType("c0"));
                Assert.AreEqual(typeof(int[]), eventType.GetPropertyType("c1"));
                Assert.AreEqual(typeof(object[]), eventType.GetPropertyType("c2"));
                Assert.AreEqual(typeof(string[][]), eventType.GetPropertyType("c3"));
                Assert.AreEqual(typeof(object[][]), eventType.GetPropertyType("c4"));

                env.SendEventBean(new SupportBean());

                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                EPAssertionUtil.AssertEqualsExactOrder(new int?[] {1, 2}, (int?[]) @event.Get("c0"));
                EPAssertionUtil.AssertEqualsExactOrder(new[] {3, 4}, (int[]) @event.Get("c1"));
                EPAssertionUtil.AssertEqualsExactOrder(new object[] {"a", "b"}, (object[]) @event.Get("c2"));
                EPAssertionUtil.AssertEqualsExactOrder(new[] {new[] {"A"}}, (string[][]) @event.Get("c3"));
                EPAssertionUtil.AssertEqualsExactOrder(new[] {new object[] {5, 6}}, (object[][]) @event.Get("c4"));

                env.UndeployAll();
            }
示例#15
0
            public void Run(RegressionEnvironment env)
            {
                var fields       = "eq,neq,sqlneq,nneq".SplitCsv();
                var eplReference = new Atomic <string>();
                var builder      = new SupportEvalBuilder("SupportBean")
                                   .WithExpression(fields[0], "IntPrimitive=all(1,IntBoxed)")
                                   .WithExpression(fields[1], "IntPrimitive!=all(1,IntBoxed)")
                                   .WithExpression(fields[2], "IntPrimitive<>all(1,IntBoxed)")
                                   .WithExpression(fields[3], "not IntPrimitive=all(1,IntBoxed)")
                                   .WithStatementConsumer(stmt => eplReference.Set(stmt.GetProperty(StatementProperty.EPL).ToString()));

                // in the format IntPrimitive, IntBoxed
                int[][] testdata =
                {
                    new[] { 1, 1 },
                    new[] { 1, 2 },
                    new[] { 2, 2 },
                    new[] { 2, 1 },
                };

                object[][] result =
                {
                    new object[] { true,  false, false, false },  // 1, 1
                    new object[] { false, false, false, true  },  // 1, 2
                    new object[] { false, false, false, true  },  // 2, 2
                    new object[] { false, true,  true,  true  }   // 2, 1
                };

                for (var i = 0; i < testdata.Length; i++)
                {
                    var bean = new SupportBean("E", testdata[i][0]);
                    bean.IntBoxed = testdata[i][1];
                    builder.WithAssertion(bean).Expect(fields, result[i]);
                }

                builder.Run(env);
                env.UndeployAll();

                // test OM
                var epl   = eplReference.Get();
                var model = env.EplToModel(epl);

                Assert.AreEqual(epl.Replace("<>", "!="), model.ToEPL());
                env.CompileDeploy(model).AddListener("s0");

                for (var i = 0; i < testdata.Length; i++)
                {
                    var bean = new SupportBean("E", testdata[i][0]);
                    bean.IntBoxed = testdata[i][1];
                    env.SendEventBean(bean);
                    EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, result[i]);
                }

                env.UndeployAll();
            }
示例#16
0
            public void Run(RegressionEnvironment env)
            {
                string[][] testdata = {
                    new[] {"1+2*3", null, "ArithmaticExpression"},
                    new[] {"1+(2*3)", "1+2*3", "ArithmaticExpression"},
                    new[] {"2-2/3-4", null, "ArithmaticExpression"},
                    new[] {"2-(2/3)-4", "2-2/3-4", "ArithmaticExpression"},
                    new[] {"1+2 in (4,5)", null, "InExpression"},
                    new[] {"(1+2) in (4,5)", "1+2 in (4,5)", "InExpression"},
                    new[] {"true and false or true", null, "Disjunction"},
                    new[] {"(true and false) or true", "true and false or true", "Disjunction"},
                    new[] {"true and (false or true)", null, "Conjunction"},
                    new[] {"true and (((false or true)))", "true and (false or true)", "Conjunction"},
                    new[] {"true and (((false or true)))", "true and (false or true)", "Conjunction"},
                    new[] {"false or false and true or false", null, "Disjunction"},
                    new[] {"false or (false and true) or false", "false or false and true or false", "Disjunction"},
                    new[] {"\"a\"||\"b\"=\"ab\"", null, "RelationalOpExpression"},
                    new[] {"(\"a\"||\"b\")=\"ab\"", "\"a\"||\"b\"=\"ab\"", "RelationalOpExpression"},
                };

                foreach (var aTestdata in testdata) {
                    var epl = "select * from System.Object where " + aTestdata[0];
                    var expected = aTestdata[1];
                    var expressionLowestPrecedenceClass = aTestdata[2];

                    var modelBefore = env.EplToModel(epl);
                    var eplAfter = modelBefore.ToEPL();

                    if (expected == null) {
                        Assert.AreEqual(epl, eplAfter);
                    }
                    else {
                        var expectedEPL = "select * from System.Object where " + expected;
                        Assert.AreEqual(expectedEPL, eplAfter);
                    }

                    // get where clause root expression of both models
                    var modelAfter = env.EplToModel(eplAfter);
                    Assert.AreEqual(modelAfter.WhereClause.GetType(), modelBefore.WhereClause.GetType());
                    Assert.AreEqual(expressionLowestPrecedenceClass, modelAfter.WhereClause.GetType().Name);
                }
            }
示例#17
0
            public void Run(RegressionEnvironment env)
            {
                // columns supplied
                var stmtText =
                    "@Name('s0') select * from OrderBean[select BookId, OrderDetail.OrderId as OrderId from Books][select ReviewId from Reviews] bookReviews order by ReviewId asc";
                env.CompileDeploy(stmtText).AddListener("s0");
                TryAssertionColumnSelect(env);
                env.UndeployAll();

                // stream wildcards identify fragments
                stmtText =
                    "@Name('s0') select OrderFrag.OrderDetail.OrderId as OrderId, BookFrag.BookId as BookId, ReviewFrag.ReviewId as ReviewId " +
                    "from OrderBean[Books as Book][select myorder.* as OrderFrag, Book.* as BookFrag, review.* as ReviewFrag from Reviews as review] as myorder";
                env.CompileDeploy(stmtText).AddListener("s0");
                TryAssertionColumnSelect(env);
                env.UndeployAll();

                // one event type dedicated as underlying
                stmtText =
                    "@Name('s0') select OrderDetail.OrderId as OrderId, BookFrag.BookId as BookId, reviewFrag.ReviewId as ReviewId " +
                    "from OrderBean[Books as Book][select myorder.*, Book.* as BookFrag, review.* as reviewFrag from Reviews as review] as myorder";
                env.CompileDeploy(stmtText).AddListener("s0");
                TryAssertionColumnSelect(env);
                env.UndeployAll();

                // wildcard unnamed as underlying
                stmtText = "@Name('s0') select OrderFrag.OrderDetail.OrderId as OrderId, BookId, ReviewId " +
                           "from OrderBean[select * from Books][select myorder.* as OrderFrag, ReviewId from Reviews as review] as myorder";
                env.CompileDeploy(stmtText).AddListener("s0");
                TryAssertionColumnSelect(env);
                env.UndeployAll();

                // wildcard named as underlying
                stmtText =
                    "@Name('s0') select OrderFrag.OrderDetail.OrderId as OrderId, BookFrag.BookId as BookId, reviewFrag.ReviewId as ReviewId " +
                    "from OrderBean[select * from Books as BookFrag][select myorder.* as OrderFrag, review.* as reviewFrag from Reviews as review] as myorder";
                env.CompileDeploy(stmtText).AddListener("s0");
                TryAssertionColumnSelect(env);
                env.UndeployAll();

                // object model
                stmtText = "@Name('s0') select OrderFrag.OrderDetail.OrderId as OrderId, BookId, ReviewId " +
                           "from OrderBean[select * from Books][select myorder.* as OrderFrag, ReviewId from Reviews as review] as myorder";
                env.EplToModelCompileDeploy(stmtText).AddListener("s0");
                TryAssertionColumnSelect(env);
                env.UndeployAll();

                // with where-clause
                stmtText = "@Name('s0') select * from AccountEvent[select * from wallets where currency=\"USD\"]";
                var model = env.EplToModel(stmtText);
                Assert.AreEqual(stmtText, model.ToEPL());
            }
示例#18
0
            public void Run(RegressionEnvironment env)
            {
                // try with alias
                var textOne = "@Name('s0') select S0 as S0stream, S1 as S1stream from " +
                              "SupportMarketDataBean#keepall as S0, " +
                              "SupportBean#keepall as S1";

                // Attach listener to feed
                env.CompileDeploy(textOne).AddListener("s0");
                var model = env.EplToModel(textOne);
                Assert.AreEqual(textOne, model.ToEPL());

                var type = env.Statement("s0").EventType;
                Assert.AreEqual(2, type.PropertyNames.Length);
                Assert.AreEqual(typeof(SupportMarketDataBean), type.GetPropertyType("S0stream"));
                Assert.AreEqual(typeof(SupportBean), type.GetPropertyType("S1stream"));

                var eventA = new SupportMarketDataBean("ACME", 0, 0L, null);
                env.SendEventBean(eventA);

                var eventB = new SupportBean();
                env.SendEventBean(eventB);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"S0stream", "S1stream"},
                    new object[] {eventA, eventB});

                env.UndeployAll();

                // try no alias
                textOne = "@Name('s0') select S0, S1 from " +
                          "SupportMarketDataBean#keepall as S0, " +
                          "SupportBean#keepall as S1";
                env.CompileDeploy(textOne).AddListener("s0");

                type = env.Statement("s0").EventType;
                Assert.AreEqual(2, type.PropertyNames.Length);
                Assert.AreEqual(typeof(SupportMarketDataBean), type.GetPropertyType("S0"));
                Assert.AreEqual(typeof(SupportBean), type.GetPropertyType("S1"));

                env.SendEventBean(eventA);
                env.SendEventBean(eventB);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new[] {"S0", "S1"},
                    new object[] {eventA, eventB});

                env.UndeployAll();
            }
示例#19
0
            public void Run(RegressionEnvironment env)
            {
                var fields       = "g,ge".SplitCsv();
                var eplReference = new Atomic <string>();
                var builder      = new SupportEvalBuilder("SupportBeanArrayCollMap")
                                   .WithExpressions(fields, "LongBoxed>all({1,2},IntArr,IntCol)", "LongBoxed>=all({1,2},IntArr,IntCol)")
                                   .WithStatementConsumer(stmt => eplReference.Set(stmt.GetProperty(StatementProperty.EPL).ToString()));

                var arrayBean = MakeBean();

                arrayBean.IntCol    = Arrays.AsList(1, 2);
                arrayBean.LongBoxed = 3L;
                builder.WithAssertion(arrayBean).Expect(fields, true, true);

                arrayBean           = MakeBean();
                arrayBean.LongBoxed = 2L;
                env.SendEventBean(arrayBean);
                builder.WithAssertion(arrayBean).Expect(fields, false, true);

                arrayBean           = new SupportBeanArrayCollMap(new[] { 1, 3 });
                arrayBean.IntCol    = Arrays.AsList(1, 2);
                arrayBean.LongBoxed = 3L;
                env.SendEventBean(arrayBean);
                builder.WithAssertion(arrayBean).Expect(fields, false, true);

                arrayBean           = new SupportBeanArrayCollMap(new[] { 1, 2 });
                arrayBean.IntCol    = Arrays.AsList(1, 3);
                arrayBean.LongBoxed = 3L;
                env.SendEventBean(arrayBean);
                builder.WithAssertion(arrayBean).Expect(fields, false, true);

                builder.Run(env);
                env.UndeployAll();

                // test OM
                var epl   = eplReference.Get();
                var model = env.EplToModel(epl);

                Assert.AreEqual(epl.Replace("<>", "!="), model.ToEPL());
                env.CompileDeploy(model).AddListener("s0");

                arrayBean           = new SupportBeanArrayCollMap(new[] { 1, 2 });
                arrayBean.IntCol    = Arrays.AsList(1, 2);
                arrayBean.LongBoxed = 3L;
                env.SendEventBean(arrayBean);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, true, true);

                env.UndeployAll();
            }
示例#20
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "@Name('s0') select " +
                               ALL_FIELDS +
                               " from " +
                               " sql:MyDBWithRetain ['select " +
                               ALL_FIELDS +
                               " from mytesttable where ${IntPrimitive} = mytesttable.myBigint'] as S0," +
                               "SupportBean#time_batch(10 sec) as S1";

                var model = env.EplToModel(stmtText);
                env.CopyMayFail(model);
                env.CompileDeploy(model).AddListener("s0");
                RuntestTimeBatch(env);
            }
示例#21
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "select * from SupportBean";
                var model = env.EplToModel(stmtText);
                SerializableObjectCopier.CopyMayFail(env.Container, model);
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));

                env.CompileDeploy(model).AddListener("s0");

                object theEvent = new SupportBean();
                env.SendEventBean(theEvent);
                Assert.AreEqual(theEvent, env.Listener("s0").AssertOneGetNewAndReset().Underlying);
                Assert.AreEqual("@Name('s0') " + stmtText, env.Statement("s0").GetProperty(StatementProperty.EPL));

                env.UndeployAll();
            }
示例#22
0
            public void Run(RegressionEnvironment env)
            {
                SendTimeEvent("2008-08-3T06:00:00.000", env);
                var expression =
                    "@Name('s0') select * from pattern [a=SupportBean -> every timer:at(2*a.IntPrimitive,*,*,*,*)]";

                env.CompileDeploy(expression);
                env.AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 20));

                SendTimeEvent("2008-08-3T06:39:59.000", env);
                Assert.IsFalse(env.Listener("s0").GetAndClearIsInvoked());

                SendTimeEvent("2008-08-3T06:40:00.000", env);
                Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked());
                env.UndeployAll();

                // test SODA
                var epl   = "select * from pattern [every timer:at(*/VFREQ,VMIN:VMAX,1 last,*,[8,2:VMAX,*/VREQ])]";
                var model = env.EplToModel(epl);

                Assert.AreEqual(epl, model.ToEPL());

                // test timezone
                var baseUtcOffset     = TimeZoneInfo.Utc.BaseUtcOffset;
                var expectedUtcOffset = TimeSpan.FromMilliseconds(-5 * 60 * 60 * 1000);

                if (baseUtcOffset.Equals(expectedUtcOffset))
                {
                    // asserting only in EST timezone, see schedule util tests
                    SendTimeEvent("2008-01-4T06:50:00.000", env);
                    env.CompileDeploy("@Name('s0') select * from pattern [timer:at(0, 5, 4, 1, *, 0, 'PST')]")
                    .AddListener("s0");

                    SendTimeEvent("2008-01-4T07:59:59.999", env);
                    Assert.IsFalse(env.Listener("s0").GetAndClearIsInvoked());

                    SendTimeEvent("2008-01-4T08:00:00.000", env);
                    Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked());
                }

                env.CompileDeploy("select * from pattern [timer:at(0, 5, 4, 8, *, 0, 'xxx')]");
                env.CompileDeploy("select * from pattern [timer:at(0, 5, 4, 8, *, 0, *)]");

                env.UndeployAll();
            }
示例#23
0
            public void Run(RegressionEnvironment env)
            {
                // External clocking
                SendTimer(0, env);

                // Set up a timer:within
                var stmtText =
                    "@Name('s0') select * from pattern [(every SupportBean) where timer:within(DD days HH hours MM minutes SS seconds MS milliseconds)]";

                env.CompileDeploy(stmtText).AddListener("s0");

                TryAssertion(env);

                var model = env.EplToModel(stmtText);

                Assert.AreEqual(stmtText, model.ToEPL());

                env.UndeployAll();
            }
示例#24
0
 public void Run(RegressionEnvironment env)
 {
     var model = new EPStatementObjectModel();
     model.SelectClause = SelectClause.Create(new[] {"S0.Id", " S0.P00", " S0.P01", " S1.Id", " S1.P10", " S1.P11"});
     var fromClause = FromClause.Create(
         FilterStream.Create(typeof(SupportBean_S0).Name, "S0").AddView("keepall"),
         FilterStream.Create(typeof(SupportBean_S1).Name, "S1").AddView("keepall"));
     fromClause.Add(OuterJoinQualifier.Create("S0.P00", OuterJoinType.LEFT, "S1.P10").Add("S1.P11", "S0.P01"));
     model.FromClause = fromClause;
     model = env.CopyMayFail(model);
     var stmtText =
         "select S0.Id, S0.P00, S0.P01, S1.Id, S1.P10, S1.P11 from SupportBean_S0#keepall as S0 left outer join SupportBean_S1#keepall as S1 on S0.P00 = S1.P10 and S1.P11 = S0.P01";
     Assert.AreEqual(stmtText, model.ToEPL());
     model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
     env.CompileDeploy(model).AddListener("s0");
     AssertMultiColumnLeft(env);
     var modelReverse = env.EplToModel(stmtText);
     Assert.AreEqual(stmtText, modelReverse.ToEPL());
     env.UndeployAll();
 }
示例#25
0
 public void Run(RegressionEnvironment env)
 {
     var soda = "@Name('create dataflow full')\n" +
                "create dataflow DFFull\n" +
                "create map schema ABC1 as (col1 int, col2 int),\n" +
                "create map schema ABC2 as (col1 int, col2 int),\n" +
                "MyOperatorOne(instream.one) -> outstream.one {}\n" +
                "MyOperatorTwo(instream.two as IN1, input.three as IN2) -> outstream.one<Test>, outstream.two<EventBean<TestTwo>> {}\n" +
                "MyOperatorThree((instream.two, input.three) as IN1) {}\n" +
                "MyOperatorFour -> teststream {}\n" +
                "MyOperatorFive {\n" +
                "const_str: \"abc\",\n" +
                "somevalue: def*2,\n" +
                "select: (select * from ABC where 1=2),\n" +
                "jsonarr: [\"a\",\"b\"],\n" +
                "jsonobj: {a: \"a\",b: \"b\"}\n" +
                "}\n";
     var model = env.EplToModel(soda);
     EPAssertionUtil.AssertEqualsIgnoreNewline(soda, model.ToEPL(new EPStatementFormatter(true)));
 }
示例#26
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') select P00 like P01 as r1, " +
                          "P00 like P01 escape \"!\" as r2, " +
                          "P02 regexp P03 as r3 " +
                          "from SupportBean_S0";

                var model = env.EplToModel(epl);

                model = SerializableObjectCopier.GetInstance(env.Container).Copy(model);
                Assert.AreEqual(epl, model.ToEPL());

                var compiled = env.Compile(model, new CompilerArguments(env.Configuration));

                env.Deploy(compiled).AddListener("s0").Milestone(0);

                RunLikeRegexStringAndNull(env);

                env.UndeployAll();
            }
示例#27
0
        internal static void RunEquivalent(
            RegressionEnvironment env,
            string before,
            string after)
        {
            var hook = "@Hook(HookType=" +
                       typeof(HookType).FullName +
                       ".INTERNAL_COMPILE,Hook='" +
                       SupportStatementCompileHook.ResetGetClassName() +
                       "')";
            var epl = hook +
                      "@Name('s0') select * from SupportBean#keepall " +
                      "match_recognize (" +
                      " measures A as a" +
                      " pattern (" +
                      before +
                      ")" +
                      " define" +
                      " A as A.TheString like \"A%\"" +
                      ")";

            var model = env.EplToModel(epl);
            env.CompileDeploy(model);
            env.UndeployAll();

            var spec = SupportStatementCompileHook.GetSpecs()[0];
            RowRecogExprNode expanded = null;
            try {
                expanded = RowRecogPatternExpandUtil.Expand(
                    spec.Raw.MatchRecognizeSpec.Pattern,
                    null);
            }
            catch (ExprValidationException e) {
                Assert.Fail(e.Message);
            }

            var writer = new StringWriter();
            expanded.ToEPL(writer, RowRecogExprNodePrecedenceEnum.MINIMUM);
            Assert.AreEqual(after, writer.ToString());
        }
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') select se1() as c0, se2() as c1 from SupportBean#keepall group by TheString";

                // test regular
                SupportAggMFMultiRTForge.Reset();
                SupportAggMFMultiRTHandler.Reset();
                SupportAggMFMultiRTSingleEventStateFactory.Reset();

                env.CompileDeploy(epl).AddListener("s0");
                TryAssertion(env);

                // test SODA
                var model = env.EplToModel(epl);

                SupportAggMFMultiRTForge.Reset();
                SupportAggMFMultiRTHandler.Reset();
                SupportAggMFMultiRTSingleEventStateFactory.Reset();
                Assert.AreEqual(epl, model.ToEPL());
                env.CompileDeploy(model).AddListener("s0");
                TryAssertion(env);
            }
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "select rstream * from SupportBean#length(3)";
                var model = env.EplToModel(stmtText);
                model = env.CopyMayFail(model);

                Assert.AreEqual(stmtText, model.ToEPL());
                model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                env.CompileDeploy(model).AddListener("s0");

                var theEvent = SendEvent(env, "a", 2);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                SendEvents(env, new[] {"a", "b"});
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                SendEvent(env, "d", 2);
                Assert.AreSame(theEvent, env.Listener("s0").LastNewData[0].Underlying); // receive 'a' as new data
                Assert.IsNull(env.Listener("s0").LastOldData); // receive no more old data

                env.UndeployAll();
            }
示例#30
0
        public void Run(RegressionEnvironment env)
        {
            if (env.IsHA) {
                return;
            }

            var epl = "@Name('flow')create dataflow VWAPSample\r\n" +
                      "create objectarray schema TradeQuoteType as (type string, ticker string, Price double, Volume long, askPrice double, asksize long),\n" +
                      "MyObjectArrayGraphSource -> TradeQuoteStream<TradeQuoteType> {}\r\n" +
                      "filter(TradeQuoteStream) -> TradeStream {\r\n" +
                      "filter: type=\"trade\"\r\n" +
                      "}\r\n" +
                      "filter(TradeQuoteStream) -> QuoteStream {\r\n" +
                      "filter: type=\"quote\"\r\n" +
                      "}\r\n" +
                      "select(TradeStream) -> VwapTrades {\r\n" +
                      "select: (select ticker, sum(Price*Volume)/sum(Volume) as vwap, min(Price) as minPrice from TradeStream#groupwin(ticker)#length(4) group by ticker)\r\n" +
                      "}\r\n" +
                      "select(VwapTrades as T, QuoteStream as Q) -> BargainIndex {\r\n" +
                      "select: " +
                      "(select case when vwap>askPrice then asksize*(Math.Exp(vwap-askPrice)) else 0.0d end as index " +
                      "from T#unique(ticker) as t, Q#lastevent as q " +
                      "where t.ticker=q.ticker)\r\n" +
                      "}\r\n" +
                      "DefaultSupportCaptureOp(BargainIndex) {}\r\n";
            env.CompileDeploy(epl);

            RunAssertion(env);

            env.UndeployAll();
            var model = env.EplToModel(epl);
            var text = model.ToEPL(new EPStatementFormatter(true));
            Assert.AreEqual(RemoveNewlines(epl), RemoveNewlines(text));
            env.CompileDeploy(model);

            RunAssertion(env);
            env.UndeployAll();
        }