Exemple #1
0
            private void TryAssertionMapTranspose(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                // create window
                var epl = eventRepresentationEnum.GetAnnotationText() +
                          " @Name('create') create window MyWindowMT#keepall as select one, two from OuterType;\n" +
                          "insert into MyWindowMT select one, two from OuterType;\n";
                env.CompileDeploy(epl).AddListener("create");

                var eventType = env.Statement("create").EventType;
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(eventType.UnderlyingType));
                EPAssertionUtil.AssertEqualsAnyOrder(eventType.PropertyNames, new[] {"one", "two"});
                Assert.AreEqual("T1", eventType.GetFragmentType("one").FragmentType.Name);
                Assert.AreEqual("T2", eventType.GetFragmentType("two").FragmentType.Name);

                IDictionary<string, object> innerDataOne = new Dictionary<string, object>();
                innerDataOne.Put("i1", 1);
                IDictionary<string, object> innerDataTwo = new Dictionary<string, object>();
                innerDataTwo.Put("i2", 2);
                IDictionary<string, object> outerData = new Dictionary<string, object>();
                outerData.Put("one", innerDataOne);
                outerData.Put("two", innerDataTwo);

                env.SendEventMap(outerData, "OuterType");
                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetNewAndReset(),
                    new[] {"one.i1", "two.i2"},
                    new object[] {1, 2});

                env.UndeployAll();
            }
            private static void TryJoinAssertion(
                RegressionEnvironment env,
                String epl,
                EventRepresentationChoice rep,
                String columnNames,
                AtomicLong milestone,
                RegressionPath path,
                Type jsonClass)
            {
                env.CompileDeploy("@Name('s0')" + rep.GetAnnotationTextWJsonProvided(jsonClass) + epl, path)
                    .AddListener("s0")
                    .MilestoneInc(milestone);

                var s0Name = "S0_" + rep.GetName();
                var s1Name = "S1_" + rep.GetName();

                SendRepEvent(env, rep, s0Name, "a", 1);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                SendRepEvent(env, rep, s1Name, "a", 2);
                var output = env.Listener("s0").AssertOneGetNewAndReset();
                EPAssertionUtil.AssertProps(
                    output,
                    columnNames.SplitCsv(),
                    new object[] {"a", "a", 1, 2});
                Assert.IsTrue(rep.MatchesClass(output.Underlying.GetType()));

                SendRepEvent(env, rep, s1Name, "b", 3);
                SendRepEvent(env, rep, s0Name, "c", 4);
                Assert.IsFalse(env.Listener("s0").IsInvoked);

                env.UndeployModuleContaining("s0");
            }
Exemple #3
0
        private void RunAssertion <T>(
            EventRepresentationChoice eventRepresentationEnum,
            string additionalAnnotations,
            string typename,
            FunctionSendEvent send,
            Func <object, object> optionalValueConversion,
            IEnumerable <Pair <T, ValueWithExistsFlag> > tests,
            Type expectedPropertyType)
        {
            var stmtText = eventRepresentationEnum.GetAnnotationText() + additionalAnnotations + " select " +
                           "item.id? as myid, " +
                           "exists(item.id?) as exists_myid " +
                           "from " + typename;
            var stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            var listener = new SupportUpdateListener();

            stmt.AddListener(listener);

            Assert.AreEqual(expectedPropertyType, stmt.EventType.GetPropertyType("myid"));
            Assert.AreEqual(typeof(bool?), TypeHelper.GetBoxedType(stmt.EventType.GetPropertyType("exists_myid")));
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            foreach (var pair in tests)
            {
                send.Invoke(_epService, pair.First);
                var @event = listener.AssertOneGetNewAndReset();
                SupportEventInfra.AssertValueMayConvert(@event, "myid", (ValueWithExistsFlag)pair.Second, optionalValueConversion);
            }

            stmt.Dispose();
        }
        private void RunAssertion(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum,
            string additionalAnnotations,
            string typename,
            FunctionSendEvent send,
            Func<object, object> optionalValueConversion,
            Pair<object, object>[] tests,
            Type expectedPropertyType)
        {
            var stmtText = "@Name('s0') " +
                           eventRepresentationEnum.GetAnnotationText() +
                           additionalAnnotations +
                           " select " +
                           "Item.Id? as myId, " +
                           "exists(Item.Id?) as exists_myId " +
                           "from " +
                           typename;
            env.CompileDeploy(stmtText).AddListener("s0");

            var eventType = env.Statement("s0").EventType;
            Assert.AreEqual(expectedPropertyType, eventType.GetPropertyType("myId"));
            Assert.AreEqual(typeof(bool?), eventType.GetPropertyType("exists_myId").GetBoxedType());
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(eventType.UnderlyingType));

            foreach (var pair in tests) {
                send.Invoke(env, pair.First, typename);
                var @event = env.Listener("s0").AssertOneGetNewAndReset();
                AssertValueMayConvert(@event, "myId", (ValueWithExistsFlag) pair.Second, optionalValueConversion);
            }

            env.UndeployAll();
        }
Exemple #5
0
            private static void TryAssertionInnerJoinLateStart(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                var schemaEPL = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedProduct>() +
                                "@Name('schema') create schema Product (product string, size int);\n" +
                                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedPortfolio>() +
                                " create schema Portfolio (portfolio string, product string);\n";
                var path = new RegressionPath();
                env.CompileDeployWBusPublicType(schemaEPL, path);

                env.CompileDeploy("@Name('window') create window ProductWin#keepall as Product", path);

                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("schema").EventType.UnderlyingType));
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("window").EventType.UnderlyingType));

                env.CompileDeploy("insert into ProductWin select * from Product", path);
                env.CompileDeploy("create window PortfolioWin#keepall as Portfolio", path);
                env.CompileDeploy("insert into PortfolioWin select * from Portfolio", path);

                SendProduct(env, eventRepresentationEnum, "productA", 1);
                SendProduct(env, eventRepresentationEnum, "productB", 2);
                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productA");

                var stmtText = "@Name(\"Query2\") select portfolio, ProductWin.product, size " +
                               "from PortfolioWin unidirectional inner join ProductWin on PortfolioWin.product=ProductWin.product";
                env.CompileDeploy(stmtText, path).AddListener("Query2");

                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productB");
                EPAssertionUtil.AssertProps(
                    env.Listener("Query2").AssertOneGetNewAndReset(),
                    new[] {"portfolio", "ProductWin.product", "size"},
                    new object[] {"Portfolio", "productB", 2});

                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productC");
                env.Listener("Query2").Reset();

                SendProduct(env, eventRepresentationEnum, "productC", 3);
                sendPortfolio(env, eventRepresentationEnum, "Portfolio", "productC");
                EPAssertionUtil.AssertProps(
                    env.Listener("Query2").AssertOneGetNewAndReset(),
                    new[] {"portfolio", "ProductWin.product", "size"},
                    new object[] {"Portfolio", "productC", 3});

                env.UndeployAll();
            }
        private void RunAssertionPerformance(EPServiceProvider epService, bool namedWindow, EventRepresentationChoice outputType)
        {
            string eplCreate = namedWindow ?
                               outputType.GetAnnotationText() + " create window MyWindow#keepall as (c1 string, c2 int)" :
                               "create table MyWindow(c1 string primary key, c2 int)";
            EPStatement stmtNamedWindow = epService.EPAdministrator.CreateEPL(eplCreate);

            Assert.IsTrue(outputType.MatchesClass(stmtNamedWindow.EventType.UnderlyingType));

            // preload events
            EPStatement stmt         = epService.EPAdministrator.CreateEPL("insert into MyWindow select TheString as c1, IntPrimitive as c2 from SupportBean");
            int         totalUpdated = 5000;

            for (int i = 0; i < totalUpdated; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean("E" + i, 0));
            }
            stmt.Dispose();

            string epl = "on SupportBean sb merge MyWindow nw where nw.c1 = sb.TheString " +
                         "when matched then update set nw.c2=sb.IntPrimitive";

            stmt = epService.EPAdministrator.CreateEPL(epl);
            var mergeListener = new SupportUpdateListener();

            stmt.Events += mergeListener.Update;

            // prime
            for (int i = 0; i < 100; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean("E" + i, 1));
            }
            long startTime = DateTimeHelper.CurrentTimeMillis;

            for (int i = 0; i < totalUpdated; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean("E" + i, 1));
            }
            long endTime = DateTimeHelper.CurrentTimeMillis;
            long delta   = endTime - startTime;

            // verify
            IEnumerator <EventBean> events = stmtNamedWindow.GetEnumerator();
            int count = 0;

            for (; events.MoveNext();)
            {
                EventBean next = events.Current;
                Assert.AreEqual(1, next.Get("c2"));
                count++;
            }
            Assert.AreEqual(totalUpdated, count);
            Assert.IsTrue(delta < 500, "Delta=" + delta);

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindow", true);
        }
