public void TestInvalidInsertInto()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBean");
            variant.AddEventTypeName("SupportBeanVariantStream");
            _epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStream", variant);

            try
            {
                _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from " + typeof(SupportBean_A).FullName);
                Assert.Fail();
            }
            catch (EPStatementException ex)
            {
                Assert.AreEqual("Error starting statement: Selected event type is not a valid event type of the variant stream 'MyVariantStream' [insert into MyVariantStream select * from com.espertech.esper.support.bean.SupportBean_A]", ex.Message);
            }

            try
            {
                _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select IntPrimitive as k0 from " + typeof(SupportBean).FullName);
                Assert.Fail();
            }
            catch (EPStatementException ex)
            {
                Assert.AreEqual("Error starting statement: Selected event type is not a valid event type of the variant stream 'MyVariantStream' [insert into MyVariantStream select IntPrimitive as k0 from com.espertech.esper.support.bean.SupportBean]", ex.Message);
            }
        }
        private void RunAssertionAnyTypeStaggered(EPServiceProvider epService)
        {
            // test insert into staggered with map
            var configVariantStream = new ConfigurationVariantStream();

            configVariantStream.TypeVariance = TypeVarianceEnum.ANY;
            epService.EPAdministrator.Configuration.AddVariantStream("VarStream", configVariantStream);
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddEventType("SupportMarketDataBean", typeof(SupportMarketDataBean));

            epService.EPAdministrator.CreateEPL("insert into MyStream select TheString, IntPrimitive from SupportBean");
            epService.EPAdministrator.CreateEPL("insert into VarStream select TheString as abc from MyStream");
            epService.EPAdministrator.CreateEPL("@Name('Target') select * from VarStream#keepall");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));

            EventBean[] arr = EPAssertionUtil.EnumeratorToArray(epService.EPAdministrator.GetStatement("Target").GetEnumerator());
            EPAssertionUtil.AssertPropsPerRow(arr, new string[] { "abc" }, new object[][] { new object[] { "E1" } });

            epService.EPAdministrator.CreateEPL("insert into MyStream2 select feed from SupportMarketDataBean");
            epService.EPAdministrator.CreateEPL("insert into VarStream select feed as abc from MyStream2");

            epService.EPRuntime.SendEvent(new SupportMarketDataBean("IBM", 1, 1L, "E2"));

            arr = EPAssertionUtil.EnumeratorToArray(epService.EPAdministrator.GetStatement("Target").GetEnumerator());
            EPAssertionUtil.AssertPropsPerRow(arr, new string[] { "abc" }, new object[][] { new object[] { "E1" }, new object[] { "E2" } });

            epService.EPAdministrator.DestroyAllStatements();
        }
