public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy(representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedNested>() + "create schema Nested(p0 string, p1 int)", path);
                env.CompileDeploy(representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedOuterType>() + "create schema OuterType(n0 Nested)", path);

                var fields = new[] {"n0.p0", "n0.p1"};
                env.CompileDeploy(
                        "@Name('out') " +
                        "expression computeNested {\n" +
                        "  sb -> case\n" +
                        "  when IntPrimitive = 1 \n" +
                        "    then new { p0 = 'a', p1 = 1}\n" +
                        "  else new { p0 = 'b', p1 = 2 }\n" +
                        "  end\n" +
                        "}\n" +
                        "insert into OuterType select computeNested(sb) as n0 from SupportBean as sb",
                        path)
                    .AddListener("out");

                env.SendEventBean(new SupportBean("E1", 2));
                EPAssertionUtil.AssertProps(
                    env.Listener("out").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"b", 2});

                env.SendEventBean(new SupportBean("E2", 1));
                EPAssertionUtil.AssertProps(
                    env.Listener("out").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"a", 1});

                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();
            }
Exemple #3
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();
        }
            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");
            }
        private static void TryAssertionSplitPremptiveNamedWindow(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType(
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTrigger>() + " create schema TypeTrigger(trigger int)",
                path);
            env.CompileDeploy(eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTypeTwo>() + " create schema TypeTwo(col2 int)", path);
            env.CompileDeploy(
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTypeTwo>() + " create window WinTwo#keepall as TypeTwo",
                path);

            var stmtOrigText = "on TypeTrigger " +
                               "insert into OtherStream select 1 " +
                               "insert into WinTwo(col2) select 2 " +
                               "output all";
            env.CompileDeploy(stmtOrigText, path);

            env.CompileDeploy("@Name('s0') on OtherStream select col2 from WinTwo", path).AddListener("s0");

            // populate WinOne
            env.SendEventBean(new SupportBean("E1", 2));

            // fire trigger
            if (eventRepresentationEnum.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {null}, "TypeTrigger");
            }
            else if (eventRepresentationEnum.IsMapEvent()) {
                env.SendEventMap(new Dictionary<string, object>(), "TypeTrigger");
            }
            else if (eventRepresentationEnum.IsAvroEvent()) {
                var @event = new GenericRecord(
                    SchemaBuilder.Record("name", TypeBuilder.OptionalInt("trigger")));
                env.SendEventAvro(@event, "TypeTrigger");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                env.SendEventJson("{}", "TypeTrigger");
            }
            else {
                Assert.Fail();
            }

            Assert.AreEqual(2, env.Listener("s0").AssertOneGetNewAndReset().Get("col2"));

            env.UndeployAll();
        }
Exemple #6
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();
            }
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();
            }
Exemple #8
0
        private static void RunAssertPopulateFromNamedWindow(
            RegressionEnvironment env,
            EventRepresentationChoice type)
        {
            var path = new RegressionPath();
            var schemaEPL = type.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedNode>() + "create schema Node(nid string)";
            env.CompileDeployWBusPublicType(schemaEPL, path);

            env.CompileDeploy("create window NodeWindow#unique(nid) as Node", path);
            env.CompileDeploy("insert into NodeWindow select * from Node", path);
            env.CompileDeploy(
                type.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedNodePlus>() + "create schema NodePlus(npid string, node Node)",
                path);
            env.CompileDeploy("@Name('s0') insert into NodePlus select 'E1' as npid, n1 as node from NodeWindow n1", path).AddListener("s0");

            if (type.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {"n1"}, "Node");
            }
            else if (type.IsMapEvent()) {
                env.SendEventMap(Collections.SingletonDataMap("nid", "n1"), "Node");
            }
            else if (type.IsAvroEvent()) {
                var genericRecord = new GenericRecord(SchemaBuilder.Record("name", RequiredString("nid")));
                genericRecord.Put("nid", "n1");
                env.SendEventAvro(genericRecord, "Node");
            }
            else if (type.IsJsonEvent() || type.IsJsonProvidedClassEvent()) {
                var @object = new JObject();
                @object.Add("nid", "n1");
                env.SendEventJson(@object.ToString(), "Node");
            }
            else {
                Assert.Fail();
            }

            var @event = env.Listener("s0").AssertOneGetNewAndReset();
            Assert.AreEqual("E1", @event.Get("npid"));
            Assert.AreEqual("n1", @event.Get("node.nid"));
            var fragment = (EventBean) @event.GetFragment("node");
            Assert.AreEqual("Node", fragment.EventType.Name);

            env.UndeployAll();
        }
            private static void RunTransposeMapAndObjectArray(
                RegressionEnvironment env,
                EventRepresentationChoice representation)
            {
                var fields = new[] {"p0", "p1"};
                var path = new RegressionPath();
                var schema = representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMySchema>() + "create schema MySchema(p0 string, p1 int)";
                env.CompileDeployWBusPublicType(schema, path);

                string generateFunction;
                if (representation.IsObjectArrayEvent()) {
                    generateFunction = "GenerateOA";
                }
                else if (representation.IsMapEvent()) {
                    generateFunction = "GenerateMap";
                }
                else if (representation.IsAvroEvent()) {
                    generateFunction = "GenerateAvro";
                }
                else if (representation.IsJsonEvent() || representation.IsJsonProvidedClassEvent()) {
                    generateFunction = "GenerateJson";
                }
                else {
                    throw new IllegalStateException("Unrecognized code " + representation);
                }

                var epl = "insert into MySchema select transpose(" +
                          generateFunction +
                          "(TheString, IntPrimitive)) from SupportBean";
                env.CompileDeploy("@Name('s0') " + epl, path).AddListener("s0");

                env.SendEventBean(new SupportBean("E1", 1));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E1", 1});

                env.SendEventBean(new SupportBean("E2", 2));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E2", 2});

                // MySchema already exists, start second statement
                env.CompileDeploy("@Name('s1') " + epl, path).AddListener("s1");
                env.UndeployModuleContaining("s0");

                env.SendEventBean(new SupportBean("E3", 3));
                EPAssertionUtil.AssertProps(
                    env.Listener("s1").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"E3", 3});

                env.UndeployAll();
            }
