public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('create') create variable int myvar = $X;\n" +
                          "on pattern[every timer:interval(10)] set myvar = myvar + 1;\n";
                env.AdvanceTime(0);
                var idOne = env.DeployGetId(env.Compile(epl.Replace("$X", "10")));
                var idTwo = env.DeployGetId(env.Compile(epl.Replace("$X", "20")));

                AssertVariable(env, idOne, 10);
                AssertVariable(env, idTwo, 20);

                env.AdvanceTime(10000);

                AssertVariable(env, idOne, 11);
                AssertVariable(env, idTwo, 21);

                env.Undeploy(idOne);

                env.AdvanceTime(20000);

                Assert.IsNull(env.Runtime.DeploymentService.GetStatement(idOne, "create"));
                AssertVariable(env, idTwo, 22);

                env.Undeploy(idTwo);
                Assert.IsNull(env.Runtime.DeploymentService.GetStatement(idTwo, "create"));
            }
            public void Run(RegressionEnvironment env)
            {
                var ns               = NamespaceGenerator.Create();
                var prefix           = INLINEDCLASS_PREFIXMAP.Replace("${NAMESPACE}", ns);
                var eplCreateInlined = "@Name('clazz') @public create " + prefix + ";\n";
                var path             = new RegressionPath();

                env.Compile(eplCreateInlined, path);

                var epl =
                    "@public @buseventtype create schema PersonEvent(name string, id string);" +
                    "@Name('table') create table TableWithTrie(nameTrie trieState(string));\n" +
                    "into table TableWithTrie select trieEnter(name) as nameTrie from PersonEvent;\n";
                var compiledTable = env.Compile(epl, path);

                env.CompileDeploy(eplCreateInlined);
                env.Deploy(compiledTable);

                MakeSendPerson(env, "Andreas", "P1");
                MakeSendPerson(env, "Andras", "P2");
                MakeSendPerson(env, "Andras", "P3");
                MakeSendPerson(env, "And", "P4");

                var trie = (SupportTrie <string, IList <object> >)env.GetEnumerator("table").Advance().Get("nameTrie");

                Assert.AreEqual(3, trie.PrefixMap("And").Count);

                // assert dependencies
                SupportDeploymentDependencies.AssertSingle(env, "table", "clazz", EPObjectType.CLASSPROVIDED, ns + ".TrieAggForge");

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                RegressionPath path = new RegressionPath();
                string eplObjects = "@public create variable int MYVAR;\n";
                env.Compile(eplObjects, path);

                env.Compile("uses dummy; select MYVAR from SupportBean", path);
            }
            public void Run(RegressionEnvironment env)
            {
                var commonEPL = "create variable int abc;\n" +
                                "create schema MySchema();" +
                                "create context MyContext partition by TheString from SupportBean;\n" +
                                "create window MyWindow#keepall as SupportBean;\n" +
                                "create table MyTable as (c count(*));\n" +
                                "create expression MyExpr { 1 };\n" +
                                "create expression double myscript(stringvalue) [0];\n" +
                                "create inlined_class \"\"\" public class MyClass { public static string DoIt() { return \"def\"; } }\"\"\";\n";

                var modOne = env.Compile("module one;\n " + commonEPL, new RegressionPath());
                var modTwo = env.Compile("module two;\n " + commonEPL, new RegressionPath());

                var path = new RegressionPath();
                path.Add(modOne);
                path.Add(modTwo);
                TryInvalidCompile(
                    env,
                    path,
                    "select abc from SupportBean",
                    "The variable by name 'abc' is ambiguous as it exists for multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "select 1 from MySchema",
                    "The event type by name 'MySchema' is ambiguous as it exists for multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "context MyContext select * from SupportBean",
                    "The context by name 'MyContext' is ambiguous as it exists for multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "select * from MyWindow",
                    "The named window by name 'MyWindow' is ambiguous as it exists for multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "select * from MyTable",
                    "The table by name 'MyTable' is ambiguous as it exists for multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "select MyExpr() from SupportBean",
                    "The declared-expression by name 'MyExpr' is ambiguous as it exists for multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "select myscript('a') from SupportBean",
                    "The script by name 'myscript' is ambiguous as it exists for multiple modules: A script by name 'myscript (1 parameters)' is exported by multiple modules");
                TryInvalidCompile(
                    env,
                    path,
                    "select MyClass.DoIt() from SupportBean",
                    "Failed to validate select-clause expression 'MyClass.DoIt()': The application-inlined class by name 'MyClass' is ambiguous as it exists for multiple modules: An application-inlined class by name 'MyClass' is exported by multiple modules");
            }
