示例#1
0
        private void TryPublicAccessors(CodeGenerationEnum codeGeneration)
        {
            var config = SupportConfigFactory.GetConfiguration();

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            var legacyDef = new ConfigurationEventTypeLegacy();

            legacyDef.AccessorStyle  = AccessorStyleEnum.PUBLIC;
            legacyDef.CodeGeneration = codeGeneration;
            legacyDef.AddFieldProperty("explicitFSimple", "fieldLegacyVal");
            legacyDef.AddFieldProperty("explicitFIndexed", "fieldStringArray");
            legacyDef.AddFieldProperty("explicitFNested", "fieldNested");
            legacyDef.AddMethodProperty("explicitMSimple", "ReadLegacyBeanVal");
            legacyDef.AddMethodProperty("explicitMArray", "ReadStringArray");
            legacyDef.AddMethodProperty("explicitMIndexed", "ReadStringIndexed");
            legacyDef.AddMethodProperty("explicitMMapped", "ReadMapByKey");
            _epService.EPAdministrator.Configuration.AddEventType("MyLegacyEvent", typeof(SupportLegacyBean).FullName, legacyDef);

            legacyDef = new ConfigurationEventTypeLegacy();
            legacyDef.AccessorStyle  = AccessorStyleEnum.PUBLIC;
            legacyDef.CodeGeneration = CodeGenerationEnum.DISABLED;
            _epService.EPAdministrator.Configuration.AddEventType("MyLegacyNestedEvent", typeof(SupportLegacyBean.LegacyNested).FullName, legacyDef);

            // assert type metadata
            var type = (EventTypeSPI)((EPServiceProviderSPI)_epService).EventAdapterService.GetEventTypeByName("MyLegacyEvent");

            Assert.AreEqual(ApplicationType.CLASS, type.Metadata.OptionalApplicationType);
            Assert.AreEqual(1, type.Metadata.OptionalSecondaryNames.Count);
            Assert.AreEqual(typeof(SupportLegacyBean).Name, type.Metadata.OptionalSecondaryNames.First());
            Assert.AreEqual("MyLegacyEvent", type.Metadata.PrimaryName);
            Assert.AreEqual("MyLegacyEvent", type.Metadata.PublicName);
            Assert.AreEqual(TypeClass.APPLICATION, type.Metadata.TypeClass);
            Assert.AreEqual(true, type.Metadata.IsApplicationConfigured);
            Assert.AreEqual(false, type.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(false, type.Metadata.IsApplicationPreConfiguredStatic);

            var statementText = "select " +
                                "fieldLegacyVal as fieldSimple," +
                                "fieldStringArray as fieldArr," +
                                "fieldStringArray[1] as fieldArrIndexed," +
                                "fieldMapped as fieldMap," +
                                "fieldNested as fieldNested," +
                                "fieldNested.ReadNestedValue as fieldNestedVal," +
                                "ReadLegacyBeanVal as simple," +
                                "ReadLegacyNested as nestedObject," +
                                "ReadLegacyNested.ReadNestedValue as nested," +
                                "ReadStringArray[0] as array," +
                                "ReadStringIndexed[1] as indexed," +
                                "ReadMapByKey('key1') as mapped," +
                                "ReadMap as mapItself," +
                                "explicitFSimple, " +
                                "explicitFIndexed[0], " +
                                "explicitFNested, " +
                                "explicitMSimple, " +
                                "explicitMArray[0], " +
                                "explicitMIndexed[1], " +
                                "explicitMMapped('key2')" +
                                " from MyLegacyEvent#length(5)";

            var statement = _epService.EPAdministrator.CreateEPL(statementText);
            var listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            var eventType = statement.EventType;

            Assert.AreEqual(typeof(string), eventType.GetPropertyType("fieldSimple"));
            Assert.AreEqual(typeof(String[]), eventType.GetPropertyType("fieldArr"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("fieldArrIndexed"));
            Assert.AreEqual(typeof(IDictionary <string, string>), eventType.GetPropertyType("fieldMap"));
            Assert.AreEqual(typeof(SupportLegacyBean.LegacyNested), eventType.GetPropertyType("fieldNested"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("fieldNestedVal"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("simple"));
            Assert.AreEqual(typeof(SupportLegacyBean.LegacyNested), eventType.GetPropertyType("nestedObject"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("nested"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("array"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("indexed"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("mapped"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitFSimple"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitFIndexed[0]"));
            Assert.AreEqual(typeof(SupportLegacyBean.LegacyNested), eventType.GetPropertyType("explicitFNested"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMSimple"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMArray[0]"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMIndexed[1]"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMMapped('key2')"));

            _epService.EPRuntime.SendEvent(_legacyBean);

            Assert.AreEqual(_legacyBean.fieldLegacyVal, listener.LastNewData[0].Get("fieldSimple"));
            Assert.AreEqual(_legacyBean.fieldStringArray, listener.LastNewData[0].Get("fieldArr"));
            Assert.AreEqual(_legacyBean.fieldStringArray[1], listener.LastNewData[0].Get("fieldArrIndexed"));
            Assert.AreEqual(_legacyBean.fieldMapped, listener.LastNewData[0].Get("fieldMap"));
            Assert.AreEqual(_legacyBean.fieldNested, listener.LastNewData[0].Get("fieldNested"));
            Assert.AreEqual(_legacyBean.fieldNested.ReadNestedValue(), listener.LastNewData[0].Get("fieldNestedVal"));

            Assert.AreEqual(_legacyBean.ReadLegacyBeanVal(), listener.LastNewData[0].Get("simple"));
            Assert.AreEqual(_legacyBean.ReadLegacyNested(), listener.LastNewData[0].Get("nestedObject"));
            Assert.AreEqual(_legacyBean.ReadLegacyNested().ReadNestedValue(), listener.LastNewData[0].Get("nested"));
            Assert.AreEqual(_legacyBean.ReadStringIndexed(0), listener.LastNewData[0].Get("array"));
            Assert.AreEqual(_legacyBean.ReadStringIndexed(1), listener.LastNewData[0].Get("indexed"));
            Assert.AreEqual(_legacyBean.ReadMapByKey("key1"), listener.LastNewData[0].Get("mapped"));
            Assert.AreEqual(_legacyBean.ReadMap(), listener.LastNewData[0].Get("mapItself"));

            Assert.AreEqual(_legacyBean.ReadLegacyBeanVal(), listener.LastNewData[0].Get("explicitFSimple"));
            Assert.AreEqual(_legacyBean.ReadLegacyBeanVal(), listener.LastNewData[0].Get("explicitMSimple"));
            Assert.AreEqual(_legacyBean.ReadLegacyNested(), listener.LastNewData[0].Get("explicitFNested"));
            Assert.AreEqual(_legacyBean.ReadStringIndexed(0), listener.LastNewData[0].Get("explicitFIndexed[0]"));
            Assert.AreEqual(_legacyBean.ReadStringIndexed(0), listener.LastNewData[0].Get("explicitMArray[0]"));
            Assert.AreEqual(_legacyBean.ReadStringIndexed(1), listener.LastNewData[0].Get("explicitMIndexed[1]"));
            Assert.AreEqual(_legacyBean.ReadMapByKey("key2"), listener.LastNewData[0].Get("explicitMMapped('key2')"));

            var stmtType = (EventTypeSPI)statement.EventType;

            Assert.AreEqual(ApplicationType.MAP, stmtType.Metadata.OptionalApplicationType);
            Assert.AreEqual(null, stmtType.Metadata.OptionalSecondaryNames);
            Assert.NotNull(stmtType.Metadata.PrimaryName);
            Assert.NotNull(stmtType.Metadata.PublicName);
            Assert.NotNull(stmtType.Name);
            Assert.AreEqual(TypeClass.ANONYMOUS, stmtType.Metadata.TypeClass);
            Assert.AreEqual(false, stmtType.Metadata.IsApplicationConfigured);
            Assert.AreEqual(false, stmtType.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(false, stmtType.Metadata.IsApplicationPreConfiguredStatic);

            _epService.Dispose();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public override void Run(EPServiceProvider epService)
        {
            var legacyDef = new ConfigurationEventTypeLegacy();

            legacyDef.AccessorStyle  = AccessorStyleEnum.PUBLIC;
            legacyDef.CodeGeneration = _codegen ? CodeGenerationEnum.ENABLED : CodeGenerationEnum.DISABLED;
            legacyDef.AddFieldProperty("explicitFSimple", "fieldLegacyVal");
            legacyDef.AddFieldProperty("explicitFIndexed", "fieldStringArray");
            legacyDef.AddFieldProperty("explicitFNested", "fieldNested");
            legacyDef.AddMethodProperty("explicitMSimple", "ReadLegacyBeanVal");
            legacyDef.AddMethodProperty("explicitMArray", "ReadStringArray");
            legacyDef.AddMethodProperty("explicitMIndexed", "ReadStringIndexed");
            legacyDef.AddMethodProperty("explicitMMapped", "ReadMapByKey");
            epService.EPAdministrator.Configuration.AddEventType <SupportLegacyBean>("MyLegacyEvent", legacyDef);

            legacyDef = new ConfigurationEventTypeLegacy();
            legacyDef.AccessorStyle  = AccessorStyleEnum.PUBLIC;
            legacyDef.CodeGeneration = CodeGenerationEnum.DISABLED;
            epService.EPAdministrator.Configuration.AddEventType <SupportLegacyBean.LegacyNested>("MyLegacyNestedEvent", legacyDef);

            // assert type metadata
            EventTypeSPI type = (EventTypeSPI)((EPServiceProviderSPI)epService).EventAdapterService.GetEventTypeByName("MyLegacyEvent");

            Assert.AreEqual(ApplicationType.CLASS, type.Metadata.OptionalApplicationType);
            Assert.AreEqual(1, type.Metadata.OptionalSecondaryNames.Count);
            Assert.AreEqual(typeof(SupportLegacyBean).Name, type.Metadata.OptionalSecondaryNames.First());
            Assert.AreEqual("MyLegacyEvent", type.Metadata.PrimaryName);
            Assert.AreEqual("MyLegacyEvent", type.Metadata.PublicName);
            Assert.AreEqual(TypeClass.APPLICATION, type.Metadata.TypeClass);
            Assert.AreEqual(true, type.Metadata.IsApplicationConfigured);
            Assert.AreEqual(false, type.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(false, type.Metadata.IsApplicationPreConfiguredStatic);

            string statementText = "select " +
                                   "fieldLegacyVal as fieldSimple," +
                                   "fieldStringArray as fieldArr," +
                                   "fieldStringArray[1] as fieldArrIndexed," +
                                   "fieldMapped as fieldMap," +
                                   "fieldNested as fieldNested," +
                                   "fieldNested.ReadNestedValue as fieldNestedVal," +
                                   "ReadLegacyBeanVal as simple," +
                                   "ReadLegacyNested as nestedObject," +
                                   "ReadLegacyNested.ReadNestedValue as nested," +
                                   "ReadStringArray[0] as array," +
                                   "ReadStringIndexed[1] as indexed," +
                                   "ReadMapByKey('key1') as mapped," +
                                   "ReadMap as mapItself," +
                                   "explicitFSimple, " +
                                   "explicitFIndexed[0], " +
                                   "explicitFNested, " +
                                   "explicitMSimple, " +
                                   "explicitMArray[0], " +
                                   "explicitMIndexed[1], " +
                                   "explicitMMapped('key2')" +
                                   " from MyLegacyEvent#length(5)";

            EPStatement statement = epService.EPAdministrator.CreateEPL(statementText);
            var         listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            EventType eventType = statement.EventType;

            Assert.AreEqual(typeof(string), eventType.GetPropertyType("fieldSimple"));
            Assert.AreEqual(typeof(string[]), eventType.GetPropertyType("fieldArr"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("fieldArrIndexed"));
            Assert.AreEqual(typeof(IDictionary <string, string>), eventType.GetPropertyType("fieldMap"));
            Assert.AreEqual(typeof(SupportLegacyBean.LegacyNested), eventType.GetPropertyType("fieldNested"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("fieldNestedVal"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("simple"));
            Assert.AreEqual(typeof(SupportLegacyBean.LegacyNested), eventType.GetPropertyType("nestedObject"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("nested"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("array"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("indexed"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("mapped"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitFSimple"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitFIndexed[0]"));
            Assert.AreEqual(typeof(SupportLegacyBean.LegacyNested), eventType.GetPropertyType("explicitFNested"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMSimple"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMArray[0]"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMIndexed[1]"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("explicitMMapped('key2')"));

            SupportLegacyBean legacyBean = MakeSampleEvent();

            epService.EPRuntime.SendEvent(legacyBean);

            Assert.AreEqual(legacyBean.fieldLegacyVal, listener.LastNewData[0].Get("fieldSimple"));
            Assert.AreEqual(legacyBean.fieldStringArray, listener.LastNewData[0].Get("fieldArr"));
            Assert.AreEqual(legacyBean.fieldStringArray[1], listener.LastNewData[0].Get("fieldArrIndexed"));
            Assert.AreEqual(legacyBean.fieldMapped, listener.LastNewData[0].Get("fieldMap"));
            Assert.AreEqual(legacyBean.fieldNested, listener.LastNewData[0].Get("fieldNested"));
            Assert.AreEqual(legacyBean.fieldNested.ReadNestedValue(), listener.LastNewData[0].Get("fieldNestedVal"));

            Assert.AreEqual(legacyBean.ReadLegacyBeanVal(), listener.LastNewData[0].Get("simple"));
            Assert.AreEqual(legacyBean.ReadLegacyNested(), listener.LastNewData[0].Get("nestedObject"));
            Assert.AreEqual(legacyBean.ReadLegacyNested().ReadNestedValue(), listener.LastNewData[0].Get("nested"));
            Assert.AreEqual(legacyBean.ReadStringIndexed(0), listener.LastNewData[0].Get("array"));
            Assert.AreEqual(legacyBean.ReadStringIndexed(1), listener.LastNewData[0].Get("indexed"));
            Assert.AreEqual(legacyBean.ReadMapByKey("key1"), listener.LastNewData[0].Get("mapped"));
            Assert.AreEqual(legacyBean.ReadMap(), listener.LastNewData[0].Get("mapItself"));

            Assert.AreEqual(legacyBean.ReadLegacyBeanVal(), listener.LastNewData[0].Get("explicitFSimple"));
            Assert.AreEqual(legacyBean.ReadLegacyBeanVal(), listener.LastNewData[0].Get("explicitMSimple"));
            Assert.AreEqual(legacyBean.ReadLegacyNested(), listener.LastNewData[0].Get("explicitFNested"));
            Assert.AreEqual(legacyBean.ReadStringIndexed(0), listener.LastNewData[0].Get("explicitFIndexed[0]"));
            Assert.AreEqual(legacyBean.ReadStringIndexed(0), listener.LastNewData[0].Get("explicitMArray[0]"));
            Assert.AreEqual(legacyBean.ReadStringIndexed(1), listener.LastNewData[0].Get("explicitMIndexed[1]"));
            Assert.AreEqual(legacyBean.ReadMapByKey("key2"), listener.LastNewData[0].Get("explicitMMapped('key2')"));

            EventTypeSPI stmtType = (EventTypeSPI)statement.EventType;

            Assert.AreEqual(ApplicationType.MAP, stmtType.Metadata.OptionalApplicationType);
            Assert.AreEqual(null, stmtType.Metadata.OptionalSecondaryNames);
            Assert.IsNotNull(stmtType.Metadata.PrimaryName);
            Assert.IsNotNull(stmtType.Metadata.PublicName);
            Assert.IsNotNull(stmtType.Name);
            Assert.AreEqual(TypeClass.ANONYMOUS, stmtType.Metadata.TypeClass);
            Assert.AreEqual(false, stmtType.Metadata.IsApplicationConfigured);
            Assert.AreEqual(false, stmtType.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(false, stmtType.Metadata.IsApplicationPreConfiguredStatic);
        }