Beispiel #3
0
        /// <summary>Validate the variant stream definition. </summary>
        /// <param name="variantStreamname">the stream name</param>
        /// <param name="variantStreamConfig">the configuration information</param>
        /// <param name="eventAdapterService">the event adapters</param>
        /// <returns>specification for variant streams</returns>
        public static VariantSpec ValidateVariantStream(String variantStreamname, ConfigurationVariantStream variantStreamConfig, EventAdapterService eventAdapterService)
        {
            if (variantStreamConfig.TypeVariance == TypeVarianceEnum.PREDEFINED)
            {
                if (variantStreamConfig.VariantTypeNames.IsEmpty())
                {
                    throw new ConfigurationException("Invalid variant stream configuration, no event type name has been added and default type variance requires at least one type, for name '" + variantStreamname + "'");
                }
            }

            ICollection <EventType> types = new LinkedHashSet <EventType>();

            foreach (String typeName in variantStreamConfig.VariantTypeNames)
            {
                EventType type = eventAdapterService.GetEventTypeByName(typeName);
                if (type == null)
                {
                    throw new ConfigurationException("Event type by name '" + typeName + "' could not be found for use in variant stream configuration by name '" + variantStreamname + "'");
                }
                types.Add(type);
            }

            EventType[] eventTypes = types.ToArray();
            return(new VariantSpec(variantStreamname, eventTypes, variantStreamConfig.TypeVariance));
        }
        public void TestDynamicMapType()
        {
            IDictionary <String, Object> types = new Dictionary <String, Object>();

            types["someprop"] = typeof(string);

            _epService.EPAdministrator.Configuration.AddEventType("MyEvent", types);
            _epService.EPAdministrator.Configuration.AddEventType("MySecondEvent", types);

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("MyEvent");
            variant.AddEventTypeName("MySecondEvent");
            _epService.EPAdministrator.Configuration.AddVariantStream("MyVariant", variant);

            _epService.EPAdministrator.CreateEPL("insert into MyVariant select * from MyEvent");
            _epService.EPAdministrator.CreateEPL("insert into MyVariant select * from MySecondEvent");

            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from MyVariant");

            stmt.Events += _listenerOne.Update;
            _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MyEvent");
            Assert.NotNull(_listenerOne.AssertOneGetNewAndReset());
            _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MySecondEvent");
            Assert.NotNull(_listenerOne.AssertOneGetNewAndReset());
        }
        private void RunAssertionDynamicMapType(EPServiceProvider epService)
        {
            var types = new Dictionary <string, Object>();

            types.Put("someprop", typeof(string));

            epService.EPAdministrator.Configuration.AddEventType("MyEvent", types);
            epService.EPAdministrator.Configuration.AddEventType("MySecondEvent", types);

            var variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("MyEvent");
            variant.AddEventTypeName("MySecondEvent");
            epService.EPAdministrator.Configuration.AddVariantStream("MyVariant", variant);

            epService.EPAdministrator.CreateEPL("insert into MyVariant select * from MyEvent");
            epService.EPAdministrator.CreateEPL("insert into MyVariant select * from MySecondEvent");

            EPStatement stmt        = epService.EPAdministrator.CreateEPL("select * from MyVariant");
            var         listenerOne = new SupportUpdateListener();

            stmt.Events += listenerOne.Update;
            epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MyEvent");
            Assert.IsNotNull(listenerOne.AssertOneGetNewAndReset());
            epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "MySecondEvent");
            Assert.IsNotNull(listenerOne.AssertOneGetNewAndReset());

            epService.EPAdministrator.DestroyAllStatements();
        }
        public void TestAnyTypeStaggered()
        {
            // test insert into staggered with map
            ConfigurationVariantStream configVariantStream = new ConfigurationVariantStream();

            configVariantStream.TypeVariance = TypeVarianceEnum.ANY;
            _epService.EPAdministrator.Configuration.AddVariantStream("VarStream", configVariantStream);
            _epService.EPAdministrator.Configuration.AddEventType("SupportBean", typeof(SupportBean));
            _epService.EPAdministrator.Configuration.AddEventType("SupportMarketDataBean", typeof(SupportMarketDataBean));

            _epService.EPAdministrator.CreateEPL("insert into MyStream select TheString, IntPrimitive from SupportBean");
            _epService.EPAdministrator.CreateEPL("insert into VarStream select TheString as abc from MyStream");
            _epService.EPAdministrator.CreateEPL("@Name('Target') select * from VarStream.win:keepall()");

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));

            EventBean[] arr = EPAssertionUtil.EnumeratorToArray(_epService.EPAdministrator.GetStatement("Target").GetEnumerator());
            EPAssertionUtil.AssertPropsPerRow(arr, new String[] { "abc" }, new Object[][] { new Object[] { "E1" } });

            _epService.EPAdministrator.CreateEPL("insert into MyStream2 select Feed from SupportMarketDataBean");
            _epService.EPAdministrator.CreateEPL("insert into VarStream select Feed as abc from MyStream2");

            _epService.EPRuntime.SendEvent(new SupportMarketDataBean("IBM", 1, 1L, "E2"));

            arr = EPAssertionUtil.EnumeratorToArray(_epService.EPAdministrator.GetStatement("Target").GetEnumerator());
            EPAssertionUtil.AssertPropsPerRow(arr, new String[] { "abc" }, new Object[][] { new Object[] { "E1" }, new Object[] { "E2" } });
        }
        public void SetUp()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();
            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.TypeVariance = TypeVarianceEnum.ANY;
            config.AddVariantStream("MyVariantStream", variant);
            Assert.IsTrue(config.IsVariantStreamExists("MyVariantStream"));

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            _listener = new SupportUpdateListener();

            // assert type metadata
            EventTypeSPI type = (EventTypeSPI)((EPServiceProviderSPI)_epService).ValueAddEventService.GetValueAddProcessor("MyVariantStream").ValueAddEventType;

            Assert.AreEqual(null, type.Metadata.OptionalApplicationType);
            Assert.AreEqual(null, type.Metadata.OptionalSecondaryNames);
            Assert.AreEqual("MyVariantStream", type.Metadata.PrimaryName);
            Assert.AreEqual("MyVariantStream", type.Metadata.PublicName);
            Assert.AreEqual("MyVariantStream", type.Name);
            Assert.AreEqual(TypeClass.VARIANT, type.Metadata.TypeClass);
            Assert.AreEqual(true, type.Metadata.IsApplicationConfigured);
            Assert.AreEqual(true, type.Metadata.IsApplicationPreConfigured);
            Assert.AreEqual(true, type.Metadata.IsApplicationPreConfiguredStatic);

            EventType[] valueAddTypes = ((EPServiceProviderSPI)_epService).ValueAddEventService.ValueAddedTypes;
            Assert.AreEqual(1, valueAddTypes.Length);
            Assert.AreSame(type, valueAddTypes[0]);

            Assert.AreEqual(0, type.PropertyNames.Length);
            Assert.AreEqual(0, type.PropertyDescriptors.Count);
        }
        public override void Configure(Configuration configuration)
        {
            var variant = new ConfigurationVariantStream();

            variant.TypeVariance = TypeVarianceEnum.ANY;
            configuration.AddVariantStream("MyVariantStream", variant);
            Assert.IsTrue(configuration.IsVariantStreamExists("MyVariantStream"));
        }
