private static void TryJoinAssertion( RegressionEnvironment env, String epl, EventRepresentationChoice rep, String columnNames, AtomicLong milestone, RegressionPath path, Type jsonClass) { env.CompileDeploy("@Name('s0')" + rep.GetAnnotationTextWJsonProvided(jsonClass) + epl, path) .AddListener("s0") .MilestoneInc(milestone); var s0Name = "S0_" + rep.GetName(); var s1Name = "S1_" + rep.GetName(); SendRepEvent(env, rep, s0Name, "a", 1); Assert.IsFalse(env.Listener("s0").IsInvoked); SendRepEvent(env, rep, s1Name, "a", 2); var output = env.Listener("s0").AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps( output, columnNames.SplitCsv(), new object[] {"a", "a", 1, 2}); Assert.IsTrue(rep.MatchesClass(output.Underlying.GetType())); SendRepEvent(env, rep, s1Name, "b", 3); SendRepEvent(env, rep, s0Name, "c", 4); Assert.IsFalse(env.Listener("s0").IsInvoked); env.UndeployModuleContaining("s0"); }
public static string GetPublicName(this EventRepresentationChoice enumValue) { if (enumValue == EventRepresentationChoice.DEFAULT) { return GetUnderlyingType(enumValue).GetName(); } else { return enumValue.GetName(); } }
private static void TryAssertionSingleRowSplitAndType( RegressionEnvironment env, EventRepresentationChoice eventRepresentationEnum) { var path = new RegressionPath(); var types = eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonSentence>() + " create schema MySentenceEvent(sentence String);\n" + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() + " create schema WordEvent(word String);\n" + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonCharacter>() + " create schema CharacterEvent(character String);\n"; env.CompileDeployWBusPublicType(types, path); string stmtText; var fields = new[] {"word"}; // test single-row method stmtText = "@Name('s0') select * from MySentenceEvent[splitSentence" + "_" + eventRepresentationEnum.GetName() + "(sentence)@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); Assert.IsTrue(eventRepresentationEnum.MatchesClass(env.Statement("s0").EventType.UnderlyingType)); SendMySentenceEvent(env, eventRepresentationEnum, "I am testing this code"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"I"}, new object[] {"am"}, new object[] {"testing"}, new object[] {"this"}, new object[] {"code"} }); SendMySentenceEvent(env, eventRepresentationEnum, "the second event"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"the"}, new object[] {"second"}, new object[] {"event"} }); env.UndeployModuleContaining("s0"); // test SODA env.EplToModelCompileDeploy(stmtText, path).AddListener("s0"); SendMySentenceEvent(env, eventRepresentationEnum, "the third event"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"the"}, new object[] {"third"}, new object[] {"event"} }); env.UndeployModuleContaining("s0"); // test script if (eventRepresentationEnum.IsMapEvent()) { stmtText = "@Name('s0') expression System.Collections.IList js:SplitSentenceJS(sentence) [" + " var listType = host.resolveType('System.Collections.Generic.List<object>');" + " var words = host.newObj(listType);" + " words.Add(Collections.SingletonDataMap('word', 'wordOne'));" + " words.Add(Collections.SingletonDataMap('word', 'wordTwo'));" + " return words;" + "]" + "select * from MySentenceEvent[SplitSentenceJS(sentence)@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); env.SendEventMap(Collections.EmptyDataMap, "MySentenceEvent"); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"wordOne"}, new object[] {"wordTwo"} }); env.UndeployModuleContaining("s0"); } // test multiple splitters stmtText = "@Name('s0') select * from " + "MySentenceEvent" + "[splitSentence_" + eventRepresentationEnum.GetName() + "(sentence)" + "@type(WordEvent)]" + "[splitWord_" + eventRepresentationEnum.GetName() + "(word)" + "@type(CharacterEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("CharacterEvent", env.Statement("s0").EventType.Name); SendMySentenceEvent(env, eventRepresentationEnum, "I am"); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Listener("s0").GetAndResetLastNewData(), new[] {"character"}, new[] { new object[] {"I"}, new object[] {"a"}, new object[] {"m"} }); env.UndeployModuleContaining("s0"); // test wildcard parameter stmtText = "@Name('s0') select * from MySentenceEvent[splitSentenceBean_" + eventRepresentationEnum.GetName() + "(*)@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); SendMySentenceEvent(env, eventRepresentationEnum, "another test sentence"); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"another"}, new object[] {"test"}, new object[] {"sentence"} }); env.UndeployModuleContaining("s0"); // test property returning untyped collection if (eventRepresentationEnum.IsObjectArrayEvent()) { stmtText = eventRepresentationEnum.GetAnnotationText() + " @Name('s0') select * from SupportObjectArrayEvent[SomeObjectArray@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); object[][] rows = { new object[] {"this"}, new object[] {"is"}, new object[] {"collection"} }; env.SendEventBean(new SupportObjectArrayEvent(rows)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"collection"} }); env.UndeployAll(); } else if (eventRepresentationEnum.IsMapEvent()) { stmtText = eventRepresentationEnum.GetAnnotationText() + " @Name('s0') select * from SupportCollectionEvent[SomeCollection@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); var coll = new List<IDictionary<string, object>>(); coll.Add(Collections.SingletonDataMap("word", "this")); coll.Add(Collections.SingletonDataMap("word", "is")); coll.Add(Collections.SingletonDataMap("word", "collection")); env.SendEventBean(new SupportCollectionEvent(coll.Unwrap<object>())); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"collection"} }); env.UndeployAll(); } else if (eventRepresentationEnum.IsAvroEvent()) { stmtText = "@Name('s0') " + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() + " select * from SupportAvroArrayEvent[SomeAvroArray@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); var rows = new GenericRecord[3]; var words = new[] {"this", "is", "avro"}; for (var i = 0; i < words.Length; i++) { rows[i] = new GenericRecord( ((AvroEventType) env.Statement("s0").EventType).SchemaAvro.AsRecordSchema()); rows[i].Put("word", words[i]); } env.SendEventBean(new SupportAvroArrayEvent(rows)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"avro"} }); env.UndeployAll(); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { stmtText = "@Name('s0') " + eventRepresentationEnum.GetAnnotationTextWJsonProvided<MyLocalJsonWord>() + " select * from SupportJsonArrayEvent[SomeJsonArray@type(WordEvent)]"; env.CompileDeploy(stmtText, path).AddListener("s0"); Assert.AreEqual("WordEvent", env.Statement("s0").EventType.Name); var rows = new string[3]; var words = "this,is,avro".SplitCsv(); for (var i = 0; i < words.Length; i++) { rows[i] = "{ \"word\": \"" + words[i] + "\"}"; } env.SendEventBean(new SupportJsonArrayEvent(rows)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new object[][] { new[] {"this"}, new[] {"is"}, new[] {"avro"} }); env.UndeployAll(); } else { throw new ArgumentException("Unrecognized enum " + eventRepresentationEnum); } // invalid: event type not found TryInvalidCompile( env, path, "select * from MySentenceEvent[splitSentence_" + eventRepresentationEnum.GetName() + "(sentence)@type(XYZ)]", "Event type by name 'XYZ' could not be found"); // invalid lib-function annotation TryInvalidCompile( env, path, "select * from MySentenceEvent[splitSentence_" + eventRepresentationEnum.GetName() + "(sentence)@dummy(WordEvent)]", "Invalid annotation for property selection, expected 'type' but found 'dummy' in text '@dummy(WordEvent)'"); // invalid type assignment to event type if (eventRepresentationEnum.IsObjectArrayEvent()) { TryInvalidCompile( env, path, "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type System.Object[] cannot be assigned a value of type"); } else if (eventRepresentationEnum.IsMapEvent()) { TryInvalidCompile( env, path, "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type System.Collections.Generic.IDictionary<System.String, System.Object> cannot be assigned a value of type"); } else if (eventRepresentationEnum.IsAvroEvent()) { TryInvalidCompile( env, path, "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type " + TypeHelper.AVRO_GENERIC_RECORD_CLASSNAME + " cannot be assigned a value of type"); } else if (eventRepresentationEnum.IsJsonEvent() || eventRepresentationEnum.IsJsonProvidedClassEvent()) { TryInvalidCompile( env, path, "select * from MySentenceEvent[invalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' requires string-type array and cannot be assigned from value of type " + typeof(SupportBean[]).CleanName()); } else { Assert.Fail(); } // invalid subquery TryInvalidCompile( env, path, "select * from MySentenceEvent[splitSentence((select * from SupportBean#keepall))@type(WordEvent)]", "Invalid Contained-event expression 'splitSentence(subselect_0)': Aggregation, sub-select, previous or prior functions are not supported in this context [select * from MySentenceEvent[splitSentence((select * from SupportBean#keepall))@type(WordEvent)]]"); env.UndeployAll(); }
private void TryAssertionSingleRowSplitAndType( EPServiceProvider epService, EventRepresentationChoice eventRepresentationEnum) { string[] methods; if (eventRepresentationEnum.IsObjectArrayEvent()) { methods = new[] { "SplitSentenceMethodReturnObjectArray", "SplitSentenceBeanMethodReturnObjectArray", "SplitWordMethodReturnObjectArray" }; } else if (eventRepresentationEnum.IsMapEvent()) { methods = new[] { "SplitSentenceMethodReturnMap", "SplitSentenceBeanMethodReturnMap", "SplitWordMethodReturnMap" }; } else if (eventRepresentationEnum.IsAvroEvent()) { methods = new[] { "SplitSentenceMethodReturnAvro", "SplitSentenceBeanMethodReturnAvro", "SplitWordMethodReturnAvro" }; } else { throw new IllegalStateException("Unrecognized enum " + eventRepresentationEnum); } var funcs = new[] { "SplitSentence", "SplitSentenceBean", "SplitWord" }; for (var i = 0; i < funcs.Length; i++) { epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction( funcs[i] + "_" + eventRepresentationEnum.GetName(), GetType(), methods[i]); } epService.EPAdministrator.CreateEPL( eventRepresentationEnum.GetAnnotationText() + " create schema SentenceEvent(sentence string)"); epService.EPAdministrator.CreateEPL( eventRepresentationEnum.GetAnnotationText() + " create schema WordEvent(word string)"); epService.EPAdministrator.CreateEPL( eventRepresentationEnum.GetAnnotationText() + " create schema CharacterEvent(char string)"); var fields = "word".Split(','); // test single-row method var stmtText = "select * from SentenceEvent[SplitSentence" + "_" + eventRepresentationEnum.GetName() + "(sentence)@Type(WordEvent)]"; var stmt = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; Assert.AreEqual("WordEvent", stmt.EventType.Name); Assert.IsTrue(eventRepresentationEnum.MatchesClass(stmt.EventType.UnderlyingType)); SendSentenceEvent(epService, eventRepresentationEnum, "I am testing this code"); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"I"}, new object[] {"am"}, new object[] {"testing"}, new object[] {"this"}, new object[] {"code"} }); SendSentenceEvent(epService, eventRepresentationEnum, "the second event"); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"the"}, new object[] {"second"}, new object[] {"event"} }); stmt.Dispose(); // test SODA var model = epService.EPAdministrator.CompileEPL(stmtText); Assert.AreEqual(stmtText, model.ToEPL()); stmt = epService.EPAdministrator.Create(model); Assert.AreEqual(stmtText, stmt.Text); stmt.Events += listener.Update; SendSentenceEvent(epService, eventRepresentationEnum, "the third event"); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new[] {new object[] {"the"}, new object[] {"third"}, new object[] {"event"}}); stmt.Dispose(); // test script if (eventRepresentationEnum.IsMapEvent()) { stmtText = "expression System.Collections.IList jscript:SplitSentenceJS(sentence) [" + " debug.Debug('test');" + " var listType = host.type('System.Collections.ArrayList');" + " var words = host.newObj(listType);" + " debug.Debug(words);" + " words.Add(Collections.SingletonDataMap('word', 'wordOne'));" + " words.Add(Collections.SingletonDataMap('word', 'wordTwo'));" + " return words;" + "]" + "select * from SentenceEvent[SplitSentenceJS(sentence)@Type(WordEvent)]"; stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; Assert.AreEqual("WordEvent", stmt.EventType.Name); epService.EPRuntime.SendEvent(Collections.EmptyDataMap, "SentenceEvent"); EPAssertionUtil.AssertPropsPerRowAnyOrder( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"wordOne"}, new object[] {"wordTwo"} }); stmt.Dispose(); } // test multiple splitters stmtText = "select * from SentenceEvent[SplitSentence_" + eventRepresentationEnum.GetName() + "(sentence)@Type(WordEvent)][SplitWord_" + eventRepresentationEnum.GetName() + "(word)@Type(CharacterEvent)]"; stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; Assert.AreEqual("CharacterEvent", stmt.EventType.Name); SendSentenceEvent(epService, eventRepresentationEnum, "I am"); EPAssertionUtil.AssertPropsPerRowAnyOrder( listener.GetAndResetLastNewData(), "char".Split(','), new[] {new object[] {"I"}, new object[] {"a"}, new object[] {"m"}}); stmt.Dispose(); // test wildcard parameter stmtText = "select * from SentenceEvent[SplitSentenceBean_" + eventRepresentationEnum.GetName() + "(*)@Type(WordEvent)]"; stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; Assert.AreEqual("WordEvent", stmt.EventType.Name); SendSentenceEvent(epService, eventRepresentationEnum, "another test sentence"); EPAssertionUtil.AssertPropsPerRowAnyOrder( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"another"}, new object[] {"test"}, new object[] {"sentence"} }); stmt.Dispose(); // test property returning untyped collection if (eventRepresentationEnum.IsObjectArrayEvent()) { epService.EPAdministrator.Configuration.AddEventType(typeof(ObjectArrayEvent)); stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from ObjectArrayEvent[someObjectArray@Type(WordEvent)]"; stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; Assert.AreEqual("WordEvent", stmt.EventType.Name); var rows = new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"collection"} }; epService.EPRuntime.SendEvent(new ObjectArrayEvent(rows)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"collection"} }); stmt.Dispose(); } else if (eventRepresentationEnum.IsMapEvent()) { epService.EPAdministrator.Configuration.AddEventType(typeof(MyCollectionEvent)); stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from MyCollectionEvent[someCollection@Type(WordEvent)]"; stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; Assert.AreEqual("WordEvent", stmt.EventType.Name); var coll = new List<Map>(); coll.Add(Collections.SingletonDataMap("word", "this")); coll.Add(Collections.SingletonDataMap("word", "is")); coll.Add(Collections.SingletonDataMap("word", "collection")); epService.EPRuntime.SendEvent(new MyCollectionEvent(coll)); EPAssertionUtil.AssertPropsPerRowAnyOrder( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"collection"} }); stmt.Dispose(); } else if (eventRepresentationEnum.IsAvroEvent()) { epService.EPAdministrator.Configuration.AddEventType(typeof(AvroArrayEvent)); stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from AvroArrayEvent[someAvroArray@Type(WordEvent)]"; stmt = epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += listener.Update; Assert.AreEqual("WordEvent", stmt.EventType.Name); var rows = new GenericRecord[3]; var words = "this,is,avro".Split(','); for (var i = 0; i < words.Length; i++) { rows[i] = new GenericRecord(((AvroEventType) stmt.EventType).SchemaAvro); rows[i].Put("word", words[i]); } epService.EPRuntime.SendEvent(new AvroArrayEvent(rows)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new[] { new object[] {"this"}, new object[] {"is"}, new object[] {"avro"} }); stmt.Dispose(); } else { throw new ArgumentException("Unrecognized enum " + eventRepresentationEnum); } // invalid: event type not found TryInvalid( epService, "select * from SentenceEvent[SplitSentence_" + eventRepresentationEnum.GetName() + "(sentence)@type(XYZ)]", "Event type by name 'XYZ' could not be found"); // invalid lib-function annotation TryInvalid( epService, "select * from SentenceEvent[splitSentence_" + eventRepresentationEnum.GetName() + "(sentence)@dummy(WordEvent)]", "Invalid annotation for property selection, expected 'type' but found 'dummy' in text '@dummy(WordEvent)'"); // invalid type assignment to event type if (eventRepresentationEnum.IsObjectArrayEvent()) { TryInvalid( epService, "select * from SentenceEvent[InvalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type System.Object[] cannot be assigned a value of type"); } else if (eventRepresentationEnum.IsMapEvent()) { TryInvalid( epService, "select * from SentenceEvent[InvalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type " + Name.Clean<IDictionary<string, object>>() + " cannot be assigned a value of type"); } else if (eventRepresentationEnum.IsAvroEvent()) { TryInvalid( epService, "select * from SentenceEvent[InvalidSentence(sentence)@Type(WordEvent)]", "Event type 'WordEvent' underlying type " + AvroConstantsNoDep.GENERIC_RECORD_CLASSNAME + " cannot be assigned a value of type"); } else { Assert.Fail(); } // invalid subquery TryInvalid( epService, "select * from SentenceEvent[SplitSentence((select * from SupportBean#keepall))@type(WordEvent)]", "Invalid contained-event expression 'SplitSentence(subselect_0)': Aggregation, sub-select, previous or prior functions are not supported in this context [select * from SentenceEvent[SplitSentence((select * from SupportBean#keepall))@type(WordEvent)]]"); epService.EPAdministrator.DestroyAllStatements(); foreach (var name in "SentenceEvent,WordEvent,CharacterEvent".Split(',')) { epService.EPAdministrator.Configuration.RemoveEventType(name, true); } }