Example #1
0
        private void RunAssertionAllTypes(String typeName, Object[] events)
        {
            String graph = "create dataflow MyGraph " +
                           "DefaultSupportSourceOp -> instream<" + typeName + ">{}" +
                           "EventBusSink(instream) {}";
            EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL(graph);

            EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from " + typeName);

            stmt.Events += _listener.Update;

            DefaultSupportSourceOp         source  = new DefaultSupportSourceOp(events);
            EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions();

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

            instance.Run();

            EPAssertionUtil.AssertPropsPerRow(
                _listener.GetNewDataListFlattened(),
                "myDouble,myInt,myString".Split(','),
                new Object[][]
            {
                new Object[] { 1.1d, 1, "one" },
                new Object[] { 2.2d, 2, "two" }
            });
            _listener.Reset();

            stmtGraph.Dispose();
        }
Example #2
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();
        }
        private void RunAssertionAllTypes(EPServiceProvider epService, string typeName, object[] events)
        {
            string graph = "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) {}";
            EPStatement stmtGraph = epService.EPAdministrator.CreateEPL(graph);

            var source  = new DefaultSupportSourceOp(events);
            var capture = new DefaultSupportCaptureOp(2, SupportContainer.Instance.LockManager());
            var options = new EPDataFlowInstantiationOptions();

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

            instance.Run();

            object[] result = capture.GetAndReset()[0].ToArray();
            EPAssertionUtil.AssertPropsPerRow(
                epService.Container, result, "myString,total".Split(','), new object[][] { new object[] { "one", 1 }, new object[] { "two", 3 } });

            instance.Cancel();

            stmtGraph.Dispose();
        }
Example #4
0
        public override void Run(EPServiceProvider epService)
        {
            MyExceptionHandler.Contexts.Clear();
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            // test exception by graph source
            EPStatement stmtGraph = epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}");

            var op      = new DefaultSupportSourceOp(new object[] { new EPRuntimeException("My-Exception-Is-Here") });
            var options = new EPDataFlowInstantiationOptions();

            options.OperatorProvider(new DefaultSupportGraphOpProvider(op));
            var handler = new MyExceptionHandler();

            options.ExceptionHandler(handler);
            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", options);

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

            Assert.AreEqual(1, MyExceptionHandler.Contexts.Count);
            EPDataFlowExceptionContext 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();
            stmtGraph.Dispose();
            MyExceptionHandler.Contexts.Clear();

            // test exception by operator
            epService.EPAdministrator.Configuration.AddImport(typeof(MyExceptionOp));
            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}" +
                                                "MyExceptionOp(outstream) {}");

            var opTwo      = new DefaultSupportSourceOp(new object[] { new SupportBean("E1", 1) });
            var optionsTwo = new EPDataFlowInstantiationOptions();

            optionsTwo.OperatorProvider(new DefaultSupportGraphOpProvider(opTwo));
            var handlerTwo = new MyExceptionHandler();

            optionsTwo.ExceptionHandler(handlerTwo);
            EPDataFlowInstance dfTwo = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", optionsTwo);

            dfTwo.Start();
            Thread.Sleep(100);

            Assert.AreEqual(1, MyExceptionHandler.Contexts.Count);
            EPDataFlowExceptionContext 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);
        }
