예제 #1
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var eplCreate = namedWindow
                    ? "create window MyInfraIS#keepall as SupportBean"
                    : "create table MyInfraIS(TheString string)";
                env.CompileDeploy(eplCreate, path);

                try {
                    env.CompileWCheckedEx("select (select TheString from MyInfraIS#lastevent) from MyInfraIS", path);
                    Assert.Fail();
                }
                catch (EPCompileException ex) {
                    if (namedWindow) {
                        StringAssert.StartsWith(
                            "Error during compilation: " +
                            "Failed to plan subquery number 1 querying MyInfraIS: " +
                            "Consuming statements to a named window cannot declare a data window view onto the named window " +
                            "[select (select TheString from MyInfraIS#lastevent) from MyInfraIS]",
                            ex.Message);
                    }
                    else {
                        SupportMessageAssertUtil.AssertMessage(ex, "Views are not supported with tables");
                    }
                }

                env.UndeployAll();
            }
예제 #2
0
        private static void TryInvalidAggMatch(
            RegressionEnvironment env,
            string name,
            string declared,
            bool unbound,
            string provided,
            string messageOrNull)
        {
            var path = new RegressionPath();
            env.CompileDeploy("@Name('create') create table " + name + "(value " + declared + ")", path);

            try {
                var epl = "into table " +
                          name +
                          " select " +
                          provided +
                          " as value from SupportBean" +
                          (unbound ? "#time(1000)" : "");
                env.CompileWCheckedEx(epl, path);
                Assert.Fail();
            }
            catch (EPCompileException ex) {
                if (messageOrNull != null && messageOrNull.Length > 10) {
                    StringAssert.StartsWith(messageOrNull, ex.Message);
                }
                else {
                    StringAssert.Contains("Incompatible aggregation function for table", ex.Message);
                }
            }

            env.UndeployModuleContaining("create");
        }
예제 #3
0
 private void TryInvalid(
     RegressionEnvironment env,
     string epl)
 {
     try {
         env.CompileWCheckedEx(epl);
         Assert.Fail();
     }
     catch (EPCompileException) {
         // Expected exception
     }
 }
예제 #4
0
 private static void TryInvalid(
     RegressionEnvironment env,
     string eplInvalidPattern)
 {
     try {
         env.CompileWCheckedEx("select * from pattern[" + eplInvalidPattern + "]");
         Assert.Fail();
     }
     catch (EPCompileException) {
         // Expected exception
     }
 }
예제 #5
0
 public static void TryInvalidCompile(
     RegressionEnvironment env,
     string epl,
     string message)
 {
     try {
         env.CompileWCheckedEx(epl);
         Assert.Fail();
     }
     catch (EPCompileException ex) {
         AssertMessage(ex, message);
     }
 }
예제 #6
0
 private static void TryInvalidContains(
     RegressionEnvironment env,
     string expression,
     string part)
 {
     try {
         env.CompileWCheckedEx(expression);
         Assert.Fail();
     }
     catch (EPCompileException ex) {
         Assert.That(ex.Message, Contains.Substring(part));
         //Assert.IsTrue(ex.Message.Contains(part), "Message not containing text '" + part + "' : " + ex.Message);
     }
 }
예제 #7
0
        private static string GetSyntaxExceptionPattern(
            RegressionEnvironment env,
            string expression)
        {
            string exceptionText = null;
            try {
                env.CompileWCheckedEx("select * from pattern[" + expression + "]");
                Assert.Fail();
            }
            catch (EPCompileException ex) {
                exceptionText = ex.Message;
                log.Debug(".getSyntaxExceptionPattern pattern=" + expression, ex);
                // Expected exception
            }

            return exceptionText;
        }
예제 #8
0
        private EPCompileExceptionSyntaxItem GetSyntaxExceptionView(
            RegressionEnvironment env,
            string expression)
        {
            try {
                env.CompileWCheckedEx(expression);
                Assert.Fail();
            }
            catch (EPCompileException ex) {
                if (Log.IsDebugEnabled) {
                    Log.Debug(".getSyntaxExceptionView expression=" + expression, ex);
                }

                // Expected exception
                return (EPCompileExceptionSyntaxItem) ex.Items[0];
            }

            throw new IllegalStateException();
        }
예제 #9
0
        private static EPCompileException GetStatementExceptionPattern(
            RegressionEnvironment env,
            string expression,
            bool isLogException)
        {
            try {
                env.CompileWCheckedEx("select * from pattern[" + expression + "]");
                Assert.Fail();
            }
            catch (EPCompileException ex) {
                // Expected exception
                if (isLogException) {
                    log.Debug(expression, ex);
                }

                return ex;
            }

            throw new IllegalStateException();
        }