Exemple #7
0
            public void Run(RegressionEnvironment env)
            {
                var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSchemaOne>() +
                          " @name('schema') create schema SchemaOne(col1 int, col2 int);\n";
                epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSchemaWindow>() +
                       " @name('create') create window SchemaWindow#lastevent as (s1 SchemaOne);\n";
                epl += "insert into SchemaWindow (s1) select sone from SchemaOne as sone;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("create");

                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("schema").EventType.UnderlyingType));
                Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("create").EventType.UnderlyingType));

                if (eventRepresentationEnum.IsObjectArrayEvent()) {
                    env.SendEventObjectArray(new object[] {10, 11}, "SchemaOne");
                }
                else if (eventRepresentationEnum.IsMapEvent()) {
                    IDictionary<string, object> theEvent = new Dictionary<string, object>();
                    theEvent.Put("col1", 10);
                    theEvent.Put("col2", 11);
                    env.SendEventMap(theEvent, "SchemaOne");
                }
                else if (eventRepresentationEnum.IsAvroEvent()) {
                    var theEvent = new GenericRecord(
                        SupportAvroUtil
                            .GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("SchemaOne"))
                            .AsRecordSchema());
                    theEvent.Put("col1", 10);
                    theEvent.Put("col2", 11);
                    env.EventService.SendEventAvro(theEvent, "SchemaOne");
                }
                else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                    env.EventService.SendEventJson("{\"col1\": 10, \"col2\": 11}", "SchemaOne");
                }
                else {
                    Assert.Fail();
                }

                EPAssertionUtil.AssertProps(
                    env.Listener("create").AssertOneGetNewAndReset(),
                    new[] {"s1.col1", "s1.col2"},
                    new object[] {10, 11});

                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();
            }
        private void TryAssertionInsertWhereOMStaggered(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            IDictionary <string, object> dataType = MakeMap(new[] { new object[] { "a", typeof(string) }, new object[] { "b", typeof(int) } });

            epService.EPAdministrator.Configuration.AddEventType("MyMap", dataType);

            string      stmtTextCreateOne = eventRepresentationEnum.GetAnnotationText() + " create window MyWindowIWOM#keepall as select a, b from MyMap";
            EPStatement stmtCreateOne     = epService.EPAdministrator.CreateEPL(stmtTextCreateOne);

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateOne.EventType.UnderlyingType));
            var listener = new SupportUpdateListener();

            stmtCreateOne.Events += listener.Update;

            // create insert into
            string stmtTextInsertOne = "insert into MyWindowIWOM select a, b from MyMap";

            epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

            // populate some data
            epService.EPRuntime.SendEvent(MakeMap(new[] { new object[] { "a", "E1" }, new object[] { "b", 2 } }), "MyMap");
            epService.EPRuntime.SendEvent(MakeMap(new[] { new object[] { "a", "E2" }, new object[] { "b", 10 } }), "MyMap");
            epService.EPRuntime.SendEvent(MakeMap(new[] { new object[] { "a", "E3" }, new object[] { "b", 10 } }), "MyMap");

            // 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"))
                                 .SetIsInsert(true)
                                 .SetInsertWhereClause(where);
            model.SelectClause = SelectClause.CreateWildcard();
            model.FromClause   = FromClause.Create(FilterStream.Create("MyWindowIWOM"));
            string text = eventRepresentationEnum.GetAnnotationTextForNonMap() + " create window MyWindowIWOMTwo#keepall as select * from MyWindowIWOM insert where b=10";

            Assert.AreEqual(text.Trim(), model.ToEPL());

            EPStatementObjectModel modelTwo = epService.EPAdministrator.CompileEPL(text);

            Assert.AreEqual(text.Trim(), modelTwo.ToEPL());

            EPStatement stmt = epService.EPAdministrator.Create(modelTwo);

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

            // test select individual fields and from an insert-from named window
            stmt = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window MyWindowIWOMThree#keepall as select a from MyWindowIWOMTwo insert where a = 'E2'");
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "a".Split(','), new[] { new object[] { "E2" } });

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowIWOM", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowIWOMTwo", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowIWOMThree", true);
        }
        private void RunAssertionEventTypeColumnDef(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            EPStatement stmtSchema = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SchemaOne(col1 int, col2 int)");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtSchema.EventType.UnderlyingType));

            EPStatement stmt = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window SchemaWindow#lastevent as (s1 SchemaOne)");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));
            var listenerWindow = new SupportUpdateListener();

            stmt.Events += listenerWindow.Update;
            epService.EPAdministrator.CreateEPL("insert into SchemaWindow (s1) select sone from SchemaOne as sone");

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { 10, 11 }, "SchemaOne");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                var theEvent = new LinkedHashMap <string, object>();
                theEvent.Put("col1", 10);
                theEvent.Put("col2", 11);
                epService.EPRuntime.SendEvent(theEvent, "SchemaOne");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "SchemaOne").AsRecordSchema());
                theEvent.Put("col1", 10);
                theEvent.Put("col2", 11);
                epService.EPRuntime.SendEventAvro(theEvent, "SchemaOne");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), "s1.col1,s1.col2".Split(','), new object[] { 10, 11 });

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("SchemaOne", true);
            epService.EPAdministrator.Configuration.RemoveEventType("SchemaWindow", true);
        }
        private void TryAssertionInnerJoinLateStart(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            EPStatement stmtOne = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema Product (product string, size int)");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtOne.EventType.UnderlyingType));
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema Portfolio (portfolio string, product string)");
            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window ProductWin#keepall as Product");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtTwo.EventType.UnderlyingType));

            epService.EPAdministrator.CreateEPL("insert into ProductWin select * from Product");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window PortfolioWin#keepall as Portfolio");
            epService.EPAdministrator.CreateEPL("insert into PortfolioWin select * from Portfolio");

            SendProduct(epService, eventRepresentationEnum, "productA", 1);
            SendProduct(epService, eventRepresentationEnum, "productB", 2);
            SendPortfolio(epService, eventRepresentationEnum, "Portfolio", "productA");

            string stmtText = "@Name(\"Query2\") select portfolio, ProductWin.product, size " +
                              "from PortfolioWin unidirectional inner join ProductWin on PortfolioWin.product=ProductWin.product";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(stmtText);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendPortfolio(epService, eventRepresentationEnum, "Portfolio", "productB");
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), new string[] { "portfolio", "ProductWin.product", "size" }, new object[] { "Portfolio", "productB", 2 });

            SendPortfolio(epService, eventRepresentationEnum, "Portfolio", "productC");
            listener.Reset();

            SendProduct(epService, eventRepresentationEnum, "productC", 3);
            SendPortfolio(epService, eventRepresentationEnum, "Portfolio", "productC");
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), new string[] { "portfolio", "ProductWin.product", "size" }, new object[] { "Portfolio", "productC", 3 });

            epService.EPAdministrator.DestroyAllStatements();
            foreach (string name in "Product,Portfolio,ProductWin,PortfolioWin".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
        private void TryJoinAssertion(
            EPServiceProvider epService, string epl, EventRepresentationChoice rep, string columnNames)
        {
            if (rep.IsMapEvent())
            {
                var typeInfo = new Dictionary<string, object>();
                typeInfo.Put("id", typeof(string));
                typeInfo.Put("p00", typeof(int));
                epService.EPAdministrator.Configuration.AddEventType("S0", typeInfo);
                epService.EPAdministrator.Configuration.AddEventType("S1", typeInfo);
            }
            else if (rep.IsObjectArrayEvent())
            {
                var names = "id,p00".Split(',');
                var types = new object[] {typeof(string), typeof(int)};
                epService.EPAdministrator.Configuration.AddEventType("S0", names, types);
                epService.EPAdministrator.Configuration.AddEventType("S1", names, types);
            }
            else if (rep.IsAvroEvent())
            {
                var schema = SchemaBuilder.Record(
                    "name",
                    TypeBuilder.Field(
                        "id", TypeBuilder.StringType(
                            TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))),
                    TypeBuilder.RequiredInt("p00"));
                epService.EPAdministrator.Configuration.AddEventTypeAvro(
                    "S0", new ConfigurationEventTypeAvro().SetAvroSchema(schema));
                epService.EPAdministrator.Configuration.AddEventTypeAvro(
                    "S1", new ConfigurationEventTypeAvro().SetAvroSchema(schema));
            }

            var stmt = epService.EPAdministrator.CreateEPL(rep.GetAnnotationText() + epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;

            SendRepEvent(epService, rep, "S0", "a", 1);
            Assert.IsFalse(listener.IsInvoked);

            SendRepEvent(epService, rep, "S1", "a", 2);
            var output = listener.AssertOneGetNewAndReset();
            EPAssertionUtil.AssertProps(output, columnNames.Split(','), new object[] {"a", "a", 1, 2});
            Assert.IsTrue(rep.MatchesClass(output.Underlying.GetType()));

            SendRepEvent(epService, rep, "S1", "b", 3);
            SendRepEvent(epService, rep, "S0", "c", 4);
            Assert.IsFalse(listener.IsInvoked);

            stmt.Dispose();
            epService.EPAdministrator.Configuration.RemoveEventType("S0", true);
            epService.EPAdministrator.Configuration.RemoveEventType("S1", true);
        }
        private void TryAssertionMapTranspose(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            var innerTypeOne = new Dictionary <string, object>();

            innerTypeOne.Put("i1", typeof(int));
            var innerTypeTwo = new Dictionary <string, object>();

            innerTypeTwo.Put("i2", typeof(int));
            var outerType = new Dictionary <string, object>();

            outerType.Put("one", "T1");
            outerType.Put("two", "T2");
            epService.EPAdministrator.Configuration.AddEventType("T1", innerTypeOne);
            epService.EPAdministrator.Configuration.AddEventType("T2", innerTypeTwo);
            epService.EPAdministrator.Configuration.AddEventType("OuterType", outerType);

            // create window
            string      stmtTextCreate = eventRepresentationEnum.GetAnnotationText() + " create window MyWindowMT#keepall as select one, two from OuterType";
            EPStatement stmtCreate     = epService.EPAdministrator.CreateEPL(stmtTextCreate);

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreate.EventType.UnderlyingType));
            var listenerWindow = new SupportUpdateListener();

            stmtCreate.Events += listenerWindow.Update;
            EPAssertionUtil.AssertEqualsAnyOrder(stmtCreate.EventType.PropertyNames, new string[] { "one", "two" });
            EventType eventType = stmtCreate.EventType;

            Assert.AreEqual("T1", eventType.GetFragmentType("one").FragmentType.Name);
            Assert.AreEqual("T2", eventType.GetFragmentType("two").FragmentType.Name);

            // create insert into
            string stmtTextInsertOne = "insert into MyWindowMT select one, two from OuterType";

            epService.EPAdministrator.CreateEPL(stmtTextInsertOne);

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

            innerDataOne.Put("i1", 1);
            var innerDataTwo = new Dictionary <string, object>();

            innerDataTwo.Put("i2", 2);
            var outerData = new Dictionary <string, object>();

            outerData.Put("one", innerDataOne);
            outerData.Put("two", innerDataTwo);

            epService.EPRuntime.SendEvent(outerData, "OuterType");
            EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), "one.i1,two.i2".Split(','), new object[] { 1, 2 });

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("MyWindowMT", true);
        }
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                var eplCreate = namedWindow
                    ? outputType.GetAnnotationText() +
                      "@Name('create') create window MyWindow#keepall as (c1 string, c2 int)"
                    : "@Name('create') create table MyWindow(c1 string primary key, c2 int)";
                env.CompileDeploy(eplCreate, path);
                Assert.IsTrue(outputType.MatchesClass(env.Statement("create").EventType.UnderlyingType));

                // preload events
                env.CompileDeploy(
                    "@Name('insert') insert into MyWindow select TheString as c1, IntPrimitive as c2 from SupportBean",
                    path);
                var totalUpdated = 5000;
                for (var i = 0; i < totalUpdated; i++) {
                    env.SendEventBean(new SupportBean("E" + i, 0));
                }

                env.UndeployModuleContaining("insert");

                var epl = "@Name('s0') on SupportBean sb merge MyWindow nw where nw.c1 = sb.TheString " +
                          "when matched then update set nw.c2=sb.IntPrimitive";
                env.CompileDeploy(epl, path);

                // prime
                for (var i = 0; i < 100; i++) {
                    env.SendEventBean(new SupportBean("E" + i, 1));
                }

                var startTime = PerformanceObserver.MilliTime;
                for (var i = 0; i < totalUpdated; i++) {
                    env.SendEventBean(new SupportBean("E" + i, 1));
                }

                var endTime = PerformanceObserver.MilliTime;
                var delta = endTime - startTime;

                // verify
                var events = env.Statement("create").GetEnumerator();
                var count = 0;
                while (events.MoveNext()) {
                    var next = events.Current;
                    Assert.AreEqual(1, next.Get("c2"));
                    count++;
                }

                Assert.AreEqual(totalUpdated, count);
                Assert.That(delta, Is.LessThan(500), "Delta=" + delta);

                env.UndeployAll();
            }