Exemple #5
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();
            }
            public void Run(RegressionEnvironment env)
            {
                // we allow empty class text
                env.Compile("inlined_class \"\"\" \"\"\" select * from SupportBean");
                // invalid class
                TryInvalidCompile(
                    env,
                    "inlined_class \"\"\" x \"\"\" select * from SupportBean",
                    "Exception processing statement: " +
                    "Failure during module compilation: " +
                    "[(1,2): error CS0116:");
                //"Failed to compile class: Line 1, Column 2: One of 'class enum interface @' expected instead of 'x' for class [\"\"\" x \"\"\"]");

                // invalid already deployed
                var path           = new RegressionPath();
                var createClassEPL = "create inlined_class \"\"\" public class MyClass {}\"\"\"";

                env.Compile(createClassEPL, path);
                SupportMessageAssertUtil.TryInvalidCompile(
                    env,
                    path,
                    createClassEPL,
                    "Class 'MyClass' has already been declared");

                // duplicate local class
                var eplDuplLocal =
                    "inlined_class \"\"\" class MyDuplicate{} \"\"\" inlined_class \"\"\" class MyDuplicate{} \"\"\" select * from SupportBean";

                TryInvalidCompile(
                    env,
                    eplDuplLocal,
                    "Exception processing statement: " +
                    "Failure during module compilation: " +
                    "[(1,8): error CS0101: The namespace '<global namespace>' already contains a definition for 'MyDuplicate']");

                // duplicate local class and create-class class
                var eplDuplLocalAndCreate = "inlined_class \"\"\" class MyDuplicate{} \"\"\" create inlined_class \"\"\" class MyDuplicate{} \"\"\"";

                TryInvalidCompile(
                    env,
                    eplDuplLocalAndCreate,
                    "Exception processing statement: " +
                    "Failure during module compilation: " +
                    "[(1,8): error CS0101: The namespace '<global namespace>' already contains a definition for 'MyDuplicate']");

                // duplicate create-class class
                var eplDuplCreate =
                    "create inlined_class \"\"\" public class MyDuplicate{} \"\"\";\n" +
                    "create inlined_class \"\"\" public class MyDuplicate{} \"\"\";\n";

                TryInvalidCompile(
                    env,
                    eplDuplCreate,
                    "Class 'MyDuplicate' has already been declared");
            }
            public void Run(RegressionEnvironment env)
            {
                var @base  = env.Compile("@Name('basevar') @public create constant variable int basevar = 1");
                var child0 = env.Compile("@Name('s0') select basevar from SupportBean", new RegressionPath().Add(@base));
                var child1 = env.Compile(
                    "@Name('child1var') create constant variable int child1var = 2;\n" +
                    "@Name('s1') select basevar, child1var from SupportBean;\n",
                    new RegressionPath().Add(@base));
                var child11 = env.Compile("@Name('s2') select basevar, child1var from SupportBean;\n", new RegressionPath().Add(@base).Add(child1));

                env.Rollout(ToRolloutItems(@base, child0, child1, child11), null);
                env.AddListener("s0").AddListener("s1").AddListener("s2");

                SendAssert(env, "s1,s2");

                env.Milestone(0);

                SendAssert(env, "s1,s2");
                AssertStatementIds(env, "basevar,s0,child1var,s1,s2", 1, 2, 3, 4, 5);

                var item = new EPDeploymentRolloutCompiled(
                    env.Compile("@Name('s3') select basevar, child1var from SupportBean", new RegressionPath().Add(@base).Add(child1)),
                    null);

                env.Rollout(Collections.SingletonList(item), null).AddListener("s3");
                var deploymentChild11 = env.Deployment.GetDeployment(env.DeploymentId("s2"));

                EPAssertionUtil.AssertEqualsAnyOrder(
                    new string[] { env.DeploymentId("basevar"), env.DeploymentId("child1var") },
                    deploymentChild11.DeploymentIdDependencies);

                env.Milestone(1);

                SendAssert(env, "s1,s2,s3");
                AssertStatementIds(env, "basevar,s0,child1var,s1,s2,s3", 1, 2, 3, 4, 5, 6);

                env.UndeployAll();

                env.Milestone(2);

                env.CompileDeploy("@Name('s1') select * from SupportBean");
                TryInvalidRollout(
                    env,
                    "A precondition is not satisfied: Required dependency variable 'basevar' cannot be found",
                    0,
                    typeof(EPDeployPreconditionException),
                    child0);
                AssertStatementIds(env, "s1", 7);

                env.UndeployAll();
            }
            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();
            }
