Exemple #1
0
        private void TryAssertionColDefPlain(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            var stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string, col2 int, col3_col4 int)");

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

            AssertTypeColDef(stmtSelect.EventType);

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

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

            stmtCreate.Stop();

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

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

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

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

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

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

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

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

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

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "MyEventType,MyEventTypeTwo".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemple #2
0
        private void TryAssertionNestableMapArray(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            var stmtInner = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyInnerType as (inn1 string[], inn2 int[])");
            var inner     = stmtInner.EventType;

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

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

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

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

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

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

            epService.EPAdministrator.Configuration.RemoveEventType("MyInnerType", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MyOuterType", true);
            epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertionDispatchBackQueue(EPServiceProvider epService, 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";
            var      listener  = new SupportUpdateListener();

            epService.EPAdministrator.CreateEPL(eplSelect).Events += listener.Update;

            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("soemthing")), "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("soemthing")), "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.EPAdministrator.DestroyAllStatements();
            foreach (string name in "StartValueEvent,TestForwardEvent,TestInputEvent,NamedWin".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
Exemple #4
0
        private void TryAssertionSchemaCopyProperties(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseOne (prop1 string, prop2 int)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema BaseTwo (prop3 long)");

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

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

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

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

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

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

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

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

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

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

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

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

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "BaseOne,BaseTwo,E1,E2,E3,MyType".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
        private void RunAssertionStaggered(EventRepresentationChoice outputType)
        {
            var fieldsOne = new string[] { "a1", "b1" };
            var fieldsTwo = new string[] { "a2", "b2" };

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

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

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

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

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

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

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

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

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

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

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

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

            stmtDelete.Dispose();
            stmtCreateOne.Dispose();
            stmtCreateTwo.Dispose();
            _listenerDelete.Reset();
            _listenerSelect.Reset();
            _listenerWindow.Reset();
            _listenerWindowTwo.Reset();
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindowOne", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("MyWindowTwo", true);
        }
        private void RunAssertionSubselect(EventRepresentationChoice eventRepresentationEnum)
        {
            string[] fields = "col1,col2".Split(',');
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEvent as (in1 string, in2 int)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MySchema as (col1 string, col2 int)");
            EPStatement namedWindowStmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window MyWindow#lastevent as MySchema");

            _epService.EPAdministrator.CreateEPL("on SupportBean_A delete from MyWindow");

            string epl = "on MyEvent me " +
                         "merge MyWindow mw " +
                         "when not matched and (select IntPrimitive>0 from SupportBean(TheString like 'A%')#lastevent) then " +
                         "insert(col1, col2) select (select TheString from SupportBean(TheString like 'A%')#lastevent), (select IntPrimitive from SupportBean(TheString like 'A%')#lastevent) " +
                         "when matched and (select IntPrimitive>0 from SupportBean(TheString like 'B%')#lastevent) then " +
                         "update set col1=(select TheString from SupportBean(TheString like 'B%')#lastevent), col2=(select IntPrimitive from SupportBean(TheString like 'B%')#lastevent) " +
                         "when matched and (select IntPrimitive>0 from SupportBean(TheString like 'C%')#lastevent) then " +
                         "delete";

            _epService.EPAdministrator.CreateEPL(epl);

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

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

            _epService.EPRuntime.SendEvent(new SupportBean_A("Y1"));
            _epService.EPRuntime.SendEvent(new SupportBean("A3", 30));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(namedWindowStmt.GetEnumerator(), fields, null);

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

            _epService.EPRuntime.SendEvent(new SupportBean("B1", 50));
            SendMyEvent(eventRepresentationEnum, "X6", 6);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(namedWindowStmt.GetEnumerator(), fields, new object[][] { new object[] { "B1", 50 } });

            _epService.EPRuntime.SendEvent(new SupportBean("B2", 60));
            SendMyEvent(eventRepresentationEnum, "X7", 7);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(namedWindowStmt.GetEnumerator(), fields, new object[][] { new object[] { "B2", 60 } });

            _epService.EPRuntime.SendEvent(new SupportBean("B2", 0));
            SendMyEvent(eventRepresentationEnum, "X8", 8);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(namedWindowStmt.GetEnumerator(), fields, new object[][] { new object[] { "B2", 60 } });

            _epService.EPRuntime.SendEvent(new SupportBean("C1", 1));
            SendMyEvent(eventRepresentationEnum, "X9", 9);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(namedWindowStmt.GetEnumerator(), fields, null);

            _epService.EPRuntime.SendEvent(new SupportBean("C1", 0));
            SendMyEvent(eventRepresentationEnum, "X10", 10);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(namedWindowStmt.GetEnumerator(), fields, new object[][] { new object[] { "A4", 40 } });

            _epService.EPAdministrator.DestroyAllStatements();
            foreach (string name in "MyEvent,MySchema,MyWindow".Split(','))
            {
                _epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
        private void RunAssertionSingleRowSplitAndType(EventRepresentationChoice eventRepresentationEnum)
        {
            string[] methods;
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                methods = "SplitSentenceMethodReturnObjectArray,SplitSentenceBeanMethodReturnObjectArray,SplitWordMethodReturnObjectArray".Split(',');
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                methods = "SplitSentenceMethodReturnMap,SplitSentenceBeanMethodReturnMap,SplitWordMethodReturnMap".Split(',');
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                methods = "SplitSentenceMethodReturnAvro,SplitSentenceBeanMethodReturnAvro,SplitWordMethodReturnAvro".Split(',');
            }
            else
            {
                throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum);
            }
            var funcs = "SplitSentence,SplitSentenceBean,SplitWord".Split(',');

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

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

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

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

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

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

            stmt.Dispose();

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

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

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

            stmt.Dispose();

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

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

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

                stmt.Dispose();
            }

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

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

            stmt.Dispose();

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

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

            stmt.Dispose();

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

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

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

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

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

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

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

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

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

            _epService.Initialize();
        }
Exemple #8
0
        private void TryAssertionVariantStream(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventOne as (key string)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTwo as (key string)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema S0 as " + typeof(SupportBean_S0).FullName);
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create variant schema VarSchema as *");

            epService.EPAdministrator.CreateEPL("insert into VarSchema select * from EventOne");
            epService.EPAdministrator.CreateEPL("insert into VarSchema select * from EventTwo");
            epService.EPAdministrator.CreateEPL("insert into VarSchema select * from S0");
            epService.EPAdministrator.CreateEPL("insert into VarSchema select * from SupportBean");

            var stmtText = "select typeof(A) as t0 from VarSchema as A";
            var stmt     = epService.EPAdministrator.CreateEPL(stmtText);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "value" }, "EventOne");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(Collections.SingletonDataMap("key", "value"), "EventOne");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var record = new GenericRecord(SchemaBuilder.Record("EventOne",
                                                                    TypeBuilder.RequiredString("key")));
                record.Put("key", "value");
                epService.EPRuntime.SendEventAvro(record, "EventOne");
            }
            else
            {
                Assert.Fail();
            }
            Assert.AreEqual("EventOne", listener.AssertOneGetNewAndReset().Get("t0"));

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "value" }, "EventTwo");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(Collections.SingletonDataMap("key", "value"), "EventTwo");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var record = new GenericRecord(SchemaBuilder.Record("EventTwo",
                                                                    TypeBuilder.RequiredString("key")));
                record.Put("key", "value");
                epService.EPRuntime.SendEventAvro(record, "EventTwo");
            }
            else
            {
                Assert.Fail();
            }
            Assert.AreEqual("EventTwo", listener.AssertOneGetNewAndReset().Get("t0"));

            epService.EPRuntime.SendEvent(new SupportBean_S0(1));
            Assert.AreEqual("S0", listener.AssertOneGetNewAndReset().Get("t0"));

            epService.EPRuntime.SendEvent(new SupportBean());
            Assert.AreEqual("SupportBean", listener.AssertOneGetNewAndReset().Get("t0"));

            stmt.Dispose();
            listener.Reset();
            stmt = epService.EPAdministrator.CreateEPL("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" +
                                                       "  )");
            stmt.Events += listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { "value" }, "EventOne");
                epService.EPRuntime.SendEvent(new object[] { "value" }, "EventTwo");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(Collections.SingletonDataMap("key", "value"), "EventOne");
                epService.EPRuntime.SendEvent(Collections.SingletonDataMap("key", "value"), "EventTwo");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var schema = SchemaBuilder.Record("EventTwo",
                                                  TypeBuilder.RequiredString("key"));
                var eventOne = new GenericRecord(schema);
                eventOne.Put("key", "value");
                var eventTwo = new GenericRecord(schema);
                eventTwo.Put("key", "value");
                epService.EPRuntime.SendEventAvro(eventOne, "EventOne");
                epService.EPRuntime.SendEventAvro(eventTwo, "EventTwo");
            }
            else
            {
                Assert.Fail();
            }
            Assert.IsTrue(listener.GetAndClearIsInvoked());

            epService.EPAdministrator.DestroyAllStatements();
            foreach (var name in "EventOne,EventTwo,S0,VarSchema".Split(','))
            {
                epService.EPAdministrator.Configuration.RemoveEventType(name, true);
            }
        }
        private static void TryAssertionSingleRowSplitAndType(
            RegressionEnvironment env,
            EventRepresentationChoice eventRepresentationEnum)
        {
            var path = new RegressionPath();
            var types =
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonSentence>() +
                " create schema MySentenceEvent(sentence String);\n" +
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() +
                " create schema WordEvent(word String);\n" +
                eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonCharacter>() +
                " create schema CharacterEvent(character String);\n";
            env.CompileDeployWBusPublicType(types, path);

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

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

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

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

            env.UndeployModuleContaining("s0");

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

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

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

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

                env.UndeployModuleContaining("s0");
            }

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

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

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

            env.UndeployModuleContaining("s0");

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

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

            env.UndeployModuleContaining("s0");

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

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

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

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

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

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

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

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

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

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

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

            }
            else {
                Assert.Fail();
            }

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

            env.UndeployAll();
        }