Example #5
0
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(DefaultSupportCaptureOp).Name);

            string[] fields = "p0,p1".Split(',');
            epService.EPAdministrator.Configuration.AddEventType("MyOAEventType", fields, new object[] { typeof(string), typeof(int) });

            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow " +
                                                "Emitter -> outstream<MyOAEventType> {name:'src1'}" +
                                                "DefaultSupportCaptureOp(outstream) {}");

            var container = epService.Container;
            var captureOp = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            var options   = new EPDataFlowInstantiationOptions();

            options.OperatorProvider(new DefaultSupportGraphOpProvider(captureOp));

            EPDataFlowInstance        instance     = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", options);
            EPDataFlowInstanceCaptive captiveStart = instance.StartCaptive();

            Assert.AreEqual(0, captiveStart.Runnables.Count);
            Assert.AreEqual(1, captiveStart.Emitters.Count);
            Emitter emitter = captiveStart.Emitters.Get("src1");

            Assert.AreEqual(EPDataFlowState.RUNNING, instance.State);

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

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

            emitter.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl());
            EPAssertionUtil.AssertPropsPerRow(container, captureOp.Current, fields, new Object[0][]);
            EPAssertionUtil.AssertPropsPerRow(container, captureOp.GetAndReset()[0].ToArray(), fields, new object[][] { new object[] { "E1", 10 }, new object[] { "E2", 20 } });

            emitter.Submit(new object[] { "E3", 30 });
            EPAssertionUtil.AssertPropsPerRow(container, captureOp.Current, fields, new object[][] { 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);

            // test doc sample
            string epl = "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) {}";

            epService.EPAdministrator.CreateEPL(epl);
            epService.EPRuntime.DataFlowRuntime.Instantiate("HelloWorldDataFlow");
        }
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(GetType().FullName);

            var epl = "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) {}";

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            epService.EPAdministrator.CreateEPL(epl);

            // prepare test
            var capture = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            var options = new EPDataFlowInstantiationOptions();

            options.OperatorProvider(new DefaultSupportGraphOpProvider(capture));

            var instanceOne = epService.EPRuntime.DataFlowRuntime.Instantiate("RollingTopWords", options);
            var emitter     = instanceOne.StartCaptive().Emitters.Get("a");

            foreach (var word in new string[] { "this", "is", "a", "test", "that", "is", "a", "word", "test" })
            {
                emitter.Submit(new object[] { word });
            }
            Assert.AreEqual(0, capture.GetCurrentAndReset().Length);

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000));
            Assert.AreEqual(1, capture.Current.Length);
            var map  = (IDictionary <string, object>)capture.Current[0];
            var rows = map.Get("rankedWords").UnwrapIntoList <object[]>();

            EPAssertionUtil.AssertPropsPerRow(
                epService.Container,
                rows,
                "word,count".Split(','),
                new object[][] {
                new object[] { "is", 2L },
                new object[] { "a", 2L },
                new object[] { "test", 2L }
            });

            instanceOne.Cancel();
        }
        public void TestGraph()
        {
            String epl = "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.win:time(30) group by word)\n" +
                         "}\n" +
                         "Select(wordcount) -> wordranks { // Rank of words\n" +
                         "  select: (select Window(*) as rankedWords from wordcount.ext:sort(3, wordcount desc) output snapshot every 2 seconds)\n" +
                         "}\n" +
                         "DefaultSupportCaptureOp(wordranks) {}";

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

            // prepare test
            DefaultSupportCaptureOp        capture = new DefaultSupportCaptureOp();
            EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions();

            options.OperatorProvider(new DefaultSupportGraphOpProvider(capture));

            EPDataFlowInstance instanceOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("RollingTopWords", options);
            Emitter            emitter     = instanceOne.StartCaptive().Emitters.Get("a");

            foreach (String word in new String[] { "this", "is", "a", "test", "that", "is", "a", "word", "test" })
            {
                emitter.Submit(new Object[] { word });
            }
            Assert.AreEqual(0, capture.GetCurrentAndReset().Length);

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000));
            Assert.AreEqual(1, capture.GetCurrent().Length);
            Map map = (Map)capture.GetCurrent()[0];
            IList <Object[]> rows = (Object[][])map.Get("rankedWords");

            EPAssertionUtil.AssertPropsPerRow(
                rows,
                "word,count".Split(','),
                new Object[][]
            {
                new Object[] { "is", 2L },
                new Object[] { "a", 2L },
                new Object[] { "test", 2L }
            });

            instanceOne.Cancel();
        }
Example #8
0
        public void TestOperatorInjectionCallback()
        {
            _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne MyOp -> outstream<SomeType> {propOne:'abc', propThree:'xyz'}");

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

            options.OperatorProvider(myOperatorProvider);

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

            Assert.AreEqual(1, myOperatorProvider.ContextMap.Count);
            EPDataFlowOperatorProviderContext context = myOperatorProvider.ContextMap.Get("MyOp");

            Assert.AreEqual("MyOp", context.OperatorName);
            Assert.NotNull(context.Spec);
            Assert.AreEqual("MyDataFlowOne", context.DataFlowName);
        }
Example #9
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();
        }
Example #10
0
        private void RunAssertionOperatorInjectionCallback(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne MyOp -> outstream<SomeType> {propOne:'abc', propThree:'xyz'}");

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

            options.OperatorProvider(myOperatorProvider);

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

            Assert.AreEqual(1, myOperatorProvider.ContextMap.Count);
            EPDataFlowOperatorProviderContext context = myOperatorProvider.ContextMap.Get("MyOp");

            Assert.AreEqual("MyOp", context.OperatorName);
            Assert.IsNotNull(context.Spec);
            Assert.AreEqual("MyDataFlowOne", context.DataFlowName);

            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);
        }