Exemple #15
0
        private static void RunAssertionCreateStreamTwo(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() +
                      " create schema MyEvent(myId int)\n;" +
                      eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedAllMyEvent>() +
                      " create schema AllMyEvent as (myEvent MyEvent, clazz String, reverse boolean);\n" +
                      eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSuspectMyEvent>() +
                      " create schema SuspectMyEvent as (myEvent MyEvent, clazz String);\n";
            env.CompileDeployWBusPublicType(epl, path);

            env.CompileDeploy(
                    "@Name('s0') insert into AllMyEvent " +
                    "select c as myEvent, 'test' as clazz, false as reverse " +
                    "from MyEvent(myId=1) c",
                    path)
                .AddListener("s0");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("s0").EventType.UnderlyingType));

            env.CompileDeploy(
                    "@Name('s1') insert into SuspectMyEvent " +
                    "select c.myEvent as myEvent, clazz " +
                    "from AllMyEvent(not reverse) c",
                    path)
                .AddListener("s1");

            if (eventRepresentationEnum.IsObjectArrayEvent()) {
                env.SendEventObjectArray(MakeEvent(1).Values.ToArray(), "MyEvent");
            }
            else if (eventRepresentationEnum.IsMapEvent()) {
                env.SendEventMap(MakeEvent(1), "MyEvent");
            }
            else if (eventRepresentationEnum.IsAvroEvent()) {
                env.SendEventAvro(MakeEventAvro(1), "MyEvent");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                env.SendEventJson("{\"myId\": 1}", "MyEvent");
            }
            else {
                Assert.Fail();
            }

            AssertCreateStreamTwo(eventRepresentationEnum, env.Listener("s0").AssertOneGetNewAndReset(), env.Statement("s0"));
            AssertCreateStreamTwo(eventRepresentationEnum, env.Listener("s1").AssertOneGetNewAndReset(), env.Statement("s1"));

            env.UndeployAll();
        }
Exemple #16
0
        private void RunAssertionObjectArrayDelivery(EventRepresentationChoice eventRepresentationEnum, SupportSubscriberRowByRowObjectArrayBase subscriber)
        {
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select TheString, IntPrimitive from SupportBean#unique(TheString)");

            stmt.Subscriber = subscriber;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            subscriber.AssertOneAndReset(stmt, new object[] { "E1", 1 });

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 10));
            subscriber.AssertOneAndReset(stmt, new object[] { "E2", 10 });

            stmt.Dispose();
        }
Exemple #17
0
        private void RunAssertionOutputLimitNoJoin(EventRepresentationChoice eventRepresentationEnum, SupportSubscriberRowByRowSpecificBase subscriber)
        {
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select TheString, IntPrimitive from SupportBean output every 2 events");

            stmt.Subscriber = subscriber;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            subscriber.AssertNoneReceived();

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            subscriber.AssertMultipleReceivedAndReset(stmt, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } });

            stmt.Dispose();
        }
