Esempio n. 1
0
 public ConditionHandler GetHandler(ConditionHandlerFactoryContext context)
 {
     FactoryContexts.Add(context);
     var handler = new SupportConditionHandler();
     Handlers.Add(handler);
     return handler.Handle;
 }
Esempio n. 2
0
        private void RunAssertionSingleMaxSimple(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_A", typeof(SupportBean_A));
            epService.EPAdministrator.Configuration.AddEventType("SupportBean_B", typeof(SupportBean_B));

            ConditionHandlerFactoryContext context = SupportConditionHandlerFactory.FactoryContexts[0];

            Assert.AreEqual(epService.URI, context.EngineURI);
            SupportConditionHandlerFactory.SupportConditionHandler handler = SupportConditionHandlerFactory.LastHandler;

            string      expression = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[2]> b=SupportBean_B]";
            EPStatement statement  = epService.EPAdministrator.CreateEPL(expression);

            RunAssertionSingleMaxSimple(epService, statement, handler);
            statement.Dispose();

            // test SODA
            EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(expression);

            Assert.AreEqual(expression, model.ToEPL());
            statement = epService.EPAdministrator.Create(model);
            Assert.AreEqual(statement.Text, model.ToEPL());
            RunAssertionSingleMaxSimple(epService, statement, handler);
            statement.Dispose();

            // test variable
            epService.EPAdministrator.CreateEPL("create variable int myvar=3");
            expression = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[myvar-1]> b=SupportBean_B]";
            statement  = epService.EPAdministrator.CreateEPL(expression);
            RunAssertionSingleMaxSimple(epService, statement, handler);

            statement.Dispose();
        }
        protected static ExceptionHandlingService InitExceptionHandling(
            string runtimeURI,
            ConfigurationRuntimeExceptionHandling exceptionHandling,
            ConfigurationRuntimeConditionHandling conditionHandling,
            ClassForNameProvider classForNameProvider)
        {
            IList<ExceptionHandler> exceptionHandlers;
            if (exceptionHandling.HandlerFactories == null || exceptionHandling.HandlerFactories.IsEmpty()) {
                exceptionHandlers = new EmptyList<ExceptionHandler>();
            }
            else {
                exceptionHandlers = new List<ExceptionHandler>();
                var context = new ExceptionHandlerFactoryContext(runtimeURI);
                foreach (var className in exceptionHandling.HandlerFactories) {
                    try {
                        var factory = TypeHelper.Instantiate<ExceptionHandlerFactory>(
                            className, classForNameProvider);
                        var handler = factory.GetHandler(context);
                        if (handler == null) {
                            Log.Warn("Exception handler factory '" + className + "' returned a null handler, skipping factory");
                            continue;
                        }

                        exceptionHandlers.Add(handler);
                    }
                    catch (Exception ex) {
                        throw new ConfigurationException(
                            "Exception initializing exception handler from exception handler factory '" + className + "': " + ex.Message, ex);
                    }
                }
            }

            IList<ConditionHandler> conditionHandlers;
            if (conditionHandling.HandlerFactories == null || conditionHandling.HandlerFactories.IsEmpty()) {
                conditionHandlers = new EmptyList<ConditionHandler>();
            }
            else {
                conditionHandlers = new List<ConditionHandler>();
                var context = new ConditionHandlerFactoryContext(runtimeURI);
                foreach (var className in conditionHandling.HandlerFactories) {
                    try {
                        var factory = TypeHelper.Instantiate<ConditionHandlerFactory>(
                            className, classForNameProvider);
                        var handler = factory.GetHandler(context);
                        if (handler == null) {
                            Log.Warn("Condition handler factory '" + className + "' returned a null handler, skipping factory");
                            continue;
                        }

                        conditionHandlers.Add(handler);
                    }
                    catch (Exception ex) {
                        throw new ConfigurationException(
                            "Exception initializing exception handler from exception handler factory '" + className + "': " + ex.Message, ex);
                    }
                }
            }

            return new ExceptionHandlingService(runtimeURI, exceptionHandlers, conditionHandlers);
        }
        public override void Run(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecPatternOperatorFollowedByMax4Prevent)))
            {
                return;
            }
            ConditionHandlerFactoryContext context = SupportConditionHandlerFactory.FactoryContexts[0];

            Assert.AreEqual(epService.URI, context.EngineURI);
            SupportConditionHandlerFactory.SupportConditionHandler handler = SupportConditionHandlerFactory.LastHandler;

            RunAssertionFollowedWithMax(epService, handler);
            RunAssertionTwoStatementsAndStopDestroy(epService, handler);
        }