Exemple #10
0
        private void TryAssertionCreateSchema(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            string startA = "2002-05-30T09:00:00.000";
            string endA   = "2002-05-30T09:00:01.000";
            string startB = "2002-05-30T09:00:00.500";
            string endB   = "2002-05-30T09:00:00.700";

            // test Map type long-type timestamps
            RunAssertionCreateSchemaWTypes(epService, eventRepresentationEnum, "long",
                                           DateTimeParser.ParseDefaultMSec(startA), DateTimeParser.ParseDefaultMSec(endA),
                                           DateTimeParser.ParseDefaultMSec(startB), DateTimeParser.ParseDefaultMSec(endB));

            // test Map type DateTimeEx-type timestamps
            if (!eventRepresentationEnum.IsAvroEvent())
            {
                RunAssertionCreateSchemaWTypes(
                    epService, eventRepresentationEnum, typeof(DateTimeEx).FullName,
                    DateTimeParser.ParseDefaultEx(startA), DateTimeParser.ParseDefaultEx(endA),
                    DateTimeParser.ParseDefaultEx(startB), DateTimeParser.ParseDefaultEx(endB));
            }

            // test Map type DateTimeEx-type timestamps
            if (!eventRepresentationEnum.IsAvroEvent())
            {
                RunAssertionCreateSchemaWTypes(epService, eventRepresentationEnum, typeof(DateTimeOffset).FullName,
                                               DateTimeParser.ParseDefaultDate(startA), DateTimeParser.ParseDefaultDate(endA),
                                               DateTimeParser.ParseDefaultDate(startB), DateTimeParser.ParseDefaultDate(endB));
            }

            // test Bean-type Date-type timestamps
            string epl = eventRepresentationEnum.GetAnnotationText() + " create schema SupportBean as " + typeof(SupportBean).FullName + " starttimestamp LongPrimitive endtimestamp LongBoxed";

            epService.EPAdministrator.CreateEPL(epl);

            EPStatement stmt     = epService.EPAdministrator.CreateEPL("select a.Get('month') as val0 from SupportBean a");
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var theEvent = new SupportBean();

            theEvent.LongPrimitive = DateTimeParser.ParseDefaultMSec(startA);
            epService.EPRuntime.SendEvent(theEvent);
            Assert.AreEqual(5, listener.AssertOneGetNewAndReset().Get("val0"));

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

            Assert.AreEqual(epl.Trim(), model.ToEPL());
            stmt = epService.EPAdministrator.Create(model);
            Assert.AreEqual(epl.Trim(), stmt.Text);

            // try XML
            var desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName            = "ABC";
            desc.StartTimestampPropertyName = "mystarttimestamp";
            desc.EndTimestampPropertyName   = "myendtimestamp";
            desc.AddXPathProperty("mystarttimestamp", "/test/prop", XPathResultType.Number);
            try {
                epService.EPAdministrator.Configuration.AddEventType("TypeXML", desc);
                Assert.Fail();
            } catch (ConfigurationException ex) {
                Assert.AreEqual("Declared start timestamp property 'mystarttimestamp' is expected to return a DateTime, DateTimeEx or long-typed value but returns '" + Name.Clean <double>() + "'", ex.Message);
            }
        }
Exemple #11
0
        private void RunAssertionFullJoin_2sides_multicolumn(EventRepresentationChoice eventRepresentationEnum)
        {
            var fields = "s0.id, s0.p00, s0.p01, s1.id, s1.p10, s1.p11, s2.id, s2.p20, s2.p21".SplitCsv();

            string joinStatement = eventRepresentationEnum.GetAnnotationText() + " select * from " +
                                   EVENT_S0 + "#length(1000) as s0 " +
                                   " full outer join " + EVENT_S1 + "#length(1000) as s1 on s0.p00 = s1.p10 and s0.p01 = s1.p11" +
                                   " full outer join " + EVENT_S2 + "#length(1000) as s2 on s0.p00 = s2.p20 and s0.p01 = s2.p21";

            EPStatement joinView = _epService.EPAdministrator.CreateEPL(joinStatement);

            joinView.AddListener(_updateListener);

            _epService.EPRuntime.SendEvent(new SupportBean_S1(10, "A_1", "B_1"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 10, "A_1", "B_1", null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S1(11, "A_2", "B_1"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 11, "A_2", "B_1", null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S1(12, "A_1", "B_2"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 12, "A_1", "B_2", null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S1(13, "A_2", "B_2"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 13, "A_2", "B_2", null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S2(20, "A_1", "B_1"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 20, "A_1", "B_1" });

            _epService.EPRuntime.SendEvent(new SupportBean_S2(21, "A_2", "B_1"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 21, "A_2", "B_1" });

            _epService.EPRuntime.SendEvent(new SupportBean_S2(22, "A_1", "B_2"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 22, "A_1", "B_2" });

            _epService.EPRuntime.SendEvent(new SupportBean_S2(23, "A_2", "B_2"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 23, "A_2", "B_2" });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A_3", "B_3"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 1, "A_3", "B_3", null, null, null, null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "A_1", "B_3"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 2, "A_1", "B_3", null, null, null, null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(3, "A_3", "B_1"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 3, "A_3", "B_1", null, null, null, null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(4, "A_2", "B_2"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 4, "A_2", "B_2", 13, "A_2", "B_2", 23, "A_2", "B_2" });

            _epService.EPRuntime.SendEvent(new SupportBean_S0(5, "A_2", "B_1"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 5, "A_2", "B_1", 11, "A_2", "B_1", 21, "A_2", "B_1" });

            _epService.EPRuntime.SendEvent(new SupportBean_S1(14, "A_4", "B_3"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 14, "A_4", "B_3", null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S1(15, "A_1", "B_3"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 2, "A_1", "B_3", 15, "A_1", "B_3", null, null, null });

            _epService.EPRuntime.SendEvent(new SupportBean_S2(24, "A_1", "B_3"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { 2, "A_1", "B_3", 15, "A_1", "B_3", 24, "A_1", "B_3" });

            _epService.EPRuntime.SendEvent(new SupportBean_S2(25, "A_2", "B_3"));
            EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 25, "A_2", "B_3" });

            _epService.EPAdministrator.DestroyAllStatements();
        }
Exemple #12
0
        private void RunAssertionNamedWindowSetMapProps(EventRepresentationChoice eventRepresentationEnum)
        {
            // test named-window update
            _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean));
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyNWInfraType(simple string, myarray int[], mymap com.espertech.esper.compat.collections.StringMap)");
            EPStatement stmtWin = _epService.EPAdministrator.CreateEPL("create window MyWindow#keepall as MyNWInfraType");

            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " insert into MyWindow select * from MyNWInfraType");

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { null, new int[10], new Dictionary <string, Object>() }, "MyNWInfraType");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyNWInfraType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyNWInfraType").AsRecordSchema());
                theEvent.Put("myarray", Collections.List(0, 0, 0, 0, 0));
                theEvent.Put("mymap", new Dictionary <string, object>());
                _epService.EPRuntime.SendEventAvro(theEvent, "MyNWInfraType");
            }
            else
            {
                Assert.Fail();
            }
            _epService.EPAdministrator.CreateEPL("on SupportBean update MyWindow set simple='A', mymap('abc') = intPrimitive, myarray[2] = intPrimitive");
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 10));
            EPAssertionUtil.AssertPropsPerRow(stmtWin.GetEnumerator(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[][] { new Object[] { "A", 10, 10 } });

            // test null and array too small
            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { null, new int[2], null }, "MyNWInfraType");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(MakeMapEvent(null, new int[2]), "MyNWInfraType");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                GenericRecord theEvent = new GenericRecord(
                    SchemaBuilder.Record(
                        "name",
                        TypeBuilder.OptionalString("simple"),
                        TypeBuilder.Field("myarray", TypeBuilder.Array(TypeBuilder.Long())),
                        TypeBuilder.Field("mymap", TypeBuilder.Map(TypeBuilder.String()))));

                theEvent.Put("myarray", Collections.List(0, 0));
                theEvent.Put("mymap", null);
                _epService.EPRuntime.SendEventAvro(theEvent, "MyNWInfraType");
            }
            else
            {
                Assert.Fail();
            }
            _epService.EPRuntime.SendEvent(new SupportBean("E2", 20));
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtWin.GetEnumerator(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[][] { new Object[] { "A", 20, 20 }, new Object[] { "A", null, null } });

            _epService.Initialize();
        }