Exemple #18
0
        private void RunAssertionInnerJoinLateStart(EventRepresentationChoice eventRepresentationEnum)
        {
            var stmtOne = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema Product (product string, size int)");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtOne.EventType.UnderlyingType));
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema Portfolio (portfolio string, product string)");
            var stmtTwo = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window ProductWin#keepall as Product");

            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtTwo.EventType.UnderlyingType));

            _epService.EPAdministrator.CreateEPL("insert into ProductWin select * from Product");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window PortfolioWin#keepall as Portfolio");
            _epService.EPAdministrator.CreateEPL("insert into PortfolioWin select * from Portfolio");

            SendProduct(eventRepresentationEnum, "productA", 1);
            SendProduct(eventRepresentationEnum, "productB", 2);
            SendPortfolio(eventRepresentationEnum, "Portfolio", "productA");

            var stmtText = "@Name(\"Query2\") select portfolio, ProductWin.product, size " +
                           "from PortfolioWin unidirectional inner join ProductWin on PortfolioWin.product=ProductWin.product";
            var stmt = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listenerStmtOne);

            SendPortfolio(eventRepresentationEnum, "Portfolio", "productB");
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), new string[] { "portfolio", "ProductWin.product", "size" }, new object[] { "Portfolio", "productB", 2 });

            SendPortfolio(eventRepresentationEnum, "Portfolio", "productC");
            _listenerStmtOne.Reset();

            SendProduct(eventRepresentationEnum, "productC", 3);
            SendPortfolio(eventRepresentationEnum, "Portfolio", "productC");
            EPAssertionUtil.AssertProps(_listenerStmtOne.AssertOneGetNewAndReset(), new string[] { "portfolio", "ProductWin.product", "size" }, new object[] { "Portfolio", "productC", 3 });

            _epService.Initialize();
        }
        private void RunAssertionCreateStreamTwo(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEvent(myId int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema AllMyEvent as (myEvent MyEvent, class string, reverse bool)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SuspectMyEvent as (myEvent MyEvent, class string)");

            EPStatement stmtOne = epService.EPAdministrator.CreateEPL("insert into AllMyEvent " +
                                                                      "select c as myEvent, 'test' as class, false as reverse " +
                                                                      "from MyEvent(myId=1) c");
            var listener = new SupportUpdateListener();

            stmtOne.Events += listener.Update;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtOne.EventType.UnderlyingType));

            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("insert into SuspectMyEvent " +
                                                                      "select c.myEvent as myEvent, class " +
                                                                      "from AllMyEvent(not reverse) c");
            var listenerTwo = new SupportUpdateListener();

            stmtTwo.Events += listenerTwo.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(MakeEvent(1).Values.ToArray(), "MyEvent");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(MakeEvent(1), "MyEvent");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                epService.EPRuntime.SendEventAvro(MakeEventAvro(1), "MyEvent");
            }
            else
            {
                Assert.Fail();
            }

            AssertCreateStreamTwo(eventRepresentationEnum, listener.AssertOneGetNewAndReset(), stmtOne);
            AssertCreateStreamTwo(eventRepresentationEnum, listenerTwo.AssertOneGetNewAndReset(), stmtTwo);

            epService.EPAdministrator.DestroyAllStatements();
            foreach (string name in "MyEvent,AllMyEvent,SuspectMyEvent".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemple #20
0
        private void TryAssertionRowMapDelivery(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum, SupportSubscriberRowByRowMapBase subscriber)
        {
            EPStatement stmt = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select irstream TheString, IntPrimitive from SupportBean#unique(TheString)");

            stmt.Subscriber = subscriber;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            subscriber.AssertIRStreamAndReset(stmt, FIELDS, new object[] { "E1", 1 }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E2", 10));
            subscriber.AssertIRStreamAndReset(stmt, FIELDS, new object[] { "E2", 10 }, null);

            epService.EPRuntime.SendEvent(new SupportBean("E1", 2));
            subscriber.AssertIRStreamAndReset(stmt, FIELDS, new object[] { "E1", 2 }, new object[] { "E1", 1 });

            stmt.Dispose();
        }
Exemple #21
0
        private void RunAssertionWidening(EventRepresentationChoice eventRepresentationEnum, SupportSubscriberRowByRowSpecificBase subscriber)
        {
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select BytePrimitive, IntPrimitive, LongPrimitive, FloatPrimitive from SupportBean(TheString='E1')");

            stmt.Subscriber = subscriber;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            var bean = new SupportBean();

            bean.TheString      = "E1";
            bean.BytePrimitive  = (byte)1;
            bean.IntPrimitive   = 2;
            bean.LongPrimitive  = 3;
            bean.FloatPrimitive = 4;
            _epService.EPRuntime.SendEvent(bean);
            subscriber.AssertOneReceivedAndReset(stmt, new object[] { 1, 2L, 3d, 4d });

            stmt.Dispose();
        }
Exemple #22
0
        private void RunAssertionCSVGraphSchema(EventRepresentationChoice representationEnum)
        {
            var fields = "MyString,MyInt,timestamp, MyDouble".SplitCsv();

            CompileDeploy(
                runtime,
                representationEnum.GetAnnotationText() +
                " @public @buseventtype create schema MyEvent(MyString string, MyInt int, timestamp long, MyDouble double)");
            var graph = "create dataflow ReadCSV " +
                        "FileSource -> mystream<MyEvent> {" +
                        " file: '../../../etc/regression/titleRow.csv'," +
                        " hasHeaderLine: true " +
                        "}" +
                        "DefaultSupportCaptureOp(mystream) {}";
            var deployment = CompileDeploy(runtime, graph);

            var outputOp = new DefaultSupportCaptureOp();
            var instance = runtime.DataFlowService.Instantiate(
                deployment.DeploymentId,
                "ReadCSV",
                new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp)));

            instance.Run();
            var received = outputOp.GetAndReset();

            Assert.AreEqual(1, received.Count);
            EPAssertionUtil.AssertPropsPerRow(
                container,
                received[0].ToArray(),
                fields,
                new object[][] {
                new object[] { "one", 1, 100L, 1.1 },
                new object[] { "three", 3, 300L, 3.3 },
                new object[] { "five", 5, 500L, 5.5 }
            });
            Assert.IsTrue(representationEnum.MatchesClass(received[0].ToArray()[0].GetType()));

            UndeployAll(runtime);
        }