Esempio n. 5
0
        private void InitService(long max, bool preventStart)
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportBean>();
            config.AddEventType <SupportBean_A>();
            config.AddEventType <SupportBean_B>();
            config.EngineDefaults.ConditionHandlingConfig.AddClass(typeof(SupportConditionHandlerFactory));
            config.EngineDefaults.PatternsConfig.MaxSubexpressions = max;
            config.EngineDefaults.PatternsConfig.IsMaxSubexpressionPreventStart = preventStart;
            config.EngineDefaults.LoggingConfig.IsEnableExecutionDebug          = true;

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();

            ConditionHandlerFactoryContext context = SupportConditionHandlerFactory.FactoryContexts[0];

            Assert.AreEqual(_epService.URI, context.EngineURI);
            _handler = SupportConditionHandlerFactory.LastHandler;
        }
Esempio n. 6
0
        public void TestSingleMaxSimple()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportBean_A>();
            config.AddEventType <SupportBean_B>();
            config.EngineDefaults.ConditionHandlingConfig.AddClass(typeof(SupportConditionHandlerFactory));

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            ConditionHandlerFactoryContext context = SupportConditionHandlerFactory.FactoryContexts[0];

            Assert.AreEqual(_epService.URI, context.EngineURI);
            SupportConditionHandlerFactory.SupportConditionHandler handler = SupportConditionHandlerFactory.LastHandler;

            String      expression = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[2]> b=SupportBean_B]";
            EPStatement statement  = _epService.EPAdministrator.CreateEPL(expression);

            RunAssertionSingleMaxSimple(_epService, statement, handler);
            statement.Dispose();

            // test SODA
            EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(expression);

            Assert.AreEqual(expression, model.ToEPL());
            statement = _epService.EPAdministrator.Create(model);
            Assert.AreEqual(statement.Text, model.ToEPL());
            RunAssertionSingleMaxSimple(_epService, statement, handler);
            statement.Dispose();

            // test variable
            _epService.EPAdministrator.CreateEPL("create variable int myvar=3");
            expression = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[myvar-1]> b=SupportBean_B]";
            statement  = _epService.EPAdministrator.CreateEPL(expression);
            RunAssertionSingleMaxSimple(_epService, statement, handler);
        }
        public override void Run(EPServiceProvider epService)
        {
            ConditionHandlerFactoryContext conditionHandlerFactoryContext = SupportConditionHandlerFactory.FactoryContexts[0];

            Assert.AreEqual(conditionHandlerFactoryContext.EngineURI, epService.URI);
            handler = SupportConditionHandlerFactory.LastHandler;

            string[] fields = "c0".Split(',');

            string epl = "@Name('S1') select * from SupportBean " +
                         "match_recognize (" +
                         "  partition by TheString " +
                         "  measures P1.TheString as c0" +
                         "  pattern (P1 P2) " +
                         "  define " +
                         "    P1 as P1.IntPrimitive = 1," +
                         "    P2 as P2.IntPrimitive = 2" +
                         ")";

            var         listener = new SupportUpdateListener();
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);

            stmt.Events += listener.Update;

            epService.EPRuntime.SendEvent(new SupportBean("A", 1));
            epService.EPRuntime.SendEvent(new SupportBean("B", 1));
            epService.EPRuntime.SendEvent(new SupportBean("C", 1));
            Assert.IsTrue(handler.Contexts.IsEmpty());

            // overflow
            epService.EPRuntime.SendEvent(new SupportBean("D", 1));
            ExecRowRecogMaxStatesEngineWide3Instance.AssertContextEnginePool(epService, stmt, handler.GetAndResetContexts(), 3, ExecRowRecogMaxStatesEngineWide3Instance.GetExpectedCountMap("S1", 3));
            epService.EPRuntime.SendEvent(new SupportBean("E", 1));
            ExecRowRecogMaxStatesEngineWide3Instance.AssertContextEnginePool(epService, stmt, handler.GetAndResetContexts(), 3, ExecRowRecogMaxStatesEngineWide3Instance.GetExpectedCountMap("S1", 4));

            epService.EPRuntime.SendEvent(new SupportBean("D", 2));    // D gone
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "D" });

            epService.EPRuntime.SendEvent(new SupportBean("A", 2));    // A gone
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "A" });

            epService.EPRuntime.SendEvent(new SupportBean("C", 2));    // C gone
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "C" });

            epService.EPRuntime.SendEvent(new SupportBean("F", 1));
            Assert.IsTrue(handler.Contexts.IsEmpty());

            epService.EPRuntime.SendEvent(new SupportBean("G", 1));
            ExecRowRecogMaxStatesEngineWide3Instance.AssertContextEnginePool(epService, stmt, handler.GetAndResetContexts(), 3, ExecRowRecogMaxStatesEngineWide3Instance.GetExpectedCountMap("S1", 3));

            epService.EPAdministrator.Configuration.MatchRecognizeMaxStates = 4L;

            epService.EPRuntime.SendEvent(new SupportBean("G", 1));
            Assert.IsTrue(handler.Contexts.IsEmpty());

            epService.EPRuntime.SendEvent(new SupportBean("H", 1));
            ExecRowRecogMaxStatesEngineWide3Instance.AssertContextEnginePool(epService, stmt, handler.GetAndResetContexts(), 4, ExecRowRecogMaxStatesEngineWide3Instance.GetExpectedCountMap("S1", 4));

            epService.EPAdministrator.Configuration.MatchRecognizeMaxStates = null;

            epService.EPRuntime.SendEvent(new SupportBean("I", 1));
            Assert.IsTrue(handler.Contexts.IsEmpty());
        }
