public void RunAssertionDispatchBackQueue(EventRepresentationChoice eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema StartValueEvent as (dummy string)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TestForwardEvent as (prop1 string)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TestInputEvent as (dummy string)");
            _epService.EPAdministrator.CreateEPL("insert into TestForwardEvent select'V1' as prop1 from TestInputEvent");

            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window NamedWin#unique(prop1) (prop1 string, prop2 string)");

            _epService.EPAdministrator.CreateEPL("insert into NamedWin select 'V1' as prop1, 'O1' as prop2 from StartValueEvent");

            _epService.EPAdministrator.CreateEPL("on TestForwardEvent update NamedWin as work set prop2 = 'U1' where work.prop1 = 'V1'");

            string[] fields    = "prop1,prop2".Split(',');
            string   eplSelect = "select irstream prop1, prop2 from NamedWin";

            _epService.EPAdministrator.CreateEPL(eplSelect).AddListener(_listener);

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new object[] { "dummyValue" }, "StartValueEvent");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "StartValueEvent");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                _epService.EPRuntime.SendEventAvro(new GenericRecord(
                                                       SchemaBuilder.Record("something")), "StartValueEvent");
            }
            else
            {
                Assert.Fail();
            }

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

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new object[] { "dummyValue" }, "TestInputEvent");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "TestInputEvent");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                _epService.EPRuntime.SendEventAvro(new GenericRecord(
                                                       SchemaBuilder.Record("something")), "TestInputEvent");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(_listener.LastOldData[0], fields, new object[] { "V1", "O1" });
            EPAssertionUtil.AssertProps(_listener.GetAndResetLastNewData()[0], fields, new object[] { "V1", "U1" });

            _epService.Initialize();
        }
Exemplo n.º 2
0
        private void RunStreamInsertAssertion(
            EPServiceProvider epService, EventRepresentationChoice rep, string epl, string fields, object[] expected)
        {
            var stmt = epService.EPAdministrator.CreateEPL(epl);
            var listener = new SupportUpdateListener();
            stmt.Events += listener.Update;
            if (rep.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(MakeMap(123, "abc"), "Src");
            }
            else if (rep.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] {123, "abc"}, "Src");
            }
            else if (rep.IsAvroEvent())
            {
                var @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "Src").AsRecordSchema());
                @event.Put("myint", 123);
                @event.Put("mystr", "abc");
                epService.EPRuntime.SendEventAvro(@event, "Src");
            }

            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields.Split(','), expected);
            stmt.Dispose();
        }
Exemplo n.º 3
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.º 4
0
 private void MakeSendEvent(EPServiceProvider epService, string typeName, EventRepresentationChoice eventRepresentationEnum, Object startTs, Object endTs)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         epService.EPRuntime.SendEvent(new object[] { startTs, endTs }, typeName);
     }
     else if (eventRepresentationEnum.IsMapEvent())
     {
         var theEvent = new LinkedHashMap <string, object>();
         theEvent.Put("startts", startTs);
         theEvent.Put("endts", endTs);
         epService.EPRuntime.SendEvent(theEvent, typeName);
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var record = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, typeName).AsRecordSchema());
         record.Put("startts", startTs);
         record.Put("endts", endTs);
         epService.EPRuntime.SendEventAvro(record, typeName);
     }
     else
     {
         throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum);
     }
 }
Exemplo n.º 5
0
        private void RunAssertionUpdateIStreamSetMapProps(EventRepresentationChoice eventRepresentationEnum)
        {
            // test update-istream with map
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyInfraType(simple string, myarray int[], mymap com.espertech.esper.compat.collections.StringMap)");
            EPStatement stmtUpdTwo = _epService.EPAdministrator.CreateEPL("update istream MyInfraType set simple='A', mymap('abc') = 1, myarray[2] = 10");

            stmtUpdTwo.AddListener(_listener);

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { null, new int[10], new Dictionary <string, Object>() }, "MyInfraType");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyInfraType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyInfraType").AsRecordSchema());
                theEvent.Put("myarray", Collections.List(0, 0, 0, 0, 0));
                theEvent.Put("mymap", new Dictionary <string, object>());
                _epService.EPRuntime.SendEventAvro(theEvent, "MyInfraType");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(_listener.AssertPairGetIRAndReset(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[] { "A", 1, 10 }, new Object[] { null, null, 0 });

            _epService.Initialize();
        }