예제 #10
0
        private EPCompileExceptionItem GetStatementExceptionView(
            RegressionEnvironment env,
            string expression,
            bool isLogException)
        {
            try {
                env.CompileWCheckedEx(expression);
                Assert.Fail();
            }
            catch (EPCompileException ex) {
                var first = ex.Items[0];
                if (isLogException) {
                    Log.Debug(".getStatementExceptionView expression=" + first, first);
                }

                if (first is EPCompileExceptionSyntaxItem) {
                    Assert.Fail();
                }

                return first;
            }

            throw new IllegalStateException();
        }
예제 #11
0
        private static void AssertIndexChoice(
            RegressionEnvironment env,
            bool namedWindow,
            bool indexShare,
            string[] indexes,
            object[] preloadedEvents,
            string datawindow,
            IndexAssertion[] assertions)
        {
            var path = new RegressionPath();
            var epl = namedWindow
                ? "create window MyInfra." + datawindow + " as select * from SupportSimpleBeanOne"
                : "create table MyInfra(S1 string primary key, I1 int, D1 double, L1 long)";
            if (indexShare) {
                epl = "@Hint('enable_window_subquery_indexshare') " + epl;
            }

            env.CompileDeploy(epl, path);
            env.CompileDeploy("insert into MyInfra select * from SupportSimpleBeanOne", path);
            foreach (var index in indexes) {
                env.CompileDeploy(index, path);
            }

            foreach (var @event in preloadedEvents) {
                env.SendEventBean(@event);
            }

            var count = 0;
            foreach (var assertion in assertions) {
                log.Info("======= Testing #" + count++);
                var consumeEpl = INDEX_CALLBACK_HOOK +
                                 "@Name('s0') " +
                                 (assertion.Hint ?? "") +
                                 "select *, " +
                                 "(select * from MyInfra where " +
                                 assertion.WhereClause +
                                 ") @eventbean as ssb1 from SupportSimpleBeanTwo as ssb2";

                EPCompiled compiled;
                try {
                    compiled = env.CompileWCheckedEx(consumeEpl, path);
                }
                catch (EPCompileException ex) {
                    if (assertion.EventSendAssertion == null) {
                        // no assertion, expected
                        Assert.IsTrue(ex.Message.Contains("index hint busted"));
                        continue;
                    }

                    throw new EPException("Unexpected statement exception: " + ex.Message, ex);
                }

                env.Deploy(compiled);

                // assert index and access
                SupportQueryPlanIndexHook.AssertSubqueryBackingAndReset(
                    0,
                    assertion.ExpectedIndexName,
                    assertion.IndexBackingClass);
                env.AddListener("s0");
                assertion.EventSendAssertion.Invoke();
                env.UndeployModuleContaining("s0");
            }

            env.UndeployAll();
        }
예제 #12
0
        private static void AssertIndexChoice(
            RegressionEnvironment env,
            string eplDeclare,
            string eplPopulate,
            string eplQuery,
            string[] indexes,
            object[] preloadedEvents,
            IndexAssertion[] assertions,
            AtomicLong milestone,
            bool multistream)
        {
            var path = new RegressionPath();
            env.CompileDeploy(eplDeclare, path);
            env.CompileDeploy(eplPopulate, path);

            foreach (var index in indexes) {
                env.CompileDeploy(index, path);
            }

            foreach (var @event in preloadedEvents) {
                env.SendEventBean(@event);
            }

            env.MilestoneInc(milestone);

            var count = -1;
            foreach (var assertion in assertions) {
                count++;
                log.Info("======= Testing #" + count++);
                var epl = INDEX_CALLBACK_HOOK + (assertion.Hint == null ? "" : assertion.Hint) + eplQuery;
                epl += ", varagg as va";
                if (multistream) {
                    epl += ", SupportBeanSimple#lastevent";
                }

                epl += " where " + assertion.WhereClause;

                try {
                    var compiled = env.CompileWCheckedEx("@Name('s0')" + epl, path);
                    env.Deploy(compiled).AddListener("s0");
                }
                catch (EPCompileException ex) {
                    if (assertion.EventSendAssertion == null) {
                        // no assertion, expected
                        Assert.IsTrue(ex.Message.Contains("index hint busted"));
                        continue;
                    }

                    throw new EPException("Unexpected statement exception: " + ex.Message, ex);
                }

                // send multistream seed event
                env.SendEventBean(new SupportBeanSimple("", -1));

                // assert index and access
                assertion.EventSendAssertion.Invoke();
                var plan = SupportQueryPlanIndexHook.AssertJoinAndReset();

                TableLookupPlanForge tableLookupPlan;
                if (plan.ExecNodeSpecs[0] is TableLookupNodeForge) {
                    tableLookupPlan = ((TableLookupNodeForge) plan.ExecNodeSpecs[0]).TableLookupPlan;
                }
                else {
                    var lqp = (LookupInstructionQueryPlanNodeForge) plan.ExecNodeSpecs[0];
                    tableLookupPlan = lqp.LookupInstructions[0].LookupPlans[0];
                }

                Assert.AreEqual(assertion.ExpectedIndexName, tableLookupPlan.IndexNum[0].IndexName);
                Assert.AreEqual(assertion.ExpectedStrategy, tableLookupPlan.GetType());
                env.UndeployModuleContaining("s0");
            }

            env.UndeployAll();
        }
