Exemplo n.º 1
0
 private static void SendRepEvent(
     RegressionEnvironment env,
     EventRepresentationChoice rep,
     string name,
     string id,
     int p00)
 {
     if (rep.IsMapEvent()) {
         IDictionary<string, object> theEvent = new Dictionary<string, object>();
         theEvent.Put("Id", id);
         theEvent.Put("P00", p00);
         env.SendEventMap(theEvent, name);
     }
     else if (rep.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new object[] {id, p00}, name);
     }
     else if (rep.IsAvroEvent()) {
         var theEvent = new GenericRecord(
             SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(name))
                 .AsRecordSchema());
         theEvent.Put("Id", id);
         theEvent.Put("P00", p00);
         env.SendEventAvro(theEvent, name);
     }
     else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
         String json = "{\"Id\": \"" + id + "\", \"P00\": " + p00 + "}";
         env.EventService.SendEventJson(json, name);
     }
     else {
         Assert.Fail();
     }
 }
        private static object SendEvent(
            RegressionEnvironment env,
            EventRepresentationChoice rep,
            string value)
        {
            object eventOne;
            if (rep.IsMapEvent()) {
                var @event = Collections.SingletonDataMap("col1", value);
                env.SendEventMap(@event, "MyEvent");
                eventOne = @event;
            }
            else if (rep.IsObjectArrayEvent()) {
                var @event = new object[] {value};
                env.SendEventObjectArray(@event, "MyEvent");
                eventOne = @event;
            }
            else if (rep.IsAvroEvent()) {
                var schema = SupportAvroUtil.GetAvroSchema(env.Statement("schema").EventType).AsRecordSchema();
                var @event = new GenericRecord(schema);
                @event.Put("col1", value);
                env.SendEventAvro(@event, "MyEvent");
                eventOne = @event;
            }
            else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                var @object = new JObject(new JProperty("col1", value));
                env.SendEventJson(@object.ToString(), "MyEvent");
                eventOne = @object.ToString();
            }
            else {
                throw new IllegalStateException();
            }

            return eventOne;
        }
Exemplo n.º 3
0
 private static void sendPortfolio(
     RegressionEnvironment env,
     EventRepresentationChoice eventRepresentationEnum,
     string portfolio,
     string product)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new object[] {portfolio, product}, "Portfolio");
     }
     else if (eventRepresentationEnum.IsMapEvent()) {
         var theEvent = new LinkedHashMap<string, object>();
         theEvent.Put("portfolio", portfolio);
         theEvent.Put("product", product);
         env.SendEventMap(theEvent, "Portfolio");
     }
     else if (eventRepresentationEnum.IsAvroEvent()) {
         var theEvent = new GenericRecord(
             SupportAvroUtil.GetAvroSchema(
                     env.Runtime.EventTypeService.GetEventTypePreconfigured("Portfolio"))
                 .AsRecordSchema());
         theEvent.Put("portfolio", portfolio);
         theEvent.Put("product", product);
         env.EventService.SendEventAvro(theEvent, "Portfolio");
     }
     else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
         var @object = new JObject();
         @object.Add("portfolio", portfolio);
         @object.Add("product", product);
         env.EventService.SendEventJson(@object.ToString(), "Portfolio");
     }
     else {
         Assert.Fail();
     }
 }
Exemplo n.º 4
0
 private void MakeSendEvent(
     RegressionEnvironment env,
     string typeName,
     EventRepresentationChoice eventRepresentationEnum,
     object startTs,
     object endTs)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new[] {startTs, endTs}, typeName);
     }
     else if (eventRepresentationEnum.IsMapEvent()) {
         var theEvent = new Dictionary<string, object>();
         theEvent.Put("startts", startTs);
         theEvent.Put("endts", endTs);
         env.SendEventMap(theEvent, typeName);
     }
     else if (eventRepresentationEnum.IsAvroEvent()) {
         var record = new GenericRecord(
             SupportAvroUtil.GetAvroSchema(
                     env.Runtime.EventTypeService.GetEventTypePreconfigured(typeName))
                 .AsRecordSchema());
         record.Put("startts", startTs);
         record.Put("endts", endTs);
         env.EventService.SendEventAvro(record, typeName);
     }
     else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
         var json = "{\"startts\": \"" + startTs + "\", \"endts\": \"" + endTs + "\"}";
         env.EventService.SendEventJson(json, typeName);
     }
     else {
         throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum);
     }
 }
Exemplo n.º 5
0
 private static void SendMySentenceEvent(
     RegressionEnvironment env,
     EventRepresentationChoice eventRepresentationEnum,
     string sentence)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new object[] {sentence}, "MySentenceEvent");
     }
     else if (eventRepresentationEnum.IsMapEvent()) {
         env.SendEventMap(Collections.SingletonDataMap("sentence", sentence), "MySentenceEvent");
     }
     else if (eventRepresentationEnum.IsAvroEvent()) {
         var schema = SchemaBuilder.Record("sentence", TypeBuilder.RequiredString("sentence"));
         var record = new GenericRecord(schema);
         record.Put("sentence", sentence);
         env.SendEventAvro(record, "MySentenceEvent");
     }
     else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
         var @object = new JObject();
         @object.Add("sentence", sentence);
         env.SendEventJson(@object.ToString(), "MySentenceEvent");
     }
     else {
         throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum);
     }
 }
Exemplo n.º 6
0
 private static void SendMyEvent(
     RegressionEnvironment env,
     EventRepresentationChoice eventRepresentationEnum,
     string in1,
     int in2)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new object[] {in1, in2}, "MyEvent");
     }
     else if (eventRepresentationEnum.IsMapEvent()) {
         IDictionary<string, object> theEvent = new Dictionary<string, object>();
         theEvent.Put("in1", in1);
         theEvent.Put("in2", in2);
         env.SendEventMap(theEvent, "MyEvent");
     }
     else if (eventRepresentationEnum.IsAvroEvent()) {
         var theEvent = new GenericRecord(
             SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("MyEvent"))
                 .AsRecordSchema());
         theEvent.Put("in1", in1);
         theEvent.Put("in2", in2);
         env.EventService.SendEventAvro(theEvent, "MyEvent");
     }
     else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
         env.EventService.SendEventJson("{\"in1\": \"" + in1 + "\", \"in2\": " + in2 + "}", "MyEvent");
     }
     else {
         Assert.Fail();
     }
 }
            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();
            }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
 private static void SendOrderEvent(
     RegressionEnvironment env,
     EventRepresentationChoice eventRepresentationEnum,
     string orderId,
     string productId,
     double price,
     int quantity,
     bool deletedFlag)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new object[] {orderId, productId, price, quantity, deletedFlag}, "OrderEvent");
     }
     else if (eventRepresentationEnum.IsMapEvent()) {
         IDictionary<string, object> theEvent = new LinkedHashMap<string, object>();
         theEvent.Put("OrderId", orderId);
         theEvent.Put("ProductId", productId);
         theEvent.Put("Price", price);
         theEvent.Put("Quantity", quantity);
         theEvent.Put("DeletedFlag", deletedFlag);
         env.SendEventMap(theEvent, "OrderEvent");
     }
     else if (eventRepresentationEnum.IsAvroEvent()) {
         var theEvent = new GenericRecord(
             SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("OrderEvent"))
                 .AsRecordSchema());
         theEvent.Put("OrderId", orderId);
         theEvent.Put("ProductId", productId);
         theEvent.Put("Price", price);
         theEvent.Put("Quantity", quantity);
         theEvent.Put("DeletedFlag", deletedFlag);
         env.EventService.SendEventAvro(theEvent, "OrderEvent");
     }
     else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
         var @object = new JObject();
         @object.Add("OrderId", orderId);
         @object.Add("ProductId", productId);
         @object.Add("Price", price);
         @object.Add("Quantity", quantity);
         @object.Add("DeletedFlag", deletedFlag);
         env.EventService.SendEventJson(@object.ToString(), "OrderEvent");
     }
     else {
         Assert.Fail();
     }
 }
Exemplo n.º 11
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();
            }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
0
 private static void MakeSendScoreEvent(
     RegressionEnvironment env,
     string typeName,
     EventRepresentationChoice eventRepresentationEnum,
     string userId,
     string keyword,
     string productId,
     long score)
 {
     if (eventRepresentationEnum.IsMapEvent()) {
         IDictionary<string, object> theEvent = new LinkedHashMap<string, object>();
         theEvent.Put("UserId", userId);
         theEvent.Put("Keyword", keyword);
         theEvent.Put("ProductId", productId);
         theEvent.Put("Score", score);
         env.SendEventMap(theEvent, typeName);
     }
     else if (eventRepresentationEnum.IsObjectArrayEvent()) {
         env.SendEventObjectArray(new object[] {userId, keyword, productId, score}, typeName);
     }
     else if (eventRepresentationEnum.IsAvroEvent()) {
         var record = new GenericRecord(
             SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(typeName))
                 .AsRecordSchema());
         record.Put("UserId", userId);
         record.Put("Keyword", keyword);
         record.Put("ProductId", productId);
         record.Put("Score", score);
         env.SendEventAvro(record, typeName);
     }
     else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) {
         var jobject = new JObject();
         jobject.Add("UserId", userId);
         jobject.Add("Keyword", keyword);
         jobject.Add("ProductId", productId);
         jobject.Add("Score", score);
         env.SendEventJson(jobject.ToString(), typeName);
     }
     else {
         Assert.Fail();
     }
 }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
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();
            }
Exemplo n.º 16
0
        private static void RunStreamInsertAssertion(
            RegressionEnvironment env,
            RegressionPath path,
            EventRepresentationChoice rep,
            string epl,
            string fields,
            object[] expected)
        {
            env.CompileDeploy("@Name('s0') " + epl, path).AddListener("s0");

            if (rep.IsMapEvent()) {
                env.SendEventMap(MakeMap(123, "abc"), "Src");
            }
            else if (rep.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {123, "abc"}, "Src");
            }
            else if (rep.IsAvroEvent()) {
                var eventType = env.Runtime.EventTypeService.GetEventType(env.DeploymentId("schema"), "Src");
                var @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(eventType).AsRecordSchema());
                @event.Put("myint", 123);
                @event.Put("mystr", "abc");
                env.SendEventAvro(@event, "Src");
            }
            else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                JObject @object = new JObject();
                @object.Add("myint", 123);
                @object.Add("mystr", "abc");
                env.SendEventJson(@object.ToString(), "Src");
            }
            else {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields.SplitCsv(), expected);
            env.UndeployModuleContaining("s0");
        }
        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();
        }
Exemplo n.º 18
0
        private static void TryAssertionNamedWindow(
            RegressionEnvironment env,
            EventRepresentationChoice rep)
        {
            RegressionPath path = new RegressionPath();
            string schema = rep.GetAnnotationText() +
                            "@Name('schema') create schema A as (myint int, mystr string);\n" +
                            rep.GetAnnotationText() +
                            "create schema C as (addprop int) inherits A;\n";
            env.CompileDeployWBusPublicType(schema, path);

            env.CompileDeploy("create window MyWindow#time(5 days) as C", path);
            env.CompileDeploy("@Name('s0') select * from MyWindow", path).AddListener("s0");

            // select underlying
            env.CompileDeploy("@Name('insert') insert into MyWindow select mya.* from A as mya", path);
            if (rep.IsMapEvent()) {
                env.SendEventMap(MakeMap(123, "abc"), "A");
            }
            else if (rep.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {123, "abc"}, "A");
            }
            else if (rep.IsAvroEvent()) {
                env.SendEventAvro(MakeAvro(env, 123, "abc"), "A");
            }
            else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                var @object = new JObject();
                @object.Add("myint", 123);
                @object.Add("mystr", "abc");
                env.SendEventJson(@object.ToString(), "A");
            }
            else {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "myint,mystr,addprop".SplitCsv(), new object[] {123, "abc", null});
            env.UndeployModuleContaining("insert");

            // select underlying plus property
            env.CompileDeploy("insert into MyWindow select mya.*, 1 as addprop from A as mya", path);
            if (rep.IsMapEvent()) {
                env.SendEventMap(MakeMap(456, "def"), "A");
            }
            else if (rep.IsObjectArrayEvent()) {
                env.SendEventObjectArray(new object[] {456, "def"}, "A");
            }
            else if (rep.IsAvroEvent()) {
                env.SendEventAvro(MakeAvro(env, 456, "def"), "A");
            }
            else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) {
                var @object = new JObject();
                @object.Add("myint", 456);
                @object.Add("mystr", "def");
                env.SendEventJson(@object.ToString(), "A");
            }
            else {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "myint,mystr,addprop".SplitCsv(), new object[] {456, "def", 1});

            env.UndeployAll();
        }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
            }