Exemple #10
0
        private static void RunAssertionCreateStream(
            RegressionEnvironment env,
            EventRepresentationChoice representation)
        {
            var epl = representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() +
                      " create schema MyEvent(myId int);\n" +
                      representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedCompositeEvent>() +
                      " create schema CompositeEvent(c1 MyEvent, c2 MyEvent, rule string);\n" +
                      "insert into MyStream select c, 'additionalValue' as value from MyEvent c;\n" +
                      "insert into CompositeEvent select e1.c as c1, e2.c as c2, '4' as rule " +
                      "  from pattern [e1=MyStream -> e2=MyStream];\n" +
                      representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedCompositeEvent>() +
                      " @Name('Target') select * from CompositeEvent;\n";
            env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("Target");

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

            var theEvent = env.Listener("Target").AssertOneGetNewAndReset();
            Assert.AreEqual(10, theEvent.Get("c1.myId"));
            Assert.AreEqual(11, theEvent.Get("c2.myId"));
            Assert.AreEqual("4", theEvent.Get("rule"));

            env.UndeployAll();
        }
Exemple #11
0
        private void RunAssertionCreateSchemaWTypes<T>(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum,
            string typeOfDatetimeProp,
            object startA,
            object endA,
            object startB,
            object endB)
        {
            var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<T>() + " create schema TypeA as (startts " + typeOfDatetimeProp + ", endts " + typeOfDatetimeProp + ") starttimestamp startts endtimestamp endts;\n";
            epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<T>() + " create schema TypeB as (startts " + typeOfDatetimeProp + ", endts " + typeOfDatetimeProp + ") starttimestamp startts endtimestamp endts;\n";
            epl += "@Name('s0') select a.includes(b) as val0 from TypeA#lastevent as a, TypeB#lastevent as b;\n";
            env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("s0");

            MakeSendEvent(env, "TypeA", eventRepresentationEnum, startA, endA);
            MakeSendEvent(env, "TypeB", eventRepresentationEnum, startB, endB);
            Assert.AreEqual(true, env.Listener("s0").AssertOneGetNewAndReset().Get("val0"));

            env.UndeployAll();
        }
Exemple #12
0
            private void TryAssertionCreateSchemaModelAfter(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                var epl =
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedEventTypeOne>() +
                    " create schema EventTypeOne (hsi int);\n" +
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedEventTypeTwo>() +
                    " create schema EventTypeTwo (event EventTypeOne);\n" +
                    "@Name('create') create window NamedWindow#unique(event.hsi) as EventTypeTwo;\n" +
                    "on EventTypeOne as ev insert into NamedWindow select ev as event;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath());

                if (eventRepresentationEnum.IsObjectArrayEvent()) {
                    env.SendEventObjectArray(new object[] {10}, "EventTypeOne");
                }
                else if (eventRepresentationEnum.IsMapEvent()) {
                    env.SendEventMap(Collections.SingletonDataMap("hsi", 10), "EventTypeOne");
                }
                else if (eventRepresentationEnum.IsAvroEvent()) {
                    var theEvent = new GenericRecord(
                        SupportAvroUtil
                            .GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("EventTypeOne"))
                            .AsRecordSchema());
                    theEvent.Put("hsi", 10);
                    env.EventService.SendEventAvro(theEvent, "EventTypeOne");
                }
                else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                    env.EventService.SendEventJson("{\"hsi\": 10}", "EventTypeOne");
                }
                else {
                    Assert.Fail();
                }

                var result = env.Statement("create").First();
                var getter = result.EventType.GetGetter("event.hsi");
                Assert.AreEqual(10, getter.Get(result));

                env.UndeployAll();
            }
Exemple #13
0
        private static void TryAssertionStreamInsertWWidenMap(
            RegressionEnvironment env,
            EventRepresentationChoice rep)
        {
            RegressionPath path = new RegressionPath();
            string schemaSrc = rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSrc>() +
                               "@Name('schema') create schema Src as (myint int, mystr string)";
            env.CompileDeployWBusPublicType(schemaSrc, path);

            env.CompileDeploy(
                rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedD1>() + "create schema D1 as (myint int, mystr string, addprop long)",
                path);
            string eplOne = "insert into D1 select 1 as addprop, mysrc.* from Src as mysrc";
            RunStreamInsertAssertion(env, path, rep, eplOne, "myint,mystr,addprop", new object[] {123, "abc", 1L});

            env.CompileDeploy(
                rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedD2>() + "create schema D2 as (mystr string, myint int, addprop double)",
                path);
            string eplTwo = "insert into D2 select 1 as addprop, mysrc.* from Src as mysrc";
            RunStreamInsertAssertion(env, path, rep, eplTwo, "myint,mystr,addprop", new object[] {123, "abc", 1d});

            env.CompileDeploy(rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedD3>() + "create schema D3 as (mystr string, addprop int)", path);
            string eplThree = "insert into D3 select 1 as addprop, mysrc.* from Src as mysrc";
            RunStreamInsertAssertion(env, path, rep, eplThree, "mystr,addprop", new object[] {"abc", 1});

            env.CompileDeploy(rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedD4>() + "create schema D4 as (myint int, mystr string)", path);
            string eplFour = "insert into D4 select mysrc.* from Src as mysrc";
            RunStreamInsertAssertion(env, path, rep, eplFour, "myint,mystr", new object[] {123, "abc"});

            string eplFive = "insert into D4 select mysrc.*, 999 as myint, 'xxx' as mystr from Src as mysrc";
            RunStreamInsertAssertion(env, path, rep, eplFive, "myint,mystr", new object[] {999, "xxx"});
            string eplSix = "insert into D4 select 999 as myint, 'xxx' as mystr, mysrc.* from Src as mysrc";
            RunStreamInsertAssertion(env, path, rep, eplSix, "myint,mystr", new object[] {999, "xxx"});

            env.UndeployAll();
        }