예제 #13
0
            public void Run(RegressionEnvironment env)
            {
                // with transpose and same input and output
                var stmtTextOne =
                    "@Name('s0') insert into SupportBean select transpose(customOne('O' || TheString, 10)) from SupportBean(TheString like 'I%')";
                env.CompileDeploy(stmtTextOne).AddListener("s0");
                Assert.AreEqual(typeof(SupportBean), env.Statement("s0").EventType.UnderlyingType);

                env.SendEventBean(new SupportBean("I1", 1));
                var resultOne = env.Listener("s0").AssertOneGetNewAndReset();
                EPAssertionUtil.AssertProps(
                    resultOne,
                    new[] {"TheString", "IntPrimitive"},
                    new object[] {"OI1", 10});
                Assert.AreEqual("OI1", ((SupportBean) resultOne.Underlying).TheString);
                env.UndeployModuleContaining("s0");

                // with transpose but different input and output (also test ignore column name)
                var stmtTextTwo =
                    "@Name('s0') insert into SupportBeanNumeric select transpose(customTwo(IntPrimitive, IntPrimitive+1)) as col1 from SupportBean(TheString like 'I%')";
                env.CompileDeploy(stmtTextTwo).AddListener("s0");
                Assert.AreEqual(typeof(SupportBeanNumeric), env.Statement("s0").EventType.UnderlyingType);

                env.SendEventBean(new SupportBean("I2", 10));
                var resultTwo = env.Listener("s0").AssertOneGetNewAndReset();
                EPAssertionUtil.AssertProps(
                    resultTwo,
                    new[] {"IntOne", "IntTwo"},
                    new object[] {10, 11});
                Assert.AreEqual(11, (int) ((SupportBeanNumeric) resultTwo.Underlying).IntTwo);
                env.UndeployModuleContaining("s0");

                // invalid wrong-bean target
                TryInvalidCompile(
                    env,
                    "insert into SupportBeanNumeric select transpose(customOne('O', 10)) from SupportBean",
                    "Expression-returned value of type '" +
                    typeof(SupportBean).CleanName() +
                    "' cannot be converted to target event type 'SupportBeanNumeric' with underlying type '" +
                    typeof(SupportBeanNumeric).CleanName() +
                    "' [insert into SupportBeanNumeric select transpose(customOne('O', 10)) from SupportBean]");

                // invalid additional properties
                TryInvalidCompile(
                    env,
                    "insert into SupportBean select 1 as dummy, transpose(customOne('O', 10)) from SupportBean",
                    "Cannot transpose additional properties in the select-clause to target event type 'SupportBean' with underlying type '" +
                    typeof(SupportBean).CleanName() +
                    "', the transpose function must occur alone in the select clause [insert into SupportBean select 1 as dummy, transpose(customOne('O', 10)) from SupportBean]");

                // invalid occurs twice
                TryInvalidCompile(
                    env,
                    "insert into SupportBean select transpose(customOne('O', 10)), transpose(customOne('O', 11)) from SupportBean",
                    "A column name must be supplied for all but one stream if multiple streams are selected via the stream.* notation");

                // invalid wrong-type target
                try {
                    var path = new RegressionPath();
                    env.CompileDeploy("create map schema SomeOtherStream()", path);
                    env.CompileWCheckedEx(
                        "insert into SomeOtherStream select transpose(customOne('O', 10)) from SupportBean",
                        path);
                    Assert.Fail();
                }
                catch (EPCompileException ex) {
                    Assert.That(
                        ex.Message,
                        Does.StartWith(
                            "Error during compilation: " +
                            "Expression-returned value of type '" +
                            typeof(SupportBean).CleanName() +
                            "' cannot be converted to target event type 'SomeOtherStream' with underlying type '" +
                            typeof(IDictionary<string, object>).CleanName() +
                            "' [insert into SomeOtherStream select transpose(customOne('O', 10)) from SupportBean]"));
                }

                env.UndeployAll();

                // invalid two parameters
                TryInvalidCompile(
                    env,
                    "select transpose(customOne('O', 10), customOne('O', 10)) from SupportBean",
                    "Failed to validate select-clause expression 'transpose(customOne(\"O\",10),customO...(46 chars)': The transpose function requires a single parameter expression [select transpose(customOne('O', 10), customOne('O', 10)) from SupportBean]");

                // test not a top-level function or used in where-clause (possible but not useful)
                env.CompileDeploy("select * from SupportBean where transpose(customOne('O', 10)) is not null");
                env.CompileDeploy("select transpose(customOne('O', 10)) is not null from SupportBean");

                // invalid insert of object-array into undefined stream
                TryInvalidCompile(
                    env,
                    "insert into SomeOther select transpose(generateOA('a', 1)) from SupportBean",
                    "Invalid expression return type 'System.Object[]' for transpose function [insert into SomeOther select transpose(generateOA('a', 1)) from SupportBean]");

                env.UndeployAll();
            }
