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 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 SendMyEvent(EPServiceProvider epService, 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(); } }
public void TestGet() { var schema = SchemaBuilder .Record("typename", TypeBuilder.RequiredInt("myInt")); var eventType = SupportAvroUtil.MakeAvroSupportEventType(schema); var record = new GenericRecord(schema); record.Put("myInt", 99); var eventBean = new AvroGenericDataEventBean(record, eventType); Assert.AreEqual(eventType, eventBean.EventType); Assert.AreEqual(record, eventBean.Underlying); Assert.AreEqual(99, eventBean.Get("myInt")); // test wrong property name try { eventBean.Get("dummy"); Assert.Fail(); } catch (PropertyAccessException ex) { // Expected Log.Debug(".testGetter Expected exception, msg=" + ex.Message); } }
private void SendOrderEvent(EPServiceProvider epService, 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 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(); } }
private void SendRepEvent( EPServiceProvider epService, EventRepresentationChoice rep, string name, string id, int p00) { if (rep.IsMapEvent()) { var 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()) { var 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 GenericRecord MakeAvro(int myint, string mystr) { var record = new GenericRecord(SupportAvroUtil.GetAvroSchema(_epService, "A").AsRecordSchema()); record.Put("myint", myint); record.Put("mystr", mystr); return(record); }
private void SendEvent( RegressionEnvironment env, string symbol) { var schema = SupportAvroUtil.GetAvroSchema(env.Statement("input").EventType).AsRecordSchema(); var rec = new GenericRecord(schema); rec.Put("symbol", symbol); env.SendEventAvro(rec, "Input"); }
private static GenericRecord MakeAvro( RegressionEnvironment env, int myint, string mystr) { EventType eventType = env.Runtime.EventTypeService.GetEventType(env.DeploymentId("schema"), "A"); var record = new GenericRecord(SupportAvroUtil.GetAvroSchema(eventType).AsRecordSchema()); record.Put("myint", myint); record.Put("mystr", mystr); return record; }
public void Run(RegressionEnvironment env) { // Bean BiConsumer <EventType, string> bean = (type, property) => { env.SendEventBean(new LocalEvent(property)); }; var beanepl = $"@public @buseventtype create schema LocalEvent as {typeof(LocalEvent).MaskTypeName()}"; RunAssertion(env, beanepl, bean); // Map BiConsumer <EventType, string> map = (type, property) => { env.SendEventMap(Collections.SingletonDataMap("Property", property), "LocalEvent"); }; RunAssertion(env, GetEpl("map"), map); // Object-array BiConsumer <EventType, string> oa = (type, property) => { env.SendEventObjectArray(new object[] { property }, "LocalEvent"); }; RunAssertion(env, GetEpl("objectarray"), oa); // Json BiConsumer <EventType, string> json = (type, property) => { if (property == null) { env.SendEventJson(new JObject(new JProperty("Property", null)).ToString(), "LocalEvent"); } else { env.SendEventJson(new JObject(new JProperty("Property", property)).ToString(), "LocalEvent"); } }; RunAssertion(env, GetEpl("json"), json); // Json-Class-Predefined var eplJsonPredefined = "@JsonSchema(ClassName='" + typeof(MyLocalJsonProvided).MaskTypeName() + "') @buseventtype @public " + "create json schema LocalEvent();\n"; RunAssertion(env, eplJsonPredefined, json); // Avro BiConsumer <EventType, string> avro = (type, property) => { var @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(type).AsRecordSchema()); @event.Put("Property", property); env.SendEventAvro(@event, "LocalEvent"); }; RunAssertion(env, GetEpl("avro"), avro); }
private void RunAssertionArrayAvroResult() { _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean)); Schema intArraySchema = SchemaBuilder.Array(TypeBuilder.Int()); Schema mixedArraySchema = SchemaBuilder.Array(TypeBuilder.Union(TypeBuilder.Int(), TypeBuilder.String(), TypeBuilder.Double())); Schema nullArraySchema = SchemaBuilder.Array(TypeBuilder.Null()); string stmtText = "@AvroSchemaField(Name='emptyArray', Schema='" + intArraySchema.ToString() + "')" + "@AvroSchemaField(Name='mixedArray', Schema='" + mixedArraySchema.ToString() + "')" + "@AvroSchemaField(Name='nullArray', Schema='" + nullArraySchema.ToString() + "')" + EventRepresentationChoice.AVRO.GetAnnotationText() + " " + "select {'a', 'b'} as stringArray," + "{} as emptyArray," + "{1} as oneEleArray," + "{1,2,3} as intArray," + "{1,null} as intNullArray," + "{1L,10L} as longArray," + "{'a',1, 1e20} as mixedArray," + "{1, 1.1d, 1e20} as doubleArray," + "{5, 6L} as intLongArray," + "{null} as nullArray," + "{true, false} as boolArray" + " from " + typeof(SupportBean).Name; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.AddListener(listener); _epService.EPRuntime.SendEvent(new SupportBean()); EventBean theEvent = listener.AssertOneGetNewAndReset(); SupportAvroUtil.AvroToJson(theEvent); CompareColl(theEvent, "stringArray", new string[] { "a", "b" }); CompareColl(theEvent, "emptyArray", new object[0]); CompareColl(theEvent, "oneEleArray", new int[] { 1 }); CompareColl(theEvent, "intArray", new int[] { 1, 2, 3 }); CompareColl(theEvent, "intNullArray", new int?[] { 1, null }); CompareColl(theEvent, "longArray", new long[] { 1L, 10L }); CompareColl(theEvent, "mixedArray", new object[] { "a", 1, 1e20 }); CompareColl(theEvent, "doubleArray", new double[] { 1d, 1.1, 1e20 }); CompareColl(theEvent, "intLongArray", new long[] { 5L, 6L }); CompareColl(theEvent, "nullArray", new object[] { null }); CompareColl(theEvent, "boolArray", new bool[] { true, false }); stmt.Dispose(); }
private void RunAssertionArrayAvroResult(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); Schema intArraySchema = SchemaBuilder.Array(IntType()); Schema mixedArraySchema = SchemaBuilder.Array(Union(IntType(), StringType(), DoubleType())); Schema nullArraySchema = SchemaBuilder.Array(NullType()); var stmtText = "@AvroSchemaField(Name='emptyArray', Schema='" + intArraySchema + "')" + "@AvroSchemaField(Name='mixedArray', Schema='" + mixedArraySchema + "')" + "@AvroSchemaField(Name='nullArray', Schema='" + nullArraySchema + "')" + EventRepresentationChoice.AVRO.GetAnnotationText() + "select {'a', 'b'} as stringArray," + "{} as emptyArray," + "{1} as oneEleArray," + "{1,2,3} as intArray," + "{1,null} as intNullArray," + "{1L,10L} as longArray," + "{'a',1, 1e20} as mixedArray," + "{1, 1.1d, 1e20} as doubleArray," + "{5, 6L} as intLongArray," + "{null} as nullArray," + "{true, false} as boolArray" + " from " + typeof(SupportBean).FullName; var stmt = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean()); var theEvent = listener.AssertOneGetNewAndReset(); SupportAvroUtil.AvroToJson(theEvent); CompareColl(theEvent, "stringArray", new object[] { "a", "b" }); CompareColl(theEvent, "emptyArray", new object[0]); CompareColl(theEvent, "oneEleArray", new object[] { 1 }); CompareColl(theEvent, "intArray", new object[] { 1, 2, 3 }); CompareColl(theEvent, "intNullArray", new object[] { 1, null }); CompareColl(theEvent, "longArray", new object[] { 1L, 10L }); CompareColl(theEvent, "mixedArray", new object[] { "a", 1, 1e20 }); CompareColl(theEvent, "doubleArray", new object[] { 1d, 1.1, 1e20 }); CompareColl(theEvent, "intLongArray", new object[] { 5L, 6L }); CompareColl(theEvent, "nullArray", new object[] { null }); CompareColl(theEvent, "boolArray", new object[] { true, false }); stmt.Dispose(); }
public void Run(RegressionEnvironment env) { var epl = "@Name('s0') insert into MyEventPopulate(sb) select " + typeof(EventAvroHook).FullName + ".MakeSupportBean() from SupportBean_S0 as e1"; env.CompileDeploy(epl).AddListener("s0"); env.SendEventBean(new SupportBean_S0(10)); var @event = env.Listener("s0").AssertOneGetNewAndReset(); Assert.AreEqual( "{\"sb\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}", SupportAvroUtil.AvroToJson(@event)); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var intArraySchema = SchemaBuilder.Array(IntType()); var mixedArraySchema = SchemaBuilder.Array(Union(IntType(), StringType(), DoubleType())); var nullArraySchema = SchemaBuilder.Array(NullType()); var stmtText = "@Name('s0') " + "@AvroSchemaField(Name='EmptyArray', Schema='" + intArraySchema + "')" + "@AvroSchemaField(Name='MixedArray', Schema='" + mixedArraySchema + "')" + "@AvroSchemaField(Name='NullArray', Schema='" + nullArraySchema + "')" + EventRepresentationChoice.AVRO.GetAnnotationText() + "select {'a', 'b'} as StringArray," + "{} as EmptyArray," + "{1} as OneEleArray," + "{1,2,3} as IntArray," + "{1,null} as IntNullArray," + "{1L,10L} as LongArray," + "{'a',1, 1e20} as MixedArray," + "{1, 1.1d, 1e20} as DoubleArray," + "{5, 6L} as IntLongArray," + "{null} as NullArray," + "{true, false} as BoolArray" + " from SupportBean"; env.CompileDeploy(stmtText).AddListener("s0"); env.SendEventBean(new SupportBean()); var theEvent = env.Listener("s0").AssertOneGetNewAndReset(); SupportAvroUtil.AvroToJson(theEvent); CompareColl(theEvent, "StringArray", new[] { "a", "b" }); CompareColl(theEvent, "EmptyArray", new object[0]); CompareColl(theEvent, "OneEleArray", new int?[] { 1 }); CompareColl(theEvent, "IntArray", new int?[] { 1, 2, 3 }); CompareColl(theEvent, "IntNullArray", new int?[] { 1, null }); CompareColl(theEvent, "LongArray", new long?[] { 1L, 10L }); CompareColl(theEvent, "MixedArray", new object[] { "a", 1, 1e20 }); CompareColl(theEvent, "DoubleArray", new double?[] { 1d, 1.1, 1e20 }); CompareColl(theEvent, "IntLongArray", new long?[] { 5L, 6L }); CompareColl(theEvent, "NullArray", new object[] { null }); CompareColl(theEvent, "BoolArray", new bool?[] { true, false }); env.UndeployAll(); }
private void RunAssertionUpdateIStreamSetMapProps( EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { // test update-istream with map epService.EPAdministrator.CreateEPL( eventRepresentationEnum.GetAnnotationText() + " create schema MyInfraType(simple string, myarray int[], mymap Map)"); var stmtUpdTwo = epService.EPAdministrator.CreateEPL( "update istream MyInfraType set simple='A', mymap('abc') = 1, myarray[2] = 10"); var listener = new SupportUpdateListener(); stmtUpdTwo.Events += listener.Update; 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()) { var @event = new GenericRecord( SupportAvroUtil.GetAvroSchema(epService, "MyInfraType").AsRecordSchema()); @event.Put("myarray", Collections.List(0, 0, 0, 0, 0)); @event.Put("mymap", new Dictionary <string, object>()); epService.EPRuntime.SendEventAvro(@event, "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.EPAdministrator.DestroyAllStatements(); foreach (var name in "MyInfraType".Split(',')) { epService.EPAdministrator.Configuration.RemoveEventType(name, true); } }
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 void RunAssertionWildcard(bool bean, EventRepresentationChoice?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.Value.IsMapEvent()) { IDictionary <String, object> map = new Dictionary <string, object>(); map.Put("P0", "a"); map.Put("P1", "b"); _epService.EPRuntime.SendEvent(map, "MySchema"); } else if (rep.Value.IsObjectArrayEvent()) { _epService.EPRuntime.SendEvent( new object[] { "a", "b" }, "MySchema"); } else if (rep.Value.IsAvroEvent()) { var theEvent = SupportAvroUtil.GetAvroRecord(_epService, "MySchema"); theEvent.Put("P0", "a"); theEvent.Put("P1", "b"); _epService.EPRuntime.SendEventAvro(theEvent, "MySchema"); } else { } EPAssertionUtil.AssertProps(stmtTheTable.First(), "P0,P1".Split(','), new object[] { "a", "b" }); _epService.EPAdministrator.DestroyAllStatements(); _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", false); }
private static void SendOrderEvent( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum, string orderId, string productId, double price, int quantity, bool deletedFlag) { if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {orderId, productId, price, quantity, deletedFlag}, "OrderEvent"); } else if (eventRepresentationEnum.IsMapEvent()) { IDictionary<string, object> 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); env.SendEventMap(theEvent, "OrderEvent"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord( SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("OrderEvent")) .AsRecordSchema()); theEvent.Put("OrderId", orderId); theEvent.Put("ProductId", productId); theEvent.Put("Price", price); theEvent.Put("Quantity", quantity); theEvent.Put("DeletedFlag", deletedFlag); env.EventService.SendEventAvro(theEvent, "OrderEvent"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { var @object = new JObject(); @object.Add("OrderId", orderId); @object.Add("ProductId", productId); @object.Add("Price", price); @object.Add("Quantity", quantity); @object.Add("DeletedFlag", deletedFlag); env.EventService.SendEventJson(@object.ToString(), "OrderEvent"); } else { Assert.Fail(); } }
public void TestSchemaFromClass() { var epl = EventRepresentationChoice.AVRO.GetAnnotationText() + "insert into MyEvent select " + this.GetType().FullName + ".MakeDateTime() as isodate from SupportBean as e1"; var stmt = _epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.AddListener(listener); Schema schema = SupportAvroUtil.GetAvroSchema(stmt.EventType); Assert.AreEqual("{\"type\":\"record\",\"name\":\"MyEvent\",\"fields\":[{\"name\":\"isodate\",\"type\":\"string\"}]}", schema.ToString()); _epService.EPRuntime.SendEvent(new SupportBean("E1", 10)); var @event = listener.AssertOneGetNewAndReset(); SupportAvroUtil.AvroToJson(@event); Assert.IsTrue(@event.Get("isodate").ToString().Length > 10); }
public void Run(RegressionEnvironment env) { var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSchemaOne>() + " @name('schema') create schema SchemaOne(col1 int, col2 int);\n"; epl += eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedSchemaWindow>() + " @name('create') create window SchemaWindow#lastevent as (s1 SchemaOne);\n"; epl += "insert into SchemaWindow (s1) select sone from SchemaOne as sone;\n"; env.CompileDeployWBusPublicType(epl, new RegressionPath()).AddListener("create"); Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("schema").EventType.UnderlyingType)); Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("create").EventType.UnderlyingType)); if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {10, 11}, "SchemaOne"); } else if (eventRepresentationEnum.IsMapEvent()) { IDictionary<string, object> theEvent = new Dictionary<string, object>(); theEvent.Put("col1", 10); theEvent.Put("col2", 11); env.SendEventMap(theEvent, "SchemaOne"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord( SupportAvroUtil .GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("SchemaOne")) .AsRecordSchema()); theEvent.Put("col1", 10); theEvent.Put("col2", 11); env.EventService.SendEventAvro(theEvent, "SchemaOne"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { env.EventService.SendEventJson("{\"col1\": 10, \"col2\": 11}", "SchemaOne"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps( env.Listener("create").AssertOneGetNewAndReset(), new[] {"s1.col1", "s1.col2"}, new object[] {10, 11}); env.UndeployAll(); }
private void TryAssertionWildcard(EPServiceProvider epService, bool bean, EventRepresentationChoice?rep) { if (bean) { epService.EPAdministrator.CreateEPL("create schema MySchema as " + typeof(MyP0P1Event).FullName); } 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.Value.IsMapEvent()) { var map = new Dictionary <string, Object>(); map.Put("p0", "a"); map.Put("p1", "b"); epService.EPRuntime.SendEvent(map, "MySchema"); } else if (rep.Value.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { "a", "b" }, "MySchema"); } else if (rep.Value.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "MySchema").AsRecordSchema()); theEvent.Put("p0", "a"); theEvent.Put("p1", "b"); epService.EPRuntime.SendEventAvro(theEvent, "MySchema"); } EPAssertionUtil.AssertProps(stmtTheTable.First(), "p0,p1".Split(','), new object[] { "a", "b" }); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MySchema", false); epService.EPAdministrator.DestroyAllStatements(); }
private static void MakeSendScoreEvent( RegressionEnvironment env, string typeName, EventRepresentationChoice eventRepresentationEnum, string userId, string keyword, string productId, long score) { if (eventRepresentationEnum.IsMapEvent()) { IDictionary<string, object> theEvent = new LinkedHashMap<string, object>(); theEvent.Put("UserId", userId); theEvent.Put("Keyword", keyword); theEvent.Put("ProductId", productId); theEvent.Put("Score", score); env.SendEventMap(theEvent, typeName); } else if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {userId, keyword, productId, score}, typeName); } else if (eventRepresentationEnum.IsAvroEvent()) { var record = new GenericRecord( SupportAvroUtil.GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured(typeName)) .AsRecordSchema()); record.Put("UserId", userId); record.Put("Keyword", keyword); record.Put("ProductId", productId); record.Put("Score", score); env.SendEventAvro(record, typeName); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { var jobject = new JObject(); jobject.Add("UserId", userId); jobject.Add("Keyword", keyword); jobject.Add("ProductId", productId); jobject.Add("Score", score); env.SendEventJson(jobject.ToString(), typeName); } else { Assert.Fail(); } }
public void TestNestedSimple() { var schemaText = "{" + " 'type' : 'record'," + " 'name' : 'MyEvent'," + " 'fields' : [ {" + " 'name' : 'innerEvent'," + " 'type' : {" + " 'type' : 'record'," + " 'name' : 'innerEventTypeName'," + " 'fields' : [ {" + " 'name' : 'innerValue'," + " 'type' : {'type':'string','avro.string':'String'}" + " } ]" + " }" + " }]" + "}"; var schema = Schema.Parse(schemaText.Replace("'", "\"")).AsRecordSchema(); EventType eventType = SupportAvroUtil.MakeAvroSupportEventType(schema); AssertPropertyType(typeof(GenericRecord), null, eventType, "innerEvent"); var propNames = "innerEvent".SplitCsv(); EPAssertionUtil.AssertEqualsExactOrder(eventType.PropertyNames, propNames); Assert.IsTrue(eventType.IsProperty("innerEvent")); var datumInner = new GenericRecord(schema.GetField("innerEvent").Schema.AsRecordSchema()); datumInner.Put("innerValue", "i1"); var datum = new GenericRecord(schema); datum.Put("innerEvent", datumInner); AssertValuesNested(datum, new AvroGenericDataEventBean(datum, eventType)); var jsonWValues = "{'innerEvent': {'innerValue' : 'i1'}}"; datum = SupportAvroUtil.ParseQuoted(schema, jsonWValues); AssertValuesNested(datum, new AvroGenericDataEventBean(datum, eventType)); }
private void RunAssertionEventTypeColumnDef(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { EPStatement stmtSchema = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SchemaOne(col1 int, col2 int)"); Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtSchema.EventType.UnderlyingType)); EPStatement stmt = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create window SchemaWindow#lastevent as (s1 SchemaOne)"); Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType)); var listenerWindow = new SupportUpdateListener(); stmt.Events += listenerWindow.Update; epService.EPAdministrator.CreateEPL("insert into SchemaWindow (s1) select sone from SchemaOne as sone"); if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { 10, 11 }, "SchemaOne"); } else if (eventRepresentationEnum.IsMapEvent()) { var theEvent = new LinkedHashMap <string, object>(); theEvent.Put("col1", 10); theEvent.Put("col2", 11); epService.EPRuntime.SendEvent(theEvent, "SchemaOne"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord(SupportAvroUtil.GetAvroSchema(epService, "SchemaOne").AsRecordSchema()); theEvent.Put("col1", 10); theEvent.Put("col2", 11); epService.EPRuntime.SendEventAvro(theEvent, "SchemaOne"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), "s1.col1,s1.col2".Split(','), new object[] { 10, 11 }); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("SchemaOne", true); epService.EPAdministrator.Configuration.RemoveEventType("SchemaWindow", true); }
public void TestRequiredType() { var schema = SchemaBuilder.Record( "typename", RequiredInt("myInt"), RequiredString("myCharSeq"), Field("myString", StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE))), RequiredBoolean("myBoolean"), RequiredBytes("myBytes"), RequiredDouble("myDouble"), RequiredFloat("myFloat"), RequiredLong("myLong")); var propNames = "myInt,myCharSeq,myString,myBoolean,myBytes,myDouble,myFloat,myLong".SplitCsv(); EventType eventType = SupportAvroUtil.MakeAvroSupportEventType(schema); EPAssertionUtil.AssertEqualsExactOrder(eventType.PropertyNames, propNames); Assert.AreEqual(typeof(GenericRecord), eventType.UnderlyingType); Assert.IsNull(eventType.SuperTypes); AssertPropertyType(typeof(int), null, eventType, "myInt"); AssertPropertyType(typeof(string), typeof(char), eventType, "myString"); AssertPropertyType(typeof(bool), null, eventType, "myBoolean"); AssertPropertyType(typeof(byte[]), null, eventType, "myBytes"); AssertPropertyType(typeof(double), null, eventType, "myDouble"); AssertPropertyType(typeof(float), null, eventType, "myFloat"); AssertPropertyType(typeof(long), null, eventType, "myLong"); foreach (var propName in propNames) { Assert.IsTrue(eventType.IsProperty(propName)); } var datum = GetRecordWithValues(schema); AssertValuesRequired(new AvroGenericDataEventBean(datum, eventType)); var jsonWValues = "{'myInt': 10, 'myCharSeq': 'x', 'myString': 'y', 'myBoolean': true, 'myBytes': '\\u00AA\'," + "'myDouble' : 50, 'myFloat':100, 'myLong':20}"; AssertValuesRequired(new AvroGenericDataEventBean(SupportAvroUtil.ParseQuoted(schema, jsonWValues), eventType)); }
/// <summary>Mapping of Type to GenericRecord</summary> private void RunAssertionPopulate(EPServiceProvider epService) { MySupportBeanWidener.supportBeanSchema = SchemaBuilder.Record("SupportBeanSchema", TypeBuilder.Field("TheString", "string"), TypeBuilder.Field("IntPrimitive", "int")); var schema = SchemaBuilder.Record("MyEventSchema", TypeBuilder.Field("sb", MySupportBeanWidener.supportBeanSchema)); epService.EPAdministrator.Configuration.AddEventTypeAvro("MyEventPopulate", new ConfigurationEventTypeAvro(schema)); string epl = "insert into MyEventPopulate(sb) select " + GetType().FullName + ".MakeSupportBean() from SupportBean_S0 as e1"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(10)); EventBean @event = listener.AssertOneGetNewAndReset(); Assert.AreEqual("{\"sb\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}", SupportAvroUtil.AvroToJson(@event)); }
public void Run(RegressionEnvironment env) { var epl = "@Name('s0') " + EventRepresentationChoice.AVRO.GetAnnotationText() + "insert into MyEventOut select " + typeof(EventAvroHook).FullName + ".MakeDateTimeOffset() as isodate from SupportBean as e1"; env.CompileDeploy(epl).AddListener("s0"); var schema = SupportAvroUtil.GetAvroSchema(env.Statement("s0").EventType); Assert.AreEqual( "{\"type\":\"record\",\"name\":\"MyEventOut\",\"fields\":[{\"name\":\"isodate\",\"type\":\"string\"}]}", schema.ToString()); env.SendEventBean(new SupportBean("E1", 10)); var @event = env.Listener("s0").AssertOneGetNewAndReset(); SupportAvroUtil.AvroToJson(@event); Assert.IsTrue(@event.Get("isodate").ToString().Length > 10); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); env.CompileDeploy("@Name('NamedWindow') create window MyWindow#keepall as MyEventWSchema", path); env.CompileDeploy("insert into MyWindow select * from MyEventWSchema", path); env.CompileDeploy("on SupportBean thebean update MyWindow set sb = thebean", path); var schema = AvroSchemaUtil .ResolveAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("MyEventWSchema")) .AsRecordSchema(); var @event = new GenericRecord(schema); env.SendEventAvro(@event, "MyEventWSchema"); env.SendEventBean(new SupportBean("E1", 10)); var eventBean = env.GetEnumerator("NamedWindow").Advance(); Assert.AreEqual( "{\"sb\":{\"SupportBeanSchema\":{\"TheString\":\"E1\",\"IntPrimitive\":10}}}", SupportAvroUtil.AvroToJson(eventBean)); env.UndeployAll(); }
private void TryAssertionCreateSchemaModelAfter( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum) { var epl = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedEventTypeOne>() + " create schema EventTypeOne (hsi int);\n" + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonProvidedEventTypeTwo>() + " create schema EventTypeTwo (event EventTypeOne);\n" + "@Name('create') create window NamedWindow#unique(event.hsi) as EventTypeTwo;\n" + "on EventTypeOne as ev insert into NamedWindow select ev as event;\n"; env.CompileDeployWBusPublicType(epl, new RegressionPath()); if (eventRepresentationEnum.IsObjectArrayEvent()) { env.SendEventObjectArray(new object[] {10}, "EventTypeOne"); } else if (eventRepresentationEnum.IsMapEvent()) { env.SendEventMap(Collections.SingletonDataMap("hsi", 10), "EventTypeOne"); } else if (eventRepresentationEnum.IsAvroEvent()) { var theEvent = new GenericRecord( SupportAvroUtil .GetAvroSchema(env.Runtime.EventTypeService.GetEventTypePreconfigured("EventTypeOne")) .AsRecordSchema()); theEvent.Put("hsi", 10); env.EventService.SendEventAvro(theEvent, "EventTypeOne"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { env.EventService.SendEventJson("{\"hsi\": 10}", "EventTypeOne"); } else { Assert.Fail(); } var result = env.Statement("create").First(); var getter = result.EventType.GetGetter("event.hsi"); Assert.AreEqual(10, getter.Get(result)); env.UndeployAll(); }