Exemple #23
0
        private void RunAssertionBindMap(EventRepresentationChoice eventRepresentationEnum, SupportSubscriberMultirowMapBase subscriber)
        {
            var stmtText = eventRepresentationEnum.GetAnnotationText() + " select irstream TheString, IntPrimitive from " + typeof(SupportBean).FullName + "#length_batch(2)";
            var stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Subscriber = subscriber;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            subscriber.AssertNoneReceived();

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            subscriber.AssertOneReceivedAndReset(stmt, _fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } }, null);

            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            subscriber.AssertNoneReceived();

            _epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            subscriber.AssertOneReceivedAndReset(stmt, _fields, new object[][] { new object[] { "E3", 3 }, new object[] { "E4", 4 } }, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } });

            stmt.Dispose();
        }
        private static void TryAssertionStaggered(
            RegressionEnvironment env,
            EventRepresentationChoice outputType)
        {
            string[] fieldsOne = {"a1", "b1"};
            string[] fieldsTwo = {"a2", "b2"};
            var path = new RegressionPath();

            // create window one
            var stmtTextCreateOne = outputType.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSTAG>() +
                                    "@Name('createOne') create window MyWindowSTAG#keepall as select TheString as a1, IntPrimitive as b1 from SupportBean";
            env.CompileDeploy(stmtTextCreateOne, path).AddListener("createOne");
            Assert.AreEqual(0, GetCount(env, "createOne", "MyWindowSTAG"));
            Assert.IsTrue(outputType.MatchesClass(env.Statement("createOne").EventType.UnderlyingType));

            // create window two
            var stmtTextCreateTwo = outputType.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSTAGTwo>() +
                                    " @Name('createTwo') create window MyWindowSTAGTwo#keepall as select TheString as a2, IntPrimitive as b2 from SupportBean";
            env.CompileDeploy(stmtTextCreateTwo, path).AddListener("createTwo");
            Assert.AreEqual(0, GetCount(env, "createTwo", "MyWindowSTAGTwo"));
            Assert.IsTrue(outputType.MatchesClass(env.Statement("createTwo").EventType.UnderlyingType));

            // create delete stmt
            var stmtTextDelete = "@Name('delete') on MyWindowSTAG delete from MyWindowSTAGTwo where a1 = a2";
            env.CompileDeploy(stmtTextDelete, path).AddListener("delete");
            Assert.AreEqual(
                StatementType.ON_DELETE,
                env.Statement("delete").GetProperty(StatementProperty.STATEMENTTYPE));

            // create insert into
            var stmtTextInsert =
                "@Name('insert') insert into MyWindowSTAG select TheString as a1, IntPrimitive as b1 from SupportBean(IntPrimitive > 0)";
            env.CompileDeploy(stmtTextInsert, path);
            stmtTextInsert =
                "@Name('insertTwo') insert into MyWindowSTAGTwo select TheString as a2, IntPrimitive as b2 from SupportBean(IntPrimitive < 0)";
            env.CompileDeploy(stmtTextInsert, path);

            SendSupportBean(env, "E1", -10);
            EPAssertionUtil.AssertProps(
                env.Listener("createTwo").AssertOneGetNewAndReset(),
                fieldsTwo,
                new object[] {"E1", -10});
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("createTwo"),
                fieldsTwo,
                new[] {new object[] {"E1", -10}});
            Assert.IsFalse(env.Listener("createOne").IsInvoked);
            Assert.AreEqual(1, GetCount(env, "createTwo", "MyWindowSTAGTwo"));

            SendSupportBean(env, "E2", 5);
            EPAssertionUtil.AssertProps(
                env.Listener("createOne").AssertOneGetNewAndReset(),
                fieldsOne,
                new object[] {"E2", 5});
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("createOne"),
                fieldsOne,
                new[] {new object[] {"E2", 5}});
            Assert.IsFalse(env.Listener("createTwo").IsInvoked);
            Assert.AreEqual(1, GetCount(env, "createOne", "MyWindowSTAG"));

            SendSupportBean(env, "E3", -1);
            EPAssertionUtil.AssertProps(
                env.Listener("createTwo").AssertOneGetNewAndReset(),
                fieldsTwo,
                new object[] {"E3", -1});
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("createTwo"),
                fieldsTwo,
                new[] {new object[] {"E1", -10}, new object[] {"E3", -1}});
            Assert.IsFalse(env.Listener("createOne").IsInvoked);
            Assert.AreEqual(2, GetCount(env, "createTwo", "MyWindowSTAGTwo"));

            SendSupportBean(env, "E3", 1);
            EPAssertionUtil.AssertProps(
                env.Listener("createOne").AssertOneGetNewAndReset(),
                fieldsOne,
                new object[] {"E3", 1});
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("createOne"),
                fieldsOne,
                new[] {new object[] {"E2", 5}, new object[] {"E3", 1}});
            EPAssertionUtil.AssertProps(
                env.Listener("createTwo").AssertOneGetOldAndReset(),
                fieldsTwo,
                new object[] {"E3", -1});
            EPAssertionUtil.AssertPropsPerRow(
                env.GetEnumerator("createTwo"),
                fieldsTwo,
                new[] {new object[] {"E1", -10}});
            Assert.AreEqual(2, GetCount(env, "createOne", "MyWindowSTAG"));
            Assert.AreEqual(1, GetCount(env, "createTwo", "MyWindowSTAGTwo"));

            env.UndeployModuleContaining("delete");
            env.UndeployModuleContaining("insert");
            env.UndeployModuleContaining("insertTwo");
            env.UndeployModuleContaining("createOne");
            env.UndeployModuleContaining("createTwo");
        }
        private static void TryAssertionSingleRowSplitAndType(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            var types =
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonSentence>() +
                " create schema MySentenceEvent(sentence String);\n" +
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() +
                " create schema WordEvent(word String);\n" +
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonCharacter>() +
                " create schema CharacterEvent(character String);\n";
            env.CompileDeployWBusPublicType(types, path);

            string stmtText;
            var fields = new[] {"word"};

            // test single-row method
            stmtText = "@Name('s0') select * from MySentenceEvent[splitSentence" +
                       "_" +
                       eventRepresentationEnum.GetName() +
                       "(sentence)@type(WordEvent)]";
            env.CompileDeploy(stmtText, path).AddListener("s0");
            Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("s0").EventType.UnderlyingType));

            SendMySentenceEvent(env, eventRepresentationEnum, "I am testing this code");
            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {
                    new object[] {"I"},
                    new object[] {"am"},
                    new object[] {"testing"},
                    new object[] {"this"},
                    new object[] {"code"}
                });

            SendMySentenceEvent(env, eventRepresentationEnum, "the second event");
            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {
                    new object[] {"the"},
                    new object[] {"second"},
                    new object[] {"event"}
                });

            env.UndeployModuleContaining("s0");

            // test SODA
            env.EplToModelCompileDeploy(stmtText, path).AddListener("s0");
            SendMySentenceEvent(env, eventRepresentationEnum, "the third event");
            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {
                    new object[] {"the"},
                    new object[] {"third"},
                    new object[] {"event"}
                });
            env.UndeployModuleContaining("s0");

            // test script
            if (eventRepresentationEnum.IsMapEvent()) {
                stmtText = "@Name('s0') expression System.Collections.IList js:SplitSentenceJS(sentence) [" +
                           "  var listType = host.resolveType('System.Collections.Generic.List<object>');" +
                           "  var words = host.newObj(listType);" +
                           "  words.Add(Collections.SingletonDataMap('word', 'wordOne'));" +
                           "  words.Add(Collections.SingletonDataMap('word', 'wordTwo'));" +
                           "  return words;" +
                           "]" +
                           "select * from MySentenceEvent[SplitSentenceJS(sentence)@type(WordEvent)]";

                env.CompileDeploy(stmtText, path).AddListener("s0");
                Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);

                env.SendEventMap(Collections.EmptyDataMap, "MySentenceEvent");
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new[] {
                        new object[] {"wordOne"},
                        new object[] {"wordTwo"}
                    });

                env.UndeployModuleContaining("s0");
            }

            // test multiple splitters
            stmtText = "@Name('s0') select * from " +
                       "MySentenceEvent" +
                       "[splitSentence_" + eventRepresentationEnum.GetName() + "(sentence)" + "@type(WordEvent)]" +
                       "[splitWord_" + eventRepresentationEnum.GetName() + "(word)" + "@type(CharacterEvent)]";

            env.CompileDeploy(stmtText, path).AddListener("s0");
            Assert.AreEqual("CharacterEvent", env.Statement("s0").EventType.Name);

            SendMySentenceEvent(env, eventRepresentationEnum, "I am");
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.Listener("s0").GetAndResetLastNewData(),
                new[] {"character"},
                new[] {
                    new object[] {"I"},
                    new object[] {"a"},
                    new object[] {"m"}
                });

            env.UndeployModuleContaining("s0");

            // test wildcard parameter
            stmtText = "@Name('s0') select * from MySentenceEvent[splitSentenceBean_" +
                       eventRepresentationEnum.GetName() +
                       "(*)@type(WordEvent)]";
            env.CompileDeploy(stmtText, path).AddListener("s0");
            Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);

            SendMySentenceEvent(env, eventRepresentationEnum, "another test sentence");
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.Listener("s0").GetAndResetLastNewData(),
                fields,
                new[] {
                    new object[] {"another"},
                    new object[] {"test"},
                    new object[] {"sentence"}
                });

            env.UndeployModuleContaining("s0");

            // test property returning untyped collection
            if (eventRepresentationEnum.IsObjectArrayEvent()) {
                stmtText = eventRepresentationEnum.GetAnnotationText() +
                           " @Name('s0') select * from SupportObjectArrayEvent[SomeObjectArray@type(WordEvent)]";
                env.CompileDeploy(stmtText, path).AddListener("s0");
                Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);

                object[][] rows = {
                    new object[] {"this"},
                    new object[] {"is"},
                    new object[] {"collection"}
                };
                env.SendEventBean(new SupportObjectArrayEvent(rows));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new[] {
                        new object[] {"this"},
                        new object[] {"is"},
                        new object[] {"collection"}
                    });
                env.UndeployAll();
            }
            else if (eventRepresentationEnum.IsMapEvent()) {
                stmtText = eventRepresentationEnum.GetAnnotationText() +
                           " @Name('s0') select * from SupportCollectionEvent[SomeCollection@type(WordEvent)]";
                env.CompileDeploy(stmtText, path).AddListener("s0");
                Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);

                var coll = new List<IDictionary<string, object>>();
                coll.Add(Collections.SingletonDataMap("word", "this"));
                coll.Add(Collections.SingletonDataMap("word", "is"));
                coll.Add(Collections.SingletonDataMap("word", "collection"));

                env.SendEventBean(new SupportCollectionEvent(coll.Unwrap<object>()));
                EPAssertionUtil.AssertPropsPerRowAnyOrder(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new[] {
                        new object[] {"this"},
                        new object[] {"is"},
                        new object[] {"collection"}
                    });
                env.UndeployAll();
            }
            else if (eventRepresentationEnum.IsAvroEvent()) {
                stmtText = "@Name('s0') " +
                           eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() +
                           " select * from SupportAvroArrayEvent[SomeAvroArray@type(WordEvent)]";
                env.CompileDeploy(stmtText, path).AddListener("s0");
                Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);

                var rows = new GenericRecord[3];
                var words = new[] {"this", "is", "avro"};
                for (var i = 0; i < words.Length; i++) {
                    rows[i] = new GenericRecord(
                        ((AvroEventType) env.Statement("s0").EventType).SchemaAvro.AsRecordSchema());
                    rows[i].Put("word", words[i]);
                }

                env.SendEventBean(new SupportAvroArrayEvent(rows));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new[] {
                        new object[] {"this"},
                        new object[] {"is"},
                        new object[] {"avro"}
                    });
                env.UndeployAll();
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                stmtText = "@Name('s0') " +
                           eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() +
                           " select * from SupportJsonArrayEvent[SomeJsonArray@type(WordEvent)]";
                env.CompileDeploy(stmtText, path).AddListener("s0");
                Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name);

                var rows = new string[3];
                var words = "this,is,avro".SplitCsv();
                for (var i = 0; i < words.Length; i++) {
                    rows[i] = "{ \"word\": \"" + words[i] + "\"}";
                }

                env.SendEventBean(new SupportJsonArrayEvent(rows));
                EPAssertionUtil.AssertPropsPerRow(
                    env.Listener("s0").GetAndResetLastNewData(),
                    fields,
                    new object[][] {
                        new[] {"this"}, new[] {"is"},
                        new[] {"avro"}
                    });
                env.UndeployAll();
            }
            else {
                throw new ArgumentException("Unrecognized enum " + eventRepresentationEnum);
            }

            // invalid: event type not found
            TryInvalidCompile(
                env,
                path,
                "select * from MySentenceEvent[splitSentence_" +
                eventRepresentationEnum.GetName() +
                "(sentence)@type(XYZ)]",
                "Event type by name 'XYZ' could not be found");

            // invalid lib-function annotation
            TryInvalidCompile(
                env,
                path,
                "select * from MySentenceEvent[splitSentence_" +
                eventRepresentationEnum.GetName() +
                "(sentence)@dummy(WordEvent)]",
                "Invalid annotation for property selection, expected 'type' but found 'dummy' in text '@dummy(WordEvent)'");

            // invalid type assignment to event type
            if (eventRepresentationEnum.IsObjectArrayEvent()) {
                TryInvalidCompile(
                    env,
                    path,
                    "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]",
                    "Event type 'WordEvent' underlying type System.Object[] cannot be assigned a value of type");
            }
            else if (eventRepresentationEnum.IsMapEvent()) {
                TryInvalidCompile(
                    env,
                    path,
                    "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]",
                    "Event type 'WordEvent' underlying type System.Collections.Generic.IDictionary<System.String, System.Object> cannot be assigned a value of type");
            }
            else if (eventRepresentationEnum.IsAvroEvent()) {
                TryInvalidCompile(
                    env,
                    path,
                    "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]",
                    "Event type 'WordEvent' underlying type " +
                    TypeHelper.AVRO_GENERIC_RECORD_CLASSNAME +
                    " cannot be assigned a value of type");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                TryInvalidCompile(
                    env,
                    path,
                    "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]",
                    "Event type 'WordEvent' requires string-type array and cannot be assigned from value of type " + typeof(SupportBean[]).CleanName());

            }
            else {
                Assert.Fail();
            }

            // invalid subquery
            TryInvalidCompile(
                env,
                path,
                "select * from MySentenceEvent[splitSentence((select * from SupportBean#keepall))@type(WordEvent)]",
                "Invalid Contained-event expression 'splitSentence(subselect_0)': Aggregation, sub-select, previous or prior functions are not supported in this context [select * from MySentenceEvent[splitSentence((select * from SupportBean#keepall))@type(WordEvent)]]");

            env.UndeployAll();
        }
        private void RunAssertionSingleRowSplitAndType(EventRepresentationChoice eventRepresentationEnum)
        {
            string[] methods;
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                methods = "SplitSentenceMethodReturnObjectArray,SplitSentenceBeanMethodReturnObjectArray,SplitWordMethodReturnObjectArray".Split(',');
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                methods = "SplitSentenceMethodReturnMap,SplitSentenceBeanMethodReturnMap,SplitWordMethodReturnMap".Split(',');
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                methods = "SplitSentenceMethodReturnAvro,SplitSentenceBeanMethodReturnAvro,SplitWordMethodReturnAvro".Split(',');
            }
            else
            {
                throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum);
            }
            var funcs = "SplitSentence,SplitSentenceBean,SplitWord".Split(',');

            for (var i = 0; i < funcs.Length; i++)
            {
                _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction(funcs[i], GetType().FullName, methods[i]);
            }
            _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("invalidSentence", GetType().FullName, "InvalidSentenceMethod");

            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SentenceEvent(sentence string)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema WordEvent(word string)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema CharacterEvent(char string)");

            string      stmtText;
            EPStatement stmt;
            var         fields = "word".Split(',');

            // test single-row method
            stmtText = "select * from SentenceEvent[SplitSentence(sentence)@Type(WordEvent)]";
            stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.AddListener(_listener);
            Assert.AreEqual("WordEvent", stmt.EventType.Name);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType));

            SendSentenceEvent(eventRepresentationEnum, "I am testing this code");
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new Object[][]
            {
                new object[] { "I" },
                new object[] { "am" },
                new object[] { "testing" },
                new object[] { "this" },
                new object[] { "code" }
            });

            SendSentenceEvent(eventRepresentationEnum, "the second event");
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new Object[][]
            {
                new object[] { "the" },
                new object[] { "second" },
                new object[] { "event" }
            });

            stmt.Dispose();

            // test SODA
            var model = _epService.EPAdministrator.CompileEPL(stmtText);

            Assert.AreEqual(stmtText, model.ToEPL());
            stmt = _epService.EPAdministrator.Create(model);
            Assert.AreEqual(stmtText, stmt.Text);
            stmt.AddListener(_listener);

            SendSentenceEvent(eventRepresentationEnum, "the third event");
            EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new Object[][]
            {
                new object[] { "the" },
                new object[] { "third" },
                new object[] { "event" }
            });

            stmt.Dispose();

            // test script
            if (eventRepresentationEnum.IsMapEvent())
            {
                stmtText = "expression System.Collections.IList jscript:SplitSentenceJS(sentence) [" +
                           "  debug.Debug('test');" +
                           "  var listType = host.type('System.Collections.ArrayList');" +
                           "  var words = host.newObj(listType);" +
                           "  debug.Debug(words);" +
                           "  words.Add(Collections.SingletonDataMap('word', 'wordOne'));" +
                           "  words.Add(Collections.SingletonDataMap('word', 'wordTwo'));" +
                           "  return words;" +
                           "]" +
                           "select * from SentenceEvent[SplitSentenceJS(sentence)@Type(WordEvent)]";

                stmt = _epService.EPAdministrator.CreateEPL(stmtText);
                stmt.AddListener(_listener);
                Assert.AreEqual("WordEvent", stmt.EventType.Name);

                _epService.EPRuntime.SendEvent(Collections.EmptyDataMap, "SentenceEvent");
                EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields, new Object[][]
                {
                    new object[] { "wordOne" },
                    new object[] { "wordTwo" }
                });

                stmt.Dispose();
            }

            // test multiple splitters
            stmtText = "select * from SentenceEvent[SplitSentence(sentence)@Type(WordEvent)][SplitWord(word)@Type(CharacterEvent)]";
            stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.AddListener(_listener);
            Assert.AreEqual("CharacterEvent", stmt.EventType.Name);

            SendSentenceEvent(eventRepresentationEnum, "I am");
            EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), "char".Split(','), new Object[][]
            {
                new object[] { "I" },
                new object[] { "a" },
                new object[] { "m" }
            });

            stmt.Dispose();

            // test wildcard parameter
            stmtText = "select * from SentenceEvent[SplitSentenceBean(*)@Type(WordEvent)]";
            stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
            stmt.AddListener(_listener);
            Assert.AreEqual("WordEvent", stmt.EventType.Name);

            SendSentenceEvent(eventRepresentationEnum, "another test sentence");
            EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields, new Object[][]
            {
                new object[] { "another" },
                new object[] { "test" },
                new object[] { "sentence" }
            });

            stmt.Dispose();

            // test property returning untyped collection
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPAdministrator.Configuration.AddEventType(typeof(ObjectArrayEvent));
                stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from ObjectArrayEvent[someObjectArray@Type(WordEvent)]";
                stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
                stmt.AddListener(_listener);
                Assert.AreEqual("WordEvent", stmt.EventType.Name);

                var rows = new Object[][]
                {
                    new object[] { "this" },
                    new object[] { "is" },
                    new object[] { "collection" }
                };
                _epService.EPRuntime.SendEvent(new ObjectArrayEvent(rows));
                EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new Object[][]
                {
                    new object[] { "this" },
                    new object[] { "is" },
                    new object[] { "collection" }
                });
                stmt.Dispose();
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPAdministrator.Configuration.AddEventType(typeof(MyCollectionEvent));
                stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from MyCollectionEvent[someCollection@Type(WordEvent)]";
                stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
                stmt.AddListener(_listener);
                Assert.AreEqual("WordEvent", stmt.EventType.Name);

                var coll = new List <Map>();
                coll.Add(Collections.SingletonDataMap("word", "this"));
                coll.Add(Collections.SingletonDataMap("word", "is"));
                coll.Add(Collections.SingletonDataMap("word", "collection"));

                _epService.EPRuntime.SendEvent(new MyCollectionEvent(coll));
                EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields, new Object[][]
                {
                    new object[] { "this" },
                    new object[] { "is" },
                    new object[] { "collection" }
                });
                stmt.Dispose();
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                _epService.EPAdministrator.Configuration.AddEventType(typeof(AvroArrayEvent));
                stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from AvroArrayEvent[someAvroArray@Type(WordEvent)]";
                stmt     = _epService.EPAdministrator.CreateEPL(stmtText);
                stmt.AddListener(_listener);
                Assert.AreEqual("WordEvent", stmt.EventType.Name);

                var rows  = new GenericRecord[3];
                var words = "this,is,avro".Split(',');
                for (var i = 0; i < words.Length; i++)
                {
                    rows[i] = new GenericRecord(((AvroEventType)stmt.EventType).SchemaAvro);
                    rows[i].Put("word", words[i]);
                }
                _epService.EPRuntime.SendEvent(new AvroArrayEvent(rows));
                EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields, new Object[][]
                {
                    new object[] { "this" },
                    new object[] { "is" },
                    new object[] { "avro" }
                });
                stmt.Dispose();
            }
            else
            {
                throw new ArgumentException("Unrecognized enum " + eventRepresentationEnum);
            }

            // invalid: event type not found
            TryInvalid("select * from SentenceEvent[SplitSentence(sentence)@type(XYZ)]",
                       "Event type by name 'XYZ' could not be found [select * from SentenceEvent[SplitSentence(sentence)@type(XYZ)]]");

            // invalid lib-function annotation
            TryInvalid("select * from SentenceEvent[SplitSentence(sentence)@dummy(WordEvent)]",
                       "Invalid annotation for property selection, expected 'type' but found 'dummy' in text '@dummy(WordEvent)'");

            // invalid type assignment to event type
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                TryInvalid("select * from SentenceEvent[InvalidSentence(sentence)@type(WordEvent)]",
                           "Event type 'WordEvent' underlying type System.Object[] cannot be assigned a value of type");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                TryInvalid("select * from SentenceEvent[InvalidSentence(sentence)@type(WordEvent)]",
                           "Event type 'WordEvent' underlying type " + Name.Of <IDictionary <string, object> >() + " cannot be assigned a value of type");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                TryInvalid("select * from SentenceEvent[InvalidSentence(sentence)@Type(WordEvent)]",
                           "Event type 'WordEvent' underlying type " + AvroConstantsNoDep.GENERIC_RECORD_CLASSNAME + " cannot be assigned a value of type");
            }
            else
            {
                Assert.Fail();
            }

            // invalid subquery
            TryInvalid("select * from SentenceEvent[SplitSentence((select * from SupportBean#keepall))@type(WordEvent)]",
                       "Invalid contained-event expression 'SplitSentence(subselect_0)': Aggregation, sub-select, previous or prior functions are not supported in this context [select * from SentenceEvent[SplitSentence((select * from SupportBean#keepall))@type(WordEvent)]]");

            _epService.Initialize();
        }
        private void RunAssertionStaggered(EventRepresentationChoice outputType)
        {
            var fieldsOne = new string[] { "a1", "b1" };
            var fieldsTwo = new string[] { "a2", "b2" };

            // create window one
            var stmtTextCreateOne = outputType.GetAnnotationText() + " create window MyWindowOne#keepall as select theString as a1, intPrimitive as b1 from " + typeof(SupportBean).FullName;
            var stmtCreateOne     = _epService.EPAdministrator.CreateEPL(stmtTextCreateOne);

            stmtCreateOne.AddListener(_listenerWindow);
            Assert.AreEqual(0, GetCount("MyWindowOne"));
            Assert.IsTrue(outputType.MatchesClass(stmtCreateOne.EventType.UnderlyingType));

            // create window two
            var stmtTextCreateTwo = outputType.GetAnnotationText() + " create window MyWindowTwo#keepall as select theString as a2, intPrimitive as b2 from " + typeof(SupportBean).FullName;
            var stmtCreateTwo     = _epService.EPAdministrator.CreateEPL(stmtTextCreateTwo);

            stmtCreateTwo.AddListener(_listenerWindowTwo);
            Assert.AreEqual(0, GetCount("MyWindowTwo"));
            Assert.IsTrue(outputType.MatchesClass(stmtCreateTwo.EventType.UnderlyingType));

            // create delete stmt
            var stmtTextDelete = "on MyWindowOne delete from MyWindowTwo where a1 = a2";
            var stmtDelete     = _epService.EPAdministrator.CreateEPL(stmtTextDelete);

            stmtDelete.AddListener(_listenerDelete);
            Assert.AreEqual(StatementType.ON_DELETE, ((EPStatementSPI)stmtDelete).StatementMetadata.StatementType);

            // create insert into
            var stmtTextInsert = "insert into MyWindowOne select theString as a1, intPrimitive as b1 from " + typeof(SupportBean).FullName + "(intPrimitive > 0)";

            _epService.EPAdministrator.CreateEPL(stmtTextInsert);
            stmtTextInsert = "insert into MyWindowTwo select theString as a2, intPrimitive as b2 from " + typeof(SupportBean).FullName + "(intPrimitive < 0)";
            _epService.EPAdministrator.CreateEPL(stmtTextInsert);

            SendSupportBean("E1", -10);
            EPAssertionUtil.AssertProps(_listenerWindowTwo.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "E1", -10 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 } });
            Assert.IsFalse(_listenerWindow.IsInvoked);
            Assert.AreEqual(1, GetCount("MyWindowTwo"));

            SendSupportBean("E2", 5);
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fieldsOne, new object[] { "E2", 5 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsOne, new object[][] { new object[] { "E2", 5 } });
            Assert.IsFalse(_listenerWindowTwo.IsInvoked);
            Assert.AreEqual(1, GetCount("MyWindowOne"));

            SendSupportBean("E3", -1);
            EPAssertionUtil.AssertProps(_listenerWindowTwo.AssertOneGetNewAndReset(), fieldsTwo, new object[] { "E3", -1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 }, new object[] { "E3", -1 } });
            Assert.IsFalse(_listenerWindow.IsInvoked);
            Assert.AreEqual(2, GetCount("MyWindowTwo"));

            SendSupportBean("E3", 1);
            EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fieldsOne, new object[] { "E3", 1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsOne, new object[][] { new object[] { "E2", 5 }, new object[] { "E3", 1 } });
            EPAssertionUtil.AssertProps(_listenerWindowTwo.AssertOneGetOldAndReset(), fieldsTwo, new object[] { "E3", -1 });
            EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsTwo, new object[][] { new object[] { "E1", -10 } });
            Assert.AreEqual(2, GetCount("MyWindowOne"));
            Assert.AreEqual(1, GetCount("MyWindowTwo"));

            stmtDelete.Dispose();
            stmtCreateOne.Dispose();
            stmtCreateTwo.Dispose();
            _listenerDelete.Reset();
            _listenerSelect.Reset();
            _listenerWindow.Reset();
            _listenerWindowTwo.Reset();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindowOne", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindowTwo", true);
        }