Exemple #9
0
            public void Run(RegressionEnvironment env)
            {
                EPCompiled compiled;
                DeploymentOptions options;

                compiled = env.Compile("select * from SupportBean(TheString='ABC')");
                options = new DeploymentOptions().WithStatementSubstitutionParameter(
                    prepared => {
                        TryInvalidSetObject(prepared, stmt => stmt.SetObject("x", 10), "The statement has no substitution parameters");
                        TryInvalidSetObject(prepared, stmt => stmt.SetObject(1, 10), "The statement has no substitution parameters");
                    });
                DeployWithOptionsWUndeploy(env, compiled, options);

                // numbered, untyped, casted at eventService
                compiled = env.Compile("select * from SupportBean(TheString=cast(?, String))");
                options = new DeploymentOptions().WithStatementSubstitutionParameter(
                    prepared => {
                        TryInvalidSetObject(
                            prepared,
                            stmt => stmt.SetObject("x", 10),
                            "Substitution parameter names have not been provided for this statement");
                        TryInvalidSetObject(
                            prepared,
                            stmt => stmt.SetObject(0, "a"),
                            "Invalid substitution parameter index, expected an index between 1 and 1");
                        TryInvalidSetObject(
                            prepared,
                            stmt => stmt.SetObject(2, "a"),
                            "Invalid substitution parameter index, expected an index between 1 and 1");
                        prepared.SetObject(1, "xxx");
                    });
                DeployWithOptionsWUndeploy(env, compiled, options);

                // named, untyped, casted at eventService
                compiled = env.Compile("select * from SupportBean(TheString=cast(?:p0, String))");
                options = new DeploymentOptions().WithStatementSubstitutionParameter(
                    prepared => {
                        TryInvalidSetObject(
                            prepared,
                            stmt => stmt.SetObject("x", 10),
                            "Failed to find substitution parameter named 'x', available parameters are [\"p0\"]");
                        TryInvalidSetObject(
                            prepared,
                            stmt => stmt.SetObject(0, "a"),
                            "Substitution parameter names have been provided for this statement, please set the value by name");
                        prepared.SetObject("p0", "xxx");
                    });
                DeployWithOptionsWUndeploy(env, compiled, options);
            }
