Ejemplo n.º 1
0
            public void Run(RegressionEnvironment env)
            {
                SupportGraphSource.GetAndResetLifecycle();

                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlow MyLineFeedSource -> outstream {} SupportOperator(outstream) {propOne:'abc'}");
                Assert.AreEqual(0, SupportOperator.GetAndResetLifecycle().Count);

                // instantiate
                var src = new MyLineFeedSource(Arrays.AsList("abc", "def").GetEnumerator());
                var
                    options = new EPDataFlowInstantiationOptions()
                        .WithOperatorProvider(new DefaultSupportGraphOpProvider(src));
                var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlow", options);

                var events = SupportOperator.GetAndResetLifecycle();
                Assert.AreEqual(1, events.Count);
                Assert.AreEqual("instantiated", events[0]); // instantiated

                // run
                df.Run();

                events = SupportOperator.GetAndResetLifecycle();
                Assert.AreEqual(4, events.Count);
                Assert.IsTrue(events[0] is DataFlowOpOpenContext); // called open (GraphSource only)
                Assert.AreEqual("abc", ((object[]) events[1])[0]);
                Assert.AreEqual("def", ((object[]) events[2])[0]);
                Assert.IsTrue(events[3] is DataFlowOpCloseContext); // called close (GraphSource only)

                env.UndeployAll();
            }
        private void RunAssertionFlowGraphOperator(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();
            epService.EPAdministrator.Configuration.AddImport(typeof(MyLineFeedSource));
            epService.EPAdministrator.Configuration.AddImport(typeof(SupportOperator));
            SupportGraphSource.GetAndResetLifecycle();

            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow MyLineFeedSource -> outstream {} SupportOperator(outstream) {propOne:'abc'}");
            Assert.AreEqual(0, SupportOperator.GetAndResetLifecycle().Count);

            // instantiate
            var src               = new MyLineFeedSource(Collections.List("abc", "def").GetEnumerator());
            var options           = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(src));
            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", options);

            IList <object> events = SupportOperator.GetAndResetLifecycle();

            Assert.AreEqual(3, events.Count);
            Assert.AreEqual("instantiated", events[0]);                // instantiated
            Assert.AreEqual("setPropOne=abc", events[1]);              // injected properties

            Assert.IsTrue(events[2] is DataFlowOpInitializateContext); // called initialize
            DataFlowOpInitializateContext initContext = (DataFlowOpInitializateContext)events[2];

            Assert.IsNotNull(initContext.AgentInstanceContext);
            Assert.IsNotNull(initContext.RuntimeEventSender);
            Assert.IsNotNull(initContext.ServicesContext);
            Assert.IsNotNull(initContext.StatementContext);
            Assert.IsNull(initContext.DataflowInstanceId);
            Assert.IsNull(initContext.DataflowInstanceUserObject);
            Assert.AreEqual(1, initContext.InputPorts.Count);
            Assert.AreEqual("[line]", CompatExtensions.Render(initContext.InputPorts[0].TypeDesc.EventType.PropertyNames));
            Assert.AreEqual("[outstream]", CompatExtensions.Render(initContext.InputPorts[0].StreamNames.ToArray()));
            Assert.AreEqual(0, initContext.OutputPorts.Count);

            // run
            df.Run();

            events = SupportOperator.GetAndResetLifecycle();
            Assert.AreEqual(4, events.Count);
            Assert.IsTrue(events[0] is DataFlowOpOpenContext); // called open (GraphSource only)
            Assert.AreEqual("abc", ((object[])events[1])[0]);
            Assert.AreEqual("def", ((object[])events[2])[0]);
            Assert.IsTrue(events[3] is DataFlowOpCloseContext); // called close (GraphSource only)

            epService.EPAdministrator.DestroyAllStatements();
        }