Exemple #28
0
        private void TryAssertionNestableMapArray(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            var stmtInner = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyInnerType as (inn1 string[], inn2 int[])");
            var inner     = stmtInner.EventType;

            Assert.AreEqual(typeof(string[]), inner.GetPropertyType("inn1"));
            Assert.IsTrue(inner.GetPropertyDescriptor("inn1").IsIndexed);
            Assert.AreEqual(typeof(int[]), inner.GetPropertyType("inn2"));
            Assert.IsTrue(inner.GetPropertyDescriptor("inn2").IsIndexed);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(inner.UnderlyingType));

            var stmtOuter = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyOuterType as (col1 MyInnerType, col2 MyInnerType[])");
            var type      = stmtOuter.EventType.GetFragmentType("col1");

            Assert.AreEqual("MyInnerType", type.FragmentType.Name);
            Assert.IsFalse(type.IsIndexed);
            Assert.IsFalse(type.IsNative);
            type = stmtOuter.EventType.GetFragmentType("col2");
            Assert.AreEqual("MyInnerType", type.FragmentType.Name);
            Assert.IsTrue(type.IsIndexed);
            Assert.IsFalse(type.IsNative);

            var stmtSelect = epService.EPAdministrator.CreateEPL("select * from MyOuterType");
            var listener   = new SupportUpdateListener();

            stmtSelect.Events += listener.Update;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtSelect.EventType.UnderlyingType));

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                var innerData = new object[] { "abc,def".Split(','), new int[] { 1, 2 } };
                var outerData = new object[] { innerData, new object[] { innerData, innerData } };
                epService.EPRuntime.SendEvent(outerData, "MyOuterType");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                var innerData = new Dictionary <string, object>();
                innerData.Put("inn1", "abc,def".Split(','));
                innerData.Put("inn2", new int[] { 1, 2 });
                var outerData = new Dictionary <string, object>();
                outerData.Put("col1", innerData);
                outerData.Put("col2", new Map[] { innerData, innerData });
                epService.EPRuntime.SendEvent(outerData, "MyOuterType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var innerData = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "MyInnerType").AsRecordSchema());
                innerData.Put("inn1", Collections.List("abc", "def"));
                innerData.Put("inn2", Collections.List(1, 2));
                var outerData = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "MyOuterType").AsRecordSchema());
                outerData.Put("col1", innerData);
                outerData.Put("col2", Collections.List(innerData, innerData));
                epService.EPRuntime.SendEventAvro(outerData, "MyOuterType");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "col1.inn1[1],col2[1].inn2[1]".Split(','), new object[] { "def", 2 });

            epService.EPAdministrator.Configuration.RemoveEventType("MyInnerType", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyOuterType", true);
            epService.EPAdministrator.DestroyAllStatements();
        }
