private static void RunAssertionAllTypes(
            RegressionEnvironment env,
            string typeName,
            object[] events)
        {
            var graph = "@Name('flow') create dataflow MyGraph " +
                        "DefaultSupportSourceOp -> instream<" +
                        typeName +
                        ">{}" +
                        "EventBusSink(instream) {}";
            env.CompileDeploy(graph);

            env.CompileDeploy("@Name('s0') select * from " + typeName).AddListener("s0");

            var source = new DefaultSupportSourceOp(events);
            var options = new EPDataFlowInstantiationOptions();
            options.WithOperatorProvider(new DefaultSupportGraphOpProvider(source));
            var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyGraph", options);
            instance.Run();

            EPAssertionUtil.AssertPropsPerRow(
                env.Listener("s0").NewDataListFlattened,
                new[] {"MyDouble", "MyInt", "MyString"},
                new[] {
                    new object[] {1.1d, 1, "one"},
                    new object[] {2.2d, 2, "two"}
                });

            env.UndeployAll();
        }
Example #2
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 #3
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();
        }
Example #4
0
        public void Run(RegressionEnvironment env)
        {
            MyExceptionHandler.Contexts.Clear();

            // test exception by graph source
            env.CompileDeploy(
                "@Name('flow') create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}");

            var op = new DefaultSupportSourceOp(new object[] {new EPRuntimeException("My-Exception-Is-Here")});
            var options = new EPDataFlowInstantiationOptions();
            options.WithOperatorProvider(new DefaultSupportGraphOpProvider(op));
            var handler = new MyExceptionHandler();
            options.WithExceptionHandler(handler);
            var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlow", options);

            df.Start();
            Sleep(100);
            Sleep(10000);
            Assert.AreEqual(EPDataFlowState.COMPLETE, df.State);

            Assert.AreEqual(1, MyExceptionHandler.Contexts.Count);
            var context = MyExceptionHandler.Contexts[0];
            Assert.AreEqual("MyDataFlow", context.DataFlowName);
            Assert.AreEqual("DefaultSupportSourceOp", context.OperatorName);
            Assert.AreEqual(0, context.OperatorNumber);
            Assert.AreEqual("DefaultSupportSourceOp#0() -> outstream<SupportBean>", context.OperatorPrettyPrint);
            Assert.AreEqual(
                "Support-graph-source generated exception: My-Exception-Is-Here",
                context.Exception.Message);
            df.Cancel();
            env.UndeployModuleContaining("flow");
            MyExceptionHandler.Contexts.Clear();

            // test exception by operator
            env.CompileDeploy(
                "@Name('flow') create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}" +
                "MyExceptionOp(outstream) {}");

            var opTwo = new DefaultSupportSourceOp(new object[] {new SupportBean("E1", 1)});
            var optionsTwo = new EPDataFlowInstantiationOptions();
            optionsTwo.WithOperatorProvider(new DefaultSupportGraphOpProvider(opTwo));
            var handlerTwo = new MyExceptionHandler();
            optionsTwo.WithExceptionHandler(handlerTwo);
            var dfTwo = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlow", optionsTwo);

            dfTwo.Start();
            Sleep(100);

            Assert.AreEqual(1, MyExceptionHandler.Contexts.Count);
            var contextTwo = MyExceptionHandler.Contexts[0];
            Assert.AreEqual("MyDataFlow", contextTwo.DataFlowName);
            Assert.AreEqual("MyExceptionOp", contextTwo.OperatorName);
            Assert.AreEqual(1, contextTwo.OperatorNumber);
            Assert.AreEqual("MyExceptionOp#1(outstream)", contextTwo.OperatorPrettyPrint);
            Assert.AreEqual("Operator-thrown-exception", contextTwo.Exception.Message);
        }
        public void Run(RegressionEnvironment env)
        {
            if (env.IsHA) {
                return;
            }

            var epl = "@Name('flow') create dataflow RollingTopWords\n" +
                      "create objectarray schema WordEvent (word string),\n" +
                      "Emitter -> wordstream<WordEvent> {name:'a'} // Produces word stream\n" +
                      "Select(wordstream) -> wordcount { // Sliding time window count per word\n" +
                      "  select: (select word, count(*) as wordcount from wordstream#time(30) group by word)\n" +
                      "}\n" +
                      "Select(wordcount) -> wordranks { // Rank of words\n" +
                      "  select: (select window(*) as rankedWords from wordcount#sort(3, wordcount desc) output snapshot every 2 seconds)\n" +
                      "}\n" +
                      "DefaultSupportCaptureOp(wordranks) {}";
            env.EventService.AdvanceTime(0);
            env.CompileDeploy(epl);

            // prepare test
            var capture = new DefaultSupportCaptureOp();
            var options = new EPDataFlowInstantiationOptions();
            options.WithOperatorProvider(new DefaultSupportGraphOpProvider(capture));

            var instanceOne = env.Runtime.DataFlowService.Instantiate(
                env.DeploymentId("flow"),
                "RollingTopWords",
                options);
            var emitter = instanceOne.StartCaptive().Emitters.Get("a");

            foreach (var word in new[] {"this", "is", "a", "test", "that", "is", "a", "word", "test"}) {
                emitter.Submit(new object[] {word});
            }

            Assert.AreEqual(0, capture.GetCurrentAndReset().Length);

            env.AdvanceTime(2000);
            Assert.AreEqual(1, capture.Current.Length);
            var row = capture.Current[0].UnwrapIntoArray<object>();
            var rows = row[0].UnwrapIntoArray<object>();
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                rows,
                new[] {"word", "count"},
                new[] {
                    new object[] {"is", 2L},
                    new object[] {"a", 2L},
                    new object[] {"test", 2L}
                });

            instanceOne.Cancel();

            env.UndeployAll();
        }
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne MyOp -> outstream<SomeType> {propOne:'abc', propThree:'xyz'}",
                    path);

                var myOperatorProvider = new MyOperatorProvider();
                var options = new EPDataFlowInstantiationOptions();
                options.WithOperatorProvider(myOperatorProvider);

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

                Assert.AreEqual(1, myOperatorProvider.contextMap.Count);
                var context = myOperatorProvider.contextMap.Get("MyOp");
                Assert.AreEqual("MyOp", context.OperatorName);
                Assert.AreEqual("MyDataFlowOne", context.DataFlowName);

                env.UndeployAll();
            }
        public void Run(RegressionEnvironment env)
        {
            var fields = new [] { "p0","p1" };

            env.CompileDeploy(
                "@Name('flow') create dataflow MyDataFlow " +
                "Emitter -> outstream<MyOAEventType> {name:'src1'}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

            var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlow", options);
            var captiveStart = instance.StartCaptive();
            Assert.AreEqual(0, captiveStart.Runnables.Count);
            Assert.AreEqual(1, captiveStart.Emitters.Count);
            var emitter = captiveStart.Emitters.Get("src1");
            Assert.AreEqual(EPDataFlowState.RUNNING, instance.State);

            emitter.Submit(new object[] {"E1", 10});
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                captureOp.Current,
                fields,
                new[] {new object[] {"E1", 10}});

            emitter.Submit(new object[] {"E2", 20});
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                captureOp.Current,
                fields,
                new[] {new object[] {"E1", 10}, new object[] {"E2", 20}});

            emitter.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl());
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                captureOp.Current,
                fields,
                new object[0][]);
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                captureOp.GetAndReset()[0].UnwrapIntoArray<object>(),
                fields,
                new[] {new object[] {"E1", 10}, new object[] {"E2", 20}});

            emitter.Submit(new object[] {"E3", 30});
            EPAssertionUtil.AssertPropsPerRow(
                env.Container,
                captureOp.Current,
                fields,
                new[] {new object[] {"E3", 30}});

            // stays running until cancelled (no transition to complete)
            Assert.AreEqual(EPDataFlowState.RUNNING, instance.State);

            instance.Cancel();
            Assert.AreEqual(EPDataFlowState.CANCELLED, instance.State);

            env.UndeployAll();

            // test doc sample
            var epl = "@Name('flow') create dataflow HelloWorldDataFlow\n" +
                      "  create schema SampleSchema(text string),\t// sample type\t\t\n" +
                      "\t\n" +
                      "  Emitter -> helloworld.stream<SampleSchema> { name: 'myemitter' }\n" +
                      "  LogSink(helloworld.stream) {}";
            env.CompileDeploy(epl);
            env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "HelloWorldDataFlow");

            env.UndeployAll();
        }