Exemplo n.º 6
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.º 7
0
 private void MakeSendScoreEvent(String typeName, EventRepresentationChoice eventRepresentationEnum, String userId, String keyword, String productId, long score)
 {
     if (eventRepresentationEnum.IsMapEvent())
     {
         var theEvent = new LinkedHashMap <string, Object>();
         theEvent.Put("userId", userId);
         theEvent.Put("keyword", keyword);
         theEvent.Put("productId", productId);
         theEvent.Put("score", score);
         _epService.EPRuntime.SendEvent(theEvent, typeName);
     }
     else if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         _epService.EPRuntime.SendEvent(new Object[] { userId, keyword, productId, score }, typeName);
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var record = SupportAvroUtil.GetAvroRecord(_epService, typeName);
         record.Put("userId", userId);
         record.Put("keyword", keyword);
         record.Put("productId", productId);
         record.Put("score", score);
         _epService.EPRuntime.SendEventAvro(record, typeName);
     }
     else
     {
         Assert.Fail();
     }
 }
Exemplo n.º 8
0
 private void SendRepEvent(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);
         _epService.EPRuntime.SendEvent(theEvent, name);
     }
     else if (rep.IsObjectArrayEvent())
     {
         _epService.EPRuntime.SendEvent(new object[] { id, p00 }, name);
     }
     else if (rep.IsAvroEvent())
     {
         GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, name).AsRecordSchema());
         theEvent.Put("id", id);
         theEvent.Put("p00", p00);
         _epService.EPRuntime.SendEventAvro(theEvent, name);
     }
     else
     {
         Assert.Fail();
     }
 }
Exemplo n.º 9
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();
     }
 }
Exemplo n.º 10
0
 private void SendPortfolio(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum, string portfolio, string product)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         epService.EPRuntime.SendEvent(new object[] { portfolio, product }, "Portfolio");
     }
     else if (eventRepresentationEnum.IsMapEvent())
     {
         var theEvent = new LinkedHashMap <string, Object>();
         theEvent.Put("portfolio", portfolio);
         theEvent.Put("product", product);
         epService.EPRuntime.SendEvent(theEvent, "Portfolio");
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "Portfolio").AsRecordSchema());
         theEvent.Put("portfolio", portfolio);
         theEvent.Put("product", product);
         epService.EPRuntime.SendEventAvro(theEvent, "Portfolio");
     }
     else
     {
         Assert.Fail();
     }
 }
Exemplo n.º 11
0
        public void RunAssertionCreateSchemaModelAfter(EventRepresentationChoice eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTypeOne (hsi int)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTypeTwo (event EventTypeOne)");
            var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window NamedWindow#unique(event.hsi) as EventTypeTwo");

            _epService.EPAdministrator.CreateEPL("on EventTypeOne as ev insert into NamedWindow select ev as event");

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { 10 }, "EventTypeOne");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(Collections.SingletonDataMap("hsi", 10), "EventTypeOne");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "EventTypeOne").AsRecordSchema());
                theEvent.Put("hsi", 10);
                _epService.EPRuntime.SendEventAvro(theEvent, "EventTypeOne");
            }
            else
            {
                Assert.Fail();
            }

            var result = stmt.First();
            var getter = result.EventType.GetGetter("event.hsi");

            Assert.AreEqual(10, getter.Get(result));

            _epService.Initialize();
        }
Exemplo n.º 12
0
 private void SendOrderEvent(EventRepresentationChoice eventRepresentationEnum, string orderId, string productId, double price, int quantity, bool deletedFlag)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         _epService.EPRuntime.SendEvent(new Object[] { orderId, productId, price, quantity, deletedFlag }, "OrderEvent");
     }
     else if (eventRepresentationEnum.IsMapEvent())
     {
         var 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);
         _epService.EPRuntime.SendEvent(theEvent, "OrderEvent");
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "OrderEvent").AsRecordSchema());
         theEvent.Put("orderId", orderId);
         theEvent.Put("productId", productId);
         theEvent.Put("price", price);
         theEvent.Put("quantity", quantity);
         theEvent.Put("deletedFlag", deletedFlag);
         _epService.EPRuntime.SendEventAvro(theEvent, "OrderEvent");
     }
     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.º 14
0
 private void MakeSendScoreEvent(EPServiceProvider epService, string typeName, EventRepresentationChoice eventRepresentationEnum, string userId, string keyword, string productId, long score)
 {
     if (eventRepresentationEnum.IsMapEvent())
     {
         var theEvent = new LinkedHashMap <string, object>();
         theEvent.Put("userId", userId);
         theEvent.Put("keyword", keyword);
         theEvent.Put("productId", productId);
         theEvent.Put("score", score);
         epService.EPRuntime.SendEvent(theEvent, typeName);
     }
     else if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         epService.EPRuntime.SendEvent(new object[] { userId, keyword, productId, score }, typeName);
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var record = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, typeName).AsRecordSchema());
         record.Put("userId", userId);
         record.Put("keyword", keyword);
         record.Put("productId", productId);
         record.Put("score", score);
         epService.EPRuntime.SendEventAvro(record, typeName);
     }
     else
     {
         Assert.Fail();
     }
 }
Exemplo n.º 15
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.º 16
0
 private void SendMyEvent(EventRepresentationChoice eventRepresentationEnum, string in1, int in2)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         _epService.EPRuntime.SendEvent(
             new Object[]
         {
             in1,
             in2
         }, "MyEvent");
     }
     else if (eventRepresentationEnum.IsMapEvent())
     {
         var theEvent = new LinkedHashMap <string, Object>();
         theEvent.Put("in1", in1);
         theEvent.Put("in2", in2);
         _epService.EPRuntime.SendEvent(theEvent, "MyEvent");
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyEvent").AsRecordSchema());
         theEvent.Put("in1", in1);
         theEvent.Put("in2", in2);
         _epService.EPRuntime.SendEventAvro(theEvent, "MyEvent");
     }
     else
     {
         Assert.Fail();
     }
 }
Exemplo n.º 17
0
        private Object SendEvent(EventRepresentationChoice rep, string value)
        {
            Object eventOne;

            if (rep.IsMapEvent())
            {
                var @event = Collections.SingletonDataMap("col1", value);
                _epService.EPRuntime.SendEvent(@event, "MyEvent");
                eventOne = @event;
            }
            else if (rep.IsObjectArrayEvent())
            {
                var @event = new Object[] { value };
                _epService.EPRuntime.SendEvent(@event, "MyEvent");
                eventOne = @event;
            }
            else if (rep.IsAvroEvent())
            {
                var schema = SupportAvroUtil.GetAvroSchema(_epService, "MyEvent").AsRecordSchema();
                var @event = new GenericRecord(schema);
                @event.Put("col1", value);
                _epService.EPRuntime.SendEventAvro(@event, "MyEvent");
                eventOne = @event;
            }
            else
            {
                throw new IllegalStateException();
            }
            return(eventOne);
        }