Exemple #14
0
        private static void TryAssertionInvalid(
            RegressionEnvironment env,
            EventRepresentationChoice rep)
        {
            RegressionPath path = new RegressionPath();
            env.CompileDeploy(rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSrc>() + "create schema Src as (myint int, mystr string)", path);

            // mismatch in type
            env.CompileDeploy(rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedE1>() + "create schema E1 as (myint long)", path);
            string message = !rep.IsAvroEvent()
                ? "Type by name 'E1' in property 'myint' expected System.Nullable<System.Int32> but receives System.Nullable<System.Int64>"
                : "Type by name 'E1' in property 'myint' expected schema '{\"type\":\"long\"}' but received schema '{\"type\":\"int\"}'";
            SupportMessageAssertUtil.TryInvalidCompile(env, path, "insert into E1 select mysrc.* from Src as mysrc", message);

            // mismatch in column name
            env.CompileDeploy(rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedE2>() + "create schema E2 as (someprop long)", path);
            SupportMessageAssertUtil.TryInvalidCompile(
                env,
                path,
                "insert into E2 select mysrc.*, 1 as otherprop from Src as mysrc",
                "Failed to find column 'otherprop' in target type 'E2' [insert into E2 select mysrc.*, 1 as otherprop from Src as mysrc]");

            env.UndeployAll();
        }