Exemple #13
0
        private void TryAssertionFragment(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema InnerSchema as (key string)");
            epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MySchema as (inside InnerSchema, insidearr InnerSchema[])");

            var fields   = new[] { "t0", "t1" };
            var stmtText = eventRepresentationEnum.GetAnnotationText() + " select typeof(s0.inside) as t0, typeof(s0.insidearr) as t1 from MySchema as s0";
            var stmt     = epService.EPAdministrator.CreateEPL(stmtText);
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[2], "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                epService.EPRuntime.SendEventAvro(new GenericRecord(
                                                      SupportAvroUtil.GetAvroSchema(epService, "MySchema").AsRecordSchema()), "MySchema");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null });

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { new object[2], null }, "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                var theEvent = new Dictionary <string, object>();
                theEvent.Put("inside", new Dictionary <string, object>());
                epService.EPRuntime.SendEvent(theEvent, "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var mySchema    = SupportAvroUtil.GetAvroSchema(epService, "MySchema").AsRecordSchema();
                var innerSchema = SupportAvroUtil.GetAvroSchema(epService, "InnerSchema").AsRecordSchema();
                var @event      = new GenericRecord(mySchema);
                @event.Put("inside", new GenericRecord(innerSchema));
                epService.EPRuntime.SendEventAvro(@event, "MySchema");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "InnerSchema", null });

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                epService.EPRuntime.SendEvent(new object[] { null, new object[2][] }, "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                var theEvent = new Dictionary <string, object>();
                theEvent.Put("insidearr", new Map[0]);
                epService.EPRuntime.SendEvent(theEvent, "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(
                                                   epService, "MySchema").AsRecordSchema());
                @event.Put("insidearr", Collections.GetEmptyList <object>());
                epService.EPRuntime.SendEventAvro(@event, "MySchema");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, "InnerSchema[]" });

            epService.EPAdministrator.DestroyAllStatements();
            epService.EPAdministrator.Configuration.RemoveEventType("InnerSchema", true);
            epService.EPAdministrator.Configuration.RemoveEventType("MySchema", true);
        }
Exemple #14
0
        private void RunAssertionVariantStream(EventRepresentationChoice eventRepresentationEnum)
        {
            _epService.EPAdministrator.Configuration.AddEventType(
                "SupportBean", typeof(SupportBean));

            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema EventOne as (key string)");
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema EventTwo as (key string)");
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create schema S0 as "
                + typeof(SupportBean_S0).FullName);
            _epService.EPAdministrator.CreateEPL(
                eventRepresentationEnum.GetAnnotationText()
                + " create variant schema VarSchema as *");

            _epService.EPAdministrator.CreateEPL(
                "insert into VarSchema select * from EventOne");
            _epService.EPAdministrator.CreateEPL(
                "insert into VarSchema select * from EventTwo");
            _epService.EPAdministrator.CreateEPL(
                "insert into VarSchema select * from S0");
            _epService.EPAdministrator.CreateEPL(
                "insert into VarSchema select * from SupportBean");

            String      stmtText = "select Typeof(A) as t0 from VarSchema as A";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.Events += _listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { "value" }, "EventOne");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(
                    Collections.SingletonMap <string, object>("key", "value"), "EventOne");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var record = new GenericRecord(SchemaBuilder.Record("EventOne", TypeBuilder.RequiredString("key")));
                record.Put("key", "value");
                _epService.EPRuntime.SendEventAvro(record, "EventOne");
            }
            else
            {
                Assert.Fail();
            }
            Assert.AreEqual("EventOne", _listener.AssertOneGetNewAndReset().Get("t0"));

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { "value" }, "EventTwo");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(
                    Collections.SingletonMap <string, object>("key", "value"), "EventTwo");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var record = new GenericRecord(SchemaBuilder.Record("EventTwo", TypeBuilder.RequiredString("key")));
                record.Put("key", "value");
                _epService.EPRuntime.SendEventAvro(record, "EventTwo");
            }
            else
            {
                Assert.Fail();
            }
            Assert.AreEqual("EventTwo", _listener.AssertOneGetNewAndReset().Get("t0"));

            _epService.EPRuntime.SendEvent(new SupportBean_S0(1));
            Assert.AreEqual("S0", _listener.AssertOneGetNewAndReset().Get("t0"));

            _epService.EPRuntime.SendEvent(new SupportBean());
            Assert.AreEqual("SupportBean", _listener.AssertOneGetNewAndReset().Get("t0"));

            stmt.Dispose();
            _listener.Reset();
            stmt = _epService.EPAdministrator.CreateEPL(
                "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" + "  )");
            stmt.Events += _listener.Update;

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { "value" }, "EventOne");
                _epService.EPRuntime.SendEvent(new Object[] { "value" }, "EventTwo");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(
                    Collections.SingletonMap <string, object>("key", "value"), "EventOne");
                _epService.EPRuntime.SendEvent(
                    Collections.SingletonMap <string, object>("key", "value"), "EventTwo");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var schema   = SchemaBuilder.Record("EventTwo", TypeBuilder.RequiredString("key"));
                var eventOne = new GenericRecord(schema);
                eventOne.Put("key", "value");
                var eventTwo = new GenericRecord(schema);
                eventTwo.Put("key", "value");
                _epService.EPRuntime.SendEventAvro(eventOne, "EventOne");
                _epService.EPRuntime.SendEventAvro(eventTwo, "EventTwo");
            }
            else
            {
                Assert.Fail();
            }
            Assert.IsTrue(_listener.GetAndClearIsInvoked());

            _listener.Reset();
            _epService.Initialize();
        }
        private void TryAssertionFullJoin_2sides_multicolumn(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum)
        {
            string[] fields = "s0.id, s0.p00, s0.p01, s1.id, s1.p10, s1.p11, s2.id, s2.p20, s2.p21".Split(',');

            string epl = eventRepresentationEnum.GetAnnotationText() + " select * from " +
                         EVENT_S0 + "#length(1000) as s0 " +
                         " full outer join " + EVENT_S1 + "#length(1000) as s1 on s0.p00 = s1.p10 and s0.p01 = s1.p11" +
                         " full outer join " + EVENT_S2 + "#length(1000) as s2 on s0.p00 = s2.p20 and s0.p01 = s2.p21";

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

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean_S1(10, "A_1", "B_1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 10, "A_1", "B_1", null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S1(11, "A_2", "B_1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 11, "A_2", "B_1", null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S1(12, "A_1", "B_2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 12, "A_1", "B_2", null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S1(13, "A_2", "B_2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 13, "A_2", "B_2", null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S2(20, "A_1", "B_1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 20, "A_1", "B_1" });

            epService.EPRuntime.SendEvent(new SupportBean_S2(21, "A_2", "B_1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 21, "A_2", "B_1" });

            epService.EPRuntime.SendEvent(new SupportBean_S2(22, "A_1", "B_2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 22, "A_1", "B_2" });

            epService.EPRuntime.SendEvent(new SupportBean_S2(23, "A_2", "B_2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 23, "A_2", "B_2" });

            epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A_3", "B_3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, "A_3", "B_3", null, null, null, null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S0(2, "A_1", "B_3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "A_1", "B_3", null, null, null, null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S0(3, "A_3", "B_1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3, "A_3", "B_1", null, null, null, null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S0(4, "A_2", "B_2"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 4, "A_2", "B_2", 13, "A_2", "B_2", 23, "A_2", "B_2" });

            epService.EPRuntime.SendEvent(new SupportBean_S0(5, "A_2", "B_1"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 5, "A_2", "B_1", 11, "A_2", "B_1", 21, "A_2", "B_1" });

            epService.EPRuntime.SendEvent(new SupportBean_S1(14, "A_4", "B_3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, 14, "A_4", "B_3", null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S1(15, "A_1", "B_3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "A_1", "B_3", 15, "A_1", "B_3", null, null, null });

            epService.EPRuntime.SendEvent(new SupportBean_S2(24, "A_1", "B_3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "A_1", "B_3", 15, "A_1", "B_3", 24, "A_1", "B_3" });

            epService.EPRuntime.SendEvent(new SupportBean_S2(25, "A_2", "B_3"));
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, 25, "A_2", "B_3" });

            epService.EPAdministrator.DestroyAllStatements();
        }
Exemple #16
0
        public void RunAssertionFragment(EventRepresentationChoice eventRepresentationEnum)
        {
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema InnerSchema as (key string)");
            _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MySchema as (inside InnerSchema, insidearr InnerSchema[])");

            var         fields   = new string[] { "t0", "t1" };
            string      stmtText = eventRepresentationEnum.GetAnnotationText() + " select typeof(s0.inside) as t0, typeof(s0.insidearr) as t1 from MySchema as s0";
            EPStatement stmt     = _epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(_listener);

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[2], "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                _epService.EPRuntime.SendEvent(new Dictionary <string, Object>(), "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                _epService.EPRuntime.SendEventAvro(
                    new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MySchema").AsRecordSchema()), "MySchema");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null });

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { new Object[2], null }, "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                var theEvent = new Dictionary <string, Object>();
                theEvent.Put("inside", new Dictionary <string, Object>());
                _epService.EPRuntime.SendEvent(theEvent, "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                var           mySchema    = SupportAvroUtil.GetAvroSchema(_epService, "MySchema");
                var           innerSchema = SupportAvroUtil.GetAvroSchema(_epService, "InnerSchema");
                GenericRecord theEvent    = new GenericRecord(mySchema.AsRecordSchema());
                theEvent.Put("inside", new GenericRecord(innerSchema.AsRecordSchema()));
                _epService.EPRuntime.SendEventAvro(theEvent, "MySchema");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "InnerSchema", null });

            if (eventRepresentationEnum.IsObjectArrayEvent())
            {
                _epService.EPRuntime.SendEvent(new Object[] { null, new Object[2][] }, "MySchema");
            }
            else if (eventRepresentationEnum.IsMapEvent())
            {
                var theEvent = new Dictionary <string, Object>();
                theEvent.Put("insidearr", new IDictionary <string, object> [0]);
                _epService.EPRuntime.SendEvent(theEvent, "MySchema");
            }
            else if (eventRepresentationEnum.IsAvroEvent())
            {
                GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MySchema").AsRecordSchema());
                theEvent.Put("insidearr", Collections.GetEmptyList <object>());
                _epService.EPRuntime.SendEventAvro(theEvent, "MySchema");
            }
            else
            {
                Assert.Fail();
            }
            EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, "InnerSchema[]" });

            _epService.EPAdministrator.DestroyAllStatements();
            _epService.EPAdministrator.Configuration.RemoveEventType("InnerSchema", true);
            _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", true);
        }
Exemple #17
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();
        }