Exemple #10
0
            public void Run(RegressionEnvironment env)
            {
                var type                  = env.Compile("@Name('s0') @public @buseventtype create schema MyEvent(p string)");
                var selectMyEvent         = env.Compile("@Name('s0') select * from MyEvent", new RegressionPath().Add(type));
                var selectSB              = env.Compile("@Name('s0') select * from SupportBean");
                var selectSBParameterized = env.Compile("@Name('s0') select * from SupportBean(TheString = ?::string)");

                env.CompileDeploy("@Name('s1') select * from SupportBean");

                // dependency not found
                var msg = "A precondition is not satisfied: Required dependency event type 'MyEvent' cannot be found";

                TryInvalidRollout(env, msg, 1, typeof(EPDeployPreconditionException), selectSB, selectMyEvent);
                TryInvalidRollout(env, msg, 0, typeof(EPDeployPreconditionException), selectMyEvent);
                TryInvalidRollout(env, msg, 2, typeof(EPDeployPreconditionException), selectSB, selectSB, selectMyEvent);
                TryInvalidRollout(env, msg, 1, typeof(EPDeployPreconditionException), selectSB, selectMyEvent, selectSB, selectSB);

                // already defined
                TryInvalidRollout(env, "Event type by name 'MyEvent' already registered", 1, typeof(EPDeployException), type, type);

                // duplicate deployment id
                TryInvalidRollout(
                    env,
                    "Deployment id 'a' occurs multiple times in the rollout",
                    1,
                    typeof(EPDeployException),
                    new EPDeploymentRolloutCompiled(selectSB, new DeploymentOptions().WithDeploymentId("a")),
                    new EPDeploymentRolloutCompiled(selectSB, new DeploymentOptions().WithDeploymentId("a")));

                // deployment id exists
                TryInvalidRollout(
                    env,
                    "Deployment by id '" + env.DeploymentId("s1") + "' already exists",
                    1,
                    typeof(EPDeployDeploymentExistsException),
                    new EPDeploymentRolloutCompiled(selectSB, new DeploymentOptions().WithDeploymentId("a")),
                    new EPDeploymentRolloutCompiled(selectSB, new DeploymentOptions().WithDeploymentId(env.DeploymentId("s1"))));

                // substitution param problem
                TryInvalidRollout(
                    env,
                    "Substitution parameters have not been provided: Statement 's0' has 1 substitution parameters",
                    1,
                    typeof(EPDeploySubstitutionParameterException),
                    selectSB,
                    selectSBParameterized);

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var namespc = NamespaceGenerator.Create();
                var createEPL = CREATE_EPL
                    .Replace("${PREFIX}", "@public")
                    .Replace("${NAMESPACE}", namespc);

                var epl = "module a.b.c;\n" + createEPL.Replace("${PREFIX}", "@public");
                var compiled = env.Compile(epl);

                var userEPL = USER_EPL.Replace("${NAMESPACE}", namespc);
                var path = new RegressionPath();
                path.Add(compiled);
                env.Compile("module x;\n" + userEPL, path);
            }
Exemple #12
0
            public void Run(RegressionEnvironment env)
            {
                // External clocking
                SendTimer(0, env);

                // Set up a timer:within
                var compiled = env
                               .Compile("@Name('s0') select * from pattern [timer:interval(?::int minute ?::int seconds)]");

                env.Deploy(
                    compiled,
                    new DeploymentOptions().WithStatementSubstitutionParameter(
                        prepared => {
                    prepared.SetObject(1, 1);
                    prepared.SetObject(2, 2);
                }));
                env.AddListener("s0");

                SendTimer(62 * 1000 - 1, env);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                SendTimer(62 * 1000, env);
                Assert.IsTrue(env.Listener("s0").IsInvoked);

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') select * from SupportBean(IntPrimitive in (1, 10))";
                env.CompileDeployAddListenerMile(epl, "s0", 0);

                SendBeanInt(env, 10);
                Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked());
                SendBeanInt(env, 11);
                Assert.IsFalse(env.Listener("s0").GetAndClearIsInvoked());
                SendBeanInt(env, 1);
                Assert.IsTrue(env.Listener("s0").GetAndClearIsInvoked());

                env.UndeployAll();

                // try enum collection with substitution param
                ISet<SupportEnum> types = new HashSet<SupportEnum>();
                types.Add(SupportEnum.ENUM_VALUE_2);
                var collectionType = typeof(ICollection<SupportEnum>).CleanName();
                var compiled = env.Compile(
                    "@Name('s0') select * from SupportBean ev " + "where ev.EnumValue in (?::`" + collectionType + "`)");
                env.Deploy(
                    compiled,
                    new DeploymentOptions().WithStatementSubstitutionParameter(
                        prepared => prepared.SetObject(1, types)));
                env.AddListener("s0");

                var theEvent = new SupportBean();
                theEvent.EnumValue = SupportEnum.ENUM_VALUE_2;
                env.SendEventBean(theEvent);

                Assert.IsTrue(env.Listener("s0").IsInvoked);

                env.UndeployAll();
            }