Exemple #15
0
        private static void TryAssertionNewWRepresentation(
            RegressionEnvironment env,
            EventRepresentationChoice rep,
            AtomicLong milestone)
        {
            var epl = rep.GetAnnotationTextWJsonProvided <MyLocalJsonProvided>() +
                      "@Name('s0') select new { TheString = 'x' || TheString || 'x', IntPrimitive = IntPrimitive + 2} as val0 from SupportBean as sb";

            env.CompileDeploy(epl).AddListener("s0").Milestone(milestone.GetAndIncrement());

            Assert.AreEqual(
                rep.IsAvroEvent() ? typeof(GenericRecord) : typeof(IDictionary <string, object>),
                env.Statement("s0").EventType.GetPropertyType("val0"));
            var fragType = env.Statement("s0").EventType.GetFragmentType("val0");

            if (rep == EventRepresentationChoice.JSONCLASSPROVIDED)
            {
                Assert.IsNull(fragType);
            }
            else
            {
                Assert.IsFalse(fragType.IsIndexed);
                Assert.IsFalse(fragType.IsNative);
                Assert.AreEqual(typeof(string), fragType.FragmentType.GetPropertyType("TheString"));
                Assert.AreEqual(typeof(int?), Boxing.GetBoxedType(fragType.FragmentType.GetPropertyType("IntPrimitive")));
            }

            var fieldsInner = "TheString,IntPrimitive".SplitCsv();

            env.SendEventBean(new SupportBean("E1", -5));
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            if (rep.IsAvroEvent())
            {
                SupportAvroUtil.AvroToJson(@event);
                GenericRecord inner = (GenericRecord)@event.Get("val0");
                Assert.AreEqual("xE1x", inner.Get("TheString"));
                Assert.AreEqual(-3, inner.Get("IntPrimitive"));
            }
            else
            {
                EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)@event.Get("val0"), fieldsInner, "xE1x", -3);
            }

            env.UndeployAll();
        }
            private static void TryAssertionFullJoin_2sides_multicolumn(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum)
            {
                var fields = new[] {"S0.Id", " S0.P00", " S0.P01", " S1.Id", " S1.P10", " S1.P11", " S2.Id", " S2.P20", " S2.P21"};

                var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvided>() +
                          " @Name('s0') select * from " +
                          "SupportBean_S0#length(1000) as S0 " +
                          " full outer join SupportBean_S1#length(1000) as S1 on S0.P00 = S1.P10 and S0.P01 = S1.P11" +
                          " full outer join SupportBean_S2#length(1000) as S2 on S0.P00 = S2.P20 and S0.P01 = S2.P21";
                env.CompileDeployAddListenerMileZero(epl, "s0");

                env.SendEventBean(new SupportBean_S1(10, "A_1", "B_1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, 10, "A_1", "B_1", null, null, null});

                env.SendEventBean(new SupportBean_S1(11, "A_2", "B_1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, 11, "A_2", "B_1", null, null, null});

                env.SendEventBean(new SupportBean_S1(12, "A_1", "B_2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, 12, "A_1", "B_2", null, null, null});

                env.SendEventBean(new SupportBean_S1(13, "A_2", "B_2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, 13, "A_2", "B_2", null, null, null});

                env.SendEventBean(new SupportBean_S2(20, "A_1", "B_1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, null, null, null, 20, "A_1", "B_1"});

                env.SendEventBean(new SupportBean_S2(21, "A_2", "B_1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, null, null, null, 21, "A_2", "B_1"});

                env.SendEventBean(new SupportBean_S2(22, "A_1", "B_2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, null, null, null, 22, "A_1", "B_2"});

                env.SendEventBean(new SupportBean_S2(23, "A_2", "B_2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, null, null, null, 23, "A_2", "B_2"});

                env.SendEventBean(new SupportBean_S0(1, "A_3", "B_3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {1, "A_3", "B_3", null, null, null, null, null, null});

                env.SendEventBean(new SupportBean_S0(2, "A_1", "B_3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {2, "A_1", "B_3", null, null, null, null, null, null});

                env.SendEventBean(new SupportBean_S0(3, "A_3", "B_1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {3, "A_3", "B_1", null, null, null, null, null, null});

                env.SendEventBean(new SupportBean_S0(4, "A_2", "B_2"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {4, "A_2", "B_2", 13, "A_2", "B_2", 23, "A_2", "B_2"});

                env.SendEventBean(new SupportBean_S0(5, "A_2", "B_1"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {5, "A_2", "B_1", 11, "A_2", "B_1", 21, "A_2", "B_1"});

                env.SendEventBean(new SupportBean_S1(14, "A_4", "B_3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, 14, "A_4", "B_3", null, null, null});

                env.SendEventBean(new SupportBean_S1(15, "A_1", "B_3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {2, "A_1", "B_3", 15, "A_1", "B_3", null, null, null});

                env.SendEventBean(new SupportBean_S2(24, "A_1", "B_3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {2, "A_1", "B_3", 15, "A_1", "B_3", 24, "A_1", "B_3"});

                env.SendEventBean(new SupportBean_S2(25, "A_2", "B_3"));
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {null, null, null, null, null, null, 25, "A_2", "B_3"});

                env.UndeployAll();
            }
        private static void TryAssertionDocExample(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            var baseModuleEPL = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedOrderEvent>() +
                                " create schema OrderEvent as (OrderId string, ProductId string, Price double, Quantity int, DeletedFlag boolean)";
            env.CompileDeployWBusPublicType(baseModuleEPL, path);

            var appModuleOne = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedProductTotalRec>() +
                               " create schema ProductTotalRec as (ProductId string, TotalPrice double);" +
                               "" +
                               "@Name('nwProd') create window ProductWindow#unique(ProductId) as ProductTotalRec;" +
                               "" +
                               "on OrderEvent oe\n" +
                               "merge ProductWindow pw\n" +
                               "where pw.ProductId = oe.ProductId\n" +
                               "when matched\n" +
                               "then update set TotalPrice = TotalPrice + oe.Price\n" +
                               "when not matched\n" +
                               "then insert select ProductId, Price as TotalPrice;";
            env.CompileDeploy(appModuleOne, path);

            var appModuleTwo =
                " @Name('nwOrd') create window OrderWindow#keepall as OrderEvent;" +
                "" +
                "on OrderEvent oe\n" +
                "  merge OrderWindow pw\n" +
                "  where pw.OrderId = oe.OrderId\n" +
                "  when not matched \n" +
                "    then insert select *\n" +
                "  when matched and oe.DeletedFlag=true\n" +
                "    then delete\n" +
                "  when matched\n" +
                "    then update set pw.Quantity = oe.Quantity, pw.Price = oe.Price";

            env.CompileDeploy(appModuleTwo, path);

            SendOrderEvent(env, eventRepresentationEnum, "O1", "P1", 10, 100, false);
            SendOrderEvent(env, eventRepresentationEnum, "O1", "P1", 11, 200, false);
            SendOrderEvent(env, eventRepresentationEnum, "O2", "P2", 3, 300, false);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.Statement("nwProd").GetEnumerator(),
                new[] {"ProductId", "TotalPrice"},
                new[] {new object[] {"P1", 21d}, new object[] {"P2", 3d}});
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.Statement("nwOrd").GetEnumerator(),
                new[] {"OrderId", "Quantity"},
                new[] {new object[] {"O1", 200}, new object[] {"O2", 300}});

            var module = "create schema StreetCarCountSchema (streetId string, carcount int);" +
                         "    create schema StreetChangeEvent (streetId string, action string);" +
                         "    create window StreetCarCountWindow#unique(streetId) as StreetCarCountSchema;" +
                         "    on StreetChangeEvent ce merge StreetCarCountWindow w where ce.streetId = w.streetId\n" +
                         "    when not matched and ce.action = 'ENTER' then insert select streetId, 1 as carcount\n" +
                         "    when matched and ce.action = 'ENTER' then update set StreetCarCountWindow.carcount = carcount + 1\n" +
                         "    when matched and ce.action = 'LEAVE' then update set StreetCarCountWindow.carcount = carcount - 1;" +
                         "    select * from StreetCarCountWindow;";
            env.CompileDeploy(module, path);

            env.UndeployAll();
        }
        private static void TryAssertionSubselect(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var fields = new[] {"col1", "col2"};
            var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() +
                      " create schema MyEvent as (in1 string, in2 int);\n";
            epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMySchema>() +
                   " create schema MySchema as (col1 string, col2 int);\n";
            epl += "@Name('create') create window MyWindowSS#lastevent as MySchema;\n";
            epl += "on SupportBean_A delete from MyWindowSS;\n";
            epl += "on MyEvent me " +
                   "merge MyWindowSS mw " +
                   "when not matched and (select IntPrimitive>0 from SupportBean(TheString like 'A%')#lastevent) then " +
                   "insert(col1, col2) select (select TheString from SupportBean(TheString like 'A%')#lastevent), (select IntPrimitive from SupportBean(TheString like 'A%')#lastevent) " +
                   "when matched and (select IntPrimitive>0 from SupportBean(TheString like 'B%')#lastevent) then " +
                   "update set col1=(select TheString from SupportBean(TheString like 'B%')#lastevent), col2=(select IntPrimitive from SupportBean(TheString like 'B%')#lastevent) " +
                   "when matched and (select IntPrimitive>0 from SupportBean(TheString like 'C%')#lastevent) then " +
                   "delete;\n";
            env.CompileDeployWBusPublicType(epl, new RegressionPath());

            // no action tests
            SendMyEvent(env, eventRepresentationEnum, "X1", 1);
            env.SendEventBean(new SupportBean("A1", 0)); // ignored
            SendMyEvent(env, eventRepresentationEnum, "X2", 2);
            env.SendEventBean(new SupportBean("A2", 20));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(env.GetEnumerator("create"), fields, null);

            SendMyEvent(env, eventRepresentationEnum, "X3", 3);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"A2", 20}});

            env.SendEventBean(new SupportBean_A("Y1"));
            env.SendEventBean(new SupportBean("A3", 30));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(env.GetEnumerator("create"), fields, null);

            SendMyEvent(env, eventRepresentationEnum, "X4", 4);
            env.SendEventBean(new SupportBean("A4", 40));
            SendMyEvent(env, eventRepresentationEnum, "X5", 5); // ignored as matched (no where clause, no B event)
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"A3", 30}});

            env.SendEventBean(new SupportBean("B1", 50));
            SendMyEvent(env, eventRepresentationEnum, "X6", 6);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"B1", 50}});

            env.SendEventBean(new SupportBean("B2", 60));
            SendMyEvent(env, eventRepresentationEnum, "X7", 7);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"B2", 60}});

            env.SendEventBean(new SupportBean("B2", 0));
            SendMyEvent(env, eventRepresentationEnum, "X8", 8);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"B2", 60}});

            env.SendEventBean(new SupportBean("C1", 1));
            SendMyEvent(env, eventRepresentationEnum, "X9", 9);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(env.GetEnumerator("create"), fields, null);

            env.SendEventBean(new SupportBean("C1", 0));
            SendMyEvent(env, eventRepresentationEnum, "X10", 10);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(
                env.GetEnumerator("create"),
                fields,
                new[] {new object[] {"A4", 40}});

            env.UndeployAll();
        }
        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();
        }
Exemple #21
0
        private static void TryAssertionVariantStream(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var eplSchemas =
                eventRepresentationEnum.GetAnnotationTextWJsonProvided <MyLocalJsonProvidedWKey>() +
                " create schema EventOne as (key string);\n" +
                eventRepresentationEnum.GetAnnotationTextWJsonProvided <MyLocalJsonProvidedWKey>() +
                " create schema EventTwo as (key string);\n" +
                " create schema S0 as " +
                typeof(SupportBean_S0).FullName +
                ";\n" +
                " create variant schema VarSchema as *;\n";
            var path = new RegressionPath();

            env.CompileDeployWBusPublicType(eplSchemas, path);

            env.CompileDeploy("insert into VarSchema select * from EventOne", path);
            env.CompileDeploy("insert into VarSchema select * from EventTwo", path);
            env.CompileDeploy("insert into VarSchema select * from S0", path);
            env.CompileDeploy("insert into VarSchema select * from SupportBean", path);

            var stmtText = "@Name('s0') select typeof(A) as t0 from VarSchema as A";

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

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                env.SendEventObjectArray(new object[] { "value" }, "EventOne");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                env.SendEventMap(Collections.SingletonDataMap("key", "value"), "EventOne");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var record = new GenericRecord(SchemaBuilder.Record("EventOne", RequiredString("key")));
                record.Put("key", "value");
                env.SendEventAvro(record, "EventOne");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent())
            {
                env.SendEventJson(new JObject(new JProperty("key", "value")).ToString(), "EventOne");
            }
            else
            {
                Assert.Fail();
            }

            Assert.AreEqual("EventOne", env.Listener("s0").AssertOneGetNewAndReset().Get("t0"));

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                env.SendEventObjectArray(new object[] { "value" }, "EventTwo");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                env.SendEventMap(Collections.SingletonDataMap("key", "value"), "EventTwo");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var record = new GenericRecord(SchemaBuilder.Record("EventTwo", RequiredString("key")));
                record.Put("key", "value");
                env.SendEventAvro(record, "EventTwo");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent())
            {
                env.SendEventJson(new JObject(new JProperty("key", "value")).ToString(), "EventTwo");
            }
            else
            {
                Assert.Fail();
            }

            Assert.AreEqual("EventTwo", env.Listener("s0").AssertOneGetNewAndReset().Get("t0"));

            env.SendEventBean(new SupportBean_S0(1), "S0");
            Assert.AreEqual("S0", env.Listener("s0").AssertOneGetNewAndReset().Get("t0"));

            env.SendEventBean(new SupportBean());
            Assert.AreEqual("SupportBean", env.Listener("s0").AssertOneGetNewAndReset().Get("t0"));

            env.UndeployModuleContaining("s0");
            env.CompileDeploy(
                "@Name('s0') select * from VarSchema match_recognize(\n" +
                "  measures A as a, B as b\n" +
                "  pattern (A B)\n" +
                "  define A as typeof(A) = \"EventOne\",\n" +
                "         B as typeof(B) = \"EventTwo\"\n" +
                "  )",
                path)
            .AddListener("s0");

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                env.SendEventObjectArray(new object[] { "value" }, "EventOne");
                env.SendEventObjectArray(new object[] { "value" }, "EventTwo");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                env.SendEventMap(Collections.SingletonDataMap("key", "value"), "EventOne");
                env.SendEventMap(Collections.SingletonDataMap("key", "value"), "EventTwo");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var schema   = SchemaBuilder.Record("EventTwo", RequiredString("key"));
                var eventOne = new GenericRecord(schema);
                eventOne.Put("key", "value");
                var eventTwo = new GenericRecord(schema);
                eventTwo.Put("key", "value");
                env.SendEventAvro(eventOne, "EventOne");
                env.SendEventAvro(eventTwo, "EventTwo");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent())
            {
                env.SendEventJson(new JObject(new JProperty("key", "value")).ToString(), "EventOne");
                env.SendEventJson(new JObject(new JProperty("key", "value")).ToString(), "EventTwo");
            }
            else
            {
                Assert.Fail();
            }

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

            env.UndeployAll();
        }
Exemple #22
0
        private static void TryAssertionWildcard(
            RegressionEnvironment env,
            bool bean,
            EventRepresentationChoice rep)
        {
            var path = new RegressionPath();

            EPCompiled schemaCompiled;
            if (bean) {
                schemaCompiled = env.Compile(
                    "create schema MySchema as " + typeof(MyP0P1Event).Name,
                    options => {
                        options.BusModifierEventType = ctx => EventTypeBusModifier.BUS;
                        options.AccessModifierEventType = ctx => NameAccessModifier.PUBLIC;
                    });
            }
            else {
                schemaCompiled = env.Compile(
                    rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMySchema>() +
                    "create schema MySchema (P0 string, P1 string)",
                    options => {
                        options.SetBusModifierEventType(ctx => EventTypeBusModifier.BUS);
                        options.SetAccessModifierEventType(ctx => NameAccessModifier.PUBLIC);
                    });
            }

            path.Add(schemaCompiled);
            env.Deploy(schemaCompiled);

            env.CompileDeploy("@Name('create') create table TheTable (P0 string, P1 string)", path);
            env.CompileDeploy("insert into TheTable select * from MySchema", path);

            if (bean) {
                env.SendEventBean(new MyP0P1Event("a", "b"), "MySchema");
            }
            else if (rep.IsMapEvent()) {
                IDictionary<string, object> map = new Dictionary<string, object>();
                map.Put("P0", "a");
                map.Put("P1", "b");
                env.SendEventMap(map, "MySchema");
            }
            else if (rep.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {"a", "b"}, "MySchema");
            }
            else if (rep.IsAvroEvent()) {
                var theEvent = new GenericRecord(
                    SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("MySchema"))
                        .AsRecordSchema());
                theEvent.Put("P0", "a");
                theEvent.Put("P1", "b");
                env.EventService.SendEventAvro(theEvent, "MySchema");
            } else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                env.EventService.SendEventJson(
                    new JObject(
                        new JProperty("P0", "a"),
                        new JProperty("P1", "b")).ToString(),
                    "MySchema");
            } else {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(
                env.GetEnumerator("create").Advance(),
                new[] {"P0", "P1"},
                new object[] {"a", "b"});
            env.UndeployAll();
        }
            public void Run(RegressionEnvironment env)
            {
                string epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedStartValueEvent>() +
                             " create schema StartValueEvent as (dummy string);\n";
                epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTestForwardEvent>() +
                       " create schema TestForwardEvent as (prop1 string);\n";
                epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTestInputEvent>() +
                       " create schema TestInputEvent as (dummy string);\n";
                epl += "insert into TestForwardEvent select'V1' as prop1 from TestInputEvent;\n";
                epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedNamedWin>() +
                       " create window NamedWin#unique(prop1) (prop1 string, prop2 string);\n";
                epl += "insert into NamedWin select 'V1' as prop1, 'O1' as prop2 from StartValueEvent;\n";
                epl += "on TestForwardEvent update NamedWin as work set prop2 = 'U1' where work.prop1 = 'V1';\n";
                epl += "@Name('select') select irstream prop1, prop2 from NamedWin;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("select");

                var fields = new[] {"prop1", "prop2"};
                if (eventRepresentationEnum.IsObjectArrayEvent()) {
                    env.SendEventObjectArray(new object[] {"dummyValue"}, "StartValueEvent");
                }
                else if (eventRepresentationEnum.IsMapEvent()) {
                    env.SendEventMap(new Dictionary<string, object>(), "StartValueEvent");
                }
                else if (eventRepresentationEnum.IsAvroEvent()) {
                    env.EventService.SendEventAvro(
                        new GenericRecord(
                            SchemaBuilder.Record("soemthing")),
                        "StartValueEvent");
                }
                else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                    env.EventService.SendEventJson("{}", "StartValueEvent");
                }
                else {
                    Assert.Fail();
                }

                EPAssertionUtil.AssertProps(
                    env.Listener("select").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"V1", "O1"});

                if (eventRepresentationEnum.IsObjectArrayEvent()) {
                    env.SendEventObjectArray(new object[] {"dummyValue"}, "TestInputEvent");
                }
                else if (eventRepresentationEnum.IsMapEvent()) {
                    env.SendEventMap(new Dictionary<string, object>(), "TestInputEvent");
                }
                else if (eventRepresentationEnum.IsAvroEvent()) {
                    env.EventService.SendEventAvro(
                        new GenericRecord(
                            SchemaBuilder.Record("soemthing")),
                        "TestInputEvent");
                }
                else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
                    env.EventService.SendEventJson("{}", "TestInputEvent");
                }
                else {
                    Assert.Fail();
                }

                EPAssertionUtil.AssertProps(
                    env.Listener("select").LastOldData[0],
                    fields,
                    new object[] {"V1", "O1"});
                EPAssertionUtil.AssertProps(
                    env.Listener("select").GetAndResetLastNewData()[0],
                    fields,
                    new object[] {"V1", "U1"});
                env.UndeployAll();
            }
Exemple #24
0
            private static void TryAssertionScoringUseCase(
                RegressionEnvironment env,
                EventRepresentationChoice eventRepresentationEnum,
                AtomicLong milestone)
            {
                var fields = new[] {"UserId", "Keyword", "SumScore"};
                var epl =
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedScoreCycle>() +
                    "create schema ScoreCycle (UserId string, Keyword string, ProductId string, Score long);\n" +
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedUserKeywordTotalStream>() +
                    "create schema UserKeywordTotalStream (UserId string, Keyword string, SumScore long);\n" +
                    "\n" +
                    eventRepresentationEnum.GetAnnotationTextWJsonProvided(typeof(ExprCoreNewStruct.MyLocalJsonProvided)) +
                    " create context HashByUserCtx as " +
                    "coalesce by consistent_hash_crc32(UserId) from ScoreCycle, " +
                    "consistent_hash_crc32(UserId) from UserKeywordTotalStream " +
                    "granularity 1000000;\n" +
                    "\n" +
                    "context HashByUserCtx create window ScoreCycleWindow#unique(ProductId, Keyword) as ScoreCycle;\n" +
                    "\n" +
                    "context HashByUserCtx insert into ScoreCycleWindow select * from ScoreCycle;\n" +
                    "\n" +
                    "@Name('s0') context HashByUserCtx insert into UserKeywordTotalStream \n" +
                    "select UserId, Keyword, sum(Score) as SumScore from ScoreCycleWindow group by Keyword;\n" +
                    "\n" +
                    "@Name('outTwo') context HashByUserCtx on UserKeywordTotalStream(SumScore > 10000) delete from ScoreCycleWindow;\n";
                env.CompileDeployWBusPublicType(epl, new RegressionPath());
                env.AddListener("s0");

                MakeSendScoreEvent(env, "ScoreCycle", eventRepresentationEnum, "Pete", "K1", "P1", 100);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"Pete", "K1", 100L});

                MakeSendScoreEvent(env, "ScoreCycle", eventRepresentationEnum, "Pete", "K1", "P2", 15);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"Pete", "K1", 115L});

                MakeSendScoreEvent(env, "ScoreCycle", eventRepresentationEnum, "Joe", "K1", "P2", 30);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"Joe", "K1", 30L});

                MakeSendScoreEvent(env, "ScoreCycle", eventRepresentationEnum, "Joe", "K2", "P1", 40);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"Joe", "K2", 40L});

                MakeSendScoreEvent(env, "ScoreCycle", eventRepresentationEnum, "Joe", "K1", "P1", 20);
                EPAssertionUtil.AssertProps(
                    env.Listener("s0").AssertOneGetNewAndReset(),
                    fields,
                    new object[] {"Joe", "K1", 50L});

                env.UndeployAll();
            }
        private static void RunAssertionFields(
            RegressionEnvironment env,
            EventRepresentationChoice representationEnum,
            bool eventbean)
        {
            EPDataFlowInstantiationOptions options;

            var path = new RegressionPath();
            var streamType = eventbean ? "EventBean<MyEvent>" : "MyEvent";
            
            env.CompileDeploy(
                representationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() +
                "create schema MyEvent(p0 string, p1 long, p2 double)", path);
            
            env.CompileDeploy(
                "@Name('flow') create dataflow MyDataFlowOne " +
                "" +
                "BeaconSource -> BeaconStream<" + streamType + "> " +
                "{" +
                "  iterations : 3," +
                "  p0 : 'abc'," +
                "  p1 : cast(Math.Round(Randomizer.Random() * 10) + 1, long)," +
                "  p2 : 1d," +
                "}" +
                "DefaultSupportCaptureOp(BeaconStream) {}",
                path);

            var future = new DefaultSupportCaptureOp(3, env.Container.LockManager());
            options = new EPDataFlowInstantiationOptions()
                .WithOperatorProvider(new DefaultSupportGraphOpProvider(future));
            var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);
            df.Start();
            object[] output;
            try {
                output = future.GetValue(2, TimeUnit.SECONDS);
            }
            catch (Exception t) {
                throw new EPException(t);
            }

            Assert.AreEqual(3, output.Length);
            for (var i = 0; i < 3; i++) {
                if (!eventbean) {
                    if (representationEnum.IsObjectArrayEvent()) {
                        var row = (object[]) output[i];
                        Assert.AreEqual("abc", row[0]);
                        var val = row[1].AsInt64();
                        Assert.IsTrue(val >= 0 && val <= 11, "val=" + val);
                        Assert.AreEqual(1d, row[2]);
                    }
                    else if (representationEnum.IsMapEvent()) {
                        var row = (IDictionary<string, object>) output[i];
                        Assert.AreEqual("abc", row.Get("p0"));
                        var val = row.Get("p1").AsInt64();
                        Assert.IsTrue(val >= 0 && val <= 11, "val=" + val);
                        Assert.AreEqual(1d, row.Get("p2"));
                    }
                    else {
                        var row = (GenericRecord) output[i];
                        Assert.AreEqual("abc", row.Get("p0"));
                        var val = row.Get("p1").AsInt64();
                        Assert.IsTrue(val >= 0 && val <= 11, "val=" + val);
                        Assert.AreEqual(1d, row.Get("p2"));
                    }
                }
                else {
                    var row = (EventBean) output[i];
                    Assert.AreEqual("abc", row.Get("p0"));
                }
            }

            env.UndeployAll();
        }
        private static void RunAssertionEventBeanAnnotation(
            RegressionEnvironment env,
            EventRepresentationChoice rep)
        {
            var path = new RegressionPath();
            env.CompileDeployWBusPublicType(
                rep.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() + "@Name('schema') create schema MyEvent(col1 string)",
                path);

            var eplInsert = "@Name('insert') insert into DStream select " +
                            "last(*) @eventbean as c0, " +
                            "window(*) @eventbean as c1, " +
                            "prevwindow(s0) @eventbean as c2 " +
                            "from MyEvent#length(2) as s0";
            env.CompileDeploy(eplInsert, path).AddListener("insert");

            foreach (var prop in "c0,c1,c2".SplitCsv()) {
                AssertFragment(prop, env.Statement("insert").EventType, "MyEvent", prop.Equals("c1") || prop.Equals("c2"));
            }

            // test consuming statement
            var fields = "f0,f1,f2,f3,f4,f5".SplitCsv();
            env.CompileDeploy(
                    "@Name('s0') select " +
                    "c0 as f0, " +
                    "c0.col1 as f1, " +
                    "c1 as f2, " +
                    "c1.lastOf().col1 as f3, " +
                    "c1 as f4, " +
                    "c1.lastOf().col1 as f5 " +
                    "from DStream",
                    path)
                .AddListener("s0");
            env.CompileDeploy("@Name('s1') select * from MyEvent", path).AddListener("s1");

            var eventOne = SendEvent(env, rep, "E1");
            if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                eventOne = env.Listener("s1").AssertOneGetNewAndReset().Underlying;
            }

            var underlying = env.Listener("insert").AssertOneGetNewAndReset().Underlying.AsStringDictionary();
            Assert.IsTrue(underlying.Get("c0") is EventBean);
            EPAssertionUtil.AssertProps(
                env.Listener("s0").AssertOneGetNewAndReset(),
                fields,
                new[] {eventOne, "E1", new[] {eventOne}, "E1", new[] {eventOne}, "E1"});

            var eventTwo = SendEvent(env, rep, "E2");
            if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                eventTwo = env.Listener("s1").AssertOneGetNewAndReset().Underlying;
            }

            EPAssertionUtil.AssertProps(
                env.Listener("s0").AssertOneGetNewAndReset(),
                fields,
                new[] {eventTwo, "E2", new[] {eventOne, eventTwo}, "E2", new[] {eventOne, eventTwo}, "E2"});

            // test SODA
            env.EplToModelCompileDeploy(eplInsert, path);

            // test invalid
            TryInvalidCompile(
                env,
                path,
                "@Name('s0') select last(*) @xxx from MyEvent",
                "Failed to recognize select-expression annotation 'xxx', expected 'eventbean' in text 'last(*) @xxx'");

            env.UndeployAll();
        }
