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 void RunAssertPopulateFromNamedWindow(EPServiceProvider epService, EventRepresentationChoice type) { epService.EPAdministrator.CreateEPL("create " + type.GetOutputTypeCreateSchemaName() + " schema Node(nid string)"); epService.EPAdministrator.CreateEPL("create window NodeWindow#unique(nid) as Node"); epService.EPAdministrator.CreateEPL("insert into NodeWindow select * from Node"); epService.EPAdministrator.CreateEPL("create " + type.GetOutputTypeCreateSchemaName() + " schema NodePlus(npid string, node Node)"); EPStatement stmt = epService.EPAdministrator.CreateEPL("insert into NodePlus select 'E1' as npid, n1 as node from NodeWindow n1"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; if (type.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { "n1" }, "Node"); } else if (type.IsMapEvent()) { epService.EPRuntime.SendEvent(Collections.SingletonDataMap("nid", "n1"), "Node"); } else if (type.IsAvroEvent()) { var genericRecord = new GenericRecord(SchemaBuilder.Record("name", RequiredString("nid"))); genericRecord.Put("nid", "n1"); epService.EPRuntime.SendEventAvro(genericRecord, "Node"); } else { Assert.Fail(); } EventBean @event = listener.AssertOneGetNewAndReset(); Assert.AreEqual("E1", @event.Get("npid")); Assert.AreEqual("n1", @event.Get("node.nid")); EventBean fragment = (EventBean)@event.GetFragment("node"); Assert.AreEqual("Node", fragment.EventType.Name); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("Node", true); epService.EPAdministrator.Configuration.RemoveEventType("NodePlus", true); epService.EPAdministrator.Configuration.RemoveEventType("NodeWindow", true); }
private void RunAssertionEventBeanAnnotation(EventRepresentationChoice rep) { _epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema MyEvent(col1 string)"); var listenerInsert = new SupportUpdateListener(); var eplInsert = "insert into DStream select " + "last(*) @eventbean as c0, " + "window(*) @eventbean as c1, " + "prevwindow(s0) @eventbean as c2 " + "from MyEvent#length(2) as s0"; var stmtInsert = _epService.EPAdministrator.CreateEPL(eplInsert); stmtInsert.AddListener(listenerInsert); foreach (var prop in "c0,c1,c2".Split(',')) { AssertFragment(prop, stmtInsert.EventType, "MyEvent", prop.Equals("c1") || prop.Equals("c2")); } // test consuming statement var fields = "f0,f1,f2,f3,f4,f5".Split(','); var listenerProps = new SupportUpdateListener(); _epService.EPAdministrator.CreateEPL("select " + "c0 as f0, " + "c0.col1 as f1, " + "c1 as f2, " + "c1.lastOf().col1 as f3, " + "c1 as f4, " + "c1.lastOf().col1 as f5 " + "from DStream").AddListener(listenerProps); var eventOne = SendEvent(rep, "E1"); Assert.IsTrue(((Map)listenerInsert.AssertOneGetNewAndReset().Underlying).Get("c0") is EventBean); EPAssertionUtil.AssertProps(listenerProps.AssertOneGetNewAndReset(), fields, new Object[] { eventOne, "E1", new Object[] { eventOne }, "E1", new Object[] { eventOne }, "E1" }); var eventTwo = SendEvent(rep, "E2"); EPAssertionUtil.AssertProps(listenerProps.AssertOneGetNewAndReset(), fields, new Object[] { eventTwo, "E2", new Object[] { eventOne, eventTwo }, "E2", new Object[] { eventOne, eventTwo }, "E2" }); // test SODA SupportModelHelper.CompileCreate(_epService, eplInsert); // test invalid try { _epService.EPAdministrator.CreateEPL("select last(*) @xxx from MyEvent"); Assert.Fail(); } catch (EPStatementException ex) { Assert.AreEqual("Failed to recognize select-expression annotation 'xxx', expected 'eventbean' in text 'last(*) @xxx' [select last(*) @xxx from MyEvent]", ex.Message); } _epService.EPAdministrator.DestroyAllStatements(); _epService.EPAdministrator.Configuration.RemoveEventType("DStream", false); _epService.EPAdministrator.Configuration.RemoveEventType("MyEvent", false); }
private void RunAssertionStreamInsertWWidenMap(EventRepresentationChoice rep) { EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(); epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema Src as (myint int, mystr string)"); epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema D1 as (myint int, mystr string, addprop long)"); var eplOne = "insert into D1 select 1 as addprop, mysrc.* from Src as mysrc"; RunStreamInsertAssertion(rep, eplOne, "myint,mystr,addprop", new Object[] { 123, "abc", 1L }); epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema D2 as (mystr string, myint int, addprop double)"); var eplTwo = "insert into D2 select 1 as addprop, mysrc.* from Src as mysrc"; RunStreamInsertAssertion(rep, eplTwo, "myint,mystr,addprop", new Object[] { 123, "abc", 1d }); epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema D3 as (mystr string, addprop int)"); var eplThree = "insert into D3 select 1 as addprop, mysrc.* from Src as mysrc"; RunStreamInsertAssertion(rep, eplThree, "mystr,addprop", new Object[] { "abc", 1 }); epService.EPAdministrator.CreateEPL("create " + rep.GetOutputTypeCreateSchemaName() + " schema D4 as (myint int, mystr string)"); var eplFour = "insert into D4 select mysrc.* from Src as mysrc"; RunStreamInsertAssertion(rep, eplFour, "myint,mystr", new Object[] { 123, "abc" }); var eplFive = "insert into D4 select mysrc.*, 999 as myint, 'xxx' as mystr from Src as mysrc"; RunStreamInsertAssertion(rep, eplFive, "myint,mystr", new Object[] { 999, "xxx" }); var eplSix = "insert into D4 select 999 as myint, 'xxx' as mystr, mysrc.* from Src as mysrc"; RunStreamInsertAssertion(rep, eplSix, "myint,mystr", new Object[] { 999, "xxx" }); epService.EPAdministrator.DestroyAllStatements(); foreach (string name in new[] { "Src", "D1", "D2", "D3", "D4" }) { epService.EPAdministrator.Configuration.RemoveEventType(name, false); } }
private void RunTransposeMapAndObjectArray(EventRepresentationChoice representation) { String[] fields = "p0,p1".Split(','); _epService.EPAdministrator.CreateEPL("create " + representation.GetOutputTypeCreateSchemaName() + " schema MySchema(p0 string, p1 int)"); String generateFunction; if (representation.IsObjectArrayEvent()) { generateFunction = "generateOA"; } else if (representation.IsMapEvent()) { generateFunction = "generateMap"; } else if (representation.IsAvroEvent()) { generateFunction = "generateAvro"; } else { throw new IllegalStateException("Unrecognized code " + representation); } String epl = "insert into MySchema select transpose(" + generateFunction + "(TheString, IntPrimitive)) from SupportBean"; _epService.EPAdministrator.CreateEPL(epl, "first").Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", 1 }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E2", 2 }); // MySchema already exists, start second statement _epService.EPAdministrator.CreateEPL(epl, "second").AddListener(_listener); _epService.EPAdministrator.GetStatement("first").Dispose(); _epService.EPRuntime.SendEvent(new SupportBean("E3", 3)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E3", 3 }); _epService.EPAdministrator.Configuration.RemoveEventType("MySchema", true); _epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionFields( EPServiceProvider epService, EventRepresentationChoice representationEnum, bool eventbean) { EPDataFlowInstantiationOptions options; epService.EPAdministrator.CreateEPL( "create " + representationEnum.GetOutputTypeCreateSchemaName() + " schema MyEvent(p0 string, p1 long, p2 double)"); var stmtGraph = epService.EPAdministrator.CreateEPL( "create dataflow MyDataFlowOne " + "" + "BeaconSource -> BeaconStream<" + (eventbean ? "EventBean<MyEvent>" : "MyEvent") + "> {" + " iterations : 3," + " p0 : 'abc'," + " p1 : MyMath.Round(MyMath.Random() * 10) + 1," + " p2 : 1d," + "}" + "DefaultSupportCaptureOp(BeaconStream) {}"); var future = new DefaultSupportCaptureOp(3, SupportContainer.Instance.LockManager()); options = new EPDataFlowInstantiationOptions() .OperatorProvider(new DefaultSupportGraphOpProvider(future)); var df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); df.Start(); var output = future.GetValue(2, TimeUnit.SECONDS); Assert.AreEqual(3, output.Length); for (var i = 0; i < 3; i++) { if (!eventbean) { if (representationEnum.IsObjectArrayEvent()) { var row = (object[])output[i]; Assert.AreEqual("abc", row[0]); var val = (long)row[1]; Assert.IsTrue(val >= 0 && val <= 11, "val=" + val); Assert.AreEqual(1d, row[2]); } else if (representationEnum.IsMapEvent()) { Map row = (Map)output[i]; Assert.AreEqual("abc", row.Get("p0")); var val = (long)row.Get("p1"); Assert.IsTrue(val >= 0 && val <= 11, "val=" + val); Assert.AreEqual(1d, row.Get("p2")); } else { var row = (GenericRecord)output[i]; Assert.AreEqual("abc", row.Get("p0")); var val = (long)row.Get("p1"); Assert.IsTrue(val >= 0 && val <= 11, "val=" + val); Assert.AreEqual(1d, row.Get("p2")); } } else { var row = (EventBean)output[i]; Assert.AreEqual("abc", row.Get("p0")); } } stmtGraph.Dispose(); epService.EPAdministrator.Configuration.RemoveEventType("MyEvent", true); }
private void TryAssertionColDefPlain(EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { var stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col1 string, col2 int, col3_col4 int)"); AssertTypeColDef(stmtCreate.EventType); var stmtSelect = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType"); AssertTypeColDef(stmtSelect.EventType); stmtSelect.Dispose(); stmtCreate.Dispose(); // destroy and create differently stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col3 string, col4 int)"); Assert.AreEqual(typeof(int?), stmtCreate.EventType.GetPropertyType("col4").GetBoxedType()); Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count); stmtCreate.Stop(); // destroy and create differently stmtCreate = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema MyEventType as (col5 string, col6 int)"); Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreate.EventType.UnderlyingType)); Assert.AreEqual(typeof(int?), stmtCreate.EventType.GetPropertyType("col6").GetBoxedType()); Assert.AreEqual(2, stmtCreate.EventType.PropertyDescriptors.Count); stmtSelect = epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " select * from MyEventType"); var listener = new SupportUpdateListener(); stmtSelect.Events += listener.Update; Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtSelect.EventType.UnderlyingType)); // send event if (eventRepresentationEnum.IsMapEvent()) { var data = new LinkedHashMap <string, object>(); data.Put("col5", "abc"); data.Put("col6", 1); epService.EPRuntime.SendEvent(data, "MyEventType"); } else if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] { "abc", 1 }, "MyEventType"); } else if (eventRepresentationEnum.IsAvroEvent()) { var schema = (RecordSchema)((AvroSchemaEventType)epService.EPAdministrator.Configuration.GetEventType("MyEventType")).Schema; var @event = new GenericRecord(schema); @event.Put("col5", "abc"); @event.Put("col6", 1); epService.EPRuntime.SendEventAvro(@event, "MyEventType"); } EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "col5,col6".Split(','), new object[] { "abc", 1 }); // assert type information var typeSPI = (EventTypeSPI)stmtSelect.EventType; Assert.AreEqual(TypeClass.APPLICATION, typeSPI.Metadata.TypeClass); Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PublicName); Assert.IsTrue(typeSPI.Metadata.IsApplicationConfigured); Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfigured); Assert.IsFalse(typeSPI.Metadata.IsApplicationPreConfiguredStatic); Assert.AreEqual(typeSPI.Name, typeSPI.Metadata.PrimaryName); // test non-enum create-schema var epl = "create" + eventRepresentationEnum.GetOutputTypeCreateSchemaName() + " schema MyEventTypeTwo as (col1 string, col2 int, col3_col4 int)"; var stmtCreateTwo = epService.EPAdministrator.CreateEPL(epl); AssertTypeColDef(stmtCreateTwo.EventType); Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateTwo.EventType.UnderlyingType)); stmtCreateTwo.Dispose(); epService.EPAdministrator.Configuration.RemoveEventType("MyEventTypeTwo", true); var model = epService.EPAdministrator.CompileEPL(epl); Assert.AreEqual(model.ToEPL(), epl); stmtCreateTwo = epService.EPAdministrator.Create(model); AssertTypeColDef(stmtCreateTwo.EventType); Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmtCreateTwo.EventType.UnderlyingType)); epService.EPAdministrator.DestroyAllStatements(); foreach (var name in "MyEventType,MyEventTypeTwo".Split(',')) { epService.EPAdministrator.Configuration.RemoveEventType(name, true); } }
private void TryAssertionNamedWindow(EPServiceProvider epService, EventRepresentationChoice rep) { if (rep.IsMapEvent()) { var typeinfo = new Dictionary<string, object>(); typeinfo.Put("myint", typeof(int)); typeinfo.Put("mystr", typeof(string)); epService.EPAdministrator.Configuration.AddEventType("A", typeinfo); epService.EPAdministrator.CreateEPL( "create " + rep.GetOutputTypeCreateSchemaName() + " schema C as (addprop int) inherits A"); } else if (rep.IsObjectArrayEvent()) { epService.EPAdministrator.Configuration.AddEventType( "A", new[] {"myint", "mystr"}, new object[] {typeof(int), typeof(string)}); epService.EPAdministrator.CreateEPL("create objectarray schema C as (addprop int) inherits A"); } else if (rep.IsAvroEvent()) { var schemaA = SchemaBuilder.Record("A", RequiredInt("myint"), RequiredString("mystr")); epService.EPAdministrator.Configuration.AddEventTypeAvro( "A", new ConfigurationEventTypeAvro().SetAvroSchema(schemaA)); epService.EPAdministrator.CreateEPL("create avro schema C as (addprop int) inherits A"); } else { Assert.Fail(); } epService.EPAdministrator.CreateEPL("create window MyWindow#time(5 days) as C"); var stmt = epService.EPAdministrator.CreateEPL("select * from MyWindow"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; // select underlying var stmtInsert = epService.EPAdministrator.CreateEPL("insert into MyWindow select mya.* from A as mya"); if (rep.IsMapEvent()) { epService.EPRuntime.SendEvent(MakeMap(123, "abc"), "A"); } else if (rep.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] {123, "abc"}, "A"); } else if (rep.IsAvroEvent()) { epService.EPRuntime.SendEventAvro(MakeAvro(epService, 123, "abc"), "A"); } else { Assert.Fail(); } EPAssertionUtil.AssertProps( listener.AssertOneGetNewAndReset(), "myint,mystr,addprop".Split(','), new object[] {123, "abc", null}); stmtInsert.Dispose(); // select underlying plus property epService.EPAdministrator.CreateEPL("insert into MyWindow select mya.*, 1 as addprop from A as mya"); if (rep.IsMapEvent()) { epService.EPRuntime.SendEvent(MakeMap(456, "def"), "A"); } else if (rep.IsObjectArrayEvent()) { epService.EPRuntime.SendEvent(new object[] {456, "def"}, "A"); } else if (rep.IsAvroEvent()) { epService.EPRuntime.SendEventAvro(MakeAvro(epService, 456, "def"), "A"); } EPAssertionUtil.AssertProps( listener.AssertOneGetNewAndReset(), "myint,mystr,addprop".Split(','), new object[] {456, "def", 1}); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyWindow", false); epService.EPAdministrator.Configuration.RemoveEventType("A", false); epService.EPAdministrator.Configuration.RemoveEventType("C", false); }