Example #1
0
        private static void RunAssertionAllTypes(
            RegressionEnvironment env,
            string typeName,
            object[] events)
        {
            var graph = "@Name('flow') create dataflow MySelect\n" +
                        "DefaultSupportSourceOp -> instream.with.dot<" +
                        typeName +
                        ">{}\n" +
                        "filter(instream.with.dot) -> outstream.dot {filter: MyString = 'two'}\n" +
                        "DefaultSupportCaptureOp(outstream.dot) {}";
            env.CompileDeploy(graph);

            var source = new DefaultSupportSourceOp(events);
            var capture = new DefaultSupportCaptureOp(2, env.Container.LockManager());
            var options = new EPDataFlowInstantiationOptions();
            options.DataFlowInstanceUserObject = "myuserobject";
            options.DataFlowInstanceId = "myinstanceId";
            options.WithOperatorProvider(new DefaultSupportGraphOpProvider(source, capture));
            var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MySelect", options);
            Assert.AreEqual("myuserobject", instance.UserObject);
            Assert.AreEqual("myinstanceId", instance.InstanceId);

            instance.Run();

            var result = capture.GetAndReset()[0].ToArray();
            Assert.AreEqual(1, result.Length);
            Assert.AreSame(events[1], result[0]);

            instance.Cancel();

            env.UndeployAll();
        }
Example #2
0
        public void TestTimeWindowTriggered()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            String graph = "create dataflow MySelect\n" +
                           "Emitter -> instream_s0<SupportBean>{name: 'emitterS0'}\n" +
                           "Select(instream_s0) -> outstream {\n" +
                           "  select: (select sum(IntPrimitive) as sumInt from instream_s0.win:time(1 minute))\n" +
                           "}\n" +
                           "CaptureOp(outstream) {}\n";

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            _epService.EPAdministrator.CreateEPL(graph);

            DefaultSupportCaptureOp      capture   = new DefaultSupportCaptureOp();
            IDictionary <String, Object> operators = CollectionUtil.PopulateNameValueMap("CaptureOp", capture);

            EPDataFlowInstantiationOptions options  = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(operators));
            EPDataFlowInstance             instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MySelect", options);
            EPDataFlowInstanceCaptive      captive  = instance.StartCaptive();

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(5000));
            captive.Emitters.Get("emitterS0").Submit(new SupportBean("E1", 2));
            EPAssertionUtil.AssertProps(capture.GetCurrentAndReset()[0], "sumInt".Split(','), new Object[] { 2 });

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));
            captive.Emitters.Get("emitterS0").Submit(new SupportBean("E2", 5));
            EPAssertionUtil.AssertProps(capture.GetCurrentAndReset()[0], "sumInt".Split(','), new Object[] { 7 });

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(65000));
            EPAssertionUtil.AssertProps(capture.GetCurrentAndReset()[0], "sumInt".Split(','), new Object[] { 5 });

            instance.Cancel();
        }