Exemple #14
0
            public void Run(RegressionEnvironment env)
            {
                MyStatementNameRuntimeResolver.Contexts.Clear();
                var epl = "@Name('s0') select * from SupportBean";
                var compiled = env.Compile(epl);
                var options = new DeploymentOptions();
                options.StatementNameRuntime = new MyStatementNameRuntimeResolver().GetStatementName;

                try {
                    env.Deployment.Deploy(compiled, options);
                }
                catch (EPDeployException e) {
                    Assert.Fail(e.Message);
                }

                var ctx = MyStatementNameRuntimeResolver.Contexts[0];
                Assert.AreEqual("s0", ctx.StatementName);
                Assert.AreEqual(env.DeploymentId("hello"), ctx.DeploymentId);
                Assert.AreSame(env.Statement("hello").Annotations, ctx.Annotations);
                Assert.AreEqual(epl, ctx.Epl);
                Assert.AreEqual("hello", env.Statement("hello").Name);

                env.Milestone(0);

                Assert.AreEqual("hello", env.Statement("hello").Name);

                env.UndeployAll();
            }
        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();
        }
Exemple #16
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('s0') select * from SupportBean_S0(Id=?:subs_1:int);\n" +
                          "@Name('s1') select * from SupportBean_S1(P10=?:subs_2:string);\n";
                var compiled = env.Compile(epl);

                var options = new DeploymentOptions().WithStatementSubstitutionParameter(
                    _ => {
                        if (_.StatementName.Equals("s1")) {
                            _.SetObject("subs_2", "abc");
                        }
                        else {
                            _.SetObject("subs_1", 100);
                        }
                    });

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

                env.AddListener("s0").AddListener("s1");

                env.SendEventBean(new SupportBean_S1(-1, "abc"));
                Assert.IsTrue(env.Listener("s1").IsInvoked);

                env.SendEventBean(new SupportBean_S0(100));
                Assert.IsTrue(env.Listener("s0").IsInvoked);

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var text = "module test.test1;\n" +
                           "create schema MyTypeOne(col1 string, col2 int);" +
                           "create window MyWindowOne#keepall as select * from MyTypeOne;" +
                           "insert into MyWindowOne select * from MyTypeOne;";
                env.CompileDeploy(text).UndeployAll();
                env.CompileDeploy(text).UndeployAll();
                text = "module test.test1;\n" +
                       "create schema MyTypeOne(col1 string, col2 int, col3 long);" +
                       "create window MyWindowOne#keepall as select * from MyTypeOne;" +
                       "insert into MyWindowOne select * from MyTypeOne;";
                env.CompileDeploy(text).UndeployAll();
                Assert.AreEqual(0, SupportFilterServiceHelper.GetFilterSvcCountApprox(env));

                // test on-merge
                var moduleString =
                    "@Name('S0') create window MyWindow#unique(IntPrimitive) as SupportBean;\n" +
                    "@Name('S1') on MyWindow insert into SecondStream select *;\n" +
                    "@Name('S2') on SecondStream merge MyWindow when matched then insert into ThirdStream select * then delete\n";
                var compiled = env.Compile(moduleString);
                env.Deploy(compiled).UndeployAll().Deploy(compiled).UndeployAll();

                // test table
                var moduleTableOne = "create table MyTable(c0 string, c1 string)";
                env.CompileDeploy(moduleTableOne).UndeployAll();
                var moduleTableTwo = "create table MyTable(c0 string, c1 string, c2 string)";
                env.CompileDeploy(moduleTableTwo).UndeployAll();
            }
        public void Run(RegressionEnvironment env)
        {
            var statementTwo = "select * from pattern[( every event1=SupportTradeEvent(UserId in ('100','101')) ->\n" +
                               "         (SupportTradeEvent(UserId in ('100','101'), Direction = event1.Direction ) ->\n" +
                               "          SupportTradeEvent(UserId in ('100','101'), Direction = event1.Direction )\n" +
                               "         ) where timer:within(8 hours)\n" +
                               "         and not eventNC=SupportTradeEvent(UserId in ('100','101'), Direction!= event1.Direction )\n" +
                               "        ) -> eventFinal=SupportTradeEvent(UserId in ('100','101'), Direction != event1.Direction ) where timer:within(1 hour)]";
            var compiledTwo = env.Compile(statementTwo);

            var runnable = new TwoPatternRunnable(env);
            var t = new Thread(runnable.Run);
            t.Name = typeof(MultithreadStmtTwoPatterns).Name;
            t.Start();
            SupportCompileDeployUtil.ThreadSleep(100);

            // Create a second pattern, wait 500 msec, destroy second pattern in a loop
            var numRepeats = env.IsHA ? 1 : 10;
            for (var i = 0; i < numRepeats; i++) {
                try {
                    var deployed = env.Deployment.Deploy(compiledTwo);
                    SupportCompileDeployUtil.ThreadSleep(200);
                    env.Undeploy(deployed.DeploymentId);
                }
                catch (Exception ex) {
                    throw new EPException(ex);
                }
            }

            runnable.Shutdown = true;
            SupportCompileDeployUtil.ThreadSleep(1000);
            Assert.IsFalse(t.IsAlive);

            env.UndeployAll();
        }