Esempio n. 8
0
        public void TestSinglePermFalseAndQuit()
        {
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            ConditionHandlerFactoryContext context = SupportConditionHandlerFactory.FactoryContexts[0];

            Assert.AreEqual(_epService.URI, context.EngineURI);
            SupportConditionHandlerFactory.SupportConditionHandler handler = SupportConditionHandlerFactory.LastHandler;
            var listener = new SupportUpdateListener();

            // not-operator
            const string expression = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[2]> (b=SupportBean_B and not SupportBean_C)]";
            var          stmt       = _epService.EPAdministrator.CreateEPL(expression);

            stmt.Events += listener.Update;
            var fields = new[] { "a", "b" };

            _epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A2"));
            _epService.EPRuntime.SendEvent(new SupportBean_C("C1"));

            _epService.EPRuntime.SendEvent(new SupportBean_A("A3"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A4"));
            _epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            Assert.IsTrue(handler.Contexts.IsEmpty());
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "A3", "B1" }, new Object[] { "A4", "B1" } });

            _epService.EPRuntime.SendEvent(new SupportBean_A("A5"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A6"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A7"));
            AssertContext(_epService, stmt, handler.Contexts, 2);
            stmt.Dispose();

            // guard
            const string expressionTwo = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[2]> (b=SupportBean_B where timer:within(1))]";
            EPStatement  stmtTwo       = _epService.EPAdministrator.CreateEPL(expressionTwo);

            stmtTwo.Events += listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A2"));
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000)); // expires sub-expressions
            Assert.IsTrue(handler.Contexts.IsEmpty());

            _epService.EPRuntime.SendEvent(new SupportBean_A("A3"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A4"));
            _epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            Assert.IsTrue(handler.Contexts.IsEmpty());
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "A3", "B1" }, new Object[] { "A4", "B1" } });

            _epService.EPRuntime.SendEvent(new SupportBean_A("A5"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A6"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A7"));
            AssertContext(_epService, stmtTwo, handler.Contexts, 2);

            // every-operator
            stmtTwo.Dispose();
            const string expressionThree = "select a.id as a, b.id as b from pattern [every a=SupportBean_A -[2]> (every b=SupportBean_B(id=a.id) and not SupportBean_C(id=a.id))]";
            EPStatement  stmtThree       = _epService.EPAdministrator.CreateEPL(expressionThree);

            stmtThree.Events += listener.Update;

            _epService.EPRuntime.SendEvent(new SupportBean_A("1"));
            _epService.EPRuntime.SendEvent(new SupportBean_A("2"));

            _epService.EPRuntime.SendEvent(new SupportBean_B("1"));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "1", "1" } });

            _epService.EPRuntime.SendEvent(new SupportBean_B("2"));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "2", "2" } });

            _epService.EPRuntime.SendEvent(new SupportBean_C("1"));

            _epService.EPRuntime.SendEvent(new SupportBean_A("3"));
            _epService.EPRuntime.SendEvent(new SupportBean_B("3"));
            EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "3", "3" } });
        }