Example #3
0
        public void RunAssertionJoinOrder(String fromClause)
        {
            String graph = "create dataflow MySelect\n" +
                           "Emitter -> instream_s0<SupportBean_S0>{name: 'emitterS0'}\n" +
                           "Emitter -> instream_s1<SupportBean_S1>{name: 'emitterS1'}\n" +
                           "Emitter -> instream_s2<SupportBean_S2>{name: 'emitterS2'}\n" +
                           "Select(instream_s0 as S0, instream_s1 as S1, instream_s2 as S2) -> outstream {\n" +
                           "  select: (select s0.id as s0id, s1.id as s1id, s2.id as s2id " + fromClause + ")\n" +
                           "}\n" +
                           "CaptureOp(outstream) {}\n";
            EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL(graph);

            DefaultSupportCaptureOp      capture   = new DefaultSupportCaptureOp();
            IDictionary <String, Object> operators = CollectionUtil.PopulateNameValueMap("CaptureOp", capture);

            EPDataFlowInstantiationOptions options  = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(operators));
            EPDataFlowInstance             instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MySelect", options);

            EPDataFlowInstanceCaptive captive = instance.StartCaptive();

            captive.Emitters.Get("emitterS0").Submit(new SupportBean_S0(1));
            captive.Emitters.Get("emitterS1").Submit(new SupportBean_S1(10));
            Assert.AreEqual(0, capture.GetCurrent().Length);

            captive.Emitters.Get("emitterS2").Submit(new SupportBean_S2(100));
            Assert.AreEqual(1, capture.GetCurrent().Length);
            EPAssertionUtil.AssertProps(capture.GetCurrentAndReset()[0], "s0id,s1id,s2id".Split(','), new Object[] { 1, 10, 100 });

            instance.Cancel();

            captive.Emitters.Get("emitterS2").Submit(new SupportBean_S2(101));
            Assert.AreEqual(0, capture.GetCurrent().Length);

            stmtGraph.Dispose();
        }
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(MyTokenizerCounter).Namespace);
            epService.EPAdministrator.Configuration.AddImport(typeof(DefaultSupportCaptureOp).Namespace);

            var epl = "create dataflow WordCount " +
                      "MyLineFeedSource -> LineOfTextStream {} " +
                      "MyTokenizerCounter(LineOfTextStream) -> SingleLineCountStream {}" +
                      "MyWordCountAggregator(SingleLineCountStream) -> WordCountStream {}" +
                      "DefaultSupportCaptureOp(WordCountStream) {}";

            epService.EPAdministrator.CreateEPL(epl);

            var future = new DefaultSupportCaptureOp(1, SupportContainer.Instance.LockManager());
            var source = new MyLineFeedSource(Collections.List("Test this code", "Test line two").GetEnumerator());

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

            epService.EPRuntime.DataFlowRuntime.Instantiate("WordCount", options).Start();

            var received = future.GetValue(3, TimeUnit.SECONDS);

            Assert.AreEqual(1, received.Length);
            var stats = (MyWordCountStats)received[0];

            EPAssertionUtil.AssertProps(
                epService.Container, stats, "Lines,Words,Chars".Split(','), new object[] { 2, 6, 23 });
        }
        private void RunAssertionSchemaObjectArray(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create objectarray schema MyEventOA(p0 string, p1 long)");

            RunAssertionOA(epService, false);
            RunAssertionOA(epService, true);

            // test collector
            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                "EventBusSource -> ReceivedStream<MyEventOA> {filter: p0 like 'A%'} " +
                                                "DefaultSupportCaptureOp(ReceivedStream) {}");

            var collector = new MyCollector();
            var future    = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            var options   = new EPDataFlowInstantiationOptions()
                            .OperatorProvider(new DefaultSupportGraphOpProvider(future))
                            .ParameterProvider(new DefaultSupportGraphParamProvider(
                                                   Collections.SingletonDataMap("collector", collector)));

            EPDataFlowInstance instance = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            instance.Start();

            epService.EPRuntime.SendEvent(new object[] { "B", 100L }, "MyEventOA");
            Thread.Sleep(50);
            Assert.IsNull(collector.Last);

            epService.EPRuntime.SendEvent(new object[] { "A", 101L }, "MyEventOA");
            future.WaitForInvocation(100, 1);
            Assert.IsNotNull(collector.Last.Emitter);
            Assert.AreEqual("MyEventOA", collector.Last.Event.EventType.Name);
            Assert.AreEqual(false, collector.Last.IsSubmitEventBean);

            epService.EPAdministrator.DestroyAllStatements();
        }
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                    "DefaultSupportCaptureOp(outstream) {}",
                    path);

                var src = new DefaultSupportSourceOp(new object[] {new MyException("TestException")});
                var output = new DefaultSupportCaptureOp();
                var options =
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(
                        new DefaultSupportGraphOpProvider(src, output));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);

                try {
                    dfOne.Run();
                    Assert.Fail();
                }
                catch (EPDataFlowExecutionException ex) {
                    Assert.IsTrue(ex.InnerException.InnerException is MyException);
                    Assert.AreEqual(
                        "Support-graph-source generated exception: TestException",
                        ex.InnerException.Message);
                }

                Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
                Assert.AreEqual(0, output.GetAndReset().Count);
                env.UndeployAll();
            }
