public override void Run(EPServiceProvider epService)
        {
            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>";

            var desc = new ConfigurationEventTypeXMLDOM();

            desc.RootElementName = "Event";
            desc.AddXPathProperty("A", "//Field[@Name='A']/@Value", XPathResultType.NodeSet, "string[]");
            epService.EPAdministrator.Configuration.AddEventType("Event", desc);

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

            stmt.Events += updateListener.Update;

            XmlDocument doc = SupportXML.GetDocument(xml);

            epService.EPRuntime.SendEvent(doc);

            EventBean theEvent = updateListener.AssertOneGetNewAndReset();

            EPAssertionUtil.AssertProps(theEvent, "A".Split(','), new object[] { new object[] { "987654321", "9876543210" } });
        }
Ejemplo n.º 2
0
        public override void Run(EPServiceProvider epService)
        {
            var container = SupportContainer.Instance;

            var    config    = new ConfigurationEventTypeXMLDOM();
            string schemaUri = container.ResourceManager().ResolveResourceURL("regression/mediaOrderSchema.xsd").ToString();

            config.SchemaResource  = schemaUri;
            config.RootElementName = "mediaorder";

            epService.EPAdministrator.Configuration.AddEventType("MediaOrder", config);
            epService.EPAdministrator.Configuration.AddEventType("Cancel", config);

            var xmlStreamOne = container.ResourceManager().GetResourceAsStream("regression/mediaOrderOne.xml");
            var eventDocOne  = SupportXML.GetDocument(xmlStreamOne);

            var xmlStreamTwo = container.ResourceManager().GetResourceAsStream("regression/mediaOrderTwo.xml");
            var eventDocTwo  = SupportXML.GetDocument(xmlStreamTwo);

            RunAssertionExample(epService, eventDocOne);
            RunAssertionJoinSelfJoin(epService, eventDocOne, eventDocTwo);
            RunAssertionJoinSelfLeftOuterJoin(epService, eventDocOne, eventDocTwo);
            RunAssertionJoinSelfFullOuterJoin(epService, eventDocOne, eventDocTwo);
            RunAssertionSolutionPattern(epService);
        }
        public override void Configure(Configuration configuration)
        {
            var avroSchema = SchemaBuilder.Record(AVRO_TYPENAME,
                                                  TypeBuilder.Field("IntPrimitive", TypeBuilder.IntType()));

            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=\"" + 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=\"" + 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=\"" + 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=\"" + AVRO_TYPENAME + "\">\n" +
                         "\t\t<avro schema-text=\"" + avroSchemaText + "\"/>\n" +
                         "\t</event-type>\n" +
                         "</esper-configuration>\n";

            configuration.Configure(SupportXML.GetDocument(xml));
        }
        public override void Run(EPServiceProvider epService)
        {
            var tagcfg = new ConfigurationEventTypeXMLDOM();

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

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

            XmlDocument doc = SupportXML.GetDocument(OBSERVATION_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());

            Object 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".Split(','), 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"));
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            _epService = EPServiceProviderManager.GetDefaultProvider(SupportConfigFactory.GetConfiguration());
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            var config    = new ConfigurationEventTypeXMLDOM();
            var schemaUri = ResourceManager.ResolveResourceURL("regression/mediaOrderSchema.xsd").ToString();

            config.SchemaResource  = schemaUri;
            config.RootElementName = "mediaorder";

            _epService.EPAdministrator.Configuration.AddEventType("MediaOrder", config);
            _epService.EPAdministrator.Configuration.AddEventType("Cancel", config);

            var xmlStreamOne = ResourceManager.GetResourceAsStream("regression/mediaOrderOne.xml");

            _eventDocOne = SupportXML.GetDocument(xmlStreamOne);

            var xmlStreamTwo = ResourceManager.GetResourceAsStream("regression/mediaOrderTwo.xml");

            _eventDocTwo = SupportXML.GetDocument(xmlStreamTwo);
        }
 private XmlNode GetXMLEvent(String xml)
 {
     try {
         return(SupportXML.GetDocument(xml));
     }
     catch (Exception ex) {
         throw new EPRuntimeException(ex);
     }
 }
