Ejemplo n.º 1
0
        public void TestReservedKeywordEscape()
        {
            var configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.EventMetaConfig.ClassPropertyResolutionStyle =
                PropertyResolutionStyle.DEFAULT;
            configuration.EngineDefaults.EventMetaConfig.DefaultAccessorStyle =
                AccessorStyleEnum.NATIVE;

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            _epService.EPAdministrator.Configuration.AddEventType <SupportBeanReservedKeyword>("SomeKeywords");
            _epService.EPAdministrator.Configuration.AddEventType <SupportBeanReservedKeyword>("Order");

            var listener = new SupportUpdateListener();
            var stmt     = _epService.EPAdministrator.CreateEPL("select `seconds`, `order` from SomeKeywords");

            stmt.Events += listener.Update;

            var theEvent = new SupportBeanReservedKeyword(1, 2);

            _epService.EPRuntime.SendEvent(theEvent);
            var eventBean = listener.AssertOneGetNewAndReset();

            Assert.AreEqual(1, eventBean.Get("seconds"));
            Assert.AreEqual(2, eventBean.Get("order"));

            stmt.Dispose();
            stmt         = _epService.EPAdministrator.CreateEPL("select * from `Order`");
            stmt.Events += listener.Update;

            _epService.EPRuntime.SendEvent(theEvent);
            eventBean = listener.AssertOneGetNewAndReset();
            Assert.AreEqual(1, eventBean.Get("seconds"));
            Assert.AreEqual(2, eventBean.Get("order"));

            stmt.Dispose();
            stmt = _epService.EPAdministrator.CreateEPL(
                "select timestamp.`hour` as val from SomeKeywords");
            stmt.Events += listener.Update;

            var bean = new SupportBeanReservedKeyword(1, 2);

            bean.Timestamp      = new SupportBeanReservedKeyword.Inner();
            bean.Timestamp.Hour = 10;
            _epService.EPRuntime.SendEvent(bean);
            eventBean = listener.AssertOneGetNewAndReset();
            Assert.AreEqual(10, eventBean.Get("val"));

            // test back-tick with spaces etc
            var defType = new Dictionary <string, object>();

            defType["candidate book"]   = typeof(string);
            defType["XML Message Type"] = typeof(string);
            defType["select"]           = typeof(int);
            defType["children's books"] = typeof(int[]);
            defType["my <> map"]        = typeof(Map);

            _epService.EPAdministrator.Configuration.AddEventType("MyType", defType);
            _epService.EPAdministrator.CreateEPL("select `candidate book` as c0, `XML Message Type` as c1, `select` as c2, `children's books`[0] as c3, `my <> map`('xx') as c4 from MyType")
            .Events += listener.Update;

            var defValues = new Dictionary <string, object>();

            defValues["candidate book"]   = "Enders Game";
            defValues["XML Message Type"] = "book";
            defValues["select"]           = 100;
            defValues["children's books"] = new int[] { 50, 51 };
            defValues["my <> map"]        = Collections.SingletonMap("xx", "abc");

            _epService.EPRuntime.SendEvent(defValues, "MyType");

            EPAssertionUtil.AssertProps(
                listener.AssertOneGetNewAndReset(),
                "c0,c1,c2,c3,c4".Split(','), new Object[]
            {
                "Enders Game", "book", 100, 50, "abc"
            });

            try {
                _epService.EPAdministrator.CreateEPL("select `select` from " + typeof(SupportBean).FullName);
                Assert.Fail();
            } catch (EPException ex) {
                Assert.AreEqual(
                    "Error starting statement: Failed to validate select-clause expression 'select': Property named 'select' is not valid in any stream [select `select` from com.espertech.esper.support.bean.SupportBean]",
                    ex.Message);
            }

            try {
                _epService.EPAdministrator.CreateEPL("select `ab cd` from " + typeof(SupportBean).FullName);
                Assert.Fail();
            } catch (EPException ex) {
                SupportMessageAssertUtil.AssertMessage(ex, "Error starting statement: Failed to validate select-clause expression 'ab cd': Failed to find property 'ab cd', the property name does not parse (are you sure?): Incorrect syntax near 'cd' at line 1 column 3 [ab cd] [select `ab cd` from com.espertech.esper.support.bean.SupportBean]");
            }

            // test resolution as nested property
            _epService.EPAdministrator.CreateEPL("create schema MyEvent as (customer string, `from` string)");
            _epService.EPAdministrator.CreateEPL("insert into DerivedStream select customer,`from` from MyEvent");
            _epService.EPAdministrator.CreateEPL("create window TheWindow.std:firstunique(customer,`from`) as DerivedStream");
            _epService.EPAdministrator.CreateEPL("on pattern [a=TheWindow -> timer:interval(12 hours)] as s0 delete from TheWindow as s1 where s0.a.`from`=s1.`from`");

            // test escape in column name
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL("select TheString as `order`, TheString as `price.for.goods` from SupportBean");

            stmtTwo.Events += listener.Update;
            Assert.AreEqual(typeof(string), stmtTwo.EventType.GetPropertyType("order"));
            Assert.AreEqual("price.for.goods", stmtTwo.EventType.PropertyDescriptors[1].PropertyName);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            var @out = (Map)listener.AssertOneGetNew().Underlying;

            Assert.AreEqual("E1", @out.Get("order"));
            Assert.AreEqual("E1", @out.Get("price.for.goods"));

            // try control character
            TryInvalidControlCharacter(listener.AssertOneGetNew());

            // try enum with keyword
            TryEnumWithKeyword();

            TryEnumItselfReserved();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Ejemplo n.º 2
0
        public void TestReservedKeywordEscape()
        {
            epService = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());
            epService.Initialize();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }
            epService.EPAdministrator.Configuration.AddEventType("SomeKeywords", typeof(SupportBeanReservedKeyword));
            epService.EPAdministrator.Configuration.AddEventType("Order", typeof(SupportBeanReservedKeyword));
            SupportUpdateListener listener = new SupportUpdateListener();

            EPStatement stmt = epService.EPAdministrator.CreateEPL("select `seconds`, `order` from SomeKeywords");

            stmt.AddListener(listener);

            object theEvent = new SupportBeanReservedKeyword(1, 2);

            epService.EPRuntime.SendEvent(theEvent);
            EventBean eventBean = listener.AssertOneGetNewAndReset();

            Assert.AreEqual(1, eventBean.Get("seconds"));
            Assert.AreEqual(2, eventBean.Get("order"));

            stmt.Dispose();
            stmt = epService.EPAdministrator.CreateEPL("select * from `Order`");
            stmt.AddListener(listener);

            epService.EPRuntime.SendEvent(theEvent);
            eventBean = listener.AssertOneGetNewAndReset();
            Assert.AreEqual(1, eventBean.Get("seconds"));
            Assert.AreEqual(2, eventBean.Get("order"));

            stmt.Dispose();
            stmt = epService.EPAdministrator.CreateEPL("select timestamp.`hour` as val from SomeKeywords");
            stmt.AddListener(listener);

            SupportBeanReservedKeyword bean = new SupportBeanReservedKeyword(1, 2);

            bean.Timestamp      = new SupportBeanReservedKeyword.Inner();
            bean.Timestamp.Hour = 10;
            epService.EPRuntime.SendEvent(bean);
            eventBean = listener.AssertOneGetNewAndReset();
            Assert.AreEqual(10, eventBean.Get("val"));

            // test back-tick with spaces etc
            IDictionary <string, object> defType = new Dictionary <string, object>();

            defType.Put("candidate book", typeof(string));
            defType.Put("XML Message UnderlyingType", typeof(string));
            defType.Put("select", typeof(int));
            defType.Put("children's books", typeof(int[]));
            defType.Put("my <> map", typeof(IDictionary <string, object>));
            epService.EPAdministrator.Configuration.AddEventType("MyType", defType);
            epService.EPAdministrator.CreateEPL("select `candidate book` as c0, `XML Message UnderlyingType` as c1, `select` as c2, `children's books`[0] as c3, `my <> map`('xx') as c4 from MyType").AddListener(listener);

            IDictionary <string, object> defValues = new Dictionary <string, object>();

            defValues.Put("candidate book", "Enders Game");
            defValues.Put("XML Message UnderlyingType", "book");
            defValues.Put("select", 100);
            defValues.Put("children's books", new int[] { 50, 51 });
            defValues.Put("my <> map", Collections.SingletonMap("xx", "abc"));
            epService.EPRuntime.SendEvent(defValues, "MyType");
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "c0,c1,c2,c3,c4".SplitCsv(), new object[] { "Enders Game", "book", 100, 50, "abc" });

            try {
                epService.EPAdministrator.CreateEPL("select `select` from " + typeof(SupportBean).FullName);
                Assert.Fail();
            } catch (EPException ex) {
                SupportMessageAssertUtil.AssertMessage(ex, "Error starting statement: Failed to validate select-clause expression 'select': Property named 'select' is not valid in any stream [");
            }

            try {
                epService.EPAdministrator.CreateEPL("select `ab cd` from " + typeof(SupportBean).FullName);
                Assert.Fail();
            } catch (EPException ex) {
                SupportMessageAssertUtil.AssertMessage(ex, "Error starting statement: Failed to validate select-clause expression 'ab cd': Property named 'ab cd' is not valid in any stream [");
            }

            // test resolution as nested property
            epService.EPAdministrator.CreateEPL("create schema MyEvent as (customer string, `from` string)");
            epService.EPAdministrator.CreateEPL("insert into DerivedStream select customer,`from` from MyEvent");
            epService.EPAdministrator.CreateEPL("create window TheWindow#firstunique(customer,`from`) as DerivedStream");
            epService.EPAdministrator.CreateEPL("on pattern [a=TheWindow -> timer:interval(12 hours)] as s0 delete from TheWindow as s1 where s0.a.`from`=s1.`from`");

            // test escape in column name
            epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean));
            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("select theString as `order`, theString as `price.for.goods` from SupportBean");

            stmtTwo.AddListener(listener);
            Assert.AreEqual(typeof(string), stmtTwo.EventType.GetPropertyType("order"));
            Assert.AreEqual("price.for.goods", stmtTwo.EventType.PropertyDescriptors[1].PropertyName);

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            IDictionary <string, object> @out = (IDictionary <string, object>)listener.AssertOneGetNew().Underlying;

            Assert.AreEqual("E1", @out.Get("order"));
            Assert.AreEqual("E1", @out.Get("price.for.goods"));

            // try control character
            TryInvalidControlCharacter(listener.AssertOneGetNew());

            // try enum with keyword
            TryEnumWithKeyword();

            TryEnumItselfReserved();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Ejemplo n.º 3