Exemple #29
0
        private void TryAssertionColDefPlain(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            var stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string, col2 int, col3_col4 int)");

            AssertTypeColDef(stmtCreate.EventType);
            var stmtSelect = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");

            AssertTypeColDef(stmtSelect.EventType);

            stmtSelect.Dispose();
            stmtCreate.Dispose();

            // destroy and create differently
            stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col3 string, col4 int)");
            Assert.AreEqual(typeof(int?), stmtCreate.EventType.GetPropertyType("col4").GetBoxedType());
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);

            stmtCreate.Stop();

            // destroy and create differently
            stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col5 string, col6 int)");
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreate.EventType.UnderlyingType));
            Assert.AreEqual(typeof(int?), stmtCreate.EventType.GetPropertyType("col6").GetBoxedType());
            Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count);
            stmtSelect = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType");
            var listener = new SupportUpdateListener();

            stmtSelect.Events += listener.Update;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtSelect.EventType.UnderlyingType));

            // send event
            if (eventRepresentationEnum.IsMapEvent())
            {
                var data = new LinkedHashMap <string, object>();
                data.Put("col5", "abc");
                data.Put("col6", 1);
                epService.EPRuntime.SendEvent(data, "MyEventType");
            }
            else if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "abc", 1 }, "MyEventType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var schema = (RecordSchema)((AvroSchemaEventType)epService.EPAdministrator.Configuration.GetEventType("MyEventType")).Schema;
                var @event = new GenericRecord(schema);
                @event.Put("col5", "abc");
                @event.Put("col6", 1);
                epService.EPRuntime.SendEventAvro(@event, "MyEventType");
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "col5,col6".Split(','), new object[] { "abc", 1 });

            // assert type information
            var typeSPI = (EventTypeSPI)stmtSelect.EventType;

            Assert.AreEqual(TypeClass.APPLICATION, typeSPI.Metadata.TypeClass);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PublicName);
            Assert.IsTrue(typeSPI.Metadata.IsApplicationConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfigured);
            Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfiguredStatic);
            Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PrimaryName);

            // test non-enum create-schema
            var epl           = "create" + eventRepresentationEnum.GetOutputTypeCreateSchemaName() + " schema MyEventTypeTwo as (col1 string, col2 int, col3_col4 int)";
            var stmtCreateTwo = epService.EPAdministrator.CreateEPL(epl);

            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateTwo.EventType.UnderlyingType));
            stmtCreateTwo.Dispose();
            epService.EPAdministrator.Configuration.RemoveEventType("MyEventTypeTwo", true);

            var model = epService.EPAdministrator.CompileEPL(epl);

            Assert.AreEqual(model.ToEPL(), epl);
            stmtCreateTwo = epService.EPAdministrator.Create(model);
            AssertTypeColDef(stmtCreateTwo.EventType);
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateTwo.EventType.UnderlyingType));

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "MyEventType,MyEventTypeTwo".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemple #30
0
        private void TryAssertionSchemaCopyProperties(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseOne (prop1 string, prop2 int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseTwo (prop3 long)");

            // test define and send
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E1 () copyfrom BaseOne");
            var stmtOne  = epService.EPAdministrator.CreateEPL("select * from E1");
            var listener = new SupportUpdateListener();

            stmtOne.Events += listener.Update;
            Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtOne.EventType.UnderlyingType));
            Assert.AreEqual(typeof(string), stmtOne.EventType.GetPropertyType("prop1"));
            Assert.AreEqual(typeof(int?), stmtOne.EventType.GetPropertyType("prop2").GetBoxedType());

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "v1", 2 }, "E1");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                IDictionary <string, object> @event = new LinkedHashMap <string, object>();
                @event.Put("prop1", "v1");
                @event.Put("prop2", 2);
                epService.EPRuntime.SendEvent(@event, "E1");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var @event = new GenericRecord(SchemaBuilder.Record("name",
                                                                    RequiredString("prop1"), RequiredInt("prop2")));
                @event.Put("prop1", "v1");
                @event.Put("prop2", 2);
                epService.EPRuntime.SendEventAvro(@event, "E1");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "prop1,prop2".Split(','), new object[] { "v1", 2 });

            // test two copy-from types
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E2 () copyfrom BaseOne, BaseTwo");
            var stmtTwo = epService.EPAdministrator.CreateEPL("select * from E2");

            Assert.AreEqual(typeof(string), stmtTwo.EventType.GetPropertyType("prop1"));
            Assert.AreEqual(typeof(int?), stmtTwo.EventType.GetPropertyType("prop2").GetBoxedType());
            Assert.AreEqual(typeof(long?), stmtTwo.EventType.GetPropertyType("prop3").GetBoxedType());

            // test API-defined type
            if (eventRepresentationEnum.IsMapEvent() ||
                eventRepresentationEnum.IsObjectArrayEvent())
            {
                var def = new Dictionary <string, object>();
                def.Put("a", "string");
                def.Put("b", typeof(string));
                def.Put("c", "BaseOne");
                def.Put("d", "BaseTwo[]");
                epService.EPAdministrator.Configuration.AddEventType("MyType", def);
            }
            else
            {
                epService.EPAdministrator.CreateEPL("create avro schema MyType(a string, b string, c BaseOne, d BaseTwo[])");
            }

            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema E3(e long, f BaseOne) copyfrom MyType");
            var stmtThree = epService.EPAdministrator.CreateEPL("select * from E3");

            Assert.AreEqual(typeof(string), stmtThree.EventType.GetPropertyType("a"));
            Assert.AreEqual(typeof(string), stmtThree.EventType.GetPropertyType("b"));
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                Assert.AreEqual(typeof(object[]), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(object[][]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(object[]), stmtThree.EventType.GetPropertyType("f"));
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                Assert.AreEqual(typeof(Map), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(Map[]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(Map), stmtThree.EventType.GetPropertyType("f"));
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                Assert.AreEqual(typeof(GenericRecord), stmtThree.EventType.GetPropertyType("c"));
                Assert.AreEqual(typeof(GenericRecord[]), stmtThree.EventType.GetPropertyType("d"));
                Assert.AreEqual(typeof(GenericRecord), stmtThree.EventType.GetPropertyType("f"));
            }
            else
            {
                Assert.Fail();
            }
            Assert.AreEqual(typeof(long?), stmtThree.EventType.GetPropertyType("e").GetBoxedType());

            // invalid tests
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4(a long) copyFrom MyType",
                       "Error starting statement: Type by name 'MyType' contributes property 'a' defined as 'System.String' which overides the same property of type '" + Name.Clean <long>(false) + "' [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4(c BaseTwo) copyFrom MyType",
                       "Error starting statement: Property by name 'c' is defined twice by adding type 'MyType' [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4(c BaseTwo) copyFrom XYZ",
                       "Error starting statement: Type by name 'XYZ' could not be located [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema E4 as " + typeof(SupportBean).FullName + " copyFrom XYZ",
                       "Error starting statement: Copy-from types are not allowed with class-provided types [");
            TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create variant schema E4(c BaseTwo) copyFrom XYZ",
                       "Error starting statement: Copy-from types are not allowed with variant types [");

            // test SODA
            var createEPL = eventRepresentationEnum.GetAnnotationText() + " create schema EX as () copyFrom BaseOne, BaseTwo";
            var model     = epService.EPAdministrator.CompileEPL(createEPL);

            Assert.AreEqual(createEPL.Trim(), model.ToEPL());
            var stmt = epService.EPAdministrator.Create(model);

            Assert.AreEqual(createEPL.Trim(), stmt.Text);

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "BaseOne,BaseTwo,E1,E2,E3,MyType".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }