public EPCompiled Compile( Module module, CompilerArguments arguments) { using (arguments.Configuration.Container.EnterContextualReflection()) { if (arguments == null) { arguments = new CompilerArguments(new Configuration()); } // determine module name var moduleName = DetermineModuleName(arguments.Options, module); var moduleUses = DetermineModuleUses(moduleName, arguments.Options, module); // get compile services var compileTimeServices = GetCompileTimeServices(arguments, moduleName, moduleUses, false); AddModuleImports(module.Imports, compileTimeServices); IList<Compilable> compilables = new List<Compilable>(); foreach (var item in module.Items) { if (item.IsCommentOnly) { continue; } if (item.Expression != null && item.Model != null) { throw new EPCompileException("Module item has both an EPL expression and a statement object model"); } if (item.Expression != null) { compilables.Add(new CompilableEPL(item.Expression)); } else if (item.Model != null) { compilables.Add(new CompilableSODA(item.Model)); } else { throw new EPCompileException( "Module item has neither an EPL expression nor a statement object model"); } } IDictionary<ModuleProperty, object> moduleProperties = new Dictionary<ModuleProperty, object>(); AddModuleProperty(moduleProperties, ModuleProperty.ARCHIVENAME, module.ArchiveName); AddModuleProperty(moduleProperties, ModuleProperty.URI, module.Uri); if (arguments.Configuration.Compiler.ByteCode.IsAttachModuleEPL) { AddModuleProperty(moduleProperties, ModuleProperty.MODULETEXT, module.ModuleText); } AddModuleProperty(moduleProperties, ModuleProperty.USEROBJECT, module.UserObjectCompileTime); AddModuleProperty(moduleProperties, ModuleProperty.USES, module.Uses.ToArrayOrNull()); AddModuleProperty(moduleProperties, ModuleProperty.IMPORTS, module.Imports.ToArrayOrNull()); // compile return CompilerHelperModuleProvider.Compile( compilables, moduleName, moduleProperties, compileTimeServices, arguments.Options); } }
public EPCompiled Compile( EPStatementObjectModel model, CompilerArguments args) { var module = new Module(); module.Items.Add(new ModuleItem(model)); return Compiler.Compile(module, args); }
private string DetermineModuleName( CompilerOptions options, Module module) { return options.ModuleName != null ? options.ModuleName.Invoke(new ModuleNameContext(module.Name)) : module.Name; }
public EPCompiled Compile(Module module) { try { return Compiler.Compile(module, new CompilerArguments(Configuration)); } catch (Exception t) { throw new EPException(t); } }
private ICollection<string> DetermineModuleUses( string moduleName, CompilerOptions options, Module module) { return options.ModuleUses != null ? options.ModuleUses.Invoke(new ModuleUsesContext(moduleName, module.Uses)) : module.Uses; }
public void SyntaxValidate( Module module, CompilerArguments arguments) { if (arguments == null) { arguments = new CompilerArguments(new Configuration()); } // determine module name var moduleName = DetermineModuleName(arguments.Options, module); var moduleUses = DetermineModuleUses(moduleName, arguments.Options, module); var moduleCompileTimeServices = GetCompileTimeServices(arguments, moduleName, moduleUses, false); var statementNumber = 0; try { foreach (var item in module.Items) { var services = new StatementCompileTimeServices(statementNumber, moduleCompileTimeServices); if (item.IsCommentOnly) { continue; } if (item.Expression != null && item.Model != null) { throw new EPCompileException( "Module item has both an EPL expression and a statement object model"); } if (item.Expression != null) { CompilerHelperSingleEPL.ParseCompileInlinedClassesWalk(new CompilableEPL(item.Expression), services); } else if (item.Model != null) { CompilerHelperSingleEPL.ParseCompileInlinedClassesWalk(new CompilableSODA(item.Model), services); item.Model.ToEPL(); } else { throw new EPCompileException( "Module item has neither an EPL expression nor a statement object model"); } statementNumber++; } } catch (Exception ex) { throw new EPCompileException(ex.Message, ex); } }
private void RunTest( RegressionEnvironment env, PatternTestStyle testStyle, AtomicLong milestone) { // Send the start time to the eventService if (sendEventCollection.GetTime(EventCollection.ON_START_EVENT_ID) != null) { var startTime = sendEventCollection.GetTime(EventCollection.ON_START_EVENT_ID); env.AdvanceTime(startTime.Value); log.Debug(".RunTest Start time is " + startTime); } // Set up expression filters and match listeners var expressions = new string[caseList.NumTests]; var index = -1; foreach (var descriptor in caseList.Results) { index++; var epl = descriptor.ExpressionText; var model = descriptor.ObjectModel; var statementName = NameOfStatement(descriptor); var nameAnnotation = "@Name(\"" + statementName + "\") "; EPCompiled compiled; log.Debug(".RunTest Deploying " + epl); try { if (model != null) { model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation(statementName)); var module = new Module(); module.Items.Add(new ModuleItem(model)); compiled = env.Compiler.Compile( module, new CompilerArguments(env.Configuration)); } else { if (testStyle == PatternTestStyle.USE_EPL) { var text = nameAnnotation + "@Audit('pattern') @Audit('pattern-instances') select * from pattern [" + epl + "]"; compiled = env.Compile(text); epl = text; } else if (testStyle == PatternTestStyle.USE_EPL_AND_CONSUME_NOCHECK) { var text = nameAnnotation + "select * from pattern @DiscardPartialsOnMatch @SuppressOverlappingMatches [" + epl + "]"; compiled = env.Compile(text); epl = text; } else if (testStyle == PatternTestStyle.COMPILE_TO_MODEL) { var text = nameAnnotation + "select * from pattern [" + epl + "]"; var mymodel = env.Compiler.EplToModel(text, env.Configuration); var module = new Module(); module.Items.Add(new ModuleItem(mymodel)); compiled = env.Compiler.Compile( module, new CompilerArguments(env.Configuration)); epl = text; } else if (testStyle == PatternTestStyle.COMPILE_TO_EPL) { var text = "select * from pattern [" + epl + "]"; var mymodel = env.Compiler.EplToModel(text, env.Configuration); var reverse = nameAnnotation + mymodel.ToEPL(); compiled = env.Compile(reverse); epl = reverse; } else { throw new ArgumentException("Unknown test style"); } } } catch (Exception ex) { var text = epl; if (model != null) { text = "Model: " + model.ToEPL(); } log.Error( ".RunTest Failed to create statement for style " + testStyle + " pattern expression=" + text, ex); #if DO_NOT_CATCH_EXCEPTIONS Assert.Fail(text + ": " + ex.Message); compiled = null; #else throw; #endif } // We stop the statement again and start after the first listener was added. // Thus we can handle patterns that fireStatementStopped on startup. var unit = compiled; env.Deploy(unit).AddListener(statementName); expressions[index] = epl; } // milestone env.Milestone(milestone.GetAndIncrement()); // Some expressions may fireStatementStopped as soon as they are started, such as a "not b()" expression, for example. // Check results for any such listeners/expressions. // NOTE: For EPL statements we do not support calling listeners when a pattern that fires upon start. // Reason is that this should not be a relevant functionality of a pattern, the start pattern // event itself cannot carry any information and is thus ignore. Note subsequent events // generated by the same pattern are fine. CheckResults(testStyle, EventCollection.ON_START_EVENT_ID, expressions, env); var totalEventsReceived = CountExpectedEvents(EventCollection.ON_START_EVENT_ID); ClearListenerEvents(caseList, env); // Send actual test events foreach (var entry in sendEventCollection) { var eventId = entry.Key; // Manipulate the time when this event was send if (sendEventCollection.GetTime(eventId) != null) { if (sendEventCollection.TryGetTime(eventId, out var currentTime)) { env.AdvanceTime(currentTime); log.Debug( ".RunTest Sending event " + entry.Key + " = " + entry.Value + " timed " + currentTime); } } // Send event itself env.SendEventBean(entry.Value); // Check expected results for this event if (testStyle != PatternTestStyle.USE_EPL_AND_CONSUME_NOCHECK) { CheckResults(testStyle, eventId, expressions, env); // Count and clear the list of events that each listener has received totalEventsReceived += CountListenerEvents(caseList, env); } ClearListenerEvents(caseList, env); env.Milestone(milestone.GetAndIncrement()); } // Count number of expected matches var totalExpected = 0; foreach (var descriptor in caseList.Results) { foreach (var events in descriptor.ExpectedResults.Values) { totalExpected += events.Count; } } if (totalExpected != totalEventsReceived && testStyle != PatternTestStyle.USE_EPL_AND_CONSUME_NOCHECK) { log.Debug( ".test Count expected does not match count received, expected=" + totalExpected + " received=" + totalEventsReceived); Assert.IsTrue(false); } // Kill all expressions env.UndeployAll(); // Send test events again to also test that all were indeed killed foreach (var entry in sendEventCollection) { env.SendEventBean(entry.Value); } // Make sure all listeners are still at zero foreach (var descriptor in caseList.Results) { var statementName = NameOfStatement(descriptor); Assert.IsNull(env.Statement(statementName)); } }