Exemple #27
0
        private static void TryAssertionFragment(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided <MyLocalJsonProvidedInnerSchema>() +
                      " create schema InnerSchema as (key string);\n" +
                      eventRepresentationEnum.GetAnnotationTextWJsonProvided <MyLocalJsonProvidedMySchema>() +
                      " create schema MySchema as (inside InnerSchema, insidearr InnerSchema[]);\n" +
                      eventRepresentationEnum.GetAnnotationTextWJsonProvided <MyLocalJsonProvidedOut>() +
                      " @name('s0') select typeof(s0.inside) as t0, typeof(s0.insidearr) as t1 from MySchema as s0;\n";
            var fields = new[] { "t0", "t1" };

            env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("s0");
            var deploymentId = env.DeploymentId("s0");

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                env.SendEventObjectArray(new object[2], "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                env.SendEventMap(new Dictionary <string, object>(), "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var schema = SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventType(deploymentId, "MySchema")).AsRecordSchema();
                env.SendEventAvro(new GenericRecord(schema), "MySchema");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent())
            {
                env.SendEventJson("{}", "MySchema");
            }
            else
            {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, null, null);

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                env.SendEventObjectArray(new object[] { new object[2], null }, "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                IDictionary <string, object> theEvent = new Dictionary <string, object>();
                theEvent.Put("inside", new Dictionary <string, object>());
                env.SendEventMap(theEvent, "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var mySchema    = SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventType(deploymentId, "MySchema")).AsRecordSchema();
                var innerSchema = SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventType(deploymentId, "InnerSchema")).AsRecordSchema();
                var @event      = new GenericRecord(mySchema);
                @event.Put("inside", new GenericRecord(innerSchema));
                env.SendEventAvro(@event, "MySchema");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent())
            {
                var theEvent = new JObject(new JProperty("inside", new JObject()));
                env.SendEventJson(theEvent.ToString(), "MySchema");
            }
            else
            {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, "InnerSchema", null);

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                env.SendEventObjectArray(new object[] { null, new object[2][] }, "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                IDictionary <string, object> theEvent = new Dictionary <string, object>();
                theEvent.Put("insidearr", new IDictionary <string, object> [0]);
                env.SendEventMap(theEvent, "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var mySchema = SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventType(deploymentId, "MySchema")).AsRecordSchema();
                var @event   = new GenericRecord(mySchema);
                @event.Put("insidearr", EmptyList <object> .Instance);
                env.SendEventAvro(@event, "MySchema");
            }
            else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent())
            {
                var theEvent = new JObject(new JProperty("insidearr", new JArray(new JObject())));
                env.SendEventJson(theEvent.ToString(), "MySchema");
            }
            else
            {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, null, "InnerSchema[]");

            env.UndeployAll();
        }