public void TestObservationExamplePropertyExpression()
        {
            var typecfg = new ConfigurationEventTypeXMLDOM();

            typecfg.RootElementName = "Sensor";
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            typecfg.SchemaResource = schemaUri;

            var configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", typecfg);

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

            var stmtExampleOneText = "select ID, Observation.Command, Observation.ID,\n" +
                                     "Observation.Tag[0].ID, Observation.Tag[1].ID\n" +
                                     "from SensorEvent";
            var stmtExampleOne = _epService.EPAdministrator.CreateEPL(stmtExampleOneText);

            var stmtExampleTwo_0 = _epService.EPAdministrator.CreateEPL("insert into ObservationStream\n" +
                                                                        "select ID, Observation from SensorEvent");
            var stmtExampleTwo_1 = _epService.EPAdministrator.CreateEPL("select Observation.Command, Observation.Tag[0].ID from ObservationStream");

            var stmtExampleThree_0 = _epService.EPAdministrator.CreateEPL("insert into TagListStream\n" +
                                                                          "select ID as sensorId, Observation.* from SensorEvent");
            var stmtExampleThree_1 = _epService.EPAdministrator.CreateEPL("select sensorId, Command, Tag[0].ID from TagListStream");

            var doc    = SupportXML.GetDocument(XML);
            var sender = _epService.EPRuntime.GetEventSender("SensorEvent");

            sender.SendEvent(doc);

            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleOne.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_1.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleThree_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleThree_1.First());

            EPAssertionUtil.AssertProps(stmtExampleTwo_1.First(), "Observation.Command,Observation.Tag[0].ID".SplitCsv(), new object[] { "READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400" });
            EPAssertionUtil.AssertProps(stmtExampleThree_1.First(), "sensorId,Command,Tag[0].ID".SplitCsv(), new object[] { "urn:epc:1:4.16.36", "READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400" });

            try {
                _epService.EPAdministrator.CreateEPL("select Observation.Tag.ID from SensorEvent");
                Assert.Fail();
            } catch (EPStatementException ex) {
                Assert.AreEqual("Error starting statement: Failed to validate select-clause expression 'Observation.Tag.ID': Failed to resolve property 'Observation.Tag.ID' to a stream or nested property in a stream [select Observation.Tag.ID from SensorEvent]", ex.Message);
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestExpressionPrimitiveArray()
        {
            var eventTypeMeta = new ConfigurationEventTypeXMLDOM();

            eventTypeMeta.RootElementName = "simpleEvent";
            eventTypeMeta.SchemaResource  = _schemaURI;
            _epService.EPAdministrator.Configuration.AddEventType("ABCType", eventTypeMeta);

            eventTypeMeta = new ConfigurationEventTypeXMLDOM();
            eventTypeMeta.RootElementName            = "//nested2";
            eventTypeMeta.SchemaResource             = _schemaURI;
            eventTypeMeta.IsEventSenderValidatesRoot = false;
            _epService.EPAdministrator.Configuration.AddEventType("TestNested2", eventTypeMeta);

            // try array property in select
            var stmtInsert = _epService.EPAdministrator.CreateEPL("select * from TestNested2#lastevent");

            stmtInsert.AddListener(_listener);
            EPAssertionUtil.AssertEqualsAnyOrder(
                new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("prop3", typeof(int?[]), typeof(int?), false, false, true, false, false),
            }, stmtInsert.EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType);

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");
            Assert.IsFalse(_listener.IsInvoked);

            var sender = _epService.EPRuntime.GetEventSender("TestNested2");

            sender.SendEvent(SupportXML.GetDocument("<nested2><prop3>2</prop3><prop3></prop3><prop3>4</prop3></nested2>"));
            var theEvent = stmtInsert.First();

            EPAssertionUtil.AssertEqualsExactOrder((int?[])theEvent.Get("prop3"), new int?[] { 2, null, 4 });
            SupportEventTypeAssertionUtil.AssertConsistency(theEvent);

            // try array property nested
            var stmtSelect = _epService.EPAdministrator.CreateEPL("select nested3.* from ABCType#lastevent");

            SupportXML.SendDefaultEvent(_epService.EPRuntime, "test");
            var stmtSelectResult = stmtSelect.First();

            SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectResult);
            Assert.AreEqual(typeof(string[]), stmtSelectResult.EventType.GetPropertyType("nested4[2].prop5"));
            Assert.AreEqual("SAMPLE_V8", stmtSelectResult.Get("nested4[0].prop5[1]"));
            EPAssertionUtil.AssertEqualsExactOrder((string[])stmtSelectResult.Get("nested4[2].prop5"), new object[] { "SAMPLE_V10", "SAMPLE_V11" });

            var fragmentNested4 = (EventBean)stmtSelectResult.GetFragment("nested4[2]");

            EPAssertionUtil.AssertEqualsExactOrder((string[])fragmentNested4.Get("prop5"), new object[] { "SAMPLE_V10", "SAMPLE_V11" });
            Assert.AreEqual("SAMPLE_V11", fragmentNested4.Get("prop5[1]"));
            SupportEventTypeAssertionUtil.AssertConsistency(fragmentNested4);
        }
        public void TestXPathArray()
        {
            String xml = "<Event IsTriggering=\"True\">\n" +
                         "<Field Name=\"A\" Value=\"987654321\"/>\n" +
                         "<Field Name=\"B\" Value=\"2196958725202\"/>\n" +
                         "<Field Name=\"C\" Value=\"1232363702\"/>\n" +
                         "<Participants>\n" +
                         "<Participant>\n" +
                         "<Field Name=\"A\" Value=\"9876543210\"/>\n" +
                         "<Field Name=\"B\" Value=\"966607340\"/>\n" +
                         "<Field Name=\"D\" Value=\"353263010930650\"/>\n" +
                         "</Participant>\n" +
                         "</Participants>\n" +
                         "</Event>";

            ConfigurationEventTypeXMLDOM desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "Event";
            desc.AddXPathProperty("A", "//Field[@Name='A']/@Value", XPathResultType.NodeSet, "String[]");

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

            _epService.EPAdministrator.Configuration.AddEventType("Event", desc);

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

            _updateListener = new SupportUpdateListener();
            stmt.Events    += _updateListener.Update;

            XmlDocument doc = SupportXML.GetDocument(xml);

            _epService.EPRuntime.SendEvent(doc);

            EventBean theEvent = _updateListener.AssertOneGetNewAndReset();
            Object    value    = theEvent.Get("A");

            EPAssertionUtil.AssertProps(theEvent, "A".Split(','), new Object[] { new Object[] { "987654321", "9876543210" } });

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestIt()
        {
            // Bean
            RunAssertionSuccess(typeof(SupportBean).FullName, new SupportBean());
            RunAssertionInvalid(typeof(SupportBean).FullName, new SupportBean_G("G1"),
                                "Event object of type " + typeof(SupportBean_G).FullName + " does not equal, extend or implement the type " + typeof(SupportBean).FullName + " of event type 'SupportBean'");
            RunAssertionSuccess("Marker", new SupportMarkerImplA("Q2"), new SupportBean_G("Q3"));

            // Map
            RunAssertionSuccess(SupportEventInfra.MAP_TYPENAME, new Dictionary <string, object>());
            RunAssertionInvalid(SupportEventInfra.MAP_TYPENAME, new SupportBean(),
                                "Unexpected event object of type " + typeof(SupportBean).FullName + ", expected " + Name.Of <IDictionary <string, object> >());

            // Object-Array
            RunAssertionSuccess(SupportEventInfra.OA_TYPENAME, new object[] { });
            RunAssertionInvalid(SupportEventInfra.OA_TYPENAME, new SupportBean(),
                                "Unexpected event object of type " + typeof(SupportBean).FullName + ", expected Object[]");

            // XML
            RunAssertionSuccess(SupportEventInfra.XML_TYPENAME, SupportXML.GetDocument("<myevent/>").DocumentElement);
            RunAssertionInvalid(SupportEventInfra.XML_TYPENAME, new SupportBean(),
                                "Unexpected event object type '" + typeof(SupportBean).FullName + "' encountered, please supply a XmlDocument or XmlElement node");
            RunAssertionInvalid(SupportEventInfra.XML_TYPENAME, SupportXML.GetDocument("<xxxx/>"),
                                "Unexpected root element name 'xxxx' encountered, expected a root element name of 'myevent'");

            // Avro
            RunAssertionSuccess(SupportEventInfra.AVRO_TYPENAME, new GenericRecord(GetAvroSchema()));
            RunAssertionInvalid(SupportEventInfra.AVRO_TYPENAME, new SupportBean(),
                                "Unexpected event object type '" + typeof(SupportBean).FullName + "' encountered, please supply a GenericRecord");

            // No such type
            try {
                _epService.EPRuntime.GetEventSender("ABC");
                Assert.Fail();
            } catch (EventTypeException ex) {
                Assert.AreEqual("Event type named 'ABC' could not be found", ex.Message);
            }

            // Internal implicit wrapper type
            _epService.EPAdministrator.CreateEPL("insert into ABC select *, theString as value from SupportBean");
            try {
                _epService.EPRuntime.GetEventSender("ABC");
                Assert.Fail("Event type named 'ABC' could not be found");
            } catch (EventTypeException ex) {
                Assert.AreEqual("An event sender for event type named 'ABC' could not be created as the type is internal", ex.Message);
            }
        }
示例#5
0
        public void TestStaticConfig()
        {
            var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                      "<esper-configuration>\t\n" +
                      "\t<event-type name=\"MyMapEvent\">\n" +
                      "\t\t<map>\n" +
                      "\t  \t\t<map-property name=\"myStringArray\" class=\"string[]\"/>\n" +
                      "\t  \t</map>\n" +
                      "\t</event-type>\n" +
                      "\t\n" +
                      "\t<event-type name=\"MyObjectArrayEvent\">\n" +
                      "\t\t<objectarray>\n" +
                      "\t  \t\t<objectarray-property name=\"myStringArray\" class=\"string[]\"/>\n" +
                      "\t  \t</objectarray>\n" +
                      "\t</event-type>\n" +
                      "</esper-configuration>\n";

            var config = new Configuration();

            config.Configure(SupportXML.GetDocument(xml));

            // add a map-type and then clear the map to test copy of type definition for preventing accidental overwrite
            var typeMyEventIsCopyDef = new Dictionary <string, object>();

            typeMyEventIsCopyDef.Put("prop1", typeof(string));
            config.AddEventType("MyEventIsCopyDef", typeMyEventIsCopyDef);
            typeMyEventIsCopyDef.Clear();

            // obtain engine
            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            // ensure cleared type is available (type information was copied to prevent accidental overwrite)
            epService.EPAdministrator.CreateEPL("select prop1 from MyEventIsCopyDef");

            // assert array types
            foreach (var name in new string[] { "MyObjectArrayEvent", "MyMapEvent" })
            {
                EPAssertionUtil.AssertEqualsAnyOrder(
                    new EventPropertyDescriptor[]
                {
                    new EventPropertyDescriptor("myStringArray", typeof(string[]), typeof(string), false, false, true, false, false),
                },
                    epService.EPAdministrator.Configuration.GetEventType(name).PropertyDescriptors);
            }
        }
        public void SetUp()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var avroSchema    = SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME,
                                                     TypeBuilder.Field("intPrimitive", TypeBuilder.Int()));

            //SchemaBuilder.Record(SupportEventInfra.AVRO_TYPENAME).Fields()
            //             .Name("intPrimitive").Type().IntType().NoDefault().EndRecord();

            string avroSchemaText = avroSchema.ToString().Replace("\"", "&quot;");

            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                         "<esper-configuration>\t\n" +
                         "\t<event-type name=\"MyStaticBean\" class=\"" + typeof(SupportBean).FullName + "\"/>\n" +
                         "\t<event-type name=\"" + SupportEventInfra.MAP_TYPENAME + "\">\n" +
                         "\t\t<map>\n" +
                         "\t  \t\t<map-property name=\"intPrimitive\" class=\"int\"/>\n" +
                         "\t  \t</map>\n" +
                         "\t</event-type>\n" +
                         "\t\n" +
                         "\t<event-type name=\"" + SupportEventInfra.OA_TYPENAME + "\">\n" +
                         "\t\t<objectarray>\n" +
                         "\t  \t\t<objectarray-property name=\"intPrimitive\" class=\"int\"/>\n" +
                         "\t  \t</objectarray>\n" +
                         "\t</event-type>\n" +
                         "\t<event-type name=\"" + SupportEventInfra.XML_TYPENAME + "\">\n" +
                         "\t\t<xml-dom root-element-name=\"myevent\">\n" +
                         "\t\t\t<xpath-property property-name=\"intPrimitive\" xpath=\"@intPrimitive\" type=\"number\"/>\n" +
                         "\t\t</xml-dom>\n" +
                         "\t</event-type>\n" +
                         "\t<event-type name=\"" + SupportEventInfra.AVRO_TYPENAME + "\">\n" +
                         "\t\t<avro schema-text=\"" + avroSchemaText + "\"/>\n" +
                         "\t</event-type>\n" +
                         "</esper-configuration>\n";

            configuration.Configure(SupportXML.GetDocument(xml));

            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, this.GetType(), this.GetType().FullName);
            }
        }
        public void TestXPathExpression()
        {
            var ctx = new XPathNamespaceContext();

            ctx.AddNamespace("n0", "samples:schemas:simpleSchema");

            var node = SupportXML.GetDocument().DocumentElement;

            var pathExprOne = XPathExpression.Compile(
                "/n0:simpleEvent/n0:nested1",
                ctx);

            var nav      = node.CreateNavigator();
            var iterator = (XPathNodeIterator)nav.Evaluate(pathExprOne);

            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());
            var result = ((IHasXmlNode)iterator.Current).GetNode();

            Assert.IsNotNull(result);

            //Console.WriteLine("Result:\n" + SchemaUtil.Serialize(result));

            var pathExprTwo = XPathExpression.Compile("/n0:simpleEvent/n0:nested1/n0:prop1", ctx);

            iterator = (XPathNodeIterator)nav.Evaluate(pathExprTwo);
            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());
            var resultTwo = (string)iterator.Current.TypedValue;
            //Console.WriteLine("Result 2: <" + resultTwo + ">");

            var pathExprThree = XPathExpression.Compile("/n0:simpleEvent/n0:nested3", ctx);

            iterator = (XPathNodeIterator)nav.Evaluate(pathExprThree);
            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());
            var resultThree = (string)iterator.Current.TypedValue;
            //Console.WriteLine("Result 3: <" + resultThress + ">");
        }