Example #7
0
        private void RunAssertionOA(bool underlying)
        {
            EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                                         "EventBusSource -> ReceivedStream<" + (underlying ? "MyEvent" : "EventBean<MyEvent>") + "> {} " +
                                                                         "DefaultSupportCaptureOp(ReceivedStream) {}");

            DefaultSupportCaptureOp        future  = new DefaultSupportCaptureOp(1);
            EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions()
                                                     .OperatorProvider(new DefaultSupportGraphOpProvider(future));

            EPDataFlowInstance instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            instance.Start();

            _epService.EPRuntime.SendEvent(new Object[] { "abc", 100L }, "MyEvent");
            Object[] rows = future.GetValue(TimeSpan.FromSeconds(1));
            Assert.AreEqual(1, rows.Length);
            if (underlying)
            {
                EPAssertionUtil.AssertEqualsExactOrder((Object[])rows[0], new Object[] { "abc", 100L });
            }
            else
            {
                EPAssertionUtil.AssertProps((EventBean)rows[0], "p0,p1".Split(','), new Object[] { "abc", 100L });
            }

            instance.Cancel();
            stmtGraph.Dispose();
        }
Example #8
0
        private void TryInvalidInstantiate(
            string dataflowName,
            string epl,
            string message)
        {
            var stmtGraph = CompileDeploy(runtime, epl).Statements[0];
            var outputOp  = new DefaultSupportCaptureOp(container.LockManager());

            try {
                runtime.DataFlowService.Instantiate(
                    stmtGraph.DeploymentId,
                    dataflowName,
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp)));
                Assert.Fail();
            }
            catch (EPDataFlowInstantiationException ex) {
                Assert.AreEqual(message, ex.Message);
            }

            try {
                runtime.DeploymentService.UndeployAll();
            }
            catch (EPUndeployException e) {
                throw new EPRuntimeException(e);
            }
        }
Example #9
0
            public void Run(RegressionEnvironment env)
            {
                if (env.IsHA) {
                    return;
                }

                var graph = "@Name('flow') create dataflow MySelect\n" +
                            "Emitter -> instream_s0<SupportEventWithLongArray>{name: 'emitterS0'}\n" +
                            "Select(instream_s0) -> outstream {\n" +
                            "  select: (select window(Id) as ids from instream_s0#unique(Coll))\n" +
                            "}\n" +
                            "DefaultSupportCaptureOp(outstream) {}\n";
                env.CompileDeploy(graph);

                var capture = new DefaultSupportCaptureOp(env.Container.LockManager());
                var operators = CollectionUtil.PopulateNameValueMap("DefaultSupportCaptureOp", capture);

                var options = new EPDataFlowInstantiationOptions()
                    .WithOperatorProvider(new DefaultSupportGraphOpProviderByOpName(operators));
                var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MySelect", options);
                var captive = instance.StartCaptive();

                AssertDataflowIds(captive, "E1", new long[] {1, 2}, capture, "E1");
                AssertDataflowIds(captive, "E2", new long[] {1, 2}, capture, "E2");
                AssertDataflowIds(captive, "E3", new long[] {1}, capture, "E2,E3");
                AssertDataflowIds(captive, "E4", new long[] {1}, capture, "E2,E4");
                AssertDataflowIds(captive, "E5", new long[] {1, 2}, capture, "E4,E5");

                instance.Cancel();
                env.UndeployAll();
            }
Example #10
0
        private void RunAssertionFastCompleteNonBlocking(EPServiceProvider epService)
        {
            // declare
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "BeaconSource -> BeaconStream {iterations : 1}" +
                "DefaultSupportCaptureOp(BeaconStream) {}");

            // instantiate
            var future = new DefaultSupportCaptureOp(1, SupportContainer.Instance.LockManager());
            var options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(future));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
            Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);
            Assert.IsFalse(future.IsDone());

            // non-blocking run, spinning wait
            dfOne.Start();
            var start = PerformanceObserver.MilliTime;
            while (dfOne.State != EPDataFlowState.COMPLETE)
            {
                if (PerformanceObserver.MilliTime - start > 1000)
                {
                    Assert.Fail();
                }
            }

            Assert.AreEqual(1, future.GetValue(TimeSpan.Zero).Length);

            // assert past-exec
            TryAssertionAfterExec(dfOne);
            epService.EPAdministrator.DestroyAllStatements();
        }
        private void RunAssertionStatementNameExists(EPServiceProvider epService, string typeName, object[] events)
        {
            epService.EPAdministrator.CreateEPL("@Name('MyStatement') select * from " + typeName);

            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                "create schema AllObject System.Object," +
                                                "EPStatementSource -> thedata<AllObject> {" +
                                                "  statementName : 'MyStatement'," +
                                                "} " +
                                                "DefaultSupportCaptureOp(thedata) {}");

            var captureOp = new DefaultSupportCaptureOp(2, SupportContainer.Instance.LockManager());
            var options   = new EPDataFlowInstantiationOptions()
                            .OperatorProvider(new DefaultSupportGraphOpProvider(captureOp));

            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            df.Start();

            EventSender sender = epService.EPRuntime.GetEventSender(typeName);

            foreach (Object @event in events)
            {
                sender.SendEvent(@event);
            }

            captureOp.GetValue(1, TimeUnit.SECONDS);
            EPAssertionUtil.AssertEqualsExactOrder(events, captureOp.Current);

            df.Cancel();
            epService.EPAdministrator.DestroyAllStatements();
        }
Example #12
0
        private void RunAssertionFastCompleteBlocking(EPServiceProvider epService)
        {
            // declare
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "BeaconSource -> BeaconStream {iterations : 1}" +
                "DefaultSupportCaptureOp(BeaconStream) {}");

            // instantiate
            var future = new DefaultSupportCaptureOp(1, SupportContainer.Instance.LockManager());
            var options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(future));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
            Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);

            // has not run
            Thread.Sleep(1000);
            Assert.IsFalse(future.IsDone());

            // blocking run
            dfOne.Run();
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(1, future.GetValue(TimeSpan.Zero).Length);

            // assert past-exec
            TryAssertionAfterExec(dfOne);

            epService.EPAdministrator.DestroyAllStatements();
        }
Example #13
0
        private void RunAssertionNonBlockingJoinSingleRunnable(EPServiceProvider epService)
        {
            // declare
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

            // instantiate
            var latch = new CountDownLatch(1);
            var source = new DefaultSupportSourceOp(new object[] {latch, new object[] {1}});
            var future = new DefaultSupportCaptureOp(1, SupportContainer.Instance.LockManager());
            var options =
                new EPDataFlowInstantiationOptions().OperatorProvider(
                    new DefaultSupportGraphOpProvider(source, future));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
            Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);

            dfOne.Start();
            Thread.Sleep(100);
            Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State);

            latch.CountDown();
            dfOne.Join();
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(1, future.GetAndReset()[0].Count);
            Assert.AreEqual(2, source.GetCurrentCount());

            dfOne.Cancel();
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            epService.EPAdministrator.DestroyAllStatements();
        }
Example #14
0
        private void RunAssertionNonBlockingCancel(EPServiceProvider epService)
        {
            // declare
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "SourceOne -> outstream<SomeType> {}" +
                "OutputOp(outstream) {}");

            // instantiate
            var latchOne = new CountDownLatch(1);
            var ops = new Dictionary<string, object>();
            ops.Put("SourceOne", new DefaultSupportSourceOp(new object[] {latchOne, new object[] {1}}));
            var output = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            ops.Put("OutputOp", output);

            var options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            dfOne.Start();
            Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State);

            dfOne.Cancel();

            latchOne.CountDown();
            Thread.Sleep(100);
            Assert.AreEqual(EPDataFlowState.CANCELLED, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);
            epService.EPAdministrator.DestroyAllStatements();
        }
        public void TestFactorial()
        {
            _epService.EPAdministrator.Configuration.AddImport(typeof(MyFactorialOp).FullName);
            _epService.EPAdministrator.Configuration.AddImport(typeof(DefaultSupportCaptureOp));

            String epl = "create dataflow FactorialGraph \n" +
                         "" +
                         "create objectarray schema InputSchema (number int),\n" +
                         "create objectarray schema TempSchema (current int, temp long),\n" +
                         "create objectarray schema FinalSchema (result long),\n" +
                         "\n" +
                         "BeaconSource -> InputData<InputSchema> {number:5, iterations:1}\n" +
                         "\n" +
                         "MyFactorialOp(InputData as Input, TempResult as Temp) -> TempResult<TempSchema>, FinalResult<FinalSchema>{}\n" +
                         "\n" +
                         "DefaultSupportCaptureOp(FinalResult) {}\n";

            _epService.EPAdministrator.CreateEPL(epl);

            var future  = new DefaultSupportCaptureOp(1);
            var options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(future));

            _epService.EPRuntime.DataFlowRuntime.Instantiate("FactorialGraph", options).Start();

            Object[] result = future.GetValue(TimeSpan.FromSeconds(3));
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual((long)5 * 4 * 3 * 2, ((Object[])result[0])[0]);
        }
Example #16
0
        public void TestBlockingException()
        {
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

            var src = new DefaultSupportSourceOp(
                new Object[]
            {
                new MyRuntimeException("TestException")
            });
            var output  = new DefaultSupportCaptureOp();
            var options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(src, output));
            var dfOne   = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            try
            {
                dfOne.Run();
                Assert.Fail();
            }
            catch (EPDataFlowExecutionException ex)
            {
                Assert.IsTrue(ex.InnerException.InnerException is MyRuntimeException);
                Assert.AreEqual("Support-graph-source generated exception: TestException", ex.InnerException.Message);
            }

            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);
        }
Example #17
0
            public void Run(RegressionEnvironment env)
            {
                var epl = "@Name('flow') create dataflow FactorialGraph \n" +
                          "" +
                          "create objectarray schema InputSchema (number int),\n" +
                          "create objectarray schema TempSchema (current int, temp long),\n" +
                          "create objectarray schema FinalSchema (result long),\n" +
                          "\n" +
                          "BeaconSource -> InputData<InputSchema> {number:5, iterations:1}\n" +
                          "\n" +
                          "MyFactorialOp(InputData as Input, TempResult as Temp) -> TempResult<TempSchema>, FinalResult<FinalSchema>{}\n" +
                          "\n" +
                          "DefaultSupportCaptureOp(FinalResult) {}\n";
                env.CompileDeploy(epl);

                var future = new DefaultSupportCaptureOp(1, env.Container.LockManager());
                var options = new EPDataFlowInstantiationOptions()
                    .WithOperatorProvider(new DefaultSupportGraphOpProvider(future));

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

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

                Assert.AreEqual(1, result.Length);
                Assert.AreEqual((long) 5 * 4 * 3 * 2, ((object[]) result[0])[0]);

                env.UndeployAll();
            }
Example #18
0
        public void TestBlockingMultipleRunnable()
        {
            // declare
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "SourceOne -> outstream<SomeType> {}" +
                "SourceTwo -> outstream<SomeType> {}" +
                "Future(outstream) {}");

            // instantiate
            var latchOne = new CountDownLatch(1);
            var latchTwo = new CountDownLatch(1);
            IDictionary <String, Object> ops = new Dictionary <String, Object>();

            ops.Put(
                "SourceOne", new DefaultSupportSourceOp(
                    new Object[]
            {
                latchOne, new Object[]
                {
                    1
                }
            }));
            ops.Put(
                "SourceTwo", new DefaultSupportSourceOp(
                    new Object[]
            {
                latchTwo, new Object[]
                {
                    1
                }
            }));
            var future = new DefaultSupportCaptureOp(2);

            ops["Future"] = future;

            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            try
            {
                dfOne.Run();
                Assert.Fail();
            }
            catch (UnsupportedOperationException ex)
            {
                Assert.AreEqual(
                    "The data flow 'MyDataFlowOne' has zero or multiple sources and requires the use of the start method instead",
                    ex.Message);
            }

            latchTwo.CountDown();
            dfOne.Start();
            latchOne.CountDown();
            dfOne.Join();

            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(2, future.GetAndReset().Count);
        }
Example #19
0
        public void TestSchemaObjectArray()
        {
            _epService.EPAdministrator.CreateEPL("create objectarray schema MyEvent(p0 string, p1 long)");

            RunAssertionOA(false);
            RunAssertionOA(true);

            // test collector
            _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                 "EventBusSource -> ReceivedStream<MyEvent> {filter: p0 like 'A%'} " +
                                                 "DefaultSupportCaptureOp(ReceivedStream) {}");

            MyCollector                    collector = new MyCollector();
            DefaultSupportCaptureOp        future    = new DefaultSupportCaptureOp();
            EPDataFlowInstantiationOptions options   = new EPDataFlowInstantiationOptions()
                                                       .OperatorProvider(new DefaultSupportGraphOpProvider(future))
                                                       .ParameterProvider(new DefaultSupportGraphParamProvider(Collections.SingletonDataMap("collector", collector)));

            EPDataFlowInstance instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            instance.Start();

            _epService.EPRuntime.SendEvent(new Object[] { "B", 100L }, "MyEvent");
            Thread.Sleep(50);
            Assert.IsNull(collector.GetLast());

            _epService.EPRuntime.SendEvent(new Object[] { "A", 101L }, "MyEvent");
            future.WaitForInvocation(100, 1);
            Assert.NotNull(collector.GetLast().Emitter);
            Assert.AreEqual("MyEvent", collector.GetLast().Event.EventType.Name);
            Assert.AreEqual(false, collector.GetLast().IsSubmitEventBean);
        }
Example #20
0
        public void TestFastCompleteBlocking()
        {
            // declare
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "BeaconSource -> BeaconStream {iterations : 1}" +
                "DefaultSupportCaptureOp(BeaconStream) {}");

            // instantiate
            var future = new DefaultSupportCaptureOp(1);
            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(future));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
            Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);

            // has not run
            Thread.Sleep(1000);
            Assert.IsFalse(future.IsDone());

            // blocking run
            dfOne.Run();
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(1, future.GetValue(TimeSpan.MaxValue).Length);

            // assert past-exec
            RunAssertionAfterExec(dfOne);
        }
        private void RunAssertionStatementNameExists(String typeName, Object[] events)
        {
            _epService.EPAdministrator.CreateEPL("@Name('MyStatement') select * from " + typeName);

            _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                 "create schema AllObject System.Object," +
                                                 "EPStatementSource -> thedata<AllObject> {" +
                                                 "  statementName : 'MyStatement'," +
                                                 "} " +
                                                 "DefaultSupportCaptureOp(thedata) {}");

            var captureOp = new DefaultSupportCaptureOp(2);
            var options   = new EPDataFlowInstantiationOptions()
                            .OperatorProvider(new DefaultSupportGraphOpProvider(captureOp));

            var df = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            df.Start();

            var sender = _epService.EPRuntime.GetEventSender(typeName);

            foreach (var theEvent in events)
            {
                sender.SendEvent(theEvent);
            }

            captureOp.GetValue(TimeSpan.FromSeconds(1));
            EPAssertionUtil.AssertEqualsExactOrder(events, captureOp.GetCurrent());

            df.Cancel();
            _epService.EPAdministrator.DestroyAllStatements();
        }
Example #22
0
        public void TestFastCompleteNonBlocking()
        {
            // declare
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "BeaconSource -> BeaconStream {iterations : 1}" +
                "DefaultSupportCaptureOp(BeaconStream) {}");

            // instantiate
            var future = new DefaultSupportCaptureOp(1);
            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(future));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
            Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);
            Assert.IsFalse(future.IsDone());

            // non-blocking run, spinning wait
            dfOne.Start();
            long start = Environment.TickCount;

            while (dfOne.State != EPDataFlowState.COMPLETE)
            {
                if (Environment.TickCount - start > 1000)
                {
                    Assert.Fail();
                }
            }
            Assert.AreEqual(1, future.GetValue(TimeSpan.MaxValue).Length);

            // assert past-exec
            RunAssertionAfterExec(dfOne);
        }
Example #23
0
        private void RunAssertionAllTypes(String typeName, Object[] events)
        {
            String graph = "create dataflow MySelect\n" +
                           "DefaultSupportSourceOp -> instream.with.dot<" + typeName + ">{}\n" +
                           "Filter(instream.with.dot) -> outstream.dot {filter: myString = 'two'}\n" +
                           "DefaultSupportCaptureOp(outstream.dot) {}";
            EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL(graph);

            DefaultSupportSourceOp         source  = new DefaultSupportSourceOp(events);
            DefaultSupportCaptureOp        capture = new DefaultSupportCaptureOp(2);
            EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions();

            options.SetDataFlowInstanceUserObject("myuserobject");
            options.SetDataFlowInstanceId("myinstanceid");

            options.OperatorProvider(new DefaultSupportGraphOpProvider(source, capture));
            EPDataFlowInstance instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MySelect", options);

            Assert.AreEqual("myuserobject", instance.UserObject);
            Assert.AreEqual("myinstanceid", instance.InstanceId);

            instance.Run();

            Object[] result = capture.GetAndReset()[0].ToArray();
            Assert.AreEqual(1, result.Length);
            Assert.AreSame(events[1], result[0]);

            instance.Cancel();

            stmtGraph.Dispose();
        }
        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();
        }
        private void RunAssertionOA(EPServiceProvider epService, bool underlying)
        {
            EPStatement stmtGraph = epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                                        "EventBusSource -> ReceivedStream<" + (underlying ? "MyEventOA" : "EventBean<MyEventOA>") + "> {} " +
                                                                        "DefaultSupportCaptureOp(ReceivedStream) {}");

            var future  = new DefaultSupportCaptureOp(1, SupportContainer.Instance.LockManager());
            var options = new EPDataFlowInstantiationOptions()
                          .OperatorProvider(new DefaultSupportGraphOpProvider(future));

            EPDataFlowInstance instance = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            instance.Start();

            epService.EPRuntime.SendEvent(new object[] { "abc", 100L }, "MyEventOA");
            object[] rows = future.GetValue(1, TimeUnit.SECONDS);
            Assert.AreEqual(1, rows.Length);
            if (underlying)
            {
                EPAssertionUtil.AssertEqualsExactOrder((object[])rows[0], new object[] { "abc", 100L });
            }
            else
            {
                EPAssertionUtil.AssertProps((EventBean)rows[0], "p0,p1".Split(','), new object[] { "abc", 100L });
            }

            instance.Cancel();
            stmtGraph.Dispose();
        }
Example #26
0
        private static void RunAssertion(RegressionEnvironment env)
        {
            var future = new DefaultSupportCaptureOp(1, env.Container.LockManager());
            var source = new MyObjectArrayGraphSource(
                Arrays.AsList(
                        new object[] {"trade", "GE", 100d, 1000L, null, null}, // vwap = 100, minPrice=100
                        new object[] {"quote", "GE", null, null, 99.5d, 2000L} //
                    )
                    .GetEnumerator());

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

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

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

            Assert.AreEqual(1, received.Length);

            var receivedArray = received[0].UnwrapIntoArray<object>();
            EPAssertionUtil.AssertProps(
                env.Container,
                receivedArray,
                new string[] { "index" },
                new object[] { 2000 * Math.Exp(100 - 99.5) });

            env.UndeployAll();
        }
Example #27
0
        public void TestOuterJoinMultirow()
        {
            _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean_S0));
            _epService.EPAdministrator.Configuration.AddEventType(typeof(SupportBean_S1));

            String graph = "create dataflow MySelect\n" +
                           "Emitter -> instream_s0<SupportBean_S0>{name: 'emitterS0'}\n" +
                           "Emitter -> instream_s1<SupportBean_S1>{name: 'emitterS1'}\n" +
                           "Select(instream_s0 as S0, instream_s1 as S1) -> outstream {\n" +
                           "  select: (select p00, p10 from S0.win:keepall() full outer join S1.win:keepall())\n" +
                           "}\n" +
                           "CaptureOp(outstream) {}\n";

            _epService.EPAdministrator.CreateEPL(graph);

            DefaultSupportCaptureOp      capture   = new DefaultSupportCaptureOp();
            IDictionary <String, Object> operators = CollectionUtil.PopulateNameValueMap("CaptureOp", capture);

            EPDataFlowInstantiationOptions options  = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(operators));
            EPDataFlowInstance             instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MySelect", options);

            EPDataFlowInstanceCaptive captive = instance.StartCaptive();

            captive.Emitters.Get("emitterS0").Submit(new SupportBean_S0(1, "S0_1"));
            EPAssertionUtil.AssertProps(capture.GetCurrentAndReset()[0], "p00,p11".Split(','), new Object[] { "S0_1", null });

            instance.Cancel();
        }
Example #28
0
        private void RunAssertionMapType(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(SupportBean));
            epService.EPAdministrator.CreateEPL("create map schema MyMap (p0 string, p1 int)");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<MyMap> {}" +
                "MyMapOutputOp(outstream) {}" +
                "DefaultSupportCaptureOp(outstream) {}");

            var source = new DefaultSupportSourceOp(new object[] {MakeMap("E1", 1)});
            var outputOne = new MyMapOutputOp();
            var outputTwo = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            var options = new EPDataFlowInstantiationOptions().OperatorProvider(
                new DefaultSupportGraphOpProvider(source, outputOne, outputTwo));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            dfOne.Run();

            EPAssertionUtil.AssertPropsPerRow(
                outputOne.GetAndReset().ToArray(), "p0,p1".Split(','), new[] {new object[] {"E1", 1}});
            EPAssertionUtil.AssertPropsPerRow(
                epService.Container,
                outputTwo.GetAndReset()[0].ToArray(), "p0,p1".Split(','), new[] {new object[] {"E1", 1}});

            epService.EPAdministrator.DestroyAllStatements();
        }
Example #29
0
        private void RunAssertionFactorial(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(MyFactorialOp));

            string epl = "create dataflow FactorialGraph \n" +
                         "" +
                         "create objectarray schema InputSchema (number int),\n" +
                         "create objectarray schema TempSchema (current int, temp long),\n" +
                         "create objectarray schema FinalSchema (result long),\n" +
                         "\n" +
                         "BeaconSource -> InputData<InputSchema> {number:5, iterations:1}\n" +
                         "\n" +
                         "MyFactorialOp(InputData as Input, TempResult as Temp) -> TempResult<TempSchema>, FinalResult<FinalSchema>{}\n" +
                         "\n" +
                         "DefaultSupportCaptureOp(FinalResult) {}\n";

            epService.EPAdministrator.CreateEPL(epl);

            var future  = new DefaultSupportCaptureOp(1, SupportContainer.Instance.LockManager());
            var options = new EPDataFlowInstantiationOptions()
                          .OperatorProvider(new DefaultSupportGraphOpProvider(future));

            epService.EPRuntime.DataFlowRuntime.Instantiate("FactorialGraph", options).Start();

            object[] result = future.GetValue(3, TimeUnit.SECONDS);
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual((long)5 * 4 * 3 * 2, ((object[])result[0])[0]);

            epService.EPAdministrator.DestroyAllStatements();
        }
Example #30
0
        private static void RunAssertionAllTypes(
            RegressionEnvironment env,
            string typeName,
            object[] events)
        {
            var graph = "@Name('flow') create dataflow MySelect\n" +
                        "DefaultSupportSourceOp -> instream<" + typeName + ">{}\n" +
                        "select(instream as ME) -> outstream {select: (select MyString, sum(MyInt) as total from ME)}\n" +
                        "DefaultSupportCaptureOp(outstream) {}";
            env.CompileDeploy(graph);

            var source = new DefaultSupportSourceOp(events);
            var capture = new DefaultSupportCaptureOp(2, env.Container.LockManager());
            var options = new EPDataFlowInstantiationOptions();
            options.WithOperatorProvider(new DefaultSupportGraphOpProvider(source, capture));
            var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MySelect", options);

            instance.Run();

            var result = capture.GetAndReset()[0].UnwrapIntoArray<object>();
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                result,
                new[] { "MyString","total" },
                new[] {
                    new object[] {"one", 1}, 
                    new object[] {"two", 3}
                });

            instance.Cancel();

            env.UndeployAll();
        }