Exemple #19
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();
        }
Exemple #20
0
        private static EPStatement[] CreateStmts(
            RegressionEnvironment env,
            string[] deploymentIds,
            string[] statementNames)
        {
            Assert.AreEqual(deploymentIds.Length, statementNames.Length);
            var statements = new EPStatement[statementNames.Length];
            var compiled = env.Compile("select * from SupportBean");

            for (var i = 0; i < statementNames.Length; i++) {
                var num = i;
                try {
                    var deployed = env.Deployment.Deploy(
                        compiled,
                        new DeploymentOptions()
                            .WithDeploymentId(deploymentIds[i])
                            .WithStatementNameRuntime(_ => statementNames[num]));
                    statements[i] = deployed.Statements[0];
                }
                catch (EPDeployException e) {
                    throw new EPException(e);
                }
            }

            return statements;
        }
Exemple #21
0
            public void Run(RegressionEnvironment env)
            {
                SupportUpdateListener listener = new SupportUpdateListener();
                for (int i = 0; i < 100; i++) {
                    string epl = "@Name('s" + i + "') select * from SupportBean(TheString = '" + i + "' or IntPrimitive=" + i + ")";
                    EPCompiled compiled = env.Compile(epl);
                    env.Deploy(compiled).Statement("s" + i).AddListener(listener);
                }

                var delta = PerformanceObserver.TimeMillis(
                    () => {
                        // System.out.println("Starting " + DateTime.print(new Date()));
                        for (int i = 0; i < 10000; i++) {
                            env.SendEventBean(new SupportBean("100", 1));
                            Assert.IsTrue(listener.IsInvoked);
                            listener.Reset();
                        }
                    });
#if DEBUG
                Assert.That(delta, Is.LessThan(1500));
#else
				Assert.That(delta, Is.LessThan(500));
#endif

                env.UndeployAll();
            }