Ejemplo n.º 7
0
        public override void Run(EPServiceProvider epService)
        {
            var schemaURI     = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString();
            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");
            var listener   = new SupportUpdateListener();

            stmtInsert.Events += listener.Update;
            EPAssertionUtil.AssertEqualsAnyOrder(new [] {
                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);

            epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 8
0
        public override void Run(EPServiceProvider epService)
        {
            AddMapEventType(epService);
            AddOAEventType(epService);
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddEventType("Marker", typeof(SupportMarkerInterface));
            AddAvroEventType(epService);

            // Bean
            RunAssertionSuccess(epService, typeof(SupportBean).FullName, new SupportBean());
            RunAssertionInvalid(epService, 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(epService, "Marker", new SupportMarkerImplA("Q2"), new SupportBean_G("Q3"));

            // Map
            RunAssertionSuccess(epService, MAP_TYPENAME, new Dictionary <string, object>());
            RunAssertionInvalid(epService, MAP_TYPENAME, new SupportBean(),
                                "Unexpected event object of type " + Name.Clean <SupportBean>() + ", expected " + Name.Clean <Map>());

            // Object-Array
            RunAssertionSuccess(epService, OA_TYPENAME, new object[] {});
            RunAssertionInvalid(epService, OA_TYPENAME, new SupportBean(),
                                "Unexpected event object of type " + Name.Clean <SupportBean>() + ", expected " + Name.Clean <object[]>());

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

            // Avro
            RunAssertionSuccess(epService, AVRO_TYPENAME, new GenericRecord(GetAvroSchema()));
            RunAssertionInvalid(epService, 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);
            }
        }
        private void RunAssertionEventsProcessed(RegressionEnvironment env)
        {
            var listenerMap = new SupportListenerTimerHRes();
            var listenerBean = new SupportListenerTimerHRes();
            var listenerXML = new SupportListenerTimerHRes();
            var listenerOA = new SupportListenerTimerHRes();
            var listenerJson = new SupportListenerTimerHRes();
            env.CompileDeploy("@Name('s0') select SupportStaticMethodLib.Sleep(100) from MyMap").Statement("s0").AddListener(listenerMap);
            env.CompileDeploy("@Name('s1') select SupportStaticMethodLib.Sleep(100) from SupportBean").Statement("s1").AddListener(listenerBean);
            env.CompileDeploy("@Name('s2') select SupportStaticMethodLib.Sleep(100) from XMLType").Statement("s2").AddListener(listenerXML);
            env.CompileDeploy("@Name('s3') select SupportStaticMethodLib.Sleep(100) from MyOA").Statement("s3").AddListener(listenerOA);
            env.CompileDeploy(
                    "@public @buseventtype create json schema JsonEvent();\n" +
                    "@Name('s4') select SupportStaticMethodLib.Sleep(100) from JsonEvent")
                .Statement("s4")
                .AddListener(listenerJson);

            var senderMap = env.EventService.GetEventSender("MyMap");
            var senderBean = env.EventService.GetEventSender("SupportBean");
            var senderXML = env.EventService.GetEventSender("XMLType");
            var senderOA = env.EventService.GetEventSender("MyOA");
            var senderJson = env.EventService.GetEventSender("JsonEvent");

            long start = PerformanceObserver.MicroTime;
            for (var i = 0; i < 2; i++) {
                env.SendEventMap(new Dictionary<string, object>(), "MyMap");
                senderMap.SendEvent(new Dictionary<string, object>());
                env.SendEventBean(new SupportBean());
                senderBean.SendEvent(new SupportBean());
                env.SendEventXMLDOM(SupportXML.GetDocument("<myevent/>"), "XMLType");
                senderXML.SendEvent(SupportXML.GetDocument("<myevent/>"));
                env.SendEventObjectArray(new object[0], "MyOA");
                senderOA.SendEvent(new object[0]);
                env.SendEventJson("{}", "JsonEvent");
                senderJson.SendEvent("{}");
            }

            long end = PerformanceObserver.MicroTime;
            var delta = (end - start) / 1000;
            Assert.IsTrue(delta < 500);

            Thread.Sleep(1000);

            foreach (var listener in Arrays.AsList(listenerMap, listenerBean, listenerXML, listenerOA, listenerJson)) {
                Assert.AreEqual(4, listener.NewEvents.Count);
            }

            var spi = (EPRuntimeSPI) env.Runtime;
            Assert.AreEqual(0, spi.ServicesContext.ThreadingService.InboundQueue.Count);
            Assert.IsNotNull(spi.ServicesContext.ThreadingService.InboundThreadPool);

            env.UndeployAll();
        }
        private void RunAssertionEventsProcessed(EPServiceProvider epService)
        {
            var         listenerOne   = new SupportListenerTimerHRes();
            var         listenerTwo   = new SupportListenerTimerHRes();
            var         listenerThree = new SupportListenerTimerHRes();
            EPStatement stmtOne       = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(100) from MyMap");

            stmtOne.Events += listenerOne.Update;
            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(100) from SupportBean");

            stmtTwo.Events += listenerTwo.Update;
            EPStatement stmtThree = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(100) from XMLType");

            stmtThree.Events += listenerThree.Update;

            EventSender senderOne   = epService.EPRuntime.GetEventSender("MyMap");
            EventSender senderTwo   = epService.EPRuntime.GetEventSender("SupportBean");
            EventSender senderThree = epService.EPRuntime.GetEventSender("XMLType");

            long start = PerformanceObserver.NanoTime;

            for (int i = 0; i < 2; i++)
            {
                epService.EPRuntime.SendEvent(new Dictionary <string, Object>(), "MyMap");
                senderOne.SendEvent(new Dictionary <string, Object>());
                epService.EPRuntime.SendEvent(new SupportBean());
                senderTwo.SendEvent(new SupportBean());
                epService.EPRuntime.SendEvent(SupportXML.GetDocument("<myevent/>"));
                senderThree.SendEvent(SupportXML.GetDocument("<myevent/>"));
            }
            long end   = PerformanceObserver.NanoTime;
            long delta = (end - start) / 1000000;

            Assert.IsTrue(delta < 500);

            Thread.Sleep(1000);
            Assert.AreEqual(4, listenerOne.NewEvents.Count);
            Assert.AreEqual(4, listenerTwo.NewEvents.Count);
            Assert.AreEqual(4, listenerThree.NewEvents.Count);

            EPServiceProviderSPI spi = (EPServiceProviderSPI)epService;

            Assert.AreEqual(0, spi.ThreadingService.InboundQueue.Count);
            Assert.IsNotNull(spi.ThreadingService.InboundThreadPool);

            stmtOne.Dispose();
            stmtTwo.Dispose();
            stmtThree.Dispose();
        }
Ejemplo n.º 11
0
        private static void RunAssertion(
            RegressionEnvironment env,
            String eventTypeNameNested,
            String eventTypeNameABC,
            RegressionPath path)
        {
            // try array property in select
            env.CompileDeploy("@Name('s0') select * from " + eventTypeNameNested + "#lastevent", path).AddListener("s0");

            CollectionAssert.AreEquivalent(
                new EventPropertyDescriptor[] {
                    new EventPropertyDescriptor("prop3", typeof(int?[]), typeof(int?), false, false, true, false, false)
                },
                env.Statement("s0").EventType.PropertyDescriptors);
            SupportEventTypeAssertionUtil.AssertConsistency(env.Statement("s0").EventType);

            EventSender sender = env.EventService.GetEventSender(eventTypeNameNested);
            sender.SendEvent(
                SupportXML.GetDocument(
                    "<nested2><prop3>2</prop3><prop3></prop3><prop3>4</prop3></nested2>"));
            var theEvent = env.GetEnumerator("s0").Advance();
            var theValues = theEvent.Get("prop3").Unwrap<object>(true);
            EPAssertionUtil.AssertEqualsExactOrder(
                theValues,
                new object[] {2, null, 4});
            SupportEventTypeAssertionUtil.AssertConsistency(theEvent);
            env.UndeployModuleContaining("s0");

            // try array property nested
            env.CompileDeploy("@Name('s0') select nested3.* from " + eventTypeNameABC + "#lastevent", path);
            SupportXML.SendDefaultEvent(env.EventService, "test", eventTypeNameABC);
            var stmtSelectResult = env.GetEnumerator("s0").Advance();
            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);

            env.UndeployAll();
        }
Ejemplo n.º 12
0
        public static IList<RegressionExecution> Executions(IResourceManager resourceManager)
        {
            using (var xmlStreamOne = resourceManager.GetResourceAsStream("regression/mediaOrderOne.xml")) {
                var eventDocOne = SupportXML.GetDocument(xmlStreamOne);

                using (var xmlStreamTwo = resourceManager.GetResourceAsStream("regression/mediaOrderTwo.xml")) {
                    var eventDocTwo = SupportXML.GetDocument(xmlStreamTwo);
                    
                    var execs = new List<RegressionExecution>();
                    execs.Add(new EPLContainedExample(eventDocOne));
                    execs.Add(new EPLContainedSolutionPattern());
                    execs.Add(new EPLContainedJoinSelfJoin(eventDocOne, eventDocTwo));
                    execs.Add(new EPLContainedJoinSelfLeftOuterJoin(eventDocOne, eventDocTwo));
                    execs.Add(new EPLContainedJoinSelfFullOuterJoin(eventDocOne, eventDocTwo));
                    execs.Add(new EPLContainedSolutionPatternFinancial());
                    return execs;
                }
            }
        }
Ejemplo n.º 13
0
        public void TestEPLVariableEngineConfigXML()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<esper-configuration xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"../esper-configuration-6-0.xsd\">" +
                "<common><variable name=\"p_1\" type=\"string\" />" +
                "<variable name=\"p_2\" type=\"bool\" initialization-value=\"true\"/>" +
                "<variable name=\"p_3\" type=\"long\" initialization-value=\"10\"/>" +
                "<variable name=\"p_4\" type=\"double\" initialization-value=\"11.1d\"/>" +
                "</common></esper-configuration>";
            var doc = SupportXML.GetDocument(xml);

            RegressionSession session = RegressionRunner.Session();
            Configuration configuration = session.Configuration;
            configuration.Common.AddEventType(typeof(SupportBean));
            configuration.Configure(doc);

            RegressionRunner.Run(session, new EPLVariableEngineConfigXML());

            session.Dispose();
        }
        private void RunAssertionXPathExpression()
        {
            var ctx = new XPathNamespaceContext();

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

            var node = SupportXML.GetDocument().DocumentElement;
            var nav  = node.CreateNavigator();

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

            Assert.AreEqual(iterator.Count, 1);
            Assert.IsTrue(iterator.MoveNext());

            var result = ((IHasXmlNode)iterator.Current).GetNode();

            //Log.Info("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());

            string resultTwo = (string)iterator.Current.TypedValue;

            //Log.Info("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());

            string resultThress = (string)iterator.Current.TypedValue;

            //Log.Info("Result 3: <" + resultThress + ">");
        }
        private static void RunAssertion(
            RegressionEnvironment env,
            string eventTypeName,
            RegressionPath path)
        {
            env.CompileDeploy("@Name('s0') select countTags, countTagsInt, idarray, tagArray, tagOne from " + eventTypeName, path);
            env.CompileDeploy("@Name('e0') insert into TagOneStream select tagOne.* from " + eventTypeName, path);
            env.CompileDeploy("@Name('e1') select ID from TagOneStream", path);
            env.CompileDeploy("@Name('e2') insert into TagArrayStream select tagArray as mytags from " + eventTypeName, path);
            env.CompileDeploy("@Name('e3') select mytags[1].ID from TagArrayStream", path);

            var doc = SupportXML.GetDocument(OBSERVATION_XML);
            env.SendEventXMLDOM(doc, eventTypeName);

            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("s0").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e0").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e1").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e2").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e3").Advance());

            var resultEnumerator = env.GetEnumerator("s0");
            Assert.That(resultEnumerator, Is.Not.Null);
            Assert.That(resultEnumerator.MoveNext(), Is.True);
            Assert.That(resultEnumerator.Current, Is.Not.Null);

            var resultArray = resultEnumerator.Current.Get("idarray");
            EPAssertionUtil.AssertEqualsExactOrder(
                (object[]) resultArray,
                new[] {"urn:epc:1:2.24.400", "urn:epc:1:2.24.401"});
            EPAssertionUtil.AssertProps(
                env.GetEnumerator("s0").Advance(),
                new[] {"countTags", "countTagsInt"},
                new object[] {2d, 2});
            Assert.AreEqual("urn:epc:1:2.24.400", env.GetEnumerator("e1").Advance().Get("ID"));
            Assert.AreEqual("urn:epc:1:2.24.401", env.GetEnumerator("e3").Advance().Get("mytags[1].ID"));

            env.UndeployAll();
        }
            public void Run(RegressionEnvironment env)
            {
                var ctx = new XPathNamespaceContext();
                ctx.AddNamespace("n0", "samples:schemas:simpleSchema");

                XmlNode node = SupportXML.GetDocument().DocumentElement;

                var pathExprOne = XPathExpression.Compile("/n0:simpleEvent/n0:nested1", ctx);
                var pathExprOneIterator = node.CreateNavigator().Select(pathExprOne);
                Assert.That(pathExprOne.ReturnType, Is.EqualTo(XPathResultType.NodeSet));
                Assert.That(pathExprOneIterator.MoveNext(), Is.True);
                Assert.That(pathExprOneIterator.Current.UnderlyingObject, Is.InstanceOf<XmlElement>());
                Assert.That(pathExprOneIterator.Current.NodeType, Is.EqualTo(XPathNodeType.Element));

                //System.out.println("Result:\n" + SchemaUtil.serialize(result));

                var pathExprTwo = XPathExpression.Compile("/n0:simpleEvent/n0:nested1/n0:prop1", ctx);
                var pathExprTwoIterator = node.CreateNavigator().Select(pathExprTwo);
                Assert.That(pathExprTwoIterator.MoveNext(), Is.True);
                Assert.That(pathExprTwoIterator.Current.UnderlyingObject, Is.InstanceOf<XmlElement>());
                Assert.That(pathExprTwoIterator.Current.NodeType, Is.EqualTo(XPathNodeType.Element));
                Assert.That(pathExprTwoIterator.Current.MoveToFirstChild(), Is.True);
                Assert.That(pathExprTwoIterator.Current.NodeType, Is.EqualTo(XPathNodeType.Text));
                Assert.That(pathExprTwoIterator.Current.TypedValue, Is.EqualTo("SAMPLE_V1"));

                //System.out.println("Result 2: <" + resultTwo + ">");

                var pathExprThree = XPathExpression.Compile("/n0:simpleEvent/n0:nested3", ctx);
                var pathExprThreeIterator = node.CreateNavigator().Select(pathExprThree);
                Assert.That(pathExprThreeIterator.MoveNext(), Is.True);
                Assert.That(pathExprThreeIterator.Current.UnderlyingObject, Is.InstanceOf<XmlElement>());
                Assert.That(pathExprThreeIterator.Current.NodeType, Is.EqualTo(XPathNodeType.Element));
                Assert.That(pathExprThreeIterator.Current.HasChildren, Is.True);

                //System.out.println("Result 3: <" + resultThree + ">");
            }
        public override void Run(EPServiceProvider epService)
        {
            string stmtExampleOneText = "select ID, Observation.Command, Observation.ID,\n" +
                                        "Observation.Tag[0].ID, Observation.Tag[1].ID\n" +
                                        "from SensorEvent";
            EPStatement stmtExampleOne = epService.EPAdministrator.CreateEPL(stmtExampleOneText);

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

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

            XmlDocument doc    = SupportXML.GetDocument(OBSERVATION_XML);
            EventSender 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".Split(','), new object[] { "READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400" });
            EPAssertionUtil.AssertProps(stmtExampleThree_1.First(), "sensorId,Command,Tag[0].ID".Split(','), 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);
            }
        }
Ejemplo n.º 18
0
            public void Run(RegressionEnvironment env)
            {
                var epl =
                    "@Name('bean') select * from " +
                    BEAN_TYPENAME +
                    ";\n" +
                    "@Name('map') select * from " +
                    MAP_TYPENAME +
                    ";\n" +
                    "@Name('oa') select * from " +
                    OA_TYPENAME +
                    ";\n" +
                    "@Name('xml') select * from " +
                    XML_TYPENAME +
                    ";\n" +
                    "@Name('avro') select * from " +
                    AVRO_TYPENAME +
                    ";\n" +
                    "@public @buseventtype create json schema JsonEvent(Ident string);\n" +
                    "@Name('json') select * from JsonEvent;\n" +
                    "@Name('trigger') select * from SupportBean;";
                env.CompileDeploy(epl)
                    .AddListener("map")
                    .AddListener("oa")
                    .AddListener("xml")
                    .AddListener("avro")
                    .AddListener("bean")
                    .AddListener("json");

                env.Statement("trigger").Events += (
                    sender,
                    updateEventArgs) => {
                    var newEvents = updateEventArgs.NewEvents;
                    var processEvent = updateEventArgs.Runtime.EventService;
                    var ident = (string) newEvents[0].Get("TheString");

                    processEvent.RouteEventBean(new RoutedBeanEvent(ident), BEAN_TYPENAME);
                    processEvent.RouteEventMap(Collections.SingletonDataMap("Ident", ident), MAP_TYPENAME);
                    processEvent.RouteEventObjectArray(new object[] {ident}, OA_TYPENAME);

                    var xml = "<Myevent Ident=\"XXXXXX\"></Myevent>\n".Replace("XXXXXX", ident);
                    processEvent.RouteEventXMLDOM(SupportXML.GetDocument(xml).DocumentElement, XML_TYPENAME);

                    var avroSchema = AvroSchemaUtil.ResolveAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(AVRO_TYPENAME));
                    var datum = new GenericRecord(avroSchema.AsRecordSchema());
                    datum.Put("Ident", ident);
                    processEvent.RouteEventAvro(datum, AVRO_TYPENAME);

                    var jsonObject = new JObject(new JProperty("Ident", ident));
                    processEvent.RouteEventJson(jsonObject.ToString(), "JsonEvent");
                };

                env.SendEventBean(new SupportBean("xy", -1));

                foreach (var name in new[] {"map", "bean", "oa", "xml", "avro", "json"}) {
                    var listener = env.Listener(name);
                    Assert.IsTrue(listener.IsInvoked, "failed for " + name);
                    Assert.AreEqual("xy", env.Listener(name).AssertOneGetNewAndReset().Get("Ident"));
                }

                env.UndeployAll();
            }