Exemplo n.º 18
0
 private void SendProduct(EventRepresentationChoice eventRepresentationEnum, string product, int size)
 {
     if (eventRepresentationEnum.IsObjectArrayEvent())
     {
         _epService.EPRuntime.SendEvent(new Object[] { product, size }, "Product");
     }
     else if (eventRepresentationEnum.IsMapEvent())
     {
         var theEvent = new LinkedHashMap <string, Object>();
         theEvent.Put("product", product);
         theEvent.Put("size", size);
         _epService.EPRuntime.SendEvent(theEvent, "Product");
     }
     else if (eventRepresentationEnum.IsAvroEvent())
     {
         var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "Product").AsRecordSchema());
         theEvent.Put("product", product);
         theEvent.Put("size", size);
         _epService.EPRuntime.SendEventAvro(theEvent, "Product");
     }
     else
     {
         Assert.Fail();
     }
 }
Exemplo n.º 19
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();
     }
 }
Exemplo n.º 20
0
            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();
            }
        private void TryJoinAssertion(
            EPServiceProvider epService, string epl, EventRepresentationChoice rep, string columnNames)
        {
            if (rep.IsMapEvent())
            {
                var typeInfo = new Dictionary<string, object>();
                typeInfo.Put("id", typeof(string));
                typeInfo.Put("p00", typeof(int));
                epService.EPAdministrator.Configuration.AddEventType("S0", typeInfo);
                epService.EPAdministrator.Configuration.AddEventType("S1", typeInfo);
            }
            else if (rep.IsObjectArrayEvent())
            {
                var names = "id,p00".Split(',');
                var types = new object[] {typeof(string), typeof(int)};
                epService.EPAdministrator.Configuration.AddEventType("S0", names, types);
                epService.EPAdministrator.Configuration.AddEventType("S1", names, types);
            }
            else if (rep.IsAvroEvent())
            {
                var schema = SchemaBuilder.Record(
                    "name",
                    TypeBuilder.Field(
                        "id", TypeBuilder.StringType(
                            TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))),
                    TypeBuilder.RequiredInt("p00"));
                epService.EPAdministrator.Configuration.AddEventTypeAvro(
                    "S0", new ConfigurationEventTypeAvro().SetAvroSchema(schema));
                epService.EPAdministrator.Configuration.AddEventTypeAvro(
                    "S1", new ConfigurationEventTypeAvro().SetAvroSchema(schema));
            }

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

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

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

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

            stmt.Dispose();
            epService.EPAdministrator.Configuration.RemoveEventType("S0", true);
            epService.EPAdministrator.Configuration.RemoveEventType("S1", true);
        }
Exemplo n.º 22
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.º 23
0
        private void TryAssertionSplitPremptiveNamedWindow(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TypeTwo(col2 int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TypeTrigger(trigger int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window WinTwo#keepall as TypeTwo");

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

            epService.EPAdministrator.CreateEPL(stmtOrigText);

            var stmt     = epService.EPAdministrator.CreateEPL("on OtherStream select col2 from WinTwo");
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            // populate WinOne
            epService.EPRuntime.SendEvent(new SupportBean("E1", 2));

            // fire trigger
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(new object[] { null });
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(new Dictionary <string, object>());
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var @event = new GenericRecord(SchemaBuilder.Record("name", OptionalInt("trigger")));
                epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(@event);
            }
            else
            {
                Assert.Fail();
            }

            Assert.AreEqual(2, listener.AssertOneGetNewAndReset().Get("col2"));

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "TypeTwo,TypeTrigger,WinTwo,OtherStream".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemplo n.º 24
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();
        }
        private void RunAssertionCreateStreamTwo(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEvent(myId int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema AllMyEvent as (myEvent MyEvent, class string, reverse bool)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SuspectMyEvent as (myEvent MyEvent, class string)");

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

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

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

            stmtTwo.Events += listenerTwo.Update;

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

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

            epService.EPAdministrator.DestroyAllStatements();
            foreach (string name in "MyEvent,AllMyEvent,SuspectMyEvent".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemplo n.º 26
0
        private void RunAssertionUpdateIStreamSetMapProps(
            EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            // test update-istream with map
            epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText() +
                " create schema MyInfraType(simple string, myarray int[], mymap Map)");
            var stmtUpdTwo = epService.EPAdministrator.CreateEPL(
                "update istream MyInfraType set simple='A', mymap('abc') = 1, myarray[2] = 10");
            var listener = new SupportUpdateListener();

            stmtUpdTwo.Events += listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(
                    new object[] { null, new int[10], new Dictionary <string, object>() }, "MyInfraType");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(
                    MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyInfraType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var @event = new GenericRecord(
                    SupportAvroUtil.GetAvroSchema(epService, "MyInfraType").AsRecordSchema());
                @event.Put("myarray", Collections.List(0, 0, 0, 0, 0));
                @event.Put("mymap", new Dictionary <string, object>());
                epService.EPRuntime.SendEventAvro(@event, "MyInfraType");
            }
            else
            {
                Assert.Fail();
            }

            EPAssertionUtil.AssertProps(
                listener.AssertPairGetIRAndReset(), "simple,mymap('abc'),myarray[2]".Split(','),
                new object[] { "A", 1, 10 }, new object[] { null, null, 0 });

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "MyInfraType".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemplo n.º 27
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.º 28
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.º 29
0
        private void RunTransposeMapAndObjectArray(EventRepresentationChoice representation)
        {
            String[] fields = "p0,p1".Split(',');
            _epService.EPAdministrator.CreateEPL("create " + representation.GetOutputTypeCreateSchemaName() + " schema MySchema(p0 string, p1 int)");

            String generateFunction;

            if (representation.IsObjectArrayEvent())
            {
                generateFunction = "generateOA";
            }
            else if (representation.IsMapEvent())
            {
                generateFunction = "generateMap";
            }
            else if (representation.IsAvroEvent())
            {
                generateFunction = "generateAvro";
            }
            else
            {
                throw new IllegalStateException("Unrecognized code " + representation);
            }

            String epl = "insert into MySchema select transpose(" + generateFunction + "(TheString, IntPrimitive)) from SupportBean";

            _epService.EPAdministrator.CreateEPL(epl, "first").Events += _listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", 1 });

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E2", 2 });

            // MySchema already exists, start second statement
            _epService.EPAdministrator.CreateEPL(epl, "second").AddListener(_listener);
            _epService.EPAdministrator.GetStatement("first").Dispose();

            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E3", 3 });

            _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", true);
            _epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertPopulateFromNamedWindow(EPServiceProvider epService, EventRepresentationChoice type)
        {
            epService.EPAdministrator.CreateEPL("create " + type.GetOutputTypeCreateSchemaName() + " schema Node(nid string)");
            epService.EPAdministrator.CreateEPL("create window NodeWindow#unique(nid) as Node");
            epService.EPAdministrator.CreateEPL("insert into NodeWindow select * from Node");
            epService.EPAdministrator.CreateEPL("create " + type.GetOutputTypeCreateSchemaName() + " schema NodePlus(npid string, node Node)");

            EPStatement stmt     = epService.EPAdministrator.CreateEPL("insert into NodePlus select 'E1' as npid, n1 as node from NodeWindow n1");
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            if (type.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "n1" }, "Node");
            }
            else if (type.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(Collections.SingletonDataMap("nid", "n1"), "Node");
            }
            else if (type.IsAvroEvent())
            {
                var genericRecord = new GenericRecord(SchemaBuilder.Record("name", RequiredString("nid")));
                genericRecord.Put("nid", "n1");
                epService.EPRuntime.SendEventAvro(genericRecord, "Node");
            }
            else
            {
                Assert.Fail();
            }
            EventBean @event = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("E1", @event.Get("npid"));
            Assert.AreEqual("n1", @event.Get("node.nid"));
            EventBean fragment = (EventBean)@event.GetFragment("node");

            Assert.AreEqual("Node", fragment.EventType.Name);

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("Node", true);
            epService.EPAdministrator.Configuration.RemoveEventType("NodePlus", true);
            epService.EPAdministrator.Configuration.RemoveEventType("NodeWindow", true);
        }