Exemplo n.º 1
0
        public void Run(RegressionEnvironment env)
        {
            var epl = "@Name('flow') create dataflow WordCount " +
                      "MyLineFeedSource -> LineOfTextStream {} " +
                      "MyTokenizerCounter(LineOfTextStream) -> SingleLineCountStream {}" +
                      "MyWordCountAggregator(SingleLineCountStream) -> WordCountStream {}" +
                      "DefaultSupportCaptureOp(WordCountStream) {}";
            env.CompileDeploy(epl);

            var future = new DefaultSupportCaptureOp(1, env.Container.LockManager());
            var source = new MyLineFeedSource(Arrays.AsList("Test this code", "Test line two").GetEnumerator());

            var options = new EPDataFlowInstantiationOptions()
                .WithOperatorProvider(new DefaultSupportGraphOpProvider(future, source));

            env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "WordCount", options).Start();

            var received = new object[0];
            try {
                received = future.GetValue(3, TimeUnit.SECONDS);
            }
            catch (Exception t) {
                throw new EPException(t);
            }

            Assert.AreEqual(1, received.Length);
            var stats = (MyWordCountStats) received[0];
            Assert.AreEqual(2, stats.Lines);
            Assert.AreEqual(6, stats.Words);
            Assert.AreEqual(23, stats.Chars);

            env.UndeployAll();
        }
Exemplo n.º 2
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();
            }