Exemple #22
0
            public void Run(RegressionEnvironment env)
            {
                var stmtText = "@Name('s0') select P00 like P01 as r1, " +
                               "P00 like P01 escape \"!\" as r2, " +
                               "P02 regexp P03 as r3 " +
                               "from SupportBean_S0";

                var model = new EPStatementObjectModel();

                model.Annotations  = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                model.SelectClause = SelectClause.Create()
                                     .Add(Expressions.Like(Expressions.Property("P00"), Expressions.Property("P01")), "r1")
                                     .Add(Expressions.Like(Expressions.Property("P00"), Expressions.Property("P01"), Expressions.Constant("!")), "r2")
                                     .Add(Expressions.Regexp(Expressions.Property("P02"), Expressions.Property("P03")), "r3");

                model.FromClause = FromClause.Create(FilterStream.Create("SupportBean_S0"));
                model            = SerializableObjectCopier.GetInstance(env.Container).Copy(model);
                Assert.AreEqual(stmtText, model.ToEPL());

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

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

                RunLikeRegexStringAndNull(env);

                env.UndeployAll();
            }
Exemple #23
0
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "@Name('s0') select ?:pint:int as c0 from SupportBean(TheString=?:pstring:string and IntPrimitive=?:pint:int and LongPrimitive=?:plong:long)";
                var compiled = env.Compile(soda, epl, new CompilerArguments(new Configuration()));
                DeployWithResolver(
                    env,
                    compiled,
                    null,
                    prepared => {
                        prepared.SetObject("pstring", "E1");
                        prepared.SetObject("pint", 10);
                        prepared.SetObject("plong", 100L);
                    });
                env.AddListener("s0");

                var @event = new SupportBean("E1", 10);
                @event.LongPrimitive = 100;
                env.SendEventBean(@event);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "c0".SplitCsv(), 10);

                env.Milestone(0);

                env.SendEventBean(@event);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "c0".SplitCsv(), 10);

                env.UndeployAll();
            }
            public void Run(RegressionEnvironment env)
            {
                var compiled = env.Compile(
                    "expression myindex {pointregionquadtree(0, 0, 100, 100)}" +
                    "select * from SupportSpatialAABB(point(?::int, ?::int, filterindex:myindex).inside(rectangle(X, Y, Width, Height)))");
                var listener = new SupportUpdateListener();

                var count = 0;

                for (var x = 0; x < 10; x++)
                {
                    for (var y = 0; y < 10; y++)
                    {
                        var finalX  = x;
                        var finalY  = y;
                        var name    = x + "_" + y;
                        var options = new DeploymentOptions().WithStatementSubstitutionParameter(
                            prepared => {
                            prepared.SetObject(1, finalX);
                            prepared.SetObject(2, finalY);
                        })
                                      .WithStatementNameRuntime(ctx => name);
                        env.Deploy(compiled, options).Statement(name).AddListener(listener);
                        // System.out.println("Deployed #" + count);
                        count++;
                    }
                }

                SendAssertSpatialAABB(env, listener, 10, 10, 1000);

                env.UndeployAll();
            }
            // Compares the performance of
            //     select * from SupportBean(TheString = 'xyz')
            //  against
            //     select * from SupportBean where theString = 'xyz'

            public void Run(RegressionEnvironment env)
            {
                var module = new StringWriter();

                for (var i = 0; i < 100; i++) {
                    var epl = string.Format(
                        "@Name('s{0}') select * from SupportBean where TheString = '{1}';\n",
                        i,
                        Convert.ToString(i));
                    module.Write(epl);
                }

                var compiled = env.Compile(module.ToString());
                env.Deploy(compiled);

                var start = PerformanceObserver.MilliTime;
                for (var i = 0; i < 10000; i++) {
                    var bean = new SupportBean("NOMATCH", 0);
                    env.SendEventBean(bean);
                }

                var end = PerformanceObserver.MilliTime;
                var delta = end - start;
                Assert.That(delta, Is.LessThan(500), "Delta=" + delta);

                env.UndeployAll();
            }
