private void TryAssertionInvalid(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { var expectedOne = !eventRepresentationEnum.IsAvroEvent() ? "Error starting statement: Nestable type configuration encountered an unexpected property type name 'xxxx' for property 'col1', expected Type or DataMap or the name of a previously-declared Map or ObjectArray type [" : "Error starting statement: Type definition encountered an unexpected property type name 'xxxx' for property 'col1', expected the name of a previously-declared Avro type"; TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 xxxx)", expectedOne); TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 int, col1 string)", "Error starting statement: Duplicate column name 'col1' ["); epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string)"); var expectedTwo = !eventRepresentationEnum.IsAvroEvent() ? "Error starting statement: Event type named 'MyEventType' has already been declared with differing column name or type information: Type by name 'MyEventType' expects 1 properties but receives 2 properties [" : "Error starting statement: Event type named 'MyEventType' has already been declared with differing column name or type information: Type by name 'MyEventType' is not a compatible type (target type underlying is '" + AvroConstantsNoDep.GENERIC_RECORD_CLASSNAME + "')"; TryInvalid(epService, "create schema MyEventType as (col1 string, col2 string)", expectedTwo); TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema MyEventTypeT1 as () inherit ABC", "Error in expression: Expected 'inherits', 'starttimestamp', 'endtimestamp' or 'copyfrom' keyword after create-schema clause but encountered 'inherit' ["); TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema MyEventTypeT2 as () inherits ABC", "Error starting statement: Supertype by name 'ABC' could not be found ["); TryInvalid(epService, eventRepresentationEnum.GetAnnotationText() + " create schema MyEventTypeT3 as () inherits", "Incorrect syntax near end-of-input expecting an identifier but found end-of-input at line 1 column "); epService.EPAdministrator.Configuration.RemoveEventType("MyEventType", true); }
public void RunAssertionDispatchBackQueue(EventRepresentationChoice eventRepresentationEnum) { _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema StartValueEvent as (dummy string)"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TestForwardEvent as (prop1 string)"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TestInputEvent as (dummy string)"); _epService.EPAdministrator.CreateEPL("insert into TestForwardEvent select'V1' as prop1 from TestInputEvent"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window NamedWin#unique(prop1) (prop1 string, prop2 string)"); _epService.EPAdministrator.CreateEPL("insert into NamedWin select 'V1' as prop1, 'O1' as prop2 from StartValueEvent"); _epService.EPAdministrator.CreateEPL("on TestForwardEvent update NamedWin as work set prop2 = 'U1' where work.prop1 = 'V1'"); string[] fields = "prop1,prop2".Split(','); string eplSelect = "select irstream prop1, prop2 from NamedWin"; _epService.EPAdministrator.CreateEPL(eplSelect).AddListener(_listener); if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new object[] { "dummyValue" }, "StartValueEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "StartValueEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { _epService.EPRuntime.SendEventAvro(new GenericRecord( SchemaBuilder.Record("something")), "StartValueEvent"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new object[] { "V1", "O1" }); if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new object[] { "dummyValue" }, "TestInputEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(new Dictionary <string, object>(), "TestInputEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { _epService.EPRuntime.SendEventAvro(new GenericRecord( SchemaBuilder.Record("something")), "TestInputEvent"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps(_listener.LastOldData[0], fields, new object[] { "V1", "O1" }); EPAssertionUtil.AssertProps(_listener.GetAndResetLastNewData()[0], fields, new object[] { "V1", "U1" }); _epService.Initialize(); }
private void RunAssertionNewWRepresentation(EventRepresentationChoice rep) { string epl = rep.GetAnnotationText() + "select new { theString = 'x' || theString || 'x', intPrimitive = intPrimitive + 2} as val0 from SupportBean as sb"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); Assert.AreEqual(rep.IsAvroEvent() ? typeof(GenericRecord) : typeof(Map), stmt.EventType.GetPropertyType("val0")); FragmentEventType fragType = stmt.EventType.GetFragmentType("val0"); Assert.IsFalse(fragType.IsIndexed); Assert.IsFalse(fragType.IsNative); Assert.AreEqual(typeof(string), fragType.FragmentType.GetPropertyType("theString")); Assert.AreEqual(typeof(int?), TypeHelper.GetBoxedType(fragType.FragmentType.GetPropertyType("intPrimitive"))); string[] fieldsInner = "theString,intPrimitive".Split(','); _epService.EPRuntime.SendEvent(new SupportBean("E1", -5)); EventBean @event = _listener.AssertOneGetNewAndReset(); if (rep.IsAvroEvent()) { SupportAvroUtil.AvroToJson(@event); var inner = (GenericRecord)@event.Get("val0"); Assert.AreEqual("xE1x", inner.Get("theString")); Assert.AreEqual(-3, inner.Get("intPrimitive")); } else { EPAssertionUtil.AssertPropsMap((Map)@event.Get("val0"), fieldsInner, new Object[] { "xE1x", -3 }); } stmt.Dispose(); }
private void MakeSendEvent(EPServiceProvider epService, string typeName, EventRepresentationChoice eventRepresentationEnum, Object startTs, Object endTs) { if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { startTs, endTs }, typeName); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, object>(); theEvent.Put("startts", startTs); theEvent.Put("endts", endTs); epService.EPRuntime.SendEvent(theEvent, typeName); } else if (eventRepresentationEnum.IsAvroEvent()) { var record = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, typeName).AsRecordSchema()); record.Put("startts", startTs); record.Put("endts", endTs); epService.EPRuntime.SendEventAvro(record, typeName); } else { throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum); } }
private static void SendMySentenceEvent( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, string sentence) { if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {sentence}, "MySentenceEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { env.SendEventMap(Collections.SingletonDataMap("sentence", sentence), "MySentenceEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { var schema = SchemaBuilder.Record("sentence", TypeBuilder.RequiredString("sentence")); var record = new GenericRecord(schema); record.Put("sentence", sentence); env.SendEventAvro(record, "MySentenceEvent"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { var @object = new JObject(); @object.Add("sentence", sentence); env.SendEventJson(@object.ToString(), "MySentenceEvent"); } else { throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum); } }
private void RunAssertionUpdateIStreamSetMapProps(EventRepresentationChoice eventRepresentationEnum) { // test update-istream with map _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyInfraType(simple string, myarray int[], mymap com.espertech.esper.compat.collections.StringMap)"); EPStatement stmtUpdTwo = _epService.EPAdministrator.CreateEPL("update istream MyInfraType set simple='A', mymap('abc') = 1, myarray[2] = 10"); stmtUpdTwo.AddListener(_listener); if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { null, new int[10], new Dictionary <string, Object>() }, "MyInfraType"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(MakeMapEvent(new Dictionary <string, object>(), new int[10]), "MyInfraType"); } else if (eventRepresentationEnum.IsAvroEvent()) { GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyInfraType").AsRecordSchema()); theEvent.Put("myarray", Collections.List(0, 0, 0, 0, 0)); theEvent.Put("mymap", new Dictionary <string, object>()); _epService.EPRuntime.SendEventAvro(theEvent, "MyInfraType"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps(_listener.AssertPairGetIRAndReset(), "simple,mymap('abc'),myarray[2]".Split(','), new Object[] { "A", 1, 10 }, new Object[] { null, null, 0 }); _epService.Initialize(); }
private void MakeSendEvent( RegressionEnvironment env, string typeName, EventRepresentationChoice eventRepresentationEnum, object startTs, object endTs) { if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new[] {startTs, endTs}, typeName); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new Dictionary<string, object>(); theEvent.Put("startts", startTs); theEvent.Put("endts", endTs); env.SendEventMap(theEvent, typeName); } else if (eventRepresentationEnum.IsAvroEvent()) { var record = new GenericRecord( SupportAvroUtil.GetAvroSchema( env.Runtime.EventTypeService.GetEventTypePreconfigured(typeName)) .AsRecordSchema()); record.Put("startts", startTs); record.Put("endts", endTs); env.EventService.SendEventAvro(record, typeName); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { var json = "{\"startts\": \"" + startTs + "\", \"endts\": \"" + endTs + "\"}"; env.EventService.SendEventJson(json, typeName); } else { throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum); } }
private void MakeSendScoreEvent(String typeName, EventRepresentationChoice eventRepresentationEnum, String userId, String keyword, String productId, long score) { if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, Object>(); theEvent.Put("userId", userId); theEvent.Put("keyword", keyword); theEvent.Put("productId", productId); theEvent.Put("score", score); _epService.EPRuntime.SendEvent(theEvent, typeName); } else if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { userId, keyword, productId, score }, typeName); } else if (eventRepresentationEnum.IsAvroEvent()) { var record = SupportAvroUtil.GetAvroRecord(_epService, typeName); record.Put("userId", userId); record.Put("keyword", keyword); record.Put("productId", productId); record.Put("score", score); _epService.EPRuntime.SendEventAvro(record, typeName); } else { Assert.Fail(); } }
public void RunAssertionCreateSchemaModelAfter(EventRepresentationChoice eventRepresentationEnum) { _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTypeOne (hsi int)"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema EventTypeTwo (event EventTypeOne)"); var stmt = _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window NamedWindow#unique(event.hsi) as EventTypeTwo"); _epService.EPAdministrator.CreateEPL("on EventTypeOne as ev insert into NamedWindow select ev as event"); if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { 10 }, "EventTypeOne"); } else if (eventRepresentationEnum.IsMapEvent()) { _epService.EPRuntime.SendEvent(Collections.SingletonDataMap("hsi", 10), "EventTypeOne"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "EventTypeOne").AsRecordSchema()); theEvent.Put("hsi", 10); _epService.EPRuntime.SendEventAvro(theEvent, "EventTypeOne"); } else { Assert.Fail(); } var result = stmt.First(); var getter = result.EventType.GetGetter("event.hsi"); Assert.AreEqual(10, getter.Get(result)); _epService.Initialize(); }
private static void SendMyEvent( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, string in1, int in2) { if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {in1, in2}, "MyEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { IDictionary<string, object> theEvent = new Dictionary<string, object>(); theEvent.Put("in1", in1); theEvent.Put("in2", in2); env.SendEventMap(theEvent, "MyEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord( SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("MyEvent")) .AsRecordSchema()); theEvent.Put("in1", in1); theEvent.Put("in2", in2); env.EventService.SendEventAvro(theEvent, "MyEvent"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { env.EventService.SendEventJson("{\"in1\": \"" + in1 + "\", \"in2\": " + in2 + "}", "MyEvent"); } else { Assert.Fail(); } }
private void SendRepEvent(EventRepresentationChoice rep, string name, string id, int p00) { if (rep.IsMapEvent()) { IDictionary <string, object> theEvent = new Dictionary <string, object>(); theEvent.Put("id", id); theEvent.Put("p00", p00); _epService.EPRuntime.SendEvent(theEvent, name); } else if (rep.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new object[] { id, p00 }, name); } else if (rep.IsAvroEvent()) { GenericRecord theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, name).AsRecordSchema()); theEvent.Put("id", id); theEvent.Put("p00", p00); _epService.EPRuntime.SendEventAvro(theEvent, name); } else { Assert.Fail(); } }
private static void SendRepEvent( RegressionEnvironment env, EventRepresentationChoice rep, string name, string id, int p00) { if (rep.IsMapEvent()) { IDictionary<string, object> theEvent = new Dictionary<string, object>(); theEvent.Put("Id", id); theEvent.Put("P00", p00); env.SendEventMap(theEvent, name); } else if (rep.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {id, p00}, name); } else if (rep.IsAvroEvent()) { var theEvent = new GenericRecord( SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(name)) .AsRecordSchema()); theEvent.Put("Id", id); theEvent.Put("P00", p00); env.SendEventAvro(theEvent, name); } else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) { String json = "{\"Id\": \"" + id + "\", \"P00\": " + p00 + "}"; env.EventService.SendEventJson(json, name); } else { Assert.Fail(); } }
private void RunStreamInsertAssertion( EPServiceProvider epService, EventRepresentationChoice rep, string epl, string fields, object[] expected) { var stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; if (rep.IsMapEvent()) { epService.EPRuntime.SendEvent(MakeMap(123, "abc"), "Src"); } else if (rep.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] {123, "abc"}, "Src"); } else if (rep.IsAvroEvent()) { var @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "Src").AsRecordSchema()); @event.Put("myint", 123); @event.Put("mystr", "abc"); epService.EPRuntime.SendEventAvro(@event, "Src"); } EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields.Split(','), expected); stmt.Dispose(); }
private void SendOrderEvent(EventRepresentationChoice eventRepresentationEnum, string orderId, string productId, double price, int quantity, bool deletedFlag) { if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { orderId, productId, price, quantity, deletedFlag }, "OrderEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, Object>(); theEvent.Put("orderId", orderId); theEvent.Put("productId", productId); theEvent.Put("price", price); theEvent.Put("quantity", quantity); theEvent.Put("deletedFlag", deletedFlag); _epService.EPRuntime.SendEvent(theEvent, "OrderEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "OrderEvent").AsRecordSchema()); theEvent.Put("orderId", orderId); theEvent.Put("productId", productId); theEvent.Put("price", price); theEvent.Put("quantity", quantity); theEvent.Put("deletedFlag", deletedFlag); _epService.EPRuntime.SendEventAvro(theEvent, "OrderEvent"); } else { Assert.Fail(); } }
private void SendProduct(EventRepresentationChoice eventRepresentationEnum, string product, int size) { if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent(new Object[] { product, size }, "Product"); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, Object>(); theEvent.Put("product", product); theEvent.Put("size", size); _epService.EPRuntime.SendEvent(theEvent, "Product"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "Product").AsRecordSchema()); theEvent.Put("product", product); theEvent.Put("size", size); _epService.EPRuntime.SendEventAvro(theEvent, "Product"); } else { Assert.Fail(); } }
private static object SendEvent( RegressionEnvironment env, EventRepresentationChoice rep, string value) { object eventOne; if (rep.IsMapEvent()) { var @event = Collections.SingletonDataMap("col1", value); env.SendEventMap(@event, "MyEvent"); eventOne = @event; } else if (rep.IsObjectArrayEvent()) { var @event = new object[] {value}; env.SendEventObjectArray(@event, "MyEvent"); eventOne = @event; } else if (rep.IsAvroEvent()) { var schema = SupportAvroUtil.GetAvroSchema(env.Statement("schema").EventType).AsRecordSchema(); var @event = new GenericRecord(schema); @event.Put("col1", value); env.SendEventAvro(@event, "MyEvent"); eventOne = @event; } else if (rep.IsJsonEvent() || rep.IsJsonProvidedClassEvent()) { var @object = new JObject(new JProperty("col1", value)); env.SendEventJson(@object.ToString(), "MyEvent"); eventOne = @object.ToString(); } else { throw new IllegalStateException(); } return eventOne; }
private void SendPortfolio(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum, string portfolio, string product) { if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { portfolio, product }, "Portfolio"); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, Object>(); theEvent.Put("portfolio", portfolio); theEvent.Put("product", product); epService.EPRuntime.SendEvent(theEvent, "Portfolio"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "Portfolio").AsRecordSchema()); theEvent.Put("portfolio", portfolio); theEvent.Put("product", product); epService.EPRuntime.SendEventAvro(theEvent, "Portfolio"); } else { Assert.Fail(); } }
private void MakeSendScoreEvent(EPServiceProvider epService, string typeName, EventRepresentationChoice eventRepresentationEnum, string userId, string keyword, string productId, long score) { if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, object>(); theEvent.Put("userId", userId); theEvent.Put("keyword", keyword); theEvent.Put("productId", productId); theEvent.Put("score", score); epService.EPRuntime.SendEvent(theEvent, typeName); } else if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { userId, keyword, productId, score }, typeName); } else if (eventRepresentationEnum.IsAvroEvent()) { var record = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, typeName).AsRecordSchema()); record.Put("userId", userId); record.Put("keyword", keyword); record.Put("productId", productId); record.Put("score", score); epService.EPRuntime.SendEventAvro(record, typeName); } else { Assert.Fail(); } }
private void SendMyEvent(EventRepresentationChoice eventRepresentationEnum, string in1, int in2) { if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent( new Object[] { in1, in2 }, "MyEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, Object>(); theEvent.Put("in1", in1); theEvent.Put("in2", in2); _epService.EPRuntime.SendEvent(theEvent, "MyEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "MyEvent").AsRecordSchema()); theEvent.Put("in1", in1); theEvent.Put("in2", in2); _epService.EPRuntime.SendEventAvro(theEvent, "MyEvent"); } else { Assert.Fail(); } }
private void TryAssertionInvalid(EPServiceProvider epService, EventRepresentationChoice rep) { epService.EPAdministrator.CreateEPL( "create " + rep.GetOutputTypeCreateSchemaName() + " schema Src as (myint int, mystr string)"); // mismatch in type epService.EPAdministrator.CreateEPL( "create " + rep.GetOutputTypeCreateSchemaName() + " schema E1 as (myint long)"); var message = !rep.IsAvroEvent() ? "Error starting statement: Type by name 'E1' in property 'myint' expected " + Name.Clean<int>() + " but receives " + Name.Clean<long>() : "Error starting statement: Type by name 'E1' in property 'myint' expected schema '{\"type\":\"long\"}' but received schema '{\"type\":\"int\"}'"; SupportMessageAssertUtil.TryInvalid(epService, "insert into E1 select mysrc.* from Src as mysrc", message); // mismatch in column name epService.EPAdministrator.CreateEPL( "create " + rep.GetOutputTypeCreateSchemaName() + " schema E2 as (someprop long)"); SupportMessageAssertUtil.TryInvalid( epService, "insert into E2 select mysrc.*, 1 as otherprop from Src as mysrc", "Error starting statement: Failed to find column 'otherprop' in target type 'E2' [insert into E2 select mysrc.*, 1 as otherprop from Src as mysrc]"); epService.EPAdministrator.DestroyAllStatements(); foreach (var name in Collections.List("Src", "E1", "E2")) { epService.EPAdministrator.Configuration.RemoveEventType(name, false); } }
private static void sendPortfolio( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, string portfolio, string product) { if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {portfolio, product}, "Portfolio"); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap<string, object>(); theEvent.Put("portfolio", portfolio); theEvent.Put("product", product); env.SendEventMap(theEvent, "Portfolio"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord( SupportAvroUtil.GetAvroSchema( env.Runtime.EventTypeService.GetEventTypePreconfigured("Portfolio")) .AsRecordSchema()); theEvent.Put("portfolio", portfolio); theEvent.Put("product", product); env.EventService.SendEventAvro(theEvent, "Portfolio"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { var @object = new JObject(); @object.Add("portfolio", portfolio); @object.Add("product", product); env.EventService.SendEventJson(@object.ToString(), "Portfolio"); } else { Assert.Fail(); } }
private Object SendEvent(EventRepresentationChoice rep, string value) { Object eventOne; if (rep.IsMapEvent()) { var @event = Collections.SingletonDataMap("col1", value); _epService.EPRuntime.SendEvent(@event, "MyEvent"); eventOne = @event; } else if (rep.IsObjectArrayEvent()) { var @event = new Object[] { value }; _epService.EPRuntime.SendEvent(@event, "MyEvent"); eventOne = @event; } else if (rep.IsAvroEvent()) { var schema = SupportAvroUtil.GetAvroSchema(_epService, "MyEvent").AsRecordSchema(); var @event = new GenericRecord(schema); @event.Put("col1", value); _epService.EPRuntime.SendEventAvro(@event, "MyEvent"); eventOne = @event; } else { throw new IllegalStateException(); } return(eventOne); }
private static void TryAssertionNewWRepresentation( RegressionEnvironment env, EventRepresentationChoice rep, AtomicLong milestone) { var epl = rep.GetAnnotationTextWJsonProvided <MyLocalJsonProvided>() + "@Name('s0') select new { TheString = 'x' || TheString || 'x', IntPrimitive = IntPrimitive + 2} as val0 from SupportBean as sb"; env.CompileDeploy(epl).AddListener("s0").Milestone(milestone.GetAndIncrement()); Assert.AreEqual( rep.IsAvroEvent() ? typeof(GenericRecord) : typeof(IDictionary <string, object>), env.Statement("s0").EventType.GetPropertyType("val0")); var fragType = env.Statement("s0").EventType.GetFragmentType("val0"); if (rep == EventRepresentationChoice.JSONCLASSPROVIDED) { Assert.IsNull(fragType); } else { Assert.IsFalse(fragType.IsIndexed); Assert.IsFalse(fragType.IsNative); Assert.AreEqual(typeof(string), fragType.FragmentType.GetPropertyType("TheString")); Assert.AreEqual(typeof(int?), Boxing.GetBoxedType(fragType.FragmentType.GetPropertyType("IntPrimitive"))); } var fieldsInner = "TheString,IntPrimitive".SplitCsv(); env.SendEventBean(new SupportBean("E1", -5)); var @event = env.Listener("s0").AssertOneGetNewAndReset(); if (rep.IsAvroEvent()) { SupportAvroUtil.AvroToJson(@event); GenericRecord inner = (GenericRecord)@event.Get("val0"); Assert.AreEqual("xE1x", inner.Get("TheString")); Assert.AreEqual(-3, inner.Get("IntPrimitive")); } else { EPAssertionUtil.AssertPropsMap((IDictionary <string, object>)@event.Get("val0"), fieldsInner, "xE1x", -3); } env.UndeployAll(); }
private static void RunTransposeMapAndObjectArray( RegressionEnvironment env, EventRepresentationChoice representation) { var fields = new[] {"p0", "p1"}; var path = new RegressionPath(); var schema = representation.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMySchema>() + "create schema MySchema(p0 string, p1 int)"; env.CompileDeployWBusPublicType(schema, path); string generateFunction; if (representation.IsObjectArrayEvent()) { generateFunction = "GenerateOA"; } else if (representation.IsMapEvent()) { generateFunction = "GenerateMap"; } else if (representation.IsAvroEvent()) { generateFunction = "GenerateAvro"; } else if (representation.IsJsonEvent() || representation.IsJsonProvidedClassEvent()) { generateFunction = "GenerateJson"; } else { throw new IllegalStateException("Unrecognized code " + representation); } var epl = "insert into MySchema select transpose(" + generateFunction + "(TheString, IntPrimitive)) from SupportBean"; env.CompileDeploy("@Name('s0') " + epl, path).AddListener("s0"); env.SendEventBean(new SupportBean("E1", 1)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E1", 1}); env.SendEventBean(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E2", 2}); // MySchema already exists, start second statement env.CompileDeploy("@Name('s1') " + epl, path).AddListener("s1"); env.UndeployModuleContaining("s0"); env.SendEventBean(new SupportBean("E3", 3)); EPAssertionUtil.AssertProps( env.Listener("s1").AssertOneGetNewAndReset(), fields, new object[] {"E3", 3}); env.UndeployAll(); }
private void TryJoinAssertion( EPServiceProvider epService, string epl, EventRepresentationChoice rep, string columnNames) { if (rep.IsMapEvent()) { var typeInfo = new Dictionary<string, object>(); typeInfo.Put("id", typeof(string)); typeInfo.Put("p00", typeof(int)); epService.EPAdministrator.Configuration.AddEventType("S0", typeInfo); epService.EPAdministrator.Configuration.AddEventType("S1", typeInfo); } else if (rep.IsObjectArrayEvent()) { var names = "id,p00".Split(','); var types = new object[] {typeof(string), typeof(int)}; epService.EPAdministrator.Configuration.AddEventType("S0", names, types); epService.EPAdministrator.Configuration.AddEventType("S1", names, types); } else if (rep.IsAvroEvent()) { var schema = SchemaBuilder.Record( "name", TypeBuilder.Field( "id", TypeBuilder.StringType( TypeBuilder.Property(AvroConstant.PROP_STRING_KEY, AvroConstant.PROP_STRING_VALUE))), TypeBuilder.RequiredInt("p00")); epService.EPAdministrator.Configuration.AddEventTypeAvro( "S0", new ConfigurationEventTypeAvro().SetAvroSchema(schema)); epService.EPAdministrator.Configuration.AddEventTypeAvro( "S1", new ConfigurationEventTypeAvro().SetAvroSchema(schema)); } var stmt = epService.EPAdministrator.CreateEPL(rep.GetAnnotationText() + epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendRepEvent(epService, rep, "S0", "a", 1); Assert.IsFalse(listener.IsInvoked); SendRepEvent(epService, rep, "S1", "a", 2); var output = listener.AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps(output, columnNames.Split(','), new object[] {"a", "a", 1, 2}); Assert.IsTrue(rep.MatchesClass(output.Underlying.GetType())); SendRepEvent(epService, rep, "S1", "b", 3); SendRepEvent(epService, rep, "S0", "c", 4); Assert.IsFalse(listener.IsInvoked); stmt.Dispose(); epService.EPAdministrator.Configuration.RemoveEventType("S0", true); epService.EPAdministrator.Configuration.RemoveEventType("S1", true); }
private void AssertCreateStreamTwo(EventRepresentationChoice eventRepresentationEnum, EventBean eventBean, EPStatement statement) { if (eventRepresentationEnum.IsAvroEvent()) { Assert.AreEqual(1, eventBean.Get("myEvent.myId")); } else { Assert.IsTrue(eventBean.Get("myEvent") is EventBean); Assert.AreEqual(1, ((EventBean)eventBean.Get("myEvent")).Get("myId")); } Assert.IsNotNull(statement.EventType.GetFragmentType("myEvent")); }
private void RunAssertion(EventRepresentationChoice outputEventRep, string additionalAnnotations) { // Bean var beanTests = new Pair <SupportBeanDynRoot, ValueWithExistsFlag>[] { new Pair <SupportBeanDynRoot, ValueWithExistsFlag>(new SupportBeanDynRoot(new SupportBean_S0(101)), ValueWithExistsFlag.Exists(101)), new Pair <SupportBeanDynRoot, ValueWithExistsFlag>(new SupportBeanDynRoot("abc"), ValueWithExistsFlag.NotExists()), new Pair <SupportBeanDynRoot, ValueWithExistsFlag>(new SupportBeanDynRoot(new SupportBean_A("e1")), ValueWithExistsFlag.Exists("e1")), new Pair <SupportBeanDynRoot, ValueWithExistsFlag>(new SupportBeanDynRoot(new SupportBean_B("e2")), ValueWithExistsFlag.Exists("e2")), new Pair <SupportBeanDynRoot, ValueWithExistsFlag>(new SupportBeanDynRoot(new SupportBean_S1(102)), ValueWithExistsFlag.Exists(102)) }; RunAssertion(outputEventRep, additionalAnnotations, BEAN_TYPENAME, SupportEventInfra.FBEAN, null, beanTests, typeof(object)); // Map var mapTests = new Pair <IDictionary <string, object>, ValueWithExistsFlag>[] { new Pair <IDictionary <string, object>, ValueWithExistsFlag>(Collections.EmptyDataMap, ValueWithExistsFlag.NotExists()), new Pair <IDictionary <string, object>, ValueWithExistsFlag>(Collections.SingletonDataMap("item", Collections.SingletonDataMap("id", 101)), ValueWithExistsFlag.Exists(101)), new Pair <IDictionary <string, object>, ValueWithExistsFlag>(Collections.SingletonDataMap("item", Collections.EmptyDataMap), ValueWithExistsFlag.NotExists()), }; RunAssertion(outputEventRep, additionalAnnotations, SupportEventInfra.MAP_TYPENAME, SupportEventInfra.FMAP, null, mapTests, typeof(object)); // Object array var oaTests = new Pair <object[], ValueWithExistsFlag>[] { new Pair <object[], ValueWithExistsFlag>(new object[] { null }, ValueWithExistsFlag.NotExists()), //new Pair<>(new Object[] {new SupportBean_S0(101)}, exists(101)), //new Pair<>(new Object[] {"abc"}, notExists()), }; RunAssertion(outputEventRep, additionalAnnotations, SupportEventInfra.OA_TYPENAME, SupportEventInfra.FOA, null, oaTests, typeof(object)); // XML var xmlTests = new Pair <string, ValueWithExistsFlag>[] { new Pair <string, ValueWithExistsFlag>("<item id=\"101\"/>", ValueWithExistsFlag.Exists("101")), new Pair <string, ValueWithExistsFlag>("<item/>", ValueWithExistsFlag.NotExists()), }; if (!outputEventRep.IsAvroEvent()) { RunAssertion(outputEventRep, additionalAnnotations, SupportEventInfra.XML_TYPENAME, SupportEventInfra.FXML, SupportEventInfra.XML_TO_VALUE, xmlTests, typeof(XmlNode)); } // Avro var avroTests = new Pair <object, ValueWithExistsFlag>[] { new Pair <object, ValueWithExistsFlag>(null, ValueWithExistsFlag.Exists(null)), new Pair <object, ValueWithExistsFlag>(101, ValueWithExistsFlag.Exists(101)), new Pair <object, ValueWithExistsFlag>("abc", ValueWithExistsFlag.Exists("abc")), }; RunAssertion(outputEventRep, additionalAnnotations, SupportEventInfra.AVRO_TYPENAME, FAVRO, null, avroTests, typeof(object)); }
private static void RunAssertionCreateStreamTwo( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum) { var path = new RegressionPath(); var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedMyEvent>() + " create schema MyEvent(myId int)\n;" + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedAllMyEvent>() + " create schema AllMyEvent as (myEvent MyEvent, clazz String, reverse boolean);\n" + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSuspectMyEvent>() + " create schema SuspectMyEvent as (myEvent MyEvent, clazz String);\n"; env.CompileDeployWBusPublicType(epl, path); env.CompileDeploy( "@Name('s0') insert into AllMyEvent " + "select c as myEvent, 'test' as clazz, false as reverse " + "from MyEvent(myId=1) c", path) .AddListener("s0"); Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("s0").EventType.UnderlyingType)); env.CompileDeploy( "@Name('s1') insert into SuspectMyEvent " + "select c.myEvent as myEvent, clazz " + "from AllMyEvent(not reverse) c", path) .AddListener("s1"); if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(MakeEvent(1).Values.ToArray(), "MyEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { env.SendEventMap(MakeEvent(1), "MyEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { env.SendEventAvro(MakeEventAvro(1), "MyEvent"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { env.SendEventJson("{\"myId\": 1}", "MyEvent"); } else { Assert.Fail(); } AssertCreateStreamTwo(eventRepresentationEnum, env.Listener("s0").AssertOneGetNewAndReset(), env.Statement("s0")); AssertCreateStreamTwo(eventRepresentationEnum, env.Listener("s1").AssertOneGetNewAndReset(), env.Statement("s1")); env.UndeployAll(); }
private void TryAssertionSplitPremptiveNamedWindow(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TypeTwo(col2 int)"); epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema TypeTrigger(trigger int)"); epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window WinTwo#keepall as TypeTwo"); var stmtOrigText = "on TypeTrigger " + "insert into OtherStream select 1 " + "insert into WinTwo(col2) select 2 " + "output all"; epService.EPAdministrator.CreateEPL(stmtOrigText); var stmt = epService.EPAdministrator.CreateEPL("on OtherStream select col2 from WinTwo"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; // populate WinOne epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); // fire trigger if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(new object[] { null }); } else if (eventRepresentationEnum.IsMapEvent()) { epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(new Dictionary <string, object>()); } else if (eventRepresentationEnum.IsAvroEvent()) { var @event = new GenericRecord(SchemaBuilder.Record("name", OptionalInt("trigger"))); epService.EPRuntime.GetEventSender("TypeTrigger").SendEvent(@event); } else { Assert.Fail(); } Assert.AreEqual(2, listener.AssertOneGetNewAndReset().Get("col2")); epService.EPAdministrator.DestroyAllStatements(); foreach (var name in "TypeTwo,TypeTrigger,WinTwo,OtherStream".Split(',')) { epService.EPAdministrator.Configuration.RemoveEventType(name, true); } }
private static void TryAssertionSplitPremptiveNamedWindow( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum) { var path = new RegressionPath(); env.CompileDeployWBusPublicType( eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTrigger>() + " create schema TypeTrigger(trigger int)", path); env.CompileDeploy(eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTypeTwo>() + " create schema TypeTwo(col2 int)", path); env.CompileDeploy( eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedTypeTwo>() + " create window WinTwo#keepall as TypeTwo", path); var stmtOrigText = "on TypeTrigger " + "insert into OtherStream select 1 " + "insert into WinTwo(col2) select 2 " + "output all"; env.CompileDeploy(stmtOrigText, path); env.CompileDeploy("@Name('s0') on OtherStream select col2 from WinTwo", path).AddListener("s0"); // populate WinOne env.SendEventBean(new SupportBean("E1", 2)); // fire trigger if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {null}, "TypeTrigger"); } else if (eventRepresentationEnum.IsMapEvent()) { env.SendEventMap(new Dictionary<string, object>(), "TypeTrigger"); } else if (eventRepresentationEnum.IsAvroEvent()) { var @event = new GenericRecord( SchemaBuilder.Record("name", TypeBuilder.OptionalInt("trigger"))); env.SendEventAvro(@event, "TypeTrigger"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { env.SendEventJson("{}", "TypeTrigger"); } else { Assert.Fail(); } Assert.AreEqual(2, env.Listener("s0").AssertOneGetNewAndReset().Get("col2")); env.UndeployAll(); }