예제 #14
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy(
                    "@Name('create') create table MyTableEUIV as (pKey0 string primary key, pkey1 int primary key, thecnt count(*))",
                    path);
                env.CompileDeploy(
                    "into table MyTableEUIV select count(*) as thecnt from SupportBean group by TheString, IntPrimitive",
                    path);
                env.SendEventBean(new SupportBean("E1", 10));
                env.SendEventBean(new SupportBean("E1", 20));

                // invalid index being created
                try {
                    var compiled = env.Compile("create unique index SecIndex on MyTableEUIV(pKey0)", path);
                    env.Runtime.DeploymentService.Deploy(compiled);
                    Assert.Fail();
                }
                catch (EPDeployException ex) {
                    SupportMessageAssertUtil.AssertMessage(
                        ex.Message,
                        "Failed to deploy: Unique index violation, index 'SecIndex' is a unique index and key 'E1' already exists");
                }

                // try fire-and-forget update of primary key to non-unique value
                try {
                    env.CompileExecuteFAF("update MyTableEUIV set pkey1 = 0", path);
                    Assert.Fail();
                }
                catch (EPException ex) {
                    SupportMessageAssertUtil.AssertMessage(
                        ex,
                        "Unique index violation, index 'MyTableEUIV' is a unique index and key 'MultiKey<E1,0>' already exists");
                    // assert events are unchanged - no update actually performed
                    EPAssertionUtil.AssertPropsPerRowAnyOrder(
                        env.GetEnumerator("create"),
                        new[] {"pKey0", "pkey1"},
                        new[] {new object[] {"E1", 10}, new object[] {"E1", 20}});
                }

                // try on-update unique index violation
                env.CompileDeploy("@Name('on-update') on SupportBean_S1 update MyTableEUIV set pkey1 = 0", path);
                try {
                    env.SendEventBean(new SupportBean_S1(0));
                    Assert.Fail();
                }
                catch (EPException ex) {
                    SupportMessageAssertUtil.AssertMessage(
                        ex,
                        "Unexpected exception in statement 'on-update': Unique index violation, index 'MyTableEUIV' is a unique index and key 'MultiKey<E1,0>' already exists");
                    // assert events are unchanged - no update actually performed
                    EPAssertionUtil.AssertPropsPerRowAnyOrder(
                        env.Statement("create").GetEnumerator(),
                        new[] {"pKey0", "pkey1"},
                        new[] {new object[] {"E1", 10}, new object[] {"E1", 20}});
                }

                // disallow on-merge unique key updates
                try {
                    env.CompileWCheckedEx(
                        "@Name('on-merge') on SupportBean_S1 merge MyTableEUIV when matched then update set pkey1 = 0",
                        path);
                    Assert.Fail();
                }
                catch (EPCompileException ex) {
                    SupportMessageAssertUtil.AssertMessage(
                        ex.InnerException,
                        "Validation failed in when-matched (clause 1): On-merge statements may not update unique keys of tables");
                }

                env.UndeployAll();
            }