Exemple #26
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var epl  = "@public create window WinSB#keepall as SupportBean;\n" +
                           "create context MyContext partition by Id from SupportBean_S0;\n" +
                           "context MyContext create window PartitionedWinS0#keepall as SupportBean_S0;\n";

                env.Compile(epl, path);

                TryInvalidFAFCompile(
                    env,
                    path,
                    "select (select * from SupportBean#lastevent) from WinSB",
                    "Fire-and-forget queries only allow subqueries against named windows and tables");

                TryInvalidFAFCompile(
                    env,
                    path,
                    "select (select * from WinSB(TheString='x')) from WinSB",
                    "Failed to plan subquery number 1 querying WinSB: Subqueries in fire-and-forget queries do not allow filter expressions");

                TryInvalidFAFCompile(
                    env,
                    path,
                    "select (select * from PartitionedWinS0) from WinSB",
                    "Failed to plan subquery number 1 querying PartitionedWinS0: Mismatch in context specification, the context for the named window 'PartitionedWinS0' is 'MyContext' and the query specifies no context");
            }
Exemple #27
0
            public void Run(RegressionEnvironment env)
            {
                SendTimer(env, 0);

                var epl = "@Name('s0') select " +
                          "current_evaluation_context() as c0, " +
                          "current_evaluation_context(), " +
                          "current_evaluation_context().GetRuntimeURI() as c2 from SupportBean";
                var resolver  = new StatementUserObjectOption(_ => "my_user_object");
                var arguments = new CompilerArguments(new Configuration());

                arguments.Options.StatementUserObject = resolver;
                var compiled = env.Compile(soda, epl, arguments);

                env.Deploy(compiled).AddListener("s0").Milestone(0);
                Assert.AreEqual(typeof(EPLExpressionEvaluationContext), env.Statement("s0").EventType.GetPropertyType("current_evaluation_context()"));

                env.SendEventBean(new SupportBean());
                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                var ctx    = (EPLExpressionEvaluationContext)@event.Get("c0");

                Assert.AreEqual(env.RuntimeURI, ctx.RuntimeURI);
                Assert.AreEqual(env.Statement("s0").Name, ctx.StatementName);
                Assert.AreEqual(-1, ctx.ContextPartitionId);
                Assert.AreEqual("my_user_object", ctx.StatementUserObject);
                Assert.AreEqual(env.RuntimeURI, @event.Get("c2"));

                env.UndeployAll();
            }
Exemple #28
0
            public void Run(RegressionEnvironment env)
            {
                var expression = "@Name('s0') select * from pattern [every timer:at(?::int,?::int,*,*,[1,2,3,4,5])]";

                var dateTimeEx = DateTimeEx.GetInstance(TimeZoneInfo.Utc);

                dateTimeEx.SetMillis(0);
                dateTimeEx.Set(2008, 8, 3, 10); // start on a Sunday at 6am, August 3 2008
                SendTimer(dateTimeEx.UtcMillis, env);

                var compiled = env.Compile(expression);

                env.Deploy(
                    compiled,
                    new DeploymentOptions().WithStatementSubstitutionParameter(
                        prepared => {
                    prepared.SetObject(1, 0);
                    prepared.SetObject(2, 8);
                }));
                env.AddListener("s0");

                TryAssertion(env);

                env.UndeployAll();
            }
Exemple #29
0
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numRepeats)
        {
            var compiled = env.Compile("@Name('upd') update istream SupportBean set TheString='a'");

            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadUpdate)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                var callable = new StmtUpdateSendCallable(i, env.Runtime, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            for (var i = 0; i < 50; i++) {
                env.Deploy(compiled);
                SupportCompileDeployUtil.ThreadSleep(10);
                env.UndeployModuleContaining("upd");
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 5, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(future);
        }
            public void Run(RegressionEnvironment env)
            {
                // External clocking
                SendTimer(0, env);

                // Set up a timer:within
                var compiled = env.Compile(
                    "@Name('s0') select * from pattern [(every SupportBean) where timer:within(?::int days ?::int hours ?::int minutes ?::int seconds ?::int milliseconds)]");

                env.Deploy(
                    compiled,
                    new DeploymentOptions().WithStatementSubstitutionParameter(
                        prepared => {
                    prepared.SetObject(1, 1);
                    prepared.SetObject(2, 2);
                    prepared.SetObject(3, 3);
                    prepared.SetObject(4, 4);
                    prepared.SetObject(5, 5);
                }));
                env.AddListener("s0");

                TryAssertion(env);

                env.UndeployAll();
            }