Beispiel #9
0
        public void AddVariantStream(String variantStreamname, ConfigurationVariantStream variantStreamConfig, EventAdapterService eventAdapterService, EventTypeIdGenerator eventTypeIdGenerator)
        {
            var variantSpec = ValidateVariantStream(variantStreamname, variantStreamConfig, eventAdapterService);
            var processor   = new VAEVariantProcessor(eventAdapterService, variantSpec, eventTypeIdGenerator, variantStreamConfig, _lockManager);

            eventAdapterService.AddTypeByName(variantStreamname, processor.ValueAddEventType);
            VariantProcessors.Put(variantStreamname, processor);
        }
 private void TryInvalidConfig(EPServiceProvider epService, string name, ConfigurationVariantStream config, string message)
 {
     try {
         epService.EPAdministrator.Configuration.AddVariantStream(name, config);
         Assert.Fail();
     } catch (ConfigurationException ex) {
         Assert.AreEqual(message, ex.Message);
     }
 }
        private void RunAssertionInvalidConfig(EPServiceProvider epService)
        {
            var config = new ConfigurationVariantStream();

            TryInvalidConfig(epService, "abc", config, "Invalid variant stream configuration, no event type name has been added and default type variance requires at least one type, for name 'abc'");

            config.AddEventTypeName("dummy");
            TryInvalidConfig(epService, "abc", config, "Event type by name 'dummy' could not be found for use in variant stream configuration by name 'abc'");
        }
        public void TestInvalidConfig()
        {
            ConfigurationVariantStream config = new ConfigurationVariantStream();

            TryInvalidConfig("abc", config, "Invalid variant stream configuration, no event type name has been added and default type variance requires at least one type, for name 'abc'");

            config.AddEventTypeName("dummy");
            TryInvalidConfig("abc", config, "Event type by name 'dummy' could not be found for use in variant stream configuration by name 'abc'");
            _epService.EPAdministrator.Configuration.AddEventType("MyEvent", typeof(SupportBean));
        }
        private void RunAssertionSuperTypesInterfaces(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantOne", typeof(SupportBeanVariantOne));
            epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantTwo", typeof(SupportBeanVariantTwo));

            var variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBeanVariantOne");
            variant.AddEventTypeName("SupportBeanVariantTwo");
            epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStreamTwo", variant);
            epService.EPAdministrator.CreateEPL("insert into MyVariantStreamTwo select * from SupportBeanVariantOne");
            epService.EPAdministrator.CreateEPL("insert into MyVariantStreamTwo select * from SupportBeanVariantTwo");

            EPStatement stmt        = epService.EPAdministrator.CreateEPL("select * from MyVariantStreamTwo");
            var         listenerOne = new SupportUpdateListener();

            stmt.Events += listenerOne.Update;
            EventType eventType = stmt.EventType;

            string[] expected      = "P0,P1,P2,P3,P4,P5,Indexed,Mapped,Inneritem".Split(',');
            string[] propertyNames = eventType.PropertyNames;
            EPAssertionUtil.AssertEqualsAnyOrder(expected, propertyNames);
            Assert.AreEqual(typeof(ISupportBaseAB), eventType.GetPropertyType("P0"));
            Assert.AreEqual(typeof(ISupportAImplSuperG), eventType.GetPropertyType("P1"));
            Assert.AreEqual(typeof(object), eventType.GetPropertyType("P2"));
            Assert.AreEqual(typeof(IList <object>), eventType.GetPropertyType("P3"));
            Assert.AreEqual(typeof(ICollection <object>), eventType.GetPropertyType("P4"));
            Assert.AreEqual(typeof(ICollection <object>), eventType.GetPropertyType("P5"));
            Assert.AreEqual(typeof(int[]), eventType.GetPropertyType("Indexed"));
            Assert.AreEqual(typeof(IDictionary <string, string>), eventType.GetPropertyType("Mapped"));
            Assert.AreEqual(typeof(SupportBeanVariantOne.SupportBeanVariantOneInner), eventType.GetPropertyType("Inneritem"));

            stmt.Dispose();
            stmt         = epService.EPAdministrator.CreateEPL("select P0,P1,P2,P3,P4,P5,Indexed[0] as P6,IndexArr[1] as P7,MappedKey('a') as P8,inneritem as P9,inneritem.val as P10 from MyVariantStreamTwo");
            stmt.Events += listenerOne.Update;
            eventType    = stmt.EventType;
            Assert.AreEqual(typeof(int?), eventType.GetPropertyType("P6"));
            Assert.AreEqual(typeof(int?), eventType.GetPropertyType("P7"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("P8"));
            Assert.AreEqual(typeof(SupportBeanVariantOne.SupportBeanVariantOneInner), eventType.GetPropertyType("P9"));
            Assert.AreEqual(typeof(string), eventType.GetPropertyType("P10"));

            var ev1 = new SupportBeanVariantOne();

            epService.EPRuntime.SendEvent(ev1);
            EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), "P6,P7,P8,P9,P10".Split(','), new object[] { 1, 2, "val1", ev1.Inneritem, ev1.Inneritem.Val });

            var ev2 = new SupportBeanVariantTwo();

            epService.EPRuntime.SendEvent(ev2);
            EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), "P6,P7,P8,P9,P10".Split(','), new object[] { 10, 20, "val2", ev2.Inneritem, ev2.Inneritem.Val });

            epService.EPAdministrator.DestroyAllStatements();
        }
        private EventType HandleCreateSchema(
            EPServicesContext services,
            StatementContext statementContext,
            CreateSchemaDesc spec)
        {
            EventType eventType;

            try
            {
                if (spec.AssignedType != AssignedType.VARIANT)
                {
                    eventType = EventTypeUtility.CreateNonVariantType(
                        false, spec, statementContext.Annotations, services.ConfigSnapshot, services.EventAdapterService,
                        services.EngineImportService);
                }
                else
                {
                    if (spec.CopyFrom != null && !spec.CopyFrom.IsEmpty())
                    {
                        throw new ExprValidationException("Copy-from types are not allowed with variant types");
                    }

                    var isAny  = false;
                    var config = new ConfigurationVariantStream();
                    foreach (var typeName in spec.Types)
                    {
                        if (typeName.Trim().Equals("*"))
                        {
                            isAny = true;
                            break;
                        }
                        config.AddEventTypeName(typeName);
                    }
                    if (!isAny)
                    {
                        config.TypeVariance = TypeVarianceEnum.PREDEFINED;
                    }
                    else
                    {
                        config.TypeVariance = TypeVarianceEnum.ANY;
                    }
                    services.ValueAddEventService.AddVariantStream(
                        spec.SchemaName, config, services.EventAdapterService, services.EventTypeIdGenerator);
                    eventType = services.ValueAddEventService.GetValueAddProcessor(spec.SchemaName).ValueAddEventType;
                }
            }
            catch (Exception ex)
            {
                throw new ExprValidationException(ex.Message, ex);
            }

            return(eventType);
        }