Example #8
0
            public void Run(RegressionEnvironment env)
            {
                // one statement exists before the data flow
                env.CompileDeploy("select Id from SupportBean_B");

                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "create schema AllObjects as System.Object," +
                    "EPStatementSource -> thedata<AllObjects> {} " +
                    "DefaultSupportCaptureOp(thedata) {}");

                var captureOp = new DefaultSupportCaptureOp(env.Container.LockManager());
                var options = new EPDataFlowInstantiationOptions();
                var myFilter = new MyFilter();
                options.WithParameterProvider(
                    new DefaultSupportGraphParamProvider(
                        Collections.SingletonMap<string, object>("statementFilter", myFilter)));
                options.WithOperatorProvider(new DefaultSupportGraphOpProvider(captureOp));
                var df = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);
                df.Start();

                env.SendEventBean(new SupportBean_B("B1"));
                captureOp.WaitForInvocation(200, 1);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    captureOp.GetCurrentAndReset()[0],
                    new [] { "Id" },
                    new object[] {"B1"});

                env.CompileDeploy("select TheString, IntPrimitive from SupportBean");
                env.SendEventBean(new SupportBean("E1", 1));
                captureOp.WaitForInvocation(200, 1);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    captureOp.GetCurrentAndReset()[0],
                    new [] { "TheString","IntPrimitive" },
                    new object[] {"E1", 1});

                env.CompileDeploy("@Name('s2') select Id from SupportBean_A");
                env.SendEventBean(new SupportBean_A("A1"));
                captureOp.WaitForInvocation(200, 1);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    captureOp.GetCurrentAndReset()[0],
                    new [] { "Id" },
                    new object[] {"A1"});

                env.UndeployModuleContaining("s2");

                env.SendEventBean(new SupportBean_A("A2"));
                Sleep(50);
                Assert.AreEqual(0, captureOp.Current.Length);

                env.CompileDeploy("@Name('s2') select Id from SupportBean_A");

                env.SendEventBean(new SupportBean_A("A3"));
                captureOp.WaitForInvocation(200, 1);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    captureOp.GetCurrentAndReset()[0],
                    new [] { "Id" },
                    new object[] {"A3"});

                env.SendEventBean(new SupportBean_B("B2"));
                captureOp.WaitForInvocation(200, 1);
                EPAssertionUtil.AssertProps(
                    env.Container,
                    captureOp.GetCurrentAndReset()[0],
                    new [] { "Id" },
                    new object[] {"B2"});

                df.Cancel();

                env.SendEventBean(new SupportBean("E1", 1));
                env.SendEventBean(new SupportBean_A("A1"));
                env.SendEventBean(new SupportBean_B("B3"));
                Assert.AreEqual(0, captureOp.Current.Length);

                env.UndeployAll();
            }