Example #1
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 void TestStmtNameDynamic()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                 "create map schema SingleProp (id string), " +
                                                 "EPStatementSource -> thedata<SingleProp> {" +
                                                 "  statementName : 'MyStatement'," +
                                                 "} " +
                                                 "DefaultSupportCaptureOp(thedata) {}");

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

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

            Assert.IsNull(df.UserObject);
            Assert.IsNull(df.InstanceId);
            df.Start();

            _epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Assert.AreEqual(0, captureOp.GetCurrent().Length);

            var stmt = _epService.EPAdministrator.CreateEPL("@Name('MyStatement') select TheString as id from SupportBean");

            _epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            captureOp.WaitForInvocation(100, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "E2" });

            stmt.Stop();

            _epService.EPRuntime.SendEvent(new SupportBean("E3", 3));
            Assert.AreEqual(0, captureOp.GetCurrent().Length);

            stmt.Start();

            _epService.EPRuntime.SendEvent(new SupportBean("E4", 4));
            captureOp.WaitForInvocation(100, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "E4" });

            stmt.Dispose();

            _epService.EPRuntime.SendEvent(new SupportBean("E5", 5));
            Assert.AreEqual(0, captureOp.GetCurrent().Length);

            _epService.EPAdministrator.CreateEPL("@Name('MyStatement') select 'X'||TheString||'X' as id from SupportBean");

            _epService.EPRuntime.SendEvent(new SupportBean("E6", 6));
            captureOp.WaitForInvocation(100, 1);
            EPAssertionUtil.AssertProps(captureOp.GetCurrentAndReset()[0], "id".Split(','), new Object[] { "XE6X" });

            df.Cancel();
            _epService.EPAdministrator.DestroyAllStatements();
        }
Example #3
0
        public void TestStartCaptiveCancel()
        {
            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) {}");

            DefaultSupportCaptureOp        captureOp = new DefaultSupportCaptureOp();
            EPDataFlowInstantiationOptions 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(captureOp.GetCurrent(), fields, new Object[][] { new Object[] { "E1", 10 } });

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

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

            emitter.Submit(new Object[] { "E3", 30 });
            EPAssertionUtil.AssertPropsPerRow(captureOp.GetCurrent(), 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 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();
        }
        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 #6
0
        private void RunAssertionAllTypes(String typeName, SendableEvent[] events)
        {
            EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                                         "EventBusSource -> ReceivedStream<" + typeName + "> {} " +
                                                                         "DefaultSupportCaptureOp(ReceivedStream) {}");

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

            events[0].Send(_epService.EPRuntime);
            Assert.AreEqual(0, future.GetCurrent().Length);

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

            events[0].Send(_epService.EPRuntime);
            Assert.AreEqual(0, future.GetCurrent().Length);

            df.Start();

            // send events
            for (int i = 0; i < events.Length; i++)
            {
                events[i].Send(_epService.EPRuntime);
            }

            // assert
            future.WaitForInvocation(200, events.Length);
            Object[] rows = future.GetCurrentAndReset();
            Assert.AreEqual(events.Length, rows.Length);
            for (int i = 0; i < events.Length; i++)
            {
                Assert.AreSame(events[i].Underlying, rows[i]);
            }

            df.Cancel();

            events[0].Send(_epService.EPRuntime);
            Thread.Sleep(50);
            Assert.AreEqual(0, future.GetCurrent().Length);

            stmtGraph.Dispose();
        }
Example #7
0
        public void TestIterateFinalMarker()
        {
            _epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            String graph = "create dataflow MySelect\n" +
                           "Emitter -> instream_s0<SupportBean>{name: 'emitterS0'}\n" +
                           "@Audit Select(instream_s0 as ALIAS) -> outstream {\n" +
                           "  select: (select TheString, sum(IntPrimitive) as SumInt from ALIAS group by TheString order by TheString asc),\n" +
                           "  iterate: true" +
                           "}\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();

            Emitter emitter = captive.Emitters.Get("emitterS0");

            emitter.Submit(new SupportBean("E3", 4));
            emitter.Submit(new SupportBean("E2", 3));
            emitter.Submit(new SupportBean("E1", 1));
            emitter.Submit(new SupportBean("E2", 2));
            emitter.Submit(new SupportBean("E1", 5));
            Assert.AreEqual(0, capture.GetCurrent().Length);

            emitter.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl());
            EPAssertionUtil.AssertPropsPerRow(capture.GetCurrent(), "TheString,SumInt".Split(','), new Object[][] { new Object[] { "E1", 6 }, new Object[] { "E2", 5 }, new Object[] { "E3", 4 } });

            instance.Cancel();
        }
        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);
        }