Esempio n. 9
0
        internal static ExceptionHandlingService InitExceptionHandling(
            String engineURI,
            ConfigurationEngineDefaults.ExceptionHandling exceptionHandling,
            ConfigurationEngineDefaults.ConditionHandling conditionHandling)
        {
            List <ExceptionHandler> exceptionHandlers;

            if (exceptionHandling.HandlerFactories == null || exceptionHandling.HandlerFactories.IsEmpty())
            {
                exceptionHandlers = new List <ExceptionHandler>();
            }
            else
            {
                exceptionHandlers = new List <ExceptionHandler>();
                var context = new ExceptionHandlerFactoryContext(engineURI);
                foreach (String className in exceptionHandling.HandlerFactories)
                {
                    try {
                        var factory = TypeHelper.Instantiate <ExceptionHandlerFactory>(className);
                        var handler = factory.GetHandler(context);
                        if (handler == null)
                        {
                            Log.Warn("Exception handler factory '" + className + "' returned a null handler, skipping factory");
                            continue;
                        }
                        exceptionHandlers.Add(handler);
                    }
                    catch (Exception ex) {
                        throw new ConfigurationException("Exception initializing exception handler from exception handler factory '" + className + "': " + ex.Message, ex);
                    }
                }
            }

            List <ConditionHandler> conditionHandlers;

            if (conditionHandling.HandlerFactories == null || conditionHandling.HandlerFactories.IsEmpty())
            {
                conditionHandlers = new List <ConditionHandler>();
            }
            else
            {
                conditionHandlers = new List <ConditionHandler>();
                var context = new ConditionHandlerFactoryContext(engineURI);
                foreach (String className in conditionHandling.HandlerFactories)
                {
                    try {
                        var factory = TypeHelper.Instantiate <ConditionHandlerFactory>(className);
                        var handler = factory.GetHandler(context);
                        if (handler == null)
                        {
                            Log.Warn("Condition handler factory '" + className + "' returned a null handler, skipping factory");
                            continue;
                        }
                        conditionHandlers.Add(handler);
                    }
                    catch (Exception ex) {
                        throw new ConfigurationException("Exception initializing exception handler from exception handler factory '" + className + "': " + ex.Message, ex);
                    }
                }
            }

            return(new ExceptionHandlingService(engineURI, exceptionHandlers, conditionHandlers));
        }