예제 #1
0
        private void RunAssertionParameterInjectionCallback(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne MyOp -> outstream<SomeType> {propOne:'abc', propThree:'xyz'}");

            var myOp    = new MyOp("myid");
            var options = new EPDataFlowInstantiationOptions();

            options.OperatorProvider(new DefaultSupportGraphOpProvider(myOp));
            var myParameterProvider = new MyParameterProvider(Collections.SingletonDataMap("propTwo", "def"));

            options.ParameterProvider(myParameterProvider);
            Assert.AreEqual("myid", myOp.Id);
            Assert.IsNull(myOp.PropOne);
            Assert.IsNull(myOp.PropTwo);

            epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            Assert.AreEqual("abc", myOp.PropOne);
            Assert.AreEqual("def", myOp.PropTwo);

            Assert.AreEqual(3, myParameterProvider.ContextMap.Count);
            Assert.IsNotNull(myParameterProvider.ContextMap.Get("propOne"));

            EPDataFlowOperatorParameterProviderContext context = myParameterProvider.ContextMap.Get("propTwo");

            Assert.AreEqual("propTwo", context.ParameterName);
            Assert.AreEqual("MyOp", context.OperatorName);
            Assert.AreSame(myOp, context.OperatorInstance);
            Assert.AreEqual(0, context.OperatorNum);
            Assert.AreEqual(null, context.ProvidedValue);
            Assert.AreEqual("MyDataFlowOne", context.DataFlowName);

            context = myParameterProvider.ContextMap.Get("propThree");
            Assert.AreEqual("propThree", context.ParameterName);
            Assert.AreEqual("MyOp", context.OperatorName);
            Assert.AreSame(myOp, context.OperatorInstance);
            Assert.AreEqual(0, context.OperatorNum);
            Assert.AreEqual("xyz", context.ProvidedValue);

            epService.EPAdministrator.DestroyAllStatements();
        }
        public void TestStatementFilter()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean_A));
            _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean_B));

            // one statement exists before the data flow
            var stmt = _epService.EPAdministrator.CreateEPL("select id from SupportBean_B");

            _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                 "create schema AllObjects Object," +
                                                 "EPStatementSource -> thedata<AllObjects> {} " +
                                                 "DefaultSupportCaptureOp(thedata) {}");

            var captureOp = new DefaultSupportCaptureOp();
            var options   = new EPDataFlowInstantiationOptions();
            var myFilter  = new MyFilter();

            options.ParameterProvider(new DefaultSupportGraphParamProvider(Collections.SingletonDataMap("statementFilter", myFilter)));
            options.OperatorProvider(new DefaultSupportGraphOpProvider(captureOp));
            var df = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            df.Start();

            _epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "B1" });

            _epService.EPAdministrator.CreateEPL("select TheString, IntPrimitive from SupportBean");
            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "TheString,IntPrimitive".Split(','), new Object[] { "E1", 1 });

            var stmtTwo = _epService.EPAdministrator.CreateEPL("select id from SupportBean_A");

            _epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "A1" });

            stmtTwo.Stop();

            _epService.EPRuntime.SendEvent(new SupportBean_A("A2"));
            Thread.Sleep(50);
            Assert.AreEqual(0, captureOp.GetCurrent().Length);

            stmtTwo.Start();

            _epService.EPRuntime.SendEvent(new SupportBean_A("A3"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "A3" });

            _epService.EPRuntime.SendEvent(new SupportBean_B("B2"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "B2" });

            df.Cancel();

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            _epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            _epService.EPRuntime.SendEvent(new SupportBean_B("B3"));
            Assert.AreEqual(0, captureOp.GetCurrent().Length);
        }