示例#8
0
        public void TestXML()
        {
            var configuration = SupportConfigFactory.GetConfiguration();
            var typeMeta      = new ConfigurationEventTypeXMLDOM();

            typeMeta.RootElementName = "a";
            typeMeta.AddXPathProperty("element1", "/a/b/c", XPathResultType.String);
            configuration.AddEventType("AEvent", typeMeta);

            var listener  = new SupportUpdateListener();
            var epService = EPServiceProviderManager.GetDefaultProvider(configuration);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName);
            }

            var stmtText = "select b.c as type, element1 from AEvent";
            var stmt     = epService.EPAdministrator.CreateEPL(stmtText);

            stmt.AddListener(listener);

            var doc    = SupportXML.GetDocument("<a><b><c>text</c></b></a>");
            var sender = epService.EPRuntime.GetEventSender("AEvent");

            sender.SendEvent(doc);

            var theEvent = listener.AssertOneGetNewAndReset();

            Assert.AreEqual("text", theEvent.Get("type"));
            Assert.AreEqual("text", theEvent.Get("element1"));

            // send wrong event
            try {
                sender.SendEvent(SupportXML.GetDocument("<xxxx><b><c>text</c></b></xxxx>"));
                Assert.Fail();
            } catch (EPException ex) {
                Assert.AreEqual("Unexpected root element name 'xxxx' encountered, expected a root element name of 'a'", ex.Message);
            }

            try {
                sender.SendEvent(new SupportBean());
                Assert.Fail();
            } catch (EPException ex) {
                Assert.AreEqual("Unexpected event object type '" + Name.Of <SupportBean>() + "' encountered, please supply a XmlDocument or XmlElement node", ex.Message);
            }

            // test adding a second type for the same root element
            configuration            = SupportConfigFactory.GetConfiguration();
            typeMeta                 = new ConfigurationEventTypeXMLDOM();
            typeMeta.RootElementName = "a";
            typeMeta.AddXPathProperty("element2", "//c", XPathResultType.String);
            typeMeta.IsEventSenderValidatesRoot = false;
            epService.EPAdministrator.Configuration.AddEventType("BEvent", typeMeta);

            stmtText = "select element2 from BEvent#lastevent";
            var stmtTwo = epService.EPAdministrator.CreateEPL(stmtText);

            // test sender that doesn't care about the root element
            var senderTwo = epService.EPRuntime.GetEventSender("BEvent");

            senderTwo.SendEvent(SupportXML.GetDocument("<xxxx><b><c>text</c></b></xxxx>"));    // allowed, not checking

            theEvent = stmtTwo.First();
            Assert.AreEqual("text", theEvent.Get("element2"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
        public void TestObservationExampleXPathExpr()
        {
            var schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();

            var sensorcfg = new ConfigurationEventTypeXMLDOM();

            sensorcfg.RootElementName = "Sensor";
            sensorcfg.AddXPathProperty("countTags", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number);
            sensorcfg.AddXPathProperty("countTagsInt", "count(/ss:Sensor/ss:Observation/ss:Tag)", XPathResultType.Number, "int");
            sensorcfg.AddNamespacePrefix("ss", "SensorSchema");
            sensorcfg.AddXPathProperty("idarray", "//ss:Tag/ss:ID", XPathResultType.NodeSet, "String[]");
            sensorcfg.AddXPathPropertyFragment("tagArray", "//ss:Tag", XPathResultType.NodeSet, "TagEvent");
            sensorcfg.AddXPathPropertyFragment("tagOne", "//ss:Tag[position() = 1]", XPathResultType.Any, "TagEvent");
            sensorcfg.SchemaResource = schemaUri;

            var configuration = SupportConfigFactory.GetConfiguration();

            configuration.EngineDefaults.ViewResources.IsIterableUnbound = true;
            configuration.AddEventType("SensorEvent", sensorcfg);

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

            var tagcfg = new ConfigurationEventTypeXMLDOM();

            tagcfg.RootElementName = "//Tag";
            tagcfg.SchemaResource  = schemaUri;
            _epService.EPAdministrator.Configuration.AddEventType("TagEvent", tagcfg);

            var stmtExampleOne   = _epService.EPAdministrator.CreateEPL("select countTags, countTagsInt, idarray, tagArray, tagOne from SensorEvent");
            var stmtExampleTwo_0 = _epService.EPAdministrator.CreateEPL("insert into TagOneStream select tagOne.* from SensorEvent");
            var stmtExampleTwo_1 = _epService.EPAdministrator.CreateEPL("select ID from TagOneStream");
            var stmtExampleTwo_2 = _epService.EPAdministrator.CreateEPL("insert into TagArrayStream select tagArray as mytags from SensorEvent");
            var stmtExampleTwo_3 = _epService.EPAdministrator.CreateEPL("select mytags[1].ID from TagArrayStream");

            var doc = SupportXML.GetDocument(XML);

            _epService.EPRuntime.SendEvent(doc);

            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleOne.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_0.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_1.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_2.First());
            SupportEventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_3.First());

            var resultArray = stmtExampleOne.First().Get("idarray");

            EPAssertionUtil.AssertEqualsExactOrder((object[])resultArray, new string[] { "urn:epc:1:2.24.400", "urn:epc:1:2.24.401" });
            EPAssertionUtil.AssertProps(stmtExampleOne.First(), "countTags,countTagsInt".SplitCsv(), new object[] { 2d, 2 });
            Assert.AreEqual("urn:epc:1:2.24.400", stmtExampleTwo_1.First().Get("ID"));
            Assert.AreEqual("urn:epc:1:2.24.401", stmtExampleTwo_3.First().Get("mytags[1].ID"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }