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")); }
private void RunAssertionRenderSimple(EPServiceProvider epService) { var bean = new SupportBean(); bean.TheString = "a\nc>"; bean.IntPrimitive = 1; bean.IntBoxed = 992; bean.CharPrimitive = 'x'; bean.EnumValue = SupportEnum.ENUM_VALUE_1; epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement statement = epService.EPAdministrator.CreateEPL("select * from SupportBean"); epService.EPRuntime.SendEvent(bean); string result = epService.EPRuntime.EventRenderer.RenderJSON("supportBean", statement.First()); //Log.Info(result); string valuesOnly = "{ \"BoolBoxed\": null, \"BoolPrimitive\": false, \"ByteBoxed\": null, \"BytePrimitive\": 0, \"CharBoxed\": null, \"CharPrimitive\": \"x\", \"DecimalBoxed\": null, \"DoubleBoxed\": null, \"DoublePrimitive\": 0.0, \"EnumValue\": \"ENUM_VALUE_1\", \"FloatBoxed\": null, \"FloatPrimitive\": 0.0, \"IntBoxed\": 992, \"IntPrimitive\": 1, \"LongBoxed\": null, \"LongPrimitive\": 0, \"ShortBoxed\": null, \"ShortPrimitive\": 0, \"TheString\": \"a\\nc>\", \"This\": { \"BoolBoxed\": null, \"BoolPrimitive\": false, \"ByteBoxed\": null, \"BytePrimitive\": 0, \"CharBoxed\": null, \"CharPrimitive\": \"x\", \"DecimalBoxed\": null, \"DoubleBoxed\": null, \"DoublePrimitive\": 0.0, \"EnumValue\": \"ENUM_VALUE_1\", \"FloatBoxed\": null, \"FloatPrimitive\": 0.0, \"IntBoxed\": 992, \"IntPrimitive\": 1, \"LongBoxed\": null, \"LongPrimitive\": 0, \"ShortBoxed\": null, \"ShortPrimitive\": 0, \"TheString\": \"a\\nc>\" } }"; string expected = "{ \"supportBean\": " + valuesOnly + " }"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); JSONEventRenderer renderer = epService.EPRuntime.EventRenderer.GetJSONRenderer(statement.EventType); string jsonEvent = renderer.Render("supportBean", statement.First()); Assert.AreEqual(RemoveNewline(expected), RemoveNewline(jsonEvent)); jsonEvent = renderer.Render(statement.First()); Assert.AreEqual(RemoveNewline(valuesOnly), RemoveNewline(jsonEvent)); statement.Dispose(); }
public void TestUnique() { _stmtCreateWin = _epService.EPAdministrator.CreateEPL("create window RevQuote.std:unique(P1) as select * from RevisableQuote"); _epService.EPAdministrator.CreateEPL("insert into RevQuote select * from FullEvent"); _epService.EPAdministrator.CreateEPL("insert into RevQuote select * from D1"); _epService.EPAdministrator.CreateEPL("insert into RevQuote select * from D5"); EPStatement consumerOne = _epService.EPAdministrator.CreateEPL("select irstream * from RevQuote"); consumerOne.Events += _listenerOne.Update; _epService.EPRuntime.SendEvent(new SupportRevisionFull("a", "a10", "a50")); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), _fields, new Object[] { "a", "a10", "a50" }); EPAssertionUtil.AssertProps(_stmtCreateWin.First(), _fields, new Object[] { "a", "a10", "a50" }); _epService.EPRuntime.SendEvent(new SupportDeltaFive("a", "a11", "a51")); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], _fields, new Object[] { "a", "a11", "a51" }); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], _fields, new Object[] { "a", "a10", "a50" }); _listenerOne.Reset(); EPAssertionUtil.AssertProps(_stmtCreateWin.First(), _fields, new Object[] { "a", "a11", "a51" }); _epService.EPRuntime.SendEvent(new SupportDeltaFive("b", "b10", "b50")); _epService.EPRuntime.SendEvent(new SupportRevisionFull("b", "b10", "b50")); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), _fields, new Object[] { "b", "b10", "b50" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(_stmtCreateWin.GetEnumerator(), _fields, new Object[][] { new Object[] { "a", "a11", "a51" }, new Object[] { "b", "b10", "b50" } }); _epService.EPRuntime.SendEvent(new SupportDeltaFive("b", "a11", "b51")); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], _fields, new Object[] { "b", "a11", "b51" }); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], _fields, new Object[] { "a", "a11", "a51" }); EPAssertionUtil.AssertProps(_stmtCreateWin.First(), _fields, new Object[] { "b", "a11", "b51" }); }
private void RunAssertionStartStop(EPServiceProvider epService) { string epl = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeStmt = epService.EPAdministrator.CreateEPL(epl); // View created is automatically started Assert.AreEqual(0L, sizeStmt.First().Get("size")); sizeStmt.Stop(); // Send an event, view stopped SendEvent(epService); Assert.IsNotNull(sizeStmt.GetEnumerator()); Assert.That(sizeStmt.GetEnumerator().MoveNext(), Is.False); // Start view sizeStmt.Start(); Assert.AreEqual(0L, sizeStmt.First().Get("size")); // Send event SendEvent(epService); Assert.AreEqual(1L, sizeStmt.First().Get("size")); // Stop view sizeStmt.Stop(); Assert.IsNotNull(sizeStmt.GetEnumerator()); Assert.That(sizeStmt.GetEnumerator().MoveNext(), Is.False); // Start again, iterator is zero sizeStmt.Start(); Assert.AreEqual(0L, sizeStmt.First().Get("size")); sizeStmt.Dispose(); }
private void RunAssertionAddRemoveListener(EPServiceProvider epService) { string epl = "@IterableUnbound every tag=" + typeof(SupportBean).FullName; EPStatement patternStmt = epService.EPAdministrator.CreatePattern(epl, "MyPattern"); Assert.AreEqual(StatementType.PATTERN, ((EPStatementSPI)patternStmt).StatementMetadata.StatementType); var listener = new SupportUpdateListener(); // Pattern started when created // Add listener patternStmt.Events += listener.Update; Assert.IsNull(listener.LastNewData); Assert.IsFalse(patternStmt.HasFirst()); // Send event SupportBean theEvent = SendEvent(epService); Assert.AreEqual(theEvent, listener.GetAndResetLastNewData()[0].Get("tag")); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); // Remove listener patternStmt.Events -= listener.Update; theEvent = SendEvent(epService); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); Assert.IsNull(listener.LastNewData); // Add listener back patternStmt.Events += listener.Update; theEvent = SendEvent(epService); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); Assert.AreEqual(theEvent, listener.GetAndResetLastNewData()[0].Get("tag")); }
public void TestAddRemoveListener() { String viewExpr = "@IterableUnbound every tag=" + typeof(SupportBean).FullName; EPStatement patternStmt = _epService.EPAdministrator.CreatePattern(viewExpr, "MyPattern"); Assert.AreEqual(StatementType.PATTERN, ((EPStatementSPI)patternStmt).StatementMetadata.StatementType); // Pattern started when created // Add listener patternStmt.Events += _listener.Update; Assert.IsNull(_listener.LastNewData); Assert.IsFalse(patternStmt.HasFirst()); // Send event SupportBean theEvent = SendEvent(); Assert.AreEqual(theEvent, _listener.GetAndResetLastNewData()[0].Get("tag")); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); // Remove listener patternStmt.Events -= _listener.Update; theEvent = SendEvent(); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); Assert.IsNull(_listener.LastNewData); // Add listener back patternStmt.Events += _listener.Update; theEvent = SendEvent(); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); Assert.AreEqual(theEvent, _listener.GetAndResetLastNewData()[0].Get("tag")); }
public override void Run(EPServiceProvider epService) { var eventTypeMeta = new ConfigurationEventTypeXMLDOM(); eventTypeMeta.RootElementName = "simpleEvent"; // eventTypeMeta.IsXPathPropertyExpr = false; <== the default epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta); EPStatement stmtInsert = epService.EPAdministrator.CreateEPL("insert into MyNestedStream select nested1 from TestXMLSchemaType"); EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] { new EventPropertyDescriptor("nested1", typeof(string), typeof(char), false, false, true, false, false), }, stmtInsert.EventType.PropertyDescriptors); SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType); EPStatement stmtSelectWildcard = epService.EPAdministrator.CreateEPL("select * from TestXMLSchemaType"); EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[0], stmtSelectWildcard.EventType.PropertyDescriptors); SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectWildcard.EventType); SupportXML.SendDefaultEvent(epService.EPRuntime, "test"); EventBean stmtInsertWildcardBean = stmtInsert.First(); EventBean stmtSelectWildcardBean = stmtSelectWildcard.First(); Assert.IsNotNull(stmtInsertWildcardBean.Get("nested1")); SupportEventTypeAssertionUtil.AssertConsistency(stmtSelectWildcardBean); SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.First()); Assert.AreEqual(0, stmtSelectWildcardBean.EventType.PropertyNames.Length); }
public void TestObservationExamplePropertyExpression() { ConfigurationEventTypeXMLDOM typecfg = new ConfigurationEventTypeXMLDOM(); typecfg.RootElementName = "Sensor"; String schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString(); typecfg.SchemaResource = schemaUri; Configuration configuration = SupportConfigFactory.GetConfiguration(); configuration.EngineDefaults.ViewResourcesConfig.IsIterableUnbound = true; configuration.AddEventType("SensorEvent", typecfg); _epService = EPServiceProviderManager.GetDefaultProvider(configuration); _epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName); } 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(XML); EventSender sender = _epService.EPRuntime.GetEventSender("SensorEvent"); sender.SendEvent(doc); EventTypeAssertionUtil.AssertConsistency(stmtExampleOne.First()); EventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_0.First()); EventTypeAssertionUtil.AssertConsistency(stmtExampleTwo_1.First()); EventTypeAssertionUtil.AssertConsistency(stmtExampleThree_0.First()); EventTypeAssertionUtil.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); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestObjectMap() { _epService.EPAdministrator.Configuration.AddEventType( "SupportBeanRendererOne", typeof(SupportBeanRendererOne)); _epService.EPAdministrator.Configuration.AddEventType( "SupportBeanRendererThree", typeof(SupportBeanRendererThree)); var beanOne = new SupportBeanRendererOne(); IDictionary <String, Object> otherMap = new LinkedHashMap <String, Object>(); otherMap["abc"] = "def"; otherMap["def"] = 123; otherMap["efg"] = null; otherMap.Put(null, 1234); beanOne.StringObjectMap = otherMap; EPStatement stmt = _epService.EPAdministrator.CreateEPL( "select * from SupportBeanRendererOne"); _epService.EPRuntime.SendEvent(beanOne); String json = _epService.EPRuntime.EventRenderer.RenderJSON( "MyEvent", stmt.First()); String expectedJson = "{ \"MyEvent\": { \"StringObjectMap\": { \"abc\": \"def\", \"def\": 123, \"efg\": null } } }"; Assert.AreEqual(RemoveNewline(expectedJson), RemoveNewline(json)); String xmlOne = _epService.EPRuntime.EventRenderer.RenderXML( "MyEvent", stmt.First()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<MyEvent>\n" + " <StringObjectMap>\n" + " <abc>def<abc>\n" + " <def>123<def>\n" + " <efg><efg>\n" + " </StringObjectMap>\n" + "</MyEvent>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(xmlOne)); var opt = new XMLRenderingOptions(); opt.IsDefaultAsAttribute = true; String xmlTwo = _epService.EPRuntime.EventRenderer.RenderXML( "MyEvent", stmt.First(), opt); String expectedTwo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<MyEvent>\n" + " <StringObjectMap abc=\"def\" def=\"123\"/>\n" + "</MyEvent>"; Assert.AreEqual(RemoveNewline(expectedTwo), RemoveNewline(xmlTwo)); // try the same Map only undeclared var beanThree = new SupportBeanRendererThree(); beanThree.StringObjectMap = otherMap; stmt = _epService.EPAdministrator.CreateEPL( "select * from SupportBeanRendererThree"); _epService.EPRuntime.SendEvent(beanThree); json = _epService.EPRuntime.EventRenderer.RenderJSON("MyEvent", stmt.First()); Assert.AreEqual(RemoveNewline(expectedJson), RemoveNewline(json)); }
public void TestTimeWindow() { SendTimer(0); _stmtCreateWin = _epService.EPAdministrator.CreateEPL( "create window RevQuote.win:time(10 sec) as select * from RevisableQuote"); _epService.EPAdministrator.CreateEPL("insert into RevQuote select * from FullEvent"); _epService.EPAdministrator.CreateEPL("insert into RevQuote select * from D1"); _epService.EPAdministrator.CreateEPL("insert into RevQuote select * from D5"); EPStatement consumerOne = _epService.EPAdministrator.CreateEPL("select irstream * from RevQuote"); consumerOne.Events += _listenerOne.Update; _epService.EPRuntime.SendEvent(new SupportRevisionFull("a", "a10", "a50")); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), _fields, new Object[] { "a", "a10", "a50" }); EPAssertionUtil.AssertProps(_stmtCreateWin.First(), _fields, new Object[] { "a", "a10", "a50" }); SendTimer(1000); _epService.EPRuntime.SendEvent(new SupportDeltaFive("a", "a11", "a51")); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], _fields, new Object[] { "a", "a11", "a51" }); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], _fields, new Object[] { "a", "a10", "a50" }); EPAssertionUtil.AssertProps(_stmtCreateWin.First(), _fields, new Object[] { "a", "a11", "a51" }); SendTimer(2000); _epService.EPRuntime.SendEvent(new SupportRevisionFull("b", "b10", "b50")); _epService.EPRuntime.SendEvent(new SupportRevisionFull("c", "c10", "c50")); SendTimer(3000); _epService.EPRuntime.SendEvent(new SupportDeltaOne("c", "c11", "c51")); SendTimer(8000); _epService.EPRuntime.SendEvent(new SupportDeltaOne("c", "c12", "c52")); _listenerOne.Reset(); SendTimer(10000); Assert.IsFalse(_listenerOne.IsInvoked); SendTimer(11000); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetOldAndReset(), _fields, new Object[] { "a", "a11", "a51" }); SendTimer(12000); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetOldAndReset(), _fields, new Object[] { "b", "b10", "b50" }); SendTimer(13000); Assert.IsFalse(_listenerOne.IsInvoked); SendTimer(18000); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetOldAndReset(), _fields, new Object[] { "c", "c12", "c52" }); }
private void RunAssertionTimeWindow(EPServiceProvider epService) { SendTimer(epService, 0); EPStatement stmtCreateWin = epService.EPAdministrator.CreateEPL("create window RevQuote#time(10 sec) as select * from RevisableQuote"); epService.EPAdministrator.CreateEPL("insert into RevQuote select * from FullEvent"); epService.EPAdministrator.CreateEPL("insert into RevQuote select * from D1"); epService.EPAdministrator.CreateEPL("insert into RevQuote select * from D5"); EPStatement consumerOne = epService.EPAdministrator.CreateEPL("select irstream * from RevQuote"); var listenerOne = new SupportUpdateListener(); consumerOne.Events += listenerOne.Update; epService.EPRuntime.SendEvent(new SupportRevisionFull("a", "a10", "a50")); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), fields, new object[] { "a", "a10", "a50" }); EPAssertionUtil.AssertProps(stmtCreateWin.First(), fields, new object[] { "a", "a10", "a50" }); SendTimer(epService, 1000); epService.EPRuntime.SendEvent(new SupportDeltaFive("a", "a11", "a51")); EPAssertionUtil.AssertProps(listenerOne.LastNewData[0], fields, new object[] { "a", "a11", "a51" }); EPAssertionUtil.AssertProps(listenerOne.LastOldData[0], fields, new object[] { "a", "a10", "a50" }); EPAssertionUtil.AssertProps(stmtCreateWin.First(), fields, new object[] { "a", "a11", "a51" }); SendTimer(epService, 2000); epService.EPRuntime.SendEvent(new SupportRevisionFull("b", "b10", "b50")); epService.EPRuntime.SendEvent(new SupportRevisionFull("c", "c10", "c50")); SendTimer(epService, 3000); epService.EPRuntime.SendEvent(new SupportDeltaOne("c", "c11", "c51")); SendTimer(epService, 8000); epService.EPRuntime.SendEvent(new SupportDeltaOne("c", "c12", "c52")); listenerOne.Reset(); SendTimer(epService, 10000); Assert.IsFalse(listenerOne.IsInvoked); SendTimer(epService, 11000); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetOldAndReset(), fields, new object[] { "a", "a11", "a51" }); SendTimer(epService, 12000); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetOldAndReset(), fields, new object[] { "b", "b10", "b50" }); SendTimer(epService, 13000); Assert.IsFalse(listenerOne.IsInvoked); SendTimer(epService, 18000); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetOldAndReset(), fields, new object[] { "c", "c12", "c52" }); }
private void RunAssertionAddRemoveListener(EPServiceProvider epService) { string epl = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeStmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); // View is started when created // Add listener send event sizeStmt.Events += listener.Update; Assert.IsNull(listener.LastNewData); Assert.AreEqual(0L, sizeStmt.First().Get("size")); SendEvent(epService); Assert.AreEqual(1L, listener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1L, sizeStmt.First().Get("size")); // Stop view, send event, view sizeStmt.Stop(); SendEvent(epService); Assert.That(sizeStmt.GetEnumerator(), Is.Not.Null); Assert.That(sizeStmt.GetEnumerator().MoveNext(), Is.False); Assert.IsNull(listener.LastNewData); // Start again sizeStmt.Events -= listener.Update; sizeStmt.Events += listener.Update; sizeStmt.Start(); SendEvent(epService); Assert.AreEqual(1L, listener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1L, sizeStmt.First().Get("size")); // Stop again, leave listeners sizeStmt.Stop(); sizeStmt.Start(); SendEvent(epService); Assert.AreEqual(1L, listener.GetAndResetLastNewData()[0].Get("size")); // Remove listener, send event sizeStmt.Events -= listener.Update; SendEvent(epService); Assert.IsNull(listener.LastNewData); // Add listener back, send event sizeStmt.Events += listener.Update; SendEvent(epService); Assert.AreEqual(3L, listener.GetAndResetLastNewData()[0].Get("size")); sizeStmt.Dispose(); }
public void TestPropertyCustomRenderer() { _epService.EPAdministrator.Configuration.AddEventType( typeof(MyRendererEvent)); EPStatement stmt = _epService.EPAdministrator.CreateEPL( "select * from MyRendererEvent"); _epService.EPRuntime.SendEvent( new MyRendererEvent("id1", new Object[][] { new Object[] { 1, "x" }, new Object[] { 2, "y" } })); MyRenderer.Contexts.Clear(); var jsonOptions = new JSONRenderingOptions(); jsonOptions.Renderer = new MyRenderer(); String json = _epService.EPRuntime.EventRenderer.RenderJSON( "MyEvent", stmt.First(), jsonOptions); Assert.AreEqual(4, MyRenderer.Contexts.Count); List <EventPropertyRendererContext> contexts = MyRenderer.Contexts; EventPropertyRendererContext context = contexts[2]; Assert.NotNull(context.DefaultRenderer); Assert.AreEqual(1, (int)context.IndexedPropertyIndex); Assert.AreEqual(typeof(MyRendererEvent).Name, context.EventType.Name); Assert.AreEqual("SomeProperties", context.PropertyName); String expectedJson = "{ \"MyEvent\": { \"Id\": \"id1\", \"SomeProperties\": [\"index#0=1;index#1=x\", \"index#0=2;index#1=y\"], \"MappedProperty\": { \"key\": \"value\" } } }"; Assert.AreEqual(RemoveNewline(expectedJson), RemoveNewline(json)); MyRenderer.Contexts.Clear(); var xmlOptions = new XMLRenderingOptions(); xmlOptions.Renderer = new MyRenderer(); String xmlOne = _epService.EPRuntime.EventRenderer.RenderXML( "MyEvent", stmt.First(), xmlOptions); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <MyEvent> <Id>id1</Id> <SomeProperties>index#0=1;index#1=x</SomeProperties> <SomeProperties>index#0=2;index#1=y</SomeProperties> <MappedProperty> <key>value<key> </MappedProperty> </MyEvent>"; Assert.AreEqual(4, MyRenderer.Contexts.Count); Assert.AreEqual(RemoveNewline(expected), RemoveNewline(xmlOne)); }
// Assures that the events inserted into the named window are preemptive to events generated by contained-event syntax. // This example generates 3 contained-events: One for each book. // It then inserts them into a named window to determine the highest price among all. // The named window updates first becoming useful to subsequent events (versus last and not useful). private void RunAssertionNamedWindowPremptive(EPServiceProvider epService) { string[] fields = "bookId".Split(','); epService.EPAdministrator.Configuration.AddEventType("OrderEvent", typeof(OrderBean)); epService.EPAdministrator.Configuration.AddEventType("BookDesc", typeof(BookDesc)); string stmtText = "insert into BookStream select * from OrderEvent[books]"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; EPStatement stmtNW = epService.EPAdministrator.CreateEPL("create window MyWindow#lastevent as BookDesc"); epService.EPAdministrator.CreateEPL("insert into MyWindow select * from BookStream bs where not exists (select * from MyWindow mw where mw.price > bs.price)"); epService.EPRuntime.SendEvent(MakeEventOne()); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, fields, new object[][] { new object[] { "10020" }, new object[] { "10021" }, new object[] { "10022" } }); listener.Reset(); // higest price (27 is the last value) EventBean theEvent = stmtNW.First(); Assert.AreEqual(35.0, theEvent.Get("price")); epService.EPAdministrator.DestroyAllStatements(); }
private void AssertResults(EPStatement stmt, string[] fields, object[] values) { var @event = stmt.First(); var map = (IDictionary <string, object>)@event.Get("varagg"); EPAssertionUtil.AssertPropsMap(map, fields, values); }
private void RunAssertionSensorPerEvent(EPServiceProvider epService) { string stmtString = "SELECT irstream * " + "FROM\n " + typeof(SupportSensorEvent).FullName + "#groupwin(type)#time(1 hour)#unique(device)#sort(1, measurement desc) as high "; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtString); var testListener = new SupportUpdateListener(); stmt.Events += testListener.Update; EPRuntime runtime = epService.EPRuntime; var eventOne = new SupportSensorEvent(1, "Temperature", "Device1", 5.0, 96.5); runtime.SendEvent(eventOne); EPAssertionUtil.AssertUnderlyingPerRow(testListener.AssertInvokedAndReset(), new object[] { eventOne }, null); var eventTwo = new SupportSensorEvent(2, "Temperature", "Device2", 7.0, 98.5); runtime.SendEvent(eventTwo); EPAssertionUtil.AssertUnderlyingPerRow(testListener.AssertInvokedAndReset(), new object[] { eventTwo }, new object[] { eventOne }); var eventThree = new SupportSensorEvent(3, "Temperature", "Device2", 4.0, 99.5); runtime.SendEvent(eventThree); EPAssertionUtil.AssertUnderlyingPerRow(testListener.AssertInvokedAndReset(), new object[] { eventThree }, new object[] { eventTwo }); SupportSensorEvent theEvent = (SupportSensorEvent)stmt.First().Underlying; Assert.AreEqual(3, theEvent.Id); stmt.Dispose(); }
public override void Run(EPServiceProvider epService) { // Note that XPath Node results when transposed must be queried by XPath that is also absolute. // For example: "nested1" => "/n0:simpleEvent/n0:nested1" results in a Node. // That result Node's "prop1" => "/n0:simpleEvent/n0:nested1/n0:prop1" and "/n0:nested1/n0:prop1" does NOT result in a value. // Therefore property transposal is disabled for Property-XPath expressions. var eventTypeMeta = new ConfigurationEventTypeXMLDOM(); eventTypeMeta.RootElementName = "simpleEvent"; string schemaUri = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString(); eventTypeMeta.SchemaResource = schemaUri; eventTypeMeta.IsXPathPropertyExpr = true; // <== note this eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema"); epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta); // note class not a fragment EPStatement stmtInsert = epService.EPAdministrator.CreateEPL("insert into MyNestedStream select nested1 from TestXMLSchemaType#lastevent"); EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] { new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, false), }, stmtInsert.EventType.PropertyDescriptors); SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType); EventType type = ((EPServiceProviderSPI)epService).EventAdapterService.GetEventTypeByName("TestXMLSchemaType"); SupportEventTypeAssertionUtil.AssertConsistency(type); Assert.IsNull(type.GetFragmentType("nested1")); Assert.IsNull(type.GetFragmentType("nested1.nested2")); SupportXML.SendDefaultEvent(epService.EPRuntime, "ABC"); SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.First()); }
private void RunAssertionWildcard(bool bean, EventRepresentationEnum?rep) { if (bean) { _epService.EPAdministrator.CreateEPL("create schema MySchema as " + typeof(MyP0P1Event).MaskTypeName()); } else { _epService.EPAdministrator.CreateEPL("create " + rep.Value.GetOutputTypeCreateSchemaName() + " schema MySchema (P0 string, P1 string)"); } EPStatement stmtTheTable = _epService.EPAdministrator.CreateEPL("create table TheTable (P0 string, P1 string)"); _epService.EPAdministrator.CreateEPL("insert into TheTable select * from MySchema"); if (bean) { _epService.EPRuntime.SendEvent(new MyP0P1Event("a", "b")); } else if (rep == EventRepresentationEnum.MAP) { IDictionary <String, object> map = new Dictionary <string, object>(); map.Put("P0", "a"); map.Put("P1", "b"); _epService.EPRuntime.SendEvent(map, "MySchema"); } else { _epService.EPRuntime.SendEvent(new object[] { "a", "b" }, "MySchema"); } EPAssertionUtil.AssertProps(stmtTheTable.First(), "P0,P1".Split(','), new object[] { "a", "b" }); _epService.EPAdministrator.DestroyAllStatements(); _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", false); }
public void TestSegmentedNWConsumeAll() { epService.EPAdministrator.CreateEPL("@Name('context') create context SegmentedByString partition by TheString from SupportBean"); EPStatement stmtNamedWindow = epService.EPAdministrator.CreateEPL("@Name('named window') context SegmentedByString create window MyWindow.std:lastevent() as SupportBean"); stmtNamedWindow.AddListener(listenerNamedWindow); epService.EPAdministrator.CreateEPL("@Name('insert') insert into MyWindow select * from SupportBean"); EPStatement stmtSelect = epService.EPAdministrator.CreateEPL("@Name('select') select * from MyWindow"); stmtSelect.AddListener(listenerSelect); string[] fields = new string[] { "TheString", "IntPrimitive" }; epService.EPRuntime.SendEvent(new SupportBean("G1", 10)); EPAssertionUtil.AssertProps(listenerNamedWindow.AssertOneGetNewAndReset(), fields, new object[] { "G1", 10 }); EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "G1", 10 }); epService.EPRuntime.SendEvent(new SupportBean("G2", 20)); EPAssertionUtil.AssertProps(listenerNamedWindow.AssertOneGetNewAndReset(), fields, new object[] { "G2", 20 }); EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "G2", 20 }); stmtSelect.Dispose(); // Out-of-context consumer not initialized EPStatement stmtSelectCount = epService.EPAdministrator.CreateEPL("@Name('select') select count(*) as cnt from MyWindow"); stmtSelectCount.AddListener(listenerSelect); EPAssertionUtil.AssertProps(stmtSelectCount.First(), "cnt".Split(','), new object[] { 0L }); }
public void TestExpressionSimpleXPathGetter() { ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM(); eventTypeMeta.RootElementName = "simpleEvent"; string schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString(); eventTypeMeta.SchemaResource = schemaUri; eventTypeMeta.IsXPathPropertyExpr = true; // <== note this eventTypeMeta.AddNamespacePrefix("ss", "samples:schemas:simpleSchema"); _epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta); // note class not a fragment EPStatement stmtInsert = _epService.EPAdministrator.CreateEPL("insert into MyNestedStream select nested1 from TestXMLSchemaType"); EPAssertionUtil.AssertEqualsAnyOrder( new EventPropertyDescriptor[] { new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, false), }, stmtInsert.EventType.PropertyDescriptors); SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType); EventType type = ((EPServiceProviderSPI)_epService).EventAdapterService.GetEventTypeByName("TestXMLSchemaType"); SupportEventTypeAssertionUtil.AssertConsistency(type); Assert.IsNull(type.GetFragmentType("nested1")); Assert.IsNull(type.GetFragmentType("nested1.nested2")); SupportXML.SendDefaultEvent(_epService.EPRuntime, "ABC"); SupportEventTypeAssertionUtil.AssertConsistency(stmtInsert.First()); }
private void RunAssertionRenderSimple(EPServiceProvider epService) { var bean = new SupportBean(); bean.TheString = "a\nc"; bean.IntPrimitive = 1; bean.IntBoxed = 992; bean.CharPrimitive = 'x'; bean.EnumValue = SupportEnum.ENUM_VALUE_2; epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement statement = epService.EPAdministrator.CreateEPL("select * from SupportBean"); epService.EPRuntime.SendEvent(bean); string result = epService.EPRuntime.EventRenderer.RenderXML("supportBean", statement.First()); //Log.Info(result); string expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<supportBean>\n" + " <BoolPrimitive>false</BoolPrimitive>\n" + " <BytePrimitive>0</BytePrimitive>\n" + " <CharPrimitive>x</CharPrimitive>\n" + " <DoublePrimitive>0.0</DoublePrimitive>\n" + " <EnumValue>ENUM_VALUE_2</EnumValue>\n" + " <FloatPrimitive>0.0</FloatPrimitive>\n" + " <IntBoxed>992</IntBoxed>\n" + " <IntPrimitive>1</IntPrimitive>\n" + " <LongPrimitive>0</LongPrimitive>\n" + " <ShortPrimitive>0</ShortPrimitive>\n" + " <TheString>a\\u000ac</TheString>\n" + " <This>\n" + " <BoolPrimitive>false</BoolPrimitive>\n" + " <BytePrimitive>0</BytePrimitive>\n" + " <CharPrimitive>x</CharPrimitive>\n" + " <DoublePrimitive>0.0</DoublePrimitive>\n" + " <EnumValue>ENUM_VALUE_2</EnumValue>\n" + " <FloatPrimitive>0.0</FloatPrimitive>\n" + " <IntBoxed>992</IntBoxed>\n" + " <IntPrimitive>1</IntPrimitive>\n" + " <LongPrimitive>0</LongPrimitive>\n" + " <ShortPrimitive>0</ShortPrimitive>\n" + " <TheString>a\\u000ac</TheString>\n" + " </This>\n" + "</supportBean>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); result = epService.EPRuntime.EventRenderer.RenderXML("supportBean", statement.First(), new XMLRenderingOptions() { IsDefaultAsAttribute = true }); // Log.Info(result); expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <supportBean BoolPrimitive=\"false\" BytePrimitive=\"0\" CharPrimitive=\"x\" DoublePrimitive=\"0.0\" EnumValue=\"ENUM_VALUE_2\" FloatPrimitive=\"0.0\" IntBoxed=\"992\" IntPrimitive=\"1\" LongPrimitive=\"0\" ShortPrimitive=\"0\" TheString=\"a\\u000ac\"> <This BoolPrimitive=\"false\" BytePrimitive=\"0\" CharPrimitive=\"x\" DoublePrimitive=\"0.0\" EnumValue=\"ENUM_VALUE_2\" FloatPrimitive=\"0.0\" IntBoxed=\"992\" IntPrimitive=\"1\" LongPrimitive=\"0\" ShortPrimitive=\"0\" TheString=\"a\\u000ac\"/> </supportBean>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); statement.Dispose(); }
public void TestStartStop() { String viewExpr = "@IterableUnbound every tag=" + typeof(SupportBean).FullName; EPStatement patternStmt = _epService.EPAdministrator.CreatePattern(viewExpr, "MyPattern"); Assert.AreEqual(StatementType.PATTERN, ((EPStatementSPI)patternStmt).StatementMetadata.StatementType); // Pattern started when created Assert.IsFalse(patternStmt.HasFirst()); using (IEnumerator <EventBean> safe = patternStmt.GetSafeEnumerator()) { Assert.IsFalse(safe.MoveNext()); } // Stop pattern patternStmt.Stop(); SendEvent(); Assert.That(patternStmt.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); // Start pattern patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // Send event SupportBean theEvent = SendEvent(); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); using (var safe = patternStmt.GetSafeEnumerator()) { Assert.That(safe.MoveNext(), Is.True); Assert.AreSame(theEvent, safe.Current.Get("tag")); } // Stop pattern patternStmt.Stop(); Assert.That(patternStmt.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); // Start again, iterator is zero patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // assert statement-eventtype reference info EPServiceProviderSPI spi = (EPServiceProviderSPI)_epService; Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); ICollection <String> stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsTrue(stmtNames.Contains("MyPattern")); patternStmt.Dispose(); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsFalse(stmtNames.Contains("MyPattern")); }
private void RunAssertionEventTypedSetProp(EPServiceProvider epService) { var listener = new SupportUpdateListener(); var listenerSet = new SupportUpdateListener(); epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); epService.EPAdministrator.Configuration.AddEventType("S0", typeof(SupportBean_S0)); epService.EPAdministrator.Configuration.AddEventType("A", typeof(SupportBean_A)); epService.EPAdministrator.CreateEPL("create variable SupportBean varbean"); string[] fields = "varbean.TheString,varbean.IntPrimitive,varbean.get_TheString()".Split(','); EPStatement stmtSelect = epService.EPAdministrator.CreateEPL("select varbean.TheString,varbean.IntPrimitive,varbean.get_TheString() from S0"); stmtSelect.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(1)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null }); EPStatement stmtSet = epService.EPAdministrator.CreateEPL("on A set varbean.TheString = 'A', varbean.IntPrimitive = 1"); stmtSet.Events += listenerSet.Update; epService.EPRuntime.SendEvent(new SupportBean_A("E1")); listenerSet.Reset(); epService.EPRuntime.SendEvent(new SupportBean_S0(2)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null }); var setBean = new SupportBean(); epService.EPRuntime.SetVariableValue("varbean", setBean); epService.EPRuntime.SendEvent(new SupportBean_A("E2")); epService.EPRuntime.SendEvent(new SupportBean_S0(3)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "A", 1, "A" }); Assert.AreNotSame(setBean, epService.EPRuntime.GetVariableValue("varbean")); Assert.AreEqual(1, ((SupportBean)epService.EPRuntime.GetVariableValue("varbean")).IntPrimitive); EPAssertionUtil.AssertProps(listenerSet.AssertOneGetNewAndReset(), "varbean.TheString,varbean.IntPrimitive".Split(','), new object[] { "A", 1 }); EPAssertionUtil.AssertProps(stmtSet.First(), "varbean.TheString,varbean.IntPrimitive".Split(','), new object[] { "A", 1 }); // test self evaluate stmtSet.Dispose(); stmtSet = epService.EPAdministrator.CreateEPL("on A set varbean.TheString = A.id, varbean.TheString = '>'||varbean.TheString||'<'"); stmtSet.Events += listenerSet.Update; epService.EPRuntime.SendEvent(new SupportBean_A("E3")); Assert.AreEqual(">E3<", ((SupportBean)epService.EPRuntime.GetVariableValue("varbean")).TheString); // test widen stmtSet.Dispose(); stmtSet = epService.EPAdministrator.CreateEPL("on A set varbean.LongPrimitive = 1"); stmtSet.Events += listenerSet.Update; epService.EPRuntime.SendEvent(new SupportBean_A("E4")); Assert.AreEqual(1, ((SupportBean)epService.EPRuntime.GetVariableValue("varbean")).LongPrimitive); epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionStartStop(EPServiceProvider epService) { string epl = "@IterableUnbound every tag=" + typeof(SupportBean).FullName; EPStatement patternStmt = epService.EPAdministrator.CreatePattern(epl, "MyPattern"); Assert.AreEqual(StatementType.PATTERN, ((EPStatementSPI)patternStmt).StatementMetadata.StatementType); // Pattern started when created Assert.IsFalse(patternStmt.HasFirst()); var safe = patternStmt.GetSafeEnumerator(); Assert.IsFalse(safe.MoveNext()); safe.Dispose(); // Stop pattern patternStmt.Stop(); SendEvent(epService); //Assert.IsNull(patternStmt.GetEnumerator()); // Start pattern patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // Send event SupportBean theEvent = SendEvent(epService); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); safe = patternStmt.GetSafeEnumerator(); Assert.IsTrue(safe.MoveNext()); Assert.AreSame(theEvent, safe.Current.Get("tag")); safe.Dispose(); // Stop pattern patternStmt.Stop(); //Assert.IsNull(patternStmt.GetEnumerator()); // Start again, iterator is zero patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // assert statement-eventtype reference info EPServiceProviderSPI spi = (EPServiceProviderSPI)epService; Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); var stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsTrue(stmtNames.Contains("MyPattern")); patternStmt.Dispose(); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsFalse(stmtNames.Contains("MyPattern")); }
public void TestEmptyMap() { _epService.EPAdministrator.Configuration.AddEventType("EmptyMapEvent", typeof(EmptyMapEvent)); EPStatement statement = _epService.EPAdministrator.CreateEPL("select * from EmptyMapEvent"); _epService.EPRuntime.SendEvent(new EmptyMapEvent(null)); String result = _epService.EPRuntime.EventRenderer.RenderJSON("outer", statement.First()); String expected = "{ \"outer\": { \"Props\": null } }"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); _epService.EPRuntime.SendEvent(new EmptyMapEvent(Collections.GetEmptyMap<String, String>())); result = _epService.EPRuntime.EventRenderer.RenderJSON("outer", statement.First()); expected = "{ \"outer\": { \"Props\": {} } }"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); _epService.EPRuntime.SendEvent(new EmptyMapEvent(Collections.SingletonMap("a", "b"))); result = _epService.EPRuntime.EventRenderer.RenderJSON("outer", statement.First()); expected = "{ \"outer\": { \"Props\": { \"a\": \"b\" } } }"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); }
private void RunFullyAggregatedAndUngrouped(bool useTable) { string epl = "select count(*) as thecnt from " + (useTable ? "MyTable" : METHOD_NAME); EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); for (int i = 0; i < 2; i++) { EventBean @event = stmt.First(); Assert.AreEqual(2L, @event.Get("thecnt")); } }
public void TestExpressionNodeArray() { ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM(); eventTypeMeta.RootElementName = "simpleEvent"; String schemaUri = ResourceManager.ResolveResourceURL(CLASSLOADER_SCHEMA_URI).ToString(); eventTypeMeta.SchemaResource = schemaUri; epService.EPAdministrator.Configuration.AddEventType("TestXMLSchemaType", eventTypeMeta); // try array property insert EPStatement stmtInsert = epService.EPAdministrator.CreateEPL("select nested3.nested4 as narr from TestXMLSchemaType.std:lastevent()"); EPAssertionUtil.AssertEqualsAnyOrder(new [] { new EventPropertyDescriptor("narr", typeof(XmlNode[]), typeof(XmlNode), false, false, true, false, true), }, stmtInsert.EventType.PropertyDescriptors); EventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType); SupportXML.SendDefaultEvent(epService.EPRuntime, "test"); EventBean result = stmtInsert.First(); EventTypeAssertionUtil.AssertConsistency(result); EventBean[] fragments = (EventBean[])result.GetFragment("narr"); Assert.AreEqual(3, fragments.Length); Assert.AreEqual("SAMPLE_V8", fragments[0].Get("prop5[1]")); Assert.AreEqual("SAMPLE_V11", fragments[2].Get("prop5[1]")); EventBean fragmentItem = (EventBean)result.GetFragment("narr[2]"); Assert.AreEqual("TestXMLSchemaType.nested3.nested4", fragmentItem.EventType.Name); Assert.AreEqual("SAMPLE_V10", fragmentItem.Get("prop5[0]")); // try array index property insert EPStatement stmtInsertItem = epService.EPAdministrator.CreateEPL("select nested3.nested4[1] as narr from TestXMLSchemaType.std:lastevent()"); EPAssertionUtil.AssertEqualsAnyOrder(new [] { new EventPropertyDescriptor("narr", typeof(XmlNode), null, false, false, false, false, true), }, stmtInsertItem.EventType.PropertyDescriptors); EventTypeAssertionUtil.AssertConsistency(stmtInsertItem.EventType); SupportXML.SendDefaultEvent(epService.EPRuntime, "test"); EventBean resultItem = stmtInsertItem.First(); Assert.AreEqual("b", resultItem.Get("narr.id")); EventTypeAssertionUtil.AssertConsistency(resultItem); EventBean fragmentsInsertItem = (EventBean)resultItem.GetFragment("narr"); EventTypeAssertionUtil.AssertConsistency(fragmentsInsertItem); Assert.AreEqual("b", fragmentsInsertItem.Get("id")); Assert.AreEqual("SAMPLE_V9", fragmentsInsertItem.Get("prop5[0]")); }
public void TestObjectArray() { String[] props = { "p0", "p1", "p2", "p3", "p4" }; Object[] types = { typeof(string), typeof(int), typeof(SupportBean_S0), typeof(long), typeof(double) }; _epService.EPAdministrator.Configuration.AddEventType( "MyObjectArrayType", props, types); Object[] values = { "abc", 1, new SupportBean_S0(1, "p00"), 2L, 3d }; EPStatement stmt = _epService.EPAdministrator.CreateEPL( "select * from MyObjectArrayType"); _epService.EPRuntime.SendEvent(values, "MyObjectArrayType"); String json = _epService.EPRuntime.EventRenderer.RenderJSON( "MyEvent", stmt.First()); String expectedJson = "{ \"MyEvent\": { \"p1\": 1, \"p3\": 2, \"p4\": 3.0, \"p0\": \"abc\", \"p2\": { \"Id\": 1, \"P00\": \"p00\", \"P01\": null, \"P02\": null, \"P03\": null } } }"; Assert.AreEqual(RemoveNewline(expectedJson), RemoveNewline(json)); String xmlOne = _epService.EPRuntime.EventRenderer.RenderXML( "MyEvent", stmt.First()); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <MyEvent> <p1>1</p1> <p3>2</p3> <p4>3.0</p4> <p0>abc</p0> <p2> <Id>1</Id> <P00>p00</P00> </p2> </MyEvent>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(xmlOne)); }
public override void Run(EPServiceProvider epService) { var listener = new SupportUpdateListener(); string stmtText = "select b.c as type, element1 from AEvent"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; XmlDocument doc = GetDocument("<a><b><c>text</c></b></a>"); EventSender sender = epService.EPRuntime.GetEventSender("AEvent"); sender.SendEvent(doc); EventBean theEvent = listener.AssertOneGetNewAndReset(); Assert.AreEqual("text", theEvent.Get("type")); Assert.AreEqual("text", theEvent.Get("element1")); // send wrong event try { sender.SendEvent(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 '" + typeof(SupportBean).FullName + "' encountered, please supply a XmlDocument or XmlElement node", ex.Message); } // test adding a second type for the same root element var 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"; EPStatement stmtTwo = epService.EPAdministrator.CreateEPL(stmtText); // test sender that doesn't care about the root element EventSender senderTwo = epService.EPRuntime.GetEventSender("BEvent"); senderTwo.SendEvent(GetDocument("<xxxx><b><c>text</c></b></xxxx>")); // allowed, not checking theEvent = stmtTwo.First(); Assert.AreEqual("text", theEvent.Get("element2")); }
public void TestExpressionPrimitiveArray() { ConfigurationEventTypeXMLDOM 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 EPStatement stmtInsert = epService.EPAdministrator.CreateEPL("select * from TestNested2.std:lastevent()"); stmtInsert.Events += listener.Update; EPAssertionUtil.AssertEqualsAnyOrder(new [] { new EventPropertyDescriptor("prop3", typeof(int?[]), typeof(int?), false, false, true, false, false), }, stmtInsert.EventType.PropertyDescriptors); EventTypeAssertionUtil.AssertConsistency(stmtInsert.EventType); SupportXML.SendDefaultEvent(epService.EPRuntime, "test"); Assert.IsFalse(listener.IsInvoked); EventSender sender = epService.EPRuntime.GetEventSender("TestNested2"); sender.SendEvent(SupportXML.GetDocument("<nested2><prop3>2</prop3><prop3></prop3><prop3>4</prop3></nested2>")); EventBean theEvent = stmtInsert.First(); EPAssertionUtil.AssertEqualsExactOrder((int?[])theEvent.Get("prop3"), new int?[] { 2, null, 4 }); EventTypeAssertionUtil.AssertConsistency(theEvent); // try array property nested EPStatement stmtSelect = epService.EPAdministrator.CreateEPL("select nested3.* from ABCType.std:lastevent()"); SupportXML.SendDefaultEvent(epService.EPRuntime, "test"); EventBean stmtSelectResult = stmtSelect.First(); EventTypeAssertionUtil.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" }); EventBean 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]")); EventTypeAssertionUtil.AssertConsistency(fragmentNested4); }