0
            public void Run(RegressionEnvironment env)
            {
                env.CompileDeploy("@Name('s0') select `Seconds`, `Order` from SomeKeywords").AddListener("s0");

                object theEvent = new SupportBeanReservedKeyword(1, 2);
                env.SendEventBean(theEvent, "SomeKeywords");
                var eventBean = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.AreEqual(1, eventBean.Get("Seconds"));
                Assert.AreEqual(2, eventBean.Get("Order"));

                env.UndeployAll();
                env.CompileDeploy("@Name('s0') select * from `Order`").AddListener("s0");

                env.SendEventBean(theEvent, "Order");
                eventBean = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.AreEqual(1, eventBean.Get("Seconds"));
                Assert.AreEqual(2, eventBean.Get("Order"));

                env.UndeployAll();
                env.CompileDeploy("@Name('s0') select Timestamp.`Hour` as val from SomeKeywords").AddListener("s0");

                var bean = new SupportBeanReservedKeyword(1, 2);
                bean.Timestamp = new SupportBeanReservedKeyword.Inner();
                bean.Timestamp.Hour = 10;
                env.SendEventBean(bean, "" + "SomeKeywords" + "");
                eventBean = env.Listener("s0").AssertOneGetNewAndReset();
                Assert.AreEqual(10, eventBean.Get("val"));
                env.UndeployAll();

                // test back-tick with spaces etc
                env.CompileDeploy(
                        "@Name('s0') select `candidate book` as c0, `XML Message Type` as c1, `select` as c2, `children's books`[0] as c3, `my <> map`('xx') as c4 from MyType")
                    .AddListener("s0");

                IDictionary<string, object> defValues = new Dictionary<string, object>();
                defValues.Put("candidate book", "Enders Game");
                defValues.Put("XML Message Type", "book");
                defValues.Put("select", 100);
                defValues.Put("children's books", new[] {50, 51});
                defValues.Put("my <> map", Collections.SingletonDataMap("xx", "abc"));
                env.SendEventMap(defValues, "MyType");
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    new [] { "c0", "c1", "c2", "c3", "c4" },
                    new object[] {"Enders Game", "book", 100, 50, "abc"});
                env.UndeployAll();

                TryInvalidCompile(
                    env,
                    "select `select` from SupportBean",
                    "Failed to validate select-clause expression 'select': Property named 'select' is not valid in any stream [");
                TryInvalidCompile(
                    env,
                    "select `ab cd` from SupportBean",
                    "Failed to validate select-clause expression 'ab cd': Property named 'ab cd' is not valid in any stream [");

                // test resolution as nested property
                var path = new RegressionPath();
                env.CompileDeploy("create schema MyEvent as (customer string, `from` string)", path);
                env.CompileDeploy("insert into DerivedStream select customer,`from` from MyEvent", path);
                env.CompileDeploy("create window TheWindow#firstunique(customer,`from`) as DerivedStream", path);
                env.CompileDeploy(
                    "on pattern [a=TheWindow -> timer:interval(12 hours)] as S0 delete from TheWindow as S1 where S0.a.`from`=S1.`from`",
                    path);

                // test escape in column name
                env.CompileDeploy("@Name('s0') select TheString as `order`, TheString as `price.for.goods` from SupportBean")
                    .AddListener("s0");
                var eventTypeS0 = env.Statement("s0").EventType;
                Assert.AreEqual(typeof(string), eventTypeS0.GetPropertyType("order"));
                Assert.AreEqual("price.for.goods", eventTypeS0.PropertyDescriptors[1].PropertyName);

                env.SendEventBean(new SupportBean("E1", 1));
                var @out = (IDictionary<string, object>) env.Listener("s0").AssertOneGetNew().Underlying;
                Assert.AreEqual("E1", @out.Get("order"));
                Assert.AreEqual("E1", @out.Get("price.for.goods"));

                // try control character
                TryInvalidControlCharacter(env.Listener("s0").AssertOneGetNew());
                // try enum with keyword
                TryEnumWithKeyword(env);

                TryEnumItselfReserved(env);

                env.UndeployAll();
            }