Ejemplo n.º 19
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();

            // Bean
            RunAssertionSendEvent(env, path, "SupportBean", new SupportBean());
            RunAssertionInvalid(
                env,
                "SupportBean",
                new SupportBean_G("G1"),
                "Event object of type " +
                typeof(SupportBean_G).MaskTypeName() +
                " does not equal, extend or implement the type " +
                typeof(SupportBean).MaskTypeName() +
                " of event type 'SupportBean'");
            RunAssertionSendEvent(env, path, "SupportMarkerInterface", new SupportMarkerImplA("Q2"), new SupportBean_G("Q3"));
            RunAssertionRouteEvent(env, path, "SupportBean", new SupportBean());

            // Map
            RunAssertionSendEvent(env, path, MAP_TYPENAME, new Dictionary <string, object>());
            RunAssertionRouteEvent(env, path, MAP_TYPENAME, new Dictionary <string, object>());
            RunAssertionInvalid(
                env,
                MAP_TYPENAME,
                new SupportBean(),
                "Unexpected event object of type " + typeof(SupportBean).MaskTypeName() + ", expected " + typeof(IDictionary <string, object>).CleanName());

            // Object-Array
            RunAssertionSendEvent(env, path, OA_TYPENAME, new object[] { });
            RunAssertionRouteEvent(env, path, OA_TYPENAME, new object[] { });
            RunAssertionInvalid(
                env,
                OA_TYPENAME,
                new SupportBean(),
                "Unexpected event object of type " + typeof(SupportBean).MaskTypeName() + ", expected Object[]");

            // XML
            RunAssertionSendEvent(env, path, XML_TYPENAME, SupportXML.GetDocument("<Myevent/>").DocumentElement);
            RunAssertionRouteEvent(env, path, XML_TYPENAME, SupportXML.GetDocument("<Myevent/>").DocumentElement);
            RunAssertionInvalid(
                env,
                XML_TYPENAME,
                new SupportBean(),
                "Unexpected event object type '" + typeof(SupportBean).MaskTypeName() + "' encountered, please supply a XmlDocument or XmlElement node");
            RunAssertionInvalid(
                env,
                XML_TYPENAME,
                SupportXML.GetDocument("<xxxx/>"),
                "Unexpected root element name 'xxxx' encountered, expected a root element name of 'Myevent'");

            // Avro
            var schema = AvroSchemaUtil.ResolveAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(AVRO_TYPENAME))
                         .AsRecordSchema();

            RunAssertionSendEvent(env, path, AVRO_TYPENAME, new GenericRecord(schema));
            RunAssertionRouteEvent(env, path, AVRO_TYPENAME, new GenericRecord(schema));
            RunAssertionInvalid(
                env,
                AVRO_TYPENAME,
                new SupportBean(),
                "Unexpected event object type '" + typeof(SupportBean).MaskTypeName() + "' encountered, please supply a GenericRecord");

            // Json
            var schemas = "@public @buseventtype @name('schema') create json schema " + JSON_TYPENAME + "()";

            env.CompileDeploy(schemas, path);
            RunAssertionSendEvent(env, path, JSON_TYPENAME, "{}");
            RunAssertionRouteEvent(env, path, JSON_TYPENAME, "{}");
            RunAssertionInvalid(
                env,
                JSON_TYPENAME,
                new SupportBean(),
                "Unexpected event object of type '" + typeof(SupportBean).Name + "', expected a Json-formatted string-type value");

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

            // Internal implicit wrapper type
            env.CompileDeploy("insert into ABC select *, TheString as value from SupportBean");
            try {
                env.EventService.GetEventSender("ABC");
                Assert.Fail("Event type named 'ABC' could not be found");
            }
            catch (EventTypeException ex) {
                Assert.AreEqual("Event type named 'ABC' could not be found", ex.Message);
            }

            env.UndeployAll();
        }
Ejemplo n.º 20
0
            public void Run(RegressionEnvironment env)
            {
                EPStage        stage = env.StageService.GetStage("ST");
                RegressionPath path  = new RegressionPath();

                // Bean
                RunAssertion(
                    env,
                    path,
                    stage,
                    "SupportBean",
                    new SupportBean(),
                    svc => svc.SendEventBean(new SupportBean(), "SupportBean"));

                // Map
                RunAssertion(
                    env,
                    path,
                    stage,
                    MAP_TYPENAME,
                    new Dictionary <string, object>(),
                    svc => svc.SendEventMap(new Dictionary <string, object>(), MAP_TYPENAME));

                // Object-Array
                RunAssertion(
                    env,
                    path,
                    stage,
                    OA_TYPENAME,
                    new object[0],
                    svc => svc.SendEventObjectArray(new object[0], OA_TYPENAME));

                // XML
                var node = SupportXML.GetDocument("<myevent/>").DocumentElement;

                RunAssertion(
                    env,
                    path,
                    stage,
                    XML_TYPENAME,
                    node,
                    svc => svc.SendEventXMLDOM(node, XML_TYPENAME));

                // Avro
                var schema = AvroSchemaUtil.ResolveAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(AVRO_TYPENAME));
                var record = new GenericRecord(schema.AsRecordSchema());

                RunAssertion(
                    env,
                    path,
                    stage,
                    AVRO_TYPENAME,
                    record,
                    svc => svc.SendEventAvro(record, AVRO_TYPENAME));

                // Json
                RunAssertion(
                    env,
                    path,
                    stage,
                    JSON_TYPENAME,
                    "{}",
                    svc => svc.SendEventJson("{}", JSON_TYPENAME));

                env.UndeployAll();
            }
Ejemplo n.º 21
0
        public void TestOp()
        {
            Configuration config = new Configuration();

            config.EngineDefaults.ThreadingConfig.IsInternalTimerEnabled      = false;
            config.EngineDefaults.ThreadingConfig.IsThreadPoolInbound         = true;
            config.EngineDefaults.ThreadingConfig.ThreadPoolInboundNumThreads = 4;
            config.EngineDefaults.ExpressionConfig.IsUdfCache = false;
            config.AddEventType("MyMap", new Dictionary <String, Object>());
            config.AddEventType <SupportBean>();
            config.AddImport(typeof(SupportStaticMethodLib).FullName);

            ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc = new ConfigurationEventTypeXMLDOM();

            xmlDOMEventTypeDesc.RootElementName = "myevent";
            config.AddEventType("XMLType", xmlDOMEventTypeDesc);

            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            SupportListenerTimerHRes listenerOne   = new SupportListenerTimerHRes();
            SupportListenerTimerHRes listenerTwo   = new SupportListenerTimerHRes();
            SupportListenerTimerHRes listenerThree = new SupportListenerTimerHRes();
            EPStatement stmtOne = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(100) from MyMap");

            stmtOne.Events += listenerOne.Update;
            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(100) from SupportBean");

            stmtTwo.Events += listenerTwo.Update;
            EPStatement stmtThree = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(100) from XMLType");

            stmtThree.Events += listenerThree.Update;

            EventSender senderOne   = epService.EPRuntime.GetEventSender("MyMap");
            EventSender senderTwo   = epService.EPRuntime.GetEventSender("SupportBean");
            EventSender senderThree = epService.EPRuntime.GetEventSender("XMLType");

            long delta = PerformanceObserver.TimeMillis(
                delegate
            {
                for (int i = 0; i < 2; i++)
                {
                    epService.EPRuntime.SendEvent(new Dictionary <String, Object>(), "MyMap");
                    senderOne.SendEvent(new Dictionary <String, Object>());
                    epService.EPRuntime.SendEvent(new SupportBean());
                    senderTwo.SendEvent(new SupportBean());
                    epService.EPRuntime.SendEvent(SupportXML.GetDocument("<myevent/>"));
                    senderThree.SendEvent(SupportXML.GetDocument("<myevent/>"));
                }
            });

            Assert.LessOrEqual(delta, 100);

            Thread.Sleep(1000);
            Assert.AreEqual(4, listenerOne.NewEvents.Count);
            Assert.AreEqual(4, listenerTwo.NewEvents.Count);
            Assert.AreEqual(4, listenerThree.NewEvents.Count);

            EPServiceProviderSPI spi = (EPServiceProviderSPI)epService;

            Assert.AreEqual(0, spi.ThreadingService.InboundQueue.Count);
            Assert.NotNull(spi.ThreadingService.InboundThreadPool);

            stmtOne.Dispose();
            stmtTwo.Dispose();
            stmtThree.Dispose();

            epService.Dispose();
        }
        private static void RunAssertion(
            RegressionEnvironment env,
            string eventTypeName,
            RegressionPath path)
        {
            var stmtExampleOneText =
                "@Name('s0') select ID, Observation.Command, Observation.ID,\n" +
                "Observation.Tag[0].ID, Observation.Tag[1].ID\n" +
                "from " +
                eventTypeName;
            env.CompileDeploy(stmtExampleOneText, path).AddListener("s0");

            env.CompileDeploy(
                "@Name('e2_0') insert into ObservationStream\n" +
                "select ID, Observation from " +
                eventTypeName,
                path);
            env.CompileDeploy("@Name('e2_1') select Observation.Command, Observation.Tag[0].ID from ObservationStream", path);

            env.CompileDeploy(
                "@Name('e3_0') insert into TagListStream\n" +
                "select ID as sensorId, Observation.* from " +
                eventTypeName,
                path);
            env.CompileDeploy("@Name('e3_1') select sensorId, Command, Tag[0].ID from TagListStream", path);

            var doc = SupportXML.GetDocument(OBSERVATION_XML);
            var sender = env.EventService.GetEventSender(eventTypeName);

            sender.SendEvent(doc);

            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("s0").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e2_0").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e2_1").Advance());
            SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e3_0").Advance());

            // e3_1 will fail because esper does not create an intermediary simple type for 'Tag' - the consequence
            // of that is that it creates a property with the name Tag[0].ID.  When consistency attempts to look
            // for Tag[0].ID[0] it fails because it cannot find a simple property matching that name, and it then
            // attempts to break it into a nested property.  As a nested property it *should* find 'Tag' but because
            // we create no intermediate structure, it fails.

            //SupportEventTypeAssertionUtil.AssertConsistency(env.GetEnumerator("e3_1").Advance());

            EPAssertionUtil.AssertProps(
                env.GetEnumerator("e2_0").Advance(),
                new[] {"Observation.Command", "Observation.Tag[0].ID"},
                new object[] {"READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400"});
            EPAssertionUtil.AssertProps(
                env.GetEnumerator("e3_0").Advance(),
                new[] {"sensorId", "Command", "Tag[0].ID"},
                new object[] {"urn:epc:1:4.16.36", "READ_PALLET_TAGS_ONLY", "urn:epc:1:2.24.400"});

            TryInvalidCompile(
                env,
                path,
                "select Observation.Tag.ID from " + eventTypeName,
                "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");

            env.UndeployAll();
        }