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();
        }
Exemple #2
0
        public void TestOperatorStatistics()
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            epService.EPAdministrator.CreateEPL("create dataflow MyGraph " +
                                                "DefaultSupportSourceOp -> outstream<SupportBean> {} " +
                                                "DefaultSupportCaptureOp(outstream) {}");

            DefaultSupportSourceOp         source  = new DefaultSupportSourceOp(new Object[] { new SupportBean("E1", 1), new SupportBean("E2", 2) });
            DefaultSupportCaptureOp        capture = new DefaultSupportCaptureOp();
            EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions()
                                                     .OperatorProvider(new DefaultSupportGraphOpProvider(source, capture))
                                                     .OperatorStatistics(true)
                                                     .CpuStatistics(true);

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

            instance.Run();

            IList <EPDataFlowInstanceOperatorStat> stats = instance.Statistics.OperatorStatistics;

            Assert.AreEqual(2, stats.Count);

            EPDataFlowInstanceOperatorStat sourceStat = stats[0];

            Assert.AreEqual("DefaultSupportSourceOp", sourceStat.OperatorName);
            Assert.AreEqual(0, sourceStat.OperatorNumber);
            Assert.AreEqual("DefaultSupportSourceOp#0() -> outstream<SupportBean>", sourceStat.OperatorPrettyPrint);
            Assert.AreEqual(2, sourceStat.SubmittedOverallCount);
            EPAssertionUtil.AssertEqualsExactOrder(new long[] { 2L }, sourceStat.SubmittedPerPortCount);
            Assert.IsTrue(sourceStat.TimeOverall > 0);
            Assert.AreEqual(sourceStat.TimeOverall, sourceStat.TimePerPort[0]);

            EPDataFlowInstanceOperatorStat destStat = stats[1];

            Assert.AreEqual("DefaultSupportCaptureOp", destStat.OperatorName);
            Assert.AreEqual(1, destStat.OperatorNumber);
            Assert.AreEqual("DefaultSupportCaptureOp#1(outstream)", destStat.OperatorPrettyPrint);
            Assert.AreEqual(0, destStat.SubmittedOverallCount);
            Assert.AreEqual(0, destStat.SubmittedPerPortCount.Length);
            Assert.AreEqual(0, destStat.TimeOverall);
            Assert.AreEqual(0, destStat.TimePerPort.Length);
        }
Exemple #3
0
        public void TestVariable()
        {
            _epService.EPAdministrator.CreateEPL("create Schema SomeEvent()");
            _epService.EPAdministrator.CreateEPL("create variable int var_iterations=3");
            EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "BeaconSource -> BeaconStream<SomeEvent> {" +
                "  iterations : var_iterations" +
                "}" +
                "DefaultSupportCaptureOp(BeaconStream) {}");

            var future  = new DefaultSupportCaptureOp(3);
            var options = new EPDataFlowInstantiationOptions()
                          .OperatorProvider(new DefaultSupportGraphOpProvider(future));
            EPDataFlowInstance df = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            df.Start();
            Object[] output = future.GetValue(TimeSpan.FromSeconds(2));
            Assert.AreEqual(3, output.Length);
            stmtGraph.Dispose();
        }
Exemple #4
0
        public void TestNonBlockingJoinException()
        {
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

            dfOne.Start();

            var unlatchingThread = new Thread(
                () =>
            {
                try
                {
                    Thread.Sleep(300);
                    latchOne.CountDown();
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
            });

            unlatchingThread.Start();
            dfOne.Join();

            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);
        }
        private void RunAssertionIterateFinalMarker(EPServiceProvider epService)
        {
            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);

            var capture = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            IDictionary <string, Object> operators = CollectionUtil.PopulateNameValueMap("CaptureOp", capture);

            var 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.Current.Length);

            emitter.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl());
            EPAssertionUtil.AssertPropsPerRow(
                epService.Container, capture.Current,
                "TheString,sumInt".Split(','),
                new[] { new object[] { "E1", 6 }, new object[] { "E2", 5 }, new object[] { "E3", 4 } });

            instance.Cancel();
            epService.EPAdministrator.DestroyAllStatements();
        }
Exemple #6
0
        public void TestNonBlockingException()
        {
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

            dfOne.Start();
            Thread.Sleep(200);
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);
        }
Exemple #7
0
        public void TestNonBlockingJoinSingleRunnable()
        {
            // declare
            _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);
            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(source, future));
            EPDataFlowInstance 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);
        }
        private static void TryAssertionAfterExec(EPDataFlowInstance df)
        {
            // cancel and join ignored
            try {
                df.Join();
            }
            catch (ThreadInterruptedException e) {
                throw new EPException(e);
            }

            // can't start or run again
            try {
                df.Run();
                Assert.Fail();
            }
            catch (IllegalStateException ex) {
                Assert.AreEqual(
                    "Data flow 'MyDataFlowOne' instance has already completed, please use instantiate to run the data flow again",
                    ex.Message);
            }

            try {
                df.Start();
                Assert.Fail();
            }
            catch (IllegalStateException ex) {
                Assert.AreEqual(
                    "Data flow 'MyDataFlowOne' instance has already completed, please use instantiate to run the data flow again",
                    ex.Message);
            }

            df.Cancel();
            try {
                df.Join();
            }
            catch (ThreadInterruptedException e) {
                throw new EPException(e);
            }
        }
Exemple #9
0
        public void TestNonBlockingCancel()
        {
            // declare
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "SourceOne -> outstream<SomeType> {}" +
                "OutputOp(outstream) {}");

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

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

            ops["OutputOp"] = output;

            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops));
            EPDataFlowInstance 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);
        }
        private void RunAssertionTimeWindowTriggered(EPServiceProvider epService)
        {
            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#time(1 minute))\n" +
                           "}\n" +
                           "CaptureOp(outstream) {}\n";

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

            var capture = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            IDictionary <string, Object> operators = CollectionUtil.PopulateNameValueMap("CaptureOp", capture);

            var 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(
                epService.Container, 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(
                epService.Container, capture.GetCurrentAndReset()[0], "sumInt".Split(','), new object[] { 7 });

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

            instance.Cancel();
            epService.EPAdministrator.DestroyAllStatements();
        }
Exemple #11
0
        private void RunAssertionAllTypes(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);

            DefaultSupportSourceOp         source  = new DefaultSupportSourceOp(events);
            DefaultSupportCaptureOp        capture = new DefaultSupportCaptureOp(2);
            EPDataFlowInstantiationOptions 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(result, "myString,total".Split(','), new Object[][] { new Object[] { "one", 1 }, new Object[] { "two", 3 } });

            instance.Cancel();

            stmtGraph.Dispose();
        }
Exemple #12
0
        private void RunAssertion(EPServiceProvider epService, string format, bool?log, string layout, string title, bool?linefeed)
        {
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            string graph = "create dataflow MyConsoleOut\n" +
                           "Emitter -> instream<SupportBean>{name : 'e1'}\n" +
                           "LogSink(instream) {\n" +
                           (format == null ? "" : "  format: '" + format + "',\n") +
                           (log == null ? "" : "  log: " + log + ",\n") +
                           (layout == null ? "" : "  layout: '" + layout + "',\n") +
                           (title == null ? "" : "  title: '" + title + "',\n") +
                           (linefeed == null ? "" : "  linefeed: " + linefeed + ",\n") +
                           "}";
            EPStatement stmtGraph = epService.EPAdministrator.CreateEPL(graph);

            EPDataFlowInstance instance = epService.EPRuntime.DataFlowRuntime.Instantiate("MyConsoleOut");

            Emitter emitter = instance.StartCaptive().Emitters.Get("e1");

            emitter.Submit(new SupportBean("E1", 1));

            instance.Cancel();
            stmtGraph.Dispose();
        }
        private void TryAssertionJoinOrder(EPServiceProvider epService, 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);

            var capture = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            IDictionary <string, Object> operators = CollectionUtil.PopulateNameValueMap("CaptureOp", capture);

            var 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.Current.Length);

            captive.Emitters.Get("emitterS2").Submit(new SupportBean_S2(100));
            Assert.AreEqual(1, capture.Current.Length);
            EPAssertionUtil.AssertProps(
                epService.Container, 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.Current.Length);

            stmtGraph.Dispose();
        }
        public override void Run(EPServiceProvider epService)
        {
            EPDataFlowRuntime dataFlowRuntime = epService.EPRuntime.DataFlowRuntime;

            Assert.AreEqual(0, dataFlowRuntime.SavedConfigurations.Length);
            Assert.IsNull(dataFlowRuntime.GetSavedConfiguration("MyFirstFlow"));
            Assert.IsFalse(dataFlowRuntime.RemoveSavedConfiguration("MyFirstFlow"));
            try {
                dataFlowRuntime.InstantiateSavedConfiguration("MyFirstFlow");
                Assert.Fail();
            } catch (EPDataFlowInstantiationException ex) {
                Assert.AreEqual("Dataflow saved configuration 'MyFirstFlow' could not be found", ex.Message);
            }
            try {
                dataFlowRuntime.SaveConfiguration("MyFirstFlow", "MyDataflow", null);
                Assert.Fail();
            } catch (EPDataFlowNotFoundException ex) {
                Assert.AreEqual("Failed to locate data flow 'MyDataflow'", ex.Message);
            }

            // finally create one
            epService.EPAdministrator.CreateEPL("create objectarray schema MyEvent ()");
            epService.EPAdministrator.CreateEPL("create dataflow MyDataflow " +
                                                "BeaconSource -> outdata<MyEvent> {" +
                                                "  iterations:1" +
                                                "}" +
                                                "EventBusSink(outdata) {}");

            // add it
            dataFlowRuntime.SaveConfiguration("MyFirstFlow", "MyDataflow", null);
            Assert.AreEqual(1, dataFlowRuntime.SavedConfigurations.Length);
            EPDataFlowSavedConfiguration savedConfiguration = dataFlowRuntime.GetSavedConfiguration(dataFlowRuntime.SavedConfigurations[0]);

            Assert.AreEqual("MyFirstFlow", savedConfiguration.SavedConfigurationName);
            Assert.AreEqual("MyDataflow", savedConfiguration.DataflowName);
            try {
                dataFlowRuntime.SaveConfiguration("MyFirstFlow", "MyDataflow", null);
                Assert.Fail();
            } catch (EPDataFlowAlreadyExistsException ex) {
                Assert.AreEqual("Data flow saved configuration by name 'MyFirstFlow' already exists", ex.Message);
            }

            // remove it
            Assert.IsTrue(dataFlowRuntime.RemoveSavedConfiguration("MyFirstFlow"));
            Assert.IsFalse(dataFlowRuntime.RemoveSavedConfiguration("MyFirstFlow"));
            Assert.AreEqual(0, dataFlowRuntime.SavedConfigurations.Length);
            Assert.IsNull(dataFlowRuntime.GetSavedConfiguration("MyFirstFlow"));

            // add once more to instantiate
            dataFlowRuntime.SaveConfiguration("MyFirstFlow", "MyDataflow", null);
            EPDataFlowInstance instance = dataFlowRuntime.InstantiateSavedConfiguration("MyFirstFlow");
            var listener = new SupportUpdateListener();

            epService.EPAdministrator.CreateEPL("select * from MyEvent").Events += listener.Update;
            instance.Run();
            Assert.IsTrue(listener.GetAndClearIsInvoked());
            EPAssertionUtil.AssertEqualsExactOrder(new string[] { "MyFirstFlow" }, dataFlowRuntime.SavedConfigurations);
            Assert.IsNotNull(dataFlowRuntime.GetSavedConfiguration("MyFirstFlow"));

            // add/remove instance
            dataFlowRuntime.SaveInstance("F1", instance);
            EPAssertionUtil.AssertEqualsExactOrder(new string[] { "F1" }, dataFlowRuntime.SavedInstances);
            EPDataFlowInstance instanceFromSvc = dataFlowRuntime.GetSavedInstance("F1");

            Assert.AreEqual("MyDataflow", instanceFromSvc.DataFlowName);
            try {
                dataFlowRuntime.SaveInstance("F1", instance);
                Assert.Fail();
            } catch (EPDataFlowAlreadyExistsException ex) {
                // expected
                Assert.AreEqual("Data flow instance name 'F1' already saved", ex.Message);
            }
            Assert.IsTrue(dataFlowRuntime.RemoveSavedInstance("F1"));
            Assert.IsFalse(dataFlowRuntime.RemoveSavedInstance("F1"));
        }
Exemple #15
0
        public void TestWithDocSamples()
        {
            String epl = "create dataflow HelloWorldDataFlow\n" +
                         "BeaconSource -> helloworldStream { text: 'hello world', iterations : 1 }\n" +
                         "LogSink(helloworldStream) {}";

            _epService.EPAdministrator.CreateEPL(epl);

            EPDataFlowInstance instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("HelloWorldDataFlow");

            instance.Run();

            TryEpl("create dataflow MyDataFlow\n" +
                   "MyOperatorSimple {}");
            TryEpl("create dataflow MyDataFlow2\n" +
                   "create schema MyEvent as (id string, price double),\n" +
                   "MyOperator(myInStream) -> myOutStream<MyEvent> {\n" +
                   "myParameter : 10\n" +
                   "}");
            TryEpl("create dataflow MyDataFlow3\n" +
                   "MyOperator(myInStream as mis) {}");
            TryEpl("create dataflow MyDataFlow4\n" +
                   "MyOperator(streamOne as one, streamTwo as two) {}");
            TryEpl("create dataflow MyDataFlow5\n" +
                   "MyOperator( (streamA, streamB) as streamsAB) {}");
            TryEpl("create dataflow MyDataFlow6\n" +
                   "MyOperator(abc) -> my.out.stream {}");
            TryEpl("create dataflow MyDataFlow7\n" +
                   "MyOperator -> my.out.one, my.out.two {}");
            TryEpl("create dataflow MyDataFlow8\n" +
                   "create objectarray schema RFIDSchema (tagId string, locX double, locy double),\n" +
                   "MyOperator -> rfid.stream<RFIDSchema> {}");
            TryEpl("create dataflow MyDataFlow9\n" +
                   "create objectarray schema RFIDSchema (tagId string, locX double, locy double),\n" +
                   "MyOperator -> rfid.stream<eventbean<RFIDSchema>> {}");
            TryEpl("create dataflow MyDataFlow10\n" +
                   "MyOperator -> my.stream<eventbean<?>> {}");
            TryEpl("create dataflow MyDataFlow11\n" +
                   "MyOperator {\n" +
                   "stringParam : 'sample',\n" +
                   "secondString : \"double-quotes are fine\",\n" +
                   "intParam : 10\n" +
                   "}");
            TryEpl("create dataflow MyDataFlow12\n" +
                   "MyOperator {\n" +
                   "intParam : 24*60^60,\n" +
                   "threshold : var_threshold, // a variable defined in the engine\n" +
                   "}");
            TryEpl("create dataflow MyDataFlow13\n" +
                   "MyOperator {\n" +
                   "someSystemProperty : SystemProperties('mySystemProperty')\n" +
                   "}");
            TryEpl("create dataflow MyDataFlow14\n" +
                   "MyOperator {\n" +
                   "  myStringArray: ['a', \"b\",],\n" +
                   "  myMapOrObject: {\n" +
                   "    a : 10,\n" +
                   "    b : 'xyz',\n" +
                   "  },\n" +
                   "  myInstance: {\n" +
                   "    class: 'com.myorg.myapp.MyImplementation',\n" +
                   "    myValue : 'sample'\n" +
                   "  }\n" +
                   "}");
        }
Exemple #16
0
        private void RunAssertionAudit(EPServiceProvider epService)
        {
            // stream, and test audit callback
            var callback = new SupportAuditCallback();

            AuditPath.AuditCallback = callback.Audit;
            AUDITLOG.Info("*** Stream: ");
            EPStatement stmtInput = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('stream') select * from SupportBean(TheString = 'E1')");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Assert.AreEqual(1, callback.Audits.Count);
            AuditContext cb = callback.Audits[0];

            Assert.AreEqual("SupportBean(TheString=...) inserted SupportBean[SupportBean(E1, 1)]", cb.Message);
            Assert.AreEqual("ABC", cb.StatementName);
            Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, cb.EngineURI);
            Assert.AreEqual(AuditEnum.STREAM, cb.Category);
            AuditPath.AuditCallback = null;
            stmtInput.Dispose();

            AUDITLOG.Info("*** Named Window And Insert-Into: ");
            EPStatement stmtNW        = epService.EPAdministrator.CreateEPL("@Name('create') @Audit create window WinOne#keepall as SupportBean");
            EPStatement stmtInsertNW  = epService.EPAdministrator.CreateEPL("@Name('insert') @Audit insert into WinOne select * from SupportBean");
            EPStatement stmtConsumeNW = epService.EPAdministrator.CreateEPL("@Name('select') @Audit select * from WinOne");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            stmtNW.Dispose();
            stmtInsertNW.Dispose();
            stmtConsumeNW.Dispose();

            AUDITLOG.Info("*** Insert-Into: ");
            EPStatement stmtInsertInto = epService.EPAdministrator.CreateEPL("@Name('insert') @Audit insert into ABC select * from SupportBean");

            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            stmtInsertInto.Dispose();

            AUDITLOG.Info("*** Schedule: ");
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            EPStatement stmtSchedule = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('schedule') select irstream * from SupportBean#time(1 sec)");
            var         listener     = new SupportUpdateListener();

            stmtSchedule.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            listener.Reset();
            Log.Info("Sending time");
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000));
            Assert.IsTrue(listener.IsInvoked);
            listener.Reset();
            stmtSchedule.Dispose();

            // exprdef-instances
            AUDITLOG.Info("*** Expression-Def: ");
            EPStatement stmtExprDef = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('exprdef') " +
                                                                          "expression DEF { 1 } " +
                                                                          "expression INN {  x => x.TheString }" +
                                                                          "expression OUT { x => INN(x) } " +
                                                                          "select DEF(), OUT(sb) from SupportBean sb");

            stmtExprDef.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("DEF()"));
            stmtExprDef.Dispose();

            // pattern-instances
            AUDITLOG.Info("*** Pattern-Lifecycle: ");
            EPStatement stmtPatternLife = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('pattern-instances') select a.IntPrimitive as val0 from pattern [every a=SupportBean -> (b=SupportBean_ST0 and not SupportBean_ST1)]");

            stmtPatternLife.Events += listener.Update;
            Log.Info("Sending E1");
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            Log.Info("Sending E2");
            epService.EPRuntime.SendEvent(new SupportBean("E2", 2));
            Log.Info("Sending E3");
            epService.EPRuntime.SendEvent(new SupportBean_ST1("E3", 3));
            stmtPatternLife.Dispose();

            // pattern
            AUDITLOG.Info("*** Pattern: ");
            EPStatement stmtPattern = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('pattern') select a.IntPrimitive as val0 from pattern [a=SupportBean -> b=SupportBean_ST0]");

            stmtPattern.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean_ST0("E2", 2));
            Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("val0"));
            stmtPattern.Dispose();

            // view
            AUDITLOG.Info("*** View: ");
            EPStatement stmtView = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('view') select IntPrimitive from SupportBean#lastevent");

            stmtView.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("IntPrimitive"));
            stmtView.Dispose();

            EPStatement stmtGroupedView = epService.EPAdministrator.CreateEPL("@Audit Select * From SupportBean#groupwin(TheString)#length(2)");

            stmtGroupedView.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            listener.Reset();
            stmtGroupedView.Dispose();

            EPStatement stmtGroupedWIntersectionView = epService.EPAdministrator.CreateEPL("@Audit Select * From SupportBean#groupwin(TheString)#length(2)#unique(IntPrimitive)");

            stmtGroupedWIntersectionView.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            listener.Reset();
            stmtGroupedWIntersectionView.Dispose();

            // expression
            AUDITLOG.Info("*** Expression: ");
            EPStatement stmtExpr = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('expression') select IntPrimitive*100 as val0, sum(IntPrimitive) as val1 from SupportBean");

            stmtExpr.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            Assert.AreEqual(5000, listener.AssertOneGetNew().Get("val0"));
            Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("val1"));
            stmtExpr.Dispose();

            // expression-detail
            AUDITLOG.Info("*** Expression-Nested: ");
            EPStatement stmtExprNested = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('expression-nested') select ('A'||TheString)||'X' as val0 from SupportBean");

            stmtExprNested.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            Assert.AreEqual("AE1X", listener.AssertOneGetNewAndReset().Get("val0"));
            stmtExprNested.Dispose();

            // property
            AUDITLOG.Info("*** Property: ");
            EPStatement stmtProp = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('property') select IntPrimitive from SupportBean");

            stmtProp.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 50));
            Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("IntPrimitive"));
            stmtProp.Dispose();

            // with aggregation
            epService.EPAdministrator.CreateEPL("@Audit @Name ('create') create window MyWindow#keepall as SupportBean");
            string      eplWithAgg  = "@Audit @Name('S0') on SupportBean as sel select count(*) from MyWindow as win having count(*)=3 order by win.IntPrimitive";
            EPStatement stmtWithAgg = epService.EPAdministrator.CreateEPL(eplWithAgg);

            stmtWithAgg.Dispose();

            // data flow
            EPStatement stmtDataflow = epService.EPAdministrator.CreateEPL("@Audit @Name('df') create dataflow MyFlow " +
                                                                           "EventBusSource -> a<SupportBean> {filter:TheString like 'I%'} " +
                                                                           "Filter(a) -> b {filter: true}" +
                                                                           "LogSink(b) {log:false}");
            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyFlow");

            df.Start();
            epService.EPRuntime.SendEvent(new SupportBean("I1", 1));
            df.Cancel();

            // context partitions
            epService.EPAdministrator.CreateEPL("create context WhenEventArrives " +
                                                "initiated by SupportBean_ST0 as st0 " +
                                                "terminated by SupportBean_ST1(id=st0.id)");
            epService.EPAdministrator.CreateEPL("@Audit('ContextPartition') context WhenEventArrives select * from SupportBean");
            epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0));
            epService.EPRuntime.SendEvent(new SupportBean_ST1("E1", 0));
            stmtDataflow.Dispose();

            // table
            AUDITLOG.Info("*** Table And Insert-Into and Into-table: ");
            EPStatement stmtTable       = epService.EPAdministrator.CreateEPL("@Name('create-table') @Audit create table TableOne(c0 string primary key, cnt count(*))");
            EPStatement stmtIntoTable   = epService.EPAdministrator.CreateEPL("@Name('into-table') @Audit into table TableOne select count(*) as cnt from SupportBean group by TheString");
            EPStatement stmtAccessTable = epService.EPAdministrator.CreateEPL("@Name('access-table') @Audit select TableOne[id].cnt from SupportBean_ST0");

            stmtAccessTable.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));
            epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0));
            stmtTable.Dispose();
            stmtIntoTable.Dispose();
            stmtAccessTable.Dispose();
        }
 public MyJoiningRunnable(EPDataFlowInstance instance)
 {
     this.instance = instance;
 }
Exemple #18
0
        public void TestBlockingRunJoin()
        {
            // declare
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> s<SomeType> {}" +
                "DefaultSupportCaptureOp(s) {}");

            // instantiate
            var latch  = new CountDownLatch(1);
            var source = new DefaultSupportSourceOp(
                new Object[]
            {
                latch, new Object[]
                {
                    1
                }
            });
            var future = new DefaultSupportCaptureOp(1);
            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(source, future));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

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

            var joiningRunnable = new MyJoiningRunnable(dfOne);
            var joiningThread   = new Thread(joiningRunnable.Run);

            var unlatchingThread = new Thread(
                () =>
            {
                try
                {
                    while (dfOne.State != EPDataFlowState.RUNNING)
                    {
                    }

                    Thread.Sleep(1000);
                    latch.CountDown();
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.StackTrace);
                }
            });

            joiningThread.Start();
            unlatchingThread.Start();
            dfOne.Run();

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

            joiningThread.Join();
            unlatchingThread.Join();
            long deltaJoin = joiningRunnable.End - joiningRunnable.Start;

            Assert.That(deltaJoin, Is.GreaterThanOrEqualTo(500));
        }
        private void RunAssertionStatementFilter(EPServiceProvider epService)
        {
            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
            EPStatement 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(SupportContainer.Instance.LockManager());
            var options   = new EPDataFlowInstantiationOptions();
            var myFilter  = new MyFilter();

            options.ParameterProvider(new DefaultSupportGraphParamProvider(Collections.SingletonDataMap("statementFilter", myFilter)));
            options.OperatorProvider(new DefaultSupportGraphOpProvider(captureOp));
            EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            df.Start();

            epService.EPRuntime.SendEvent(new SupportBean_B("B1"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(
                epService.Container, 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(
                epService.Container, captureOp.GetCurrentAndReset()[0], "TheString,IntPrimitive".Split(','), new object[] { "E1", 1 });

            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("select id from SupportBean_A");

            epService.EPRuntime.SendEvent(new SupportBean_A("A1"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(
                epService.Container, captureOp.GetCurrentAndReset()[0], "id".Split(','), new object[] { "A1" });

            stmtTwo.Stop();

            epService.EPRuntime.SendEvent(new SupportBean_A("A2"));
            Thread.Sleep(50);
            Assert.AreEqual(0, captureOp.Current.Length);

            stmtTwo.Start();

            epService.EPRuntime.SendEvent(new SupportBean_A("A3"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(
                epService.Container, captureOp.GetCurrentAndReset()[0], "id".Split(','), new object[] { "A3" });

            epService.EPRuntime.SendEvent(new SupportBean_B("B2"));
            captureOp.WaitForInvocation(200, 1);
            EPAssertionUtil.AssertProps(
                epService.Container, 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.Current.Length);

            epService.EPAdministrator.DestroyAllStatements();
        }