public void TestStartStop() { String viewExpr = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeView = _epService.EPAdministrator.CreateEPL(viewExpr); // View created is automatically started Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); sizeView.Stop(); // Send an event, view stopped SendEvent(); var sizeViewEnum = sizeView.GetEnumerator(); Assert.IsNotNull(sizeViewEnum); var sizeViewArray = sizeViewEnum.EnumeratorToArray(); Assert.That(sizeViewArray.Length, Is.EqualTo(0)); // Start view sizeView.Start(); Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); // Send event SendEvent(); Assert.AreEqual(1l, sizeView.FirstOrDefault().Get("size")); // Stop view sizeView.Stop(); Assert.That(sizeView.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); // Start again, iterator is zero sizeView.Start(); Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); }
public void TestAddRemoveListener() { String viewExpr = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeView = _epService.EPAdministrator.CreateEPL(viewExpr); // View is started when created // Add listener send event sizeView.Events += _testListener.Update; Assert.IsNull(_testListener.LastNewData); Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); SendEvent(); Assert.AreEqual(1l, _testListener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1l, sizeView.FirstOrDefault().Get("size")); // Stop view, send event, view sizeView.Stop(); SendEvent(); Assert.That(sizeView.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); Assert.IsNull(_testListener.LastNewData); // Start again sizeView.Events -= _testListener.Update; sizeView.Events += _testListener.Update; sizeView.Start(); SendEvent(); Assert.AreEqual(1l, _testListener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1l, sizeView.FirstOrDefault().Get("size")); // Stop again, leave listeners sizeView.Stop(); sizeView.Start(); SendEvent(); Assert.AreEqual(1l, _testListener.GetAndResetLastNewData()[0].Get("size")); // Remove listener, send event sizeView.Events -= _testListener.Update; SendEvent(); Assert.IsNull(_testListener.LastNewData); // Add listener back, send event sizeView.Events += _testListener.Update; SendEvent(); Assert.AreEqual(3l, _testListener.GetAndResetLastNewData()[0].Get("size")); }
public void TestRenderSimple() { SupportBean 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.FirstOrDefault()); //Console.Out.WriteLine(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.FirstOrDefault(), new XMLRenderingOptions { IsDefaultAsAttribute = true }); // Console.Out.WriteLine(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)); }
public void TestSQLDate() { // ESPER-469 _epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement statement = _epService.EPAdministrator.CreateEPL("select DateTime.Parse(\"2010-01-31\") as mySqlDate from SupportBean"); _epService.EPRuntime.SendEvent(new SupportBean()); EventBean theEvent = statement.FirstOrDefault(); Assert.AreEqual(DateTime.Parse("2010-01-31"), theEvent.Get("mySqlDate")); EventPropertyGetter getter = statement.EventType.GetGetter("mySqlDate"); Assert.AreEqual(DateTime.Parse("2010-01-31"), getter.Get(theEvent)); String result = _epService.EPRuntime.EventRenderer.RenderXML("testsqldate", theEvent); // Console.Out.WriteLine(result); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <testsqldate> <mySqlDate>2010-01-31</mySqlDate> </testsqldate>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); }
public void TestXML() { Configuration configuration = SupportConfigFactory.GetConfiguration(); var typeMeta = new ConfigurationEventTypeXMLDOM(); typeMeta.RootElementName = "a"; typeMeta.AddXPathProperty("element1", "/a/b/c", XPathResultType.String); configuration.AddEventType("AEvent", typeMeta); _epService = EPServiceProviderManager.GetDefaultProvider(configuration); _epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName); } 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 'com.espertech.esper.support.bean.SupportBean' encountered, please supply a System.Xml.XmlDocument or Element node", ex.Message); } // test adding a second type for the same root element configuration = SupportConfigFactory.GetConfiguration(); typeMeta = new ConfigurationEventTypeXMLDOM(); typeMeta.RootElementName = "a"; typeMeta.AddXPathProperty("element2", "//c", XPathResultType.String); typeMeta.IsEventSenderValidatesRoot = false; _epService.EPAdministrator.Configuration.AddEventType("BEvent", typeMeta); stmtText = "select element2 from BEvent.std: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.FirstOrDefault(); Assert.AreEqual("text", theEvent.Get("element2")); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestMapAndNestedArray() { IDictionary <String, Object> defOuter = new LinkedHashMap <String, Object>(); defOuter["intarr"] = typeof(int[]); defOuter["innersimple"] = "InnerMap"; defOuter["innerarray"] = "InnerMap[]"; defOuter["prop0"] = typeof(SupportBean_A); IDictionary <String, Object> defInner = new LinkedHashMap <String, Object>(); defInner["stringarr"] = typeof(String[]); defInner["prop1"] = typeof(string); _epService.EPAdministrator.Configuration.AddEventType("InnerMap", defInner); _epService.EPAdministrator.Configuration.AddEventType("OuterMap", defOuter); EPStatement statement = _epService.EPAdministrator.CreateEPL("select * from OuterMap"); IDictionary <String, Object> dataInner = new LinkedHashMap <String, Object>(); dataInner["stringarr"] = new String[] { "a", null }; dataInner["prop1"] = ""; IDictionary <String, Object> dataArrayOne = new LinkedHashMap <String, Object>(); dataArrayOne["stringarr"] = new String[0]; dataArrayOne["prop1"] = "abcdef"; IDictionary <String, Object> dataArrayTwo = new LinkedHashMap <String, Object>(); dataArrayTwo["stringarr"] = new String[] { "R&R", "a>b" }; dataArrayTwo["prop1"] = ""; IDictionary <String, Object> dataArrayThree = new LinkedHashMap <String, Object>(); dataArrayOne["stringarr"] = null; IDictionary <String, Object> dataOuter = new LinkedHashMap <String, Object>(); dataOuter["intarr"] = new int[] { 1, 2 }; dataOuter["innersimple"] = dataInner; dataOuter["innerarray"] = new Map[] { dataArrayOne, dataArrayTwo, dataArrayThree }; dataOuter["prop0"] = new SupportBean_A("A1"); _epService.EPRuntime.SendEvent(dataOuter, "OuterMap"); String result = _epService.EPRuntime.EventRenderer.RenderXML("outerMap", statement.FirstOrDefault()); // Console.Out.WriteLine(result); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<outerMap>\n" + " <intarr>1</intarr>\n" + " <intarr>2</intarr>\n" + " <innerarray>\n" + " <prop1>abcdef</prop1>\n" + " </innerarray>\n" + " <innerarray>\n" + " <prop1></prop1>\n" + " <stringarr>R&R</stringarr>\n" + " <stringarr>a>b</stringarr>\n" + " </innerarray>\n" + " <innerarray>\n" + " </innerarray>\n" + " <innersimple>\n" + " <prop1></prop1>\n" + " <stringarr>a</stringarr>\n" + " </innersimple>\n" + " <prop0>\n" + " <Id>A1</Id>\n" + " </prop0>\n" + "</outerMap>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); result = _epService.EPRuntime.EventRenderer.RenderXML( "outerMap xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", statement.FirstOrDefault(), new XMLRenderingOptions { IsDefaultAsAttribute = true }); // Console.Out.WriteLine(result); expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<outerMap xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " <intarr>1</intarr>\n" + " <intarr>2</intarr>\n" + " <innerarray prop1=\"abcdef\"/>\n" + " <innerarray prop1=\"\">\n" + " <stringarr>R&R</stringarr>\n" + " <stringarr>a>b</stringarr>\n" + " </innerarray>\n" + " <innerarray/>\n" + " <innersimple prop1=\"\">\n" + " <stringarr>a</stringarr>\n" + " </innersimple>\n" + " <prop0 Id=\"A1\"/>\n" + "</outerMap>"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); }