Beispiel #15
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="eventAdapterService">The event adapter service.</param>
        /// <param name="metadata">event type metadata</param>
        /// <param name="eventTypeId">The event type id.</param>
        /// <param name="variantSpec">the variant specification</param>
        /// <param name="propertyResStrategy">stragegy for resolving properties</param>
        /// <param name="config">The config.</param>
        public VariantEventType(
            EventAdapterService eventAdapterService,
            EventTypeMetadata metadata,
            int eventTypeId,
            VariantSpec variantSpec,
            VariantPropResolutionStrategy propertyResStrategy,
            ConfigurationVariantStream config)
        {
            _eventAdapterService = eventAdapterService;
            _metadata            = metadata;
            _eventTypeId         = eventTypeId;
            _variants            = variantSpec.EventTypes;
            _propertyResStrategy = propertyResStrategy;
            _config = config;

            _propertyDesc = new Dictionary <String, VariantPropertyDesc>();

            foreach (EventType type in _variants)
            {
                IList <string> properties = type.PropertyNames;
                properties = PropertyUtility.CopyAndSort(properties);
                foreach (String property in properties)
                {
                    if (!_propertyDesc.ContainsKey(property))
                    {
                        FindProperty(property);
                    }
                }
            }

            ICollection <String> propertyNameKeySet = _propertyDesc.Keys;

            _propertyNames = propertyNameKeySet.ToArray();

            // for each of the properties in each type, attempt to load the property to build a property list
            _propertyDescriptors   = new EventPropertyDescriptor[_propertyDesc.Count];
            _propertyDescriptorMap = new Dictionary <String, EventPropertyDescriptor>();
            int count = 0;

            foreach (var desc in _propertyDesc)
            {
                var type       = desc.Value.PropertyType;
                var indexType  = type.GetIndexType();
                var isIndexed  = indexType != null;
                var descriptor = new EventPropertyDescriptor(desc.Key, type, indexType, false, false, isIndexed, false, desc.Value.PropertyType.IsFragmentableType());
                _propertyDescriptors[count++] = descriptor;
                _propertyDescriptorMap.Put(desc.Key, descriptor);
            }
        }
        private void RunAssertionInvalidInsertInto(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));

            var variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBean");
            variant.AddEventTypeName("SupportBeanVariantStream");
            epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStreamFive", variant);

            SupportMessageAssertUtil.TryInvalid(epService, "insert into MyVariantStreamFive select * from " + typeof(SupportBean_A).FullName,
                                                "Error starting statement: Selected event type is not a valid event type of the variant stream 'MyVariantStreamFive'");

            SupportMessageAssertUtil.TryInvalid(epService, "insert into MyVariantStreamFive select IntPrimitive as k0 from " + typeof(SupportBean).FullName,
                                                "Error starting statement: Selected event type is not a valid event type of the variant stream 'MyVariantStreamFive' ");
        }
        public void TestInvalidInsertInto()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBean");
            variant.AddEventTypeName("SupportBeanVariantStream");
            _epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStream", variant);

            SupportMessageAssertUtil.TryInvalid(_epService, "insert into MyVariantStream select * from " + Name.Of <SupportBean_A>(),
                                                "Error starting statement: Selected event type is not a valid event type of the variant stream 'MyVariantStream'");

            SupportMessageAssertUtil.TryInvalid(_epService, "insert into MyVariantStream select intPrimitive as k0 from " + Name.Of <SupportBean>(),
                                                "Error starting statement: Selected event type is not a valid event type of the variant stream 'MyVariantStream' ");
        }
        private void RunAssertionNamedWin(EPServiceProvider epService)
        {
            var variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBeanVariantStream");
            variant.AddEventTypeName("SupportBean");
            epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStreamThree", variant);

            // test named window
            EPStatement stmt        = epService.EPAdministrator.CreateEPL("create window MyVariantWindow#unique(TheString) as select * from MyVariantStreamThree");
            var         listenerOne = new SupportUpdateListener();

            stmt.Events += listenerOne.Update;
            epService.EPAdministrator.CreateEPL("insert into MyVariantWindow select * from MyVariantStreamThree");
            epService.EPAdministrator.CreateEPL("insert into MyVariantStreamThree select * from SupportBeanVariantStream");
            epService.EPAdministrator.CreateEPL("insert into MyVariantStreamThree select * from SupportBean");

            var eventOne = new SupportBean("E1", -1);

            epService.EPRuntime.SendEvent(eventOne);
            Assert.AreSame(eventOne, listenerOne.AssertOneGetNewAndReset().Underlying);

            var eventTwo = new SupportBeanVariantStream("E2");

            epService.EPRuntime.SendEvent(eventTwo);
            Assert.AreSame(eventTwo, listenerOne.AssertOneGetNewAndReset().Underlying);

            var eventThree = new SupportBean("E2", -1);

            epService.EPRuntime.SendEvent(eventThree);
            Assert.AreSame(eventThree, listenerOne.LastNewData[0].Underlying);
            Assert.AreSame(eventTwo, listenerOne.LastOldData[0].Underlying);
            listenerOne.Reset();

            var eventFour = new SupportBeanVariantStream("E1");

            epService.EPRuntime.SendEvent(eventFour);
            Assert.AreSame(eventFour, listenerOne.LastNewData[0].Underlying);
            Assert.AreSame(eventOne, listenerOne.LastOldData[0].Underlying);
            listenerOne.Reset();

            epService.EPAdministrator.DestroyAllStatements();
        }
        public void TestNamedWin()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBeanVariantStream");
            variant.AddEventTypeName("SupportBean");
            _epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStream", variant);

            // test named window
            EPStatement stmt = _epService.EPAdministrator.CreateEPL("create window MyVariantWindow.std:unique(TheString) as select * from MyVariantStream");

            stmt.Events += _listenerOne.Update;
            _epService.EPAdministrator.CreateEPL("insert into MyVariantWindow select * from MyVariantStream");
            _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from SupportBeanVariantStream");
            _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from SupportBean");

            Object eventOne = new SupportBean("E1", -1);

            _epService.EPRuntime.SendEvent(eventOne);
            Assert.AreSame(eventOne, _listenerOne.AssertOneGetNewAndReset().Underlying);

            Object eventTwo = new SupportBeanVariantStream("E2");

            _epService.EPRuntime.SendEvent(eventTwo);
            Assert.AreSame(eventTwo, _listenerOne.AssertOneGetNewAndReset().Underlying);

            Object eventThree = new SupportBean("E2", -1);

            _epService.EPRuntime.SendEvent(eventThree);
            Assert.AreSame(eventThree, _listenerOne.LastNewData[0].Underlying);
            Assert.AreSame(eventTwo, _listenerOne.LastOldData[0].Underlying);
            _listenerOne.Reset();

            Object eventFour = new SupportBeanVariantStream("E1");

            _epService.EPRuntime.SendEvent(eventFour);
            Assert.AreSame(eventFour, _listenerOne.LastNewData[0].Underlying);
            Assert.AreSame(eventOne, _listenerOne.LastOldData[0].Underlying);
            _listenerOne.Reset();
        }
        private void RunAssertionSingleColumnConversion(EPServiceProvider epService)
        {
            var variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBean");
            variant.AddEventTypeName("SupportBeanVariantStream");
            epService.EPAdministrator.Configuration.AddVariantStream("AllEvents", variant);

            epService.EPAdministrator.CreateEPL("insert into AllEvents select * from SupportBean");
            epService.EPAdministrator.CreateEPL("create window MainEventWindow#length(10000) as AllEvents");
            epService.EPAdministrator.CreateEPL("insert into MainEventWindow select " + GetType().Name + ".PreProcessEvent(event) from AllEvents as event");

            EPStatement statement = epService.EPAdministrator.CreateEPL("select * from MainEventWindow where TheString = 'E'");

            statement.AddEventHandlerWithReplay((new SupportUpdateListener()).Update);

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));

            epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertionPatternSubquery(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_A", typeof(SupportBean_A));

            var variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBeanVariantStream");
            variant.AddEventTypeName("SupportBean");
            epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStreamFour", variant);

            epService.EPAdministrator.CreateEPL("insert into MyVariantStreamFour select * from SupportBeanVariantStream");
            epService.EPAdministrator.CreateEPL("insert into MyVariantStreamFour select * from SupportBean");

            // test pattern
            EPStatement stmt        = epService.EPAdministrator.CreateEPL("select * from pattern [a=MyVariantStreamFour -> b=MyVariantStreamFour]");
            var         listenerOne = new SupportUpdateListener();

            stmt.Events += listenerOne.Update;
            object[] events = { new SupportBean("E1", -1), new SupportBeanVariantStream("E2") };
            epService.EPRuntime.SendEvent(events[0]);
            epService.EPRuntime.SendEvent(events[1]);
            EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), "a,b".Split(','), events);

            // test subquery
            stmt.Dispose();
            stmt         = epService.EPAdministrator.CreateEPL("select * from SupportBean_A as a where Exists(select * from MyVariantStreamFour#lastevent as b where b.TheString=a.id)");
            stmt.Events += listenerOne.Update;
            events       = new object[] { new SupportBean("E1", -1), new SupportBeanVariantStream("E2"), new SupportBean_A("E2") };

            epService.EPRuntime.SendEvent(events[0]);
            epService.EPRuntime.SendEvent(events[2]);
            Assert.IsFalse(listenerOne.IsInvoked);

            epService.EPRuntime.SendEvent(events[1]);
            epService.EPRuntime.SendEvent(events[2]);
            Assert.IsTrue(listenerOne.IsInvoked);

            epService.EPAdministrator.DestroyAllStatements();
        }
        public void TestSingleColumnConversion()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));
            _epService.EPAdministrator.Configuration.AddImport(GetType().FullName);

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBean");
            variant.AddEventTypeName("SupportBeanVariantStream");
            _epService.EPAdministrator.Configuration.AddVariantStream("AllEvents", variant);

            _epService.EPAdministrator.CreateEPL("insert into AllEvents select * from SupportBean");
            _epService.EPAdministrator.CreateEPL("create window MainEventWindow.win:length(10000) as AllEvents");
            _epService.EPAdministrator.CreateEPL("insert into MainEventWindow select " + GetType().Name + ".PreProcessEvent(event) from AllEvents as event");

            EPStatement statement = _epService.EPAdministrator.CreateEPL("select * from MainEventWindow where TheString = 'E'");

            statement.AddEventHandlerWithReplay(new SupportUpdateListener().Update);

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
        }
        public void TestPatternSubquery()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean_A>();
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBeanVariantStream");
            variant.AddEventTypeName("SupportBean");
            _epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStream", variant);

            _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from SupportBeanVariantStream");
            _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from SupportBean");

            // test pattern
            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from pattern [a=MyVariantStream -> b=MyVariantStream]");

            stmt.Events += _listenerOne.Update;
            Object[] events = { new SupportBean("E1", -1), new SupportBeanVariantStream("E2") };
            _epService.EPRuntime.SendEvent(events[0]);
            _epService.EPRuntime.SendEvent(events[1]);
            EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), "a,b".Split(','), events);

            // test subquery
            stmt.Dispose();
            stmt         = _epService.EPAdministrator.CreateEPL("select * from SupportBean_A as a where Exists(select * from MyVariantStream.std:lastevent() as b where b.TheString=a.id)");
            stmt.Events += _listenerOne.Update;
            events       = new Object[] { new SupportBean("E1", -1), new SupportBeanVariantStream("E2"), new SupportBean_A("E2") };

            _epService.EPRuntime.SendEvent(events[0]);
            _epService.EPRuntime.SendEvent(events[2]);
            Assert.IsFalse(_listenerOne.IsInvoked);

            _epService.EPRuntime.SendEvent(events[1]);
            _epService.EPRuntime.SendEvent(events[2]);
            Assert.IsTrue(_listenerOne.IsInvoked);
        }
Beispiel #24
0
        public void TestVariantStream()
        {
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_A", typeof(SupportBean_A));
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_B", typeof(SupportBean_B));

            ConfigurationVariantStream config = new ConfigurationVariantStream();

            //config.setTypeVariance(ConfigurationVariantStream.TypeVariance.ANY);
            config.AddEventTypeName("SupportBean_A");
            config.AddEventTypeName("SupportBean_B");
            epService.EPAdministrator.Configuration.AddVariantStream("VarStream", config);
            epService.EPAdministrator.CreateEPL("create window MyWindow.win:keepall() as select * from VarStream");
            EPStatement stmt = epService.EPAdministrator.CreateEPL("create window MyWindowTwo.win:keepall() as MyWindow");

            epService.EPAdministrator.CreateEPL("insert into VarStream select * from SupportBean_A");
            epService.EPAdministrator.CreateEPL("insert into VarStream select * from SupportBean_B");
            epService.EPAdministrator.CreateEPL("insert into MyWindowTwo select * from VarStream");
            epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            EventBean[] events = EPAssertionUtil.EnumeratorToArray(stmt.GetEnumerator());
            Assert.AreEqual("A1", events[0].Get("id?"));
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "id?".Split(','), new object[][] { new object[] { "A1" }, new object[] { "B1" } });
        }
        private void RunAssertionVariantStream(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_A", typeof(SupportBean_A));
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_B", typeof(SupportBean_B));

            var config = new ConfigurationVariantStream();

            //config.TypeVariance = TypeVarianceEnum.ANY;
            config.AddEventTypeName("SupportBean_A");
            config.AddEventTypeName("SupportBean_B");
            epService.EPAdministrator.Configuration.AddVariantStream("VarStream", config);
            epService.EPAdministrator.CreateEPL("create window MyWindowVS#keepall as select * from VarStream");
            EPStatement stmt = epService.EPAdministrator.CreateEPL("create window MyWindowVSTwo#keepall as MyWindowVS");

            epService.EPAdministrator.CreateEPL("insert into VarStream select * from SupportBean_A");
            epService.EPAdministrator.CreateEPL("insert into VarStream select * from SupportBean_B");
            epService.EPAdministrator.CreateEPL("insert into MyWindowVSTwo select * from VarStream");
            epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            EventBean[] events = EPAssertionUtil.EnumeratorToArray(stmt.GetEnumerator());
            Assert.AreEqual("A1", events[0].Get("id?"));
            EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), "id?".Split(','), new[] { new object[] { "A1" }, new object[] { "B1" } });
        }
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="eventAdapterService">The event adapter service.</param>
        /// <param name="variantSpec">specifies how to handle the disparate events</param>
        /// <param name="eventTypeIdGenerator">The event type id generator.</param>
        /// <param name="config">The config.</param>
        /// <param name="lockManager">The lock manager.</param>
        public VAEVariantProcessor(
            EventAdapterService eventAdapterService,
            VariantSpec variantSpec,
            EventTypeIdGenerator eventTypeIdGenerator,
            ConfigurationVariantStream config,
            ILockManager lockManager)
        {
            VariantSpec = variantSpec;

            VariantPropResolutionStrategy strategy;

            if (variantSpec.TypeVariance == TypeVarianceEnum.ANY)
            {
                strategy = new VariantPropResolutionStrategyAny(lockManager, variantSpec);
            }
            else
            {
                strategy = new VariantPropResolutionStrategyDefault(lockManager, variantSpec);
            }

            EventTypeMetadata metadata = EventTypeMetadata.CreateValueAdd(variantSpec.VariantStreamName, TypeClass.VARIANT);

            VariantEventType = new VariantEventType(eventAdapterService, metadata, eventTypeIdGenerator.GetTypeId(variantSpec.VariantStreamName), variantSpec, strategy, config);
        }
 public void AddVariantStream(String variantEventTypeName, ConfigurationVariantStream variantStreamConfig, EventAdapterService eventAdapterService, EventTypeIdGenerator eventTypeIdGenerator)
 {
 }
 public void AddVariantStream(String variantEventTypeName, ConfigurationVariantStream variantStreamConfig)
 {
     CheckTableExists(variantEventTypeName);
     _valueAddEventService.AddVariantStream(variantEventTypeName, variantStreamConfig, _eventAdapterService, _eventTypeIdGenerator);
 }
        public void TestCoercionBoxedTypeMatch()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType("SupportBeanVariantStream", typeof(SupportBeanVariantStream));

            ConfigurationVariantStream variant = new ConfigurationVariantStream();

            variant.AddEventTypeName("SupportBean");
            variant.AddEventTypeName("SupportBeanVariantStream");
            _epService.EPAdministrator.Configuration.AddVariantStream("MyVariantStream", variant);

            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from MyVariantStream");

            stmt.Events += _listenerOne.Update;
            EventType typeSelectAll = stmt.EventType;

            AssertEventTypeDefault(typeSelectAll);
            Assert.AreEqual(typeof(Object), stmt.EventType.UnderlyingType);

            _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from SupportBean");
            _epService.EPAdministrator.CreateEPL("insert into MyVariantStream select * from SupportBeanVariantStream");

            // try wildcard
            Object eventOne = new SupportBean("E0", -1);

            _epService.EPRuntime.SendEvent(eventOne);
            Assert.AreSame(eventOne, _listenerOne.AssertOneGetNewAndReset().Underlying);

            Object eventTwo = new SupportBeanVariantStream("E1");

            _epService.EPRuntime.SendEvent(eventTwo);
            Assert.AreSame(eventTwo, _listenerOne.AssertOneGetNewAndReset().Underlying);

            stmt.Dispose();
            String fields = "TheString,BoolBoxed,IntPrimitive,LongPrimitive,DoublePrimitive,EnumValue";

            stmt         = _epService.EPAdministrator.CreateEPL("select " + fields + " from MyVariantStream");
            stmt.Events += _listenerOne.Update;
            AssertEventTypeDefault(stmt.EventType);

            // coerces to the higher resolution type, accepts boxed versus not boxed
            _epService.EPRuntime.SendEvent(new SupportBeanVariantStream("s1", true, 1, 20, 30, SupportEnum.ENUM_VALUE_1));
            EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields.Split(','), new Object[] { "s1", true, 1, 20L, 30d, SupportEnum.ENUM_VALUE_1 });

            SupportBean bean = new SupportBean("s2", 99);

            bean.LongPrimitive   = 33;
            bean.DoublePrimitive = 50;
            bean.EnumValue       = SupportEnum.ENUM_VALUE_3;
            _epService.EPRuntime.SendEvent(bean);
            EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields.Split(','), new Object[] { "s2", null, 99, 33L, 50d, SupportEnum.ENUM_VALUE_3 });

            // make sure a property is not known since the property is not found on SupportBeanVariantStream
            try
            {
                _epService.EPAdministrator.CreateEPL("select CharBoxed from MyVariantStream");
                Assert.Fail();
            }
            catch (EPStatementException ex)
            {
                Assert.AreEqual("Error starting statement: Failed to validate select-clause expression 'CharBoxed': Property named 'CharBoxed' is not valid in any stream [select CharBoxed from MyVariantStream]", ex.Message);
            }

            // try dynamic property: should exists but not show up as a declared property
            stmt.Dispose();
            fields       = "v1,v2,v3";
            stmt         = _epService.EPAdministrator.CreateEPL("select LongBoxed? as v1,CharBoxed? as v2,DoubleBoxed? as v3 from MyVariantStream");
            stmt.Events += _listenerOne.Update;
            AssertEventTypeDefault(typeSelectAll);  // asserts prior "select *" event type

            bean             = new SupportBean();
            bean.LongBoxed   = 33L;
            bean.CharBoxed   = 'a';
            bean.DoubleBoxed = Double.NaN;
            _epService.EPRuntime.SendEvent(bean);
            EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields.Split(','), new Object[] { 33L, 'a', Double.NaN });

            _epService.EPRuntime.SendEvent(new SupportBeanVariantStream("s2"));
            EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields.Split(','), new Object[] { null, null, null });
        }