コード例 #1
0
            public void Run(RegressionEnvironment env)
            {
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<SupportBean> {}" +
                    "MySupportBeanOutputOp(outstream) {}" +
                    "SupportGenericOutputOpWPort(outstream) {}");

                var source = new DefaultSupportSourceOp(new object[] {new SupportBean("E1", 1)});
                var outputOne = new MySupportBeanOutputOp();
                var outputTwo = new SupportGenericOutputOpWPort();
                var options =
                    new EPDataFlowInstantiationOptions()
                        .WithOperatorProvider(new DefaultSupportGraphOpProvider(source, outputOne, outputTwo));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);
                dfOne.Run();

                SupportBean.Compare(
                    outputOne.GetAndReset().ToArray(),
                    new [] { "TheString","IntPrimitive" },
                    new[] {
                        new object[] {"E1", 1}
                    });
                var received = outputTwo.GetAndReset();
                SupportBean.Compare(
                    received.First.ToArray(),
                    new [] { "TheString","IntPrimitive" },
                    new[] {
                        new object[] {"E1", 1}
                    });
                EPAssertionUtil.AssertEqualsExactOrder(new int?[] {0}, received.Second.ToArray());

                env.UndeployAll();
            }
コード例 #2
0
        private void RunAssertionBeanType(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport<SupportBean>();
            epService.EPAdministrator.CreateEPL("create schema SupportBean SupportBean");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SupportBean> {}" +
                "MySupportBeanOutputOp(outstream) {}" +
                "SupportGenericOutputOpWPort(outstream) {}");

            var source = new DefaultSupportSourceOp(new object[] {new SupportBean("E1", 1)});
            var outputOne = new MySupportBeanOutputOp();
            var outputTwo = new SupportGenericOutputOpWPort();
            var options = new EPDataFlowInstantiationOptions().OperatorProvider(
                new DefaultSupportGraphOpProvider(source, outputOne, outputTwo));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            dfOne.Run();

            EPAssertionUtil.AssertPropsPerRow(
                epService.Container,
                outputOne.GetAndReset().ToArray(), "TheString,IntPrimitive".Split(','), new[] {new object[] {"E1", 1}});
            var received = outputTwo.GetAndReset();
            EPAssertionUtil.AssertPropsPerRow(
                epService.Container,
                received.First.ToArray(), "TheString,IntPrimitive".Split(','), new[] {new object[] {"E1", 1}});
            EPAssertionUtil.AssertEqualsExactOrder(new[] {0}, received.Second.ToArray());

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #3
0
        private void RunAssertionMapType(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(SupportBean));
            epService.EPAdministrator.CreateEPL("create map schema MyMap (p0 string, p1 int)");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<MyMap> {}" +
                "MyMapOutputOp(outstream) {}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

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

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #4
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();
        }
コード例 #5
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();
        }
コード例 #6
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                    "DefaultSupportCaptureOp(outstream) {}",
                    path);

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

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

                Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
                Assert.AreEqual(0, output.GetAndReset().Count);
                env.UndeployAll();
            }
コード例 #7
0
        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();
        }
コード例 #8
0
        private void RunAssertionNonBlockingJoinSingleRunnable(EPServiceProvider epService)
        {
            // declare
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

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

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

            dfOne.Cancel();
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #9
0
ファイル: EPLDataflowOpFilter.cs プロジェクト: lanicon/nesper
        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();
        }
コード例 #10
0
ファイル: EPLDataflowOpSelect.cs プロジェクト: lanicon/nesper
        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();
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        public void TestBlockingException()
        {
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

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

            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);
        }
コード例 #13
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);
        }
コード例 #14
0
            public void Run(RegressionEnvironment env)
            {
                // declare
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> s<SomeType> {}" +
                    "DefaultSupportCaptureOp(s) {}",
                    path);

                // instantiate
                var latch = new CountDownLatch(1);
                var source = new DefaultSupportSourceOp(
                    new object[] {
                        latch,
                        new object[] {1}
                    });
                var future = new DefaultSupportCaptureOp(1, env.Container.LockManager());
                var options =
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(
                        new DefaultSupportGraphOpProvider(future, source));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);
                Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
                Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);

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

                            Thread.Sleep(100);
                            latch.CountDown();
                        }
                        catch (Exception e) {
                            log.Error("Unexpected exception", e);
                        }
                    });
                unlatchingThread.Name = GetType().Name + "-unlatching";

                // blocking run
                unlatchingThread.Start();
                dfOne.Run();
                Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
                Assert.AreEqual(1, future.GetAndReset()[0].Count);
                Assert.AreEqual(2, source.CurrentCount);
                try {
                    unlatchingThread.Join();
                }
                catch (ThreadInterruptedException e) {
                    throw new EPException(e);
                }

                env.UndeployAll();
            }
コード例 #15
0
        public void TestInvalidJoinRun()
        {
            _epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "BeaconSource -> BeaconStream {iterations : 1}");

            var source = new DefaultSupportSourceOp(
                new Object[]
            {
                5000
            });
            EPDataFlowInstantiationOptions options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(source));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            // invalid join
            try
            {
                dfOne.Join();
                Assert.Fail();
            }
            catch (IllegalStateException ex)
            {
                Assert.AreEqual(
                    "Data flow 'MyDataFlowOne' instance has not been executed, please use join after start or run",
                    ex.Message);
            }

            // cancel
            dfOne.Cancel();

            // invalid run and start
            try
            {
                dfOne.Run();
                Assert.Fail();
            }
            catch (IllegalStateException ex)
            {
                Assert.AreEqual(
                    "Data flow 'MyDataFlowOne' instance has been cancelled and cannot be run or started", ex.Message);
            }

            try
            {
                dfOne.Start();
                Assert.Fail();
            }
            catch (IllegalStateException ex)
            {
                Assert.AreEqual(
                    "Data flow 'MyDataFlowOne' instance has been cancelled and cannot be run or started", ex.Message);
            }

            // cancel again
            dfOne.Cancel();
        }
コード例 #16
0
        private void RunAssertionBlockingRunJoin(EPServiceProvider epService)
        {
            // declare
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            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, SupportContainer.Instance.LockManager());
            var options =
                new EPDataFlowInstantiationOptions().OperatorProvider(
                    new DefaultSupportGraphOpProvider(source, future));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);
            Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
            Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);

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

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

                        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();
            var deltaJoin = joiningRunnable.End - joiningRunnable.Start;
            Assert.IsTrue(deltaJoin >= 500, "deltaJoin=" + deltaJoin);
            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #17
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);
        }
コード例 #18
0
            public void Run(RegressionEnvironment env)
            {
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "BeaconSource -> BeaconStream {iterations : 1}");

                var source = new DefaultSupportSourceOp(new object[] {5000});
                var options =
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(
                        new DefaultSupportGraphOpProvider(source));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);

                // invalid join
                try {
                    dfOne.Join();
                    Assert.Fail();
                }
                catch (IllegalStateException ex) {
                    Assert.AreEqual(
                        "Data flow 'MyDataFlowOne' instance has not been executed, please use join after start or run",
                        ex.Message);
                }
                catch (ThreadInterruptedException ex) {
                    throw new EPException(ex);
                }

                // cancel
                dfOne.Cancel();

                // invalid run and start
                try {
                    dfOne.Run();
                    Assert.Fail();
                }
                catch (IllegalStateException ex) {
                    Assert.AreEqual(
                        "Data flow 'MyDataFlowOne' instance has been cancelled and cannot be run or started",
                        ex.Message);
                }

                try {
                    dfOne.Start();
                    Assert.Fail();
                }
                catch (IllegalStateException ex) {
                    Assert.AreEqual(
                        "Data flow 'MyDataFlowOne' instance has been cancelled and cannot be run or started",
                        ex.Message);
                }

                // cancel again
                dfOne.Cancel();
                env.UndeployAll();
            }
コード例 #19
0
        public void TestRunBlocking()
        {
            // 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(future, source));
            EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

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

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

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

            // blocking run
            unlatchingThread.Start();
            dfOne.Run();
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(1, future.GetAndReset()[0].Count);
            Assert.AreEqual(2, source.GetCurrentCount());
            unlatchingThread.Join();
        }
コード例 #20
0
ファイル: TestFileSinkGraphs.cs プロジェクト: lanicon/nesper
        private void RunAssertion(
            string typeName,
            object[] events,
            bool append)
        {
            // test classpath file
            var tempPath = Path.GetTempPath();
            var tempFile = Path.Combine(tempPath, "out_1.csv").Replace("\\", "/");

            try {
                var graph =
                    "create dataflow WriteCSV " +
                    "DefaultSupportSourceOp -> instream<" + typeName + ">{}" +
                    "FileSink(instream) { " +
                    "file: '" + tempFile + "', " +
                    "append: " + append +
                    "}";
                var stmtGraph = CompileDeploy(runtime, graph).Statements[0];

                var source  = new DefaultSupportSourceOp(events);
                var options = new EPDataFlowInstantiationOptions();
                options.OperatorProvider = new DefaultSupportGraphOpProvider(source);
                var instance = runtime.DataFlowService.Instantiate(stmtGraph.DeploymentId, "WriteCSV", options);
                instance.Run();

                var contents = File.ReadAllLines(tempFile)
                               .Where(_ => !string.IsNullOrEmpty(_))
                               .ToArray();
                var expected = new string[] {
                    "1.1,1,\"one\"",
                    "2.2,2,\"two\""
                };

                CollectionAssert.AreEqual(expected, contents);
                //EPAssertionUtil.AssertEqualsExactOrder(expected, contents);
            }
            finally {
                try {
                    File.Delete(tempFile);
                }
                catch {
                    // ignored
                }
            }


            UndeployAll(runtime);
        }
コード例 #21
0
            public void Run(RegressionEnvironment env)
            {
                // declare
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                    "DefaultSupportCaptureOp(outstream) {}",
                    path);

                // instantiate
                var latch = new CountDownLatch(1);
                var source = new DefaultSupportSourceOp(
                    new object[] {
                        latch,
                        new object[] {1}
                    });
                var future = new DefaultSupportCaptureOp(1, env.Container.LockManager());
                var options =
                    new EPDataFlowInstantiationOptions().WithOperatorProvider(
                        new DefaultSupportGraphOpProvider(source, future));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);
                Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName);
                Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State);

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

                latch.CountDown();
                try {
                    dfOne.Join();
                }
                catch (ThreadInterruptedException e) {
                    throw new EPException(e);
                }

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

                dfOne.Cancel();
                Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
                env.UndeployAll();
            }
コード例 #22
0
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.Configuration.AddImport(typeof(DefaultSupportCaptureOp).Name);
            epService.EPAdministrator.Configuration.AddImport(typeof(DefaultSupportSourceOp).Name);

            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

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

            var source  = new DefaultSupportSourceOp(new object[] { new SupportBean("E1", 1), new SupportBean("E2", 2) });
            var capture = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            var 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);
        }
コード例 #23
0
        public void Run(RegressionEnvironment env)
        {
            env.CompileDeploy(
                "@Name('flow') create dataflow MyGraph " +
                "DefaultSupportSourceOp -> outstream<SupportBean> {} " +
                "DefaultSupportCaptureOp(outstream) {}");
            Assert.AreEqual(StatementType.CREATE_DATAFLOW, env.Statement("flow").GetProperty(StatementProperty.STATEMENTTYPE));
            Assert.AreEqual("MyGraph", env.Statement("flow").GetProperty(StatementProperty.CREATEOBJECTNAME));


            var source = new DefaultSupportSourceOp(new object[] {new SupportBean("E1", 1), new SupportBean("E2", 2)});
            var capture = new DefaultSupportCaptureOp();
            var options = new EPDataFlowInstantiationOptions()
                .WithOperatorProvider(new DefaultSupportGraphOpProvider(source, capture))
                .WithOperatorStatistics(true)
                .WithCpuStatistics(true);

            var instance = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyGraph", options);

            instance.Run();

            var stats = instance.Statistics.OperatorStatistics;
            Assert.AreEqual(2, stats.Count);

            var 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[] {2L}, sourceStat.SubmittedPerPortCount);
            Assert.IsTrue(sourceStat.TimeOverall > 0);
            Assert.AreEqual(sourceStat.TimeOverall, sourceStat.TimePerPort[0]);

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

            env.UndeployAll();
        }
コード例 #24
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create schema SomeType ()", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                    "DefaultSupportCaptureOp(outstream) {}",
                    path);

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

                dfOne.Start();

                var unlatchingThread = new Thread(
                    () => {
                        try {
                            Thread.Sleep(300);
                            latchOne.CountDown();
                        }
                        catch (Exception e) {
                            log.Error("Unexpected exception", e);
                        }
                    });
                unlatchingThread.Name = GetType().Name + "-unlatching";
                unlatchingThread.Start();

                try {
                    dfOne.Join();
                }
                catch (ThreadInterruptedException e) {
                    throw new EPException(e);
                }

                Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
                Assert.AreEqual(0, output.GetAndReset().Count);
                env.UndeployAll();
            }
コード例 #25
0
ファイル: TestTypes.cs プロジェクト: ikvm/nesper
        public void TestMapType()
        {
            _epService.EPAdministrator.Configuration.AddImport(typeof(SupportBean));
            _epService.EPAdministrator.CreateEPL("create map schema MyMap (p0 String, p1 int)");
            _epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " +
                                                 "DefaultSupportSourceOp -> outstream<MyMap> {}" +
                                                 "MyMapOutputOp(outstream) {}" +
                                                 "DefaultSupportCaptureOp(outstream) {}");

            var source    = new DefaultSupportSourceOp(new Object[] { MakeMap("E1", 1) });
            var outputOne = new MyMapOutputOp();
            var outputTwo = new DefaultSupportCaptureOp();
            var options   = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(source, outputOne, outputTwo));
            var dfOne     = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            dfOne.Run();

            EPAssertionUtil.AssertPropsPerRow(outputOne.GetAndReset().ToArray(), "p0,p1".Split(','), new Object[][] { new Object[] { "E1", 1 } });
            EPAssertionUtil.AssertPropsPerRow(outputTwo.GetAndReset()[0].ToArray(), "p0,p1".Split(','), new Object[][] { new Object[] { "E1", 1 } });
        }
コード例 #26
0
        private void RunAssertionNonBlockingException(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

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

            dfOne.Start();
            Thread.Sleep(200);
            Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);
            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #27
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);
        }
コード例 #28
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);
        }
コード例 #29
0
        private void RunAssertionNonBlockingJoinCancel(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create schema SomeType ()");
            epService.EPAdministrator.CreateEPL(
                "create dataflow MyDataFlowOne " +
                "DefaultSupportSourceOp -> outstream<SomeType> {}" +
                "DefaultSupportCaptureOp(outstream) {}");

            var latchOne = new CountDownLatch(1);
            var src = new DefaultSupportSourceOp(new object[] {latchOne});
            var output = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager());
            var options =
                new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(src, output));
            var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options);

            dfOne.Start();

            var cancellingThread = new Thread(
                () =>
                {
                    try
                    {
                        Thread.Sleep(300);
                        dfOne.Cancel();
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e.StackTrace);
                    }
                });
            cancellingThread.Start();
            dfOne.Join();

            Assert.AreEqual(EPDataFlowState.CANCELLED, dfOne.State);
            Assert.AreEqual(0, output.GetAndReset().Count);

            epService.EPAdministrator.DestroyAllStatements();
        }
コード例 #30
0
            public void Run(RegressionEnvironment env)
            {
                var path = new RegressionPath();
                env.CompileDeploy("create map schema MyMap (p0 String, p1 int)", path);
                env.CompileDeploy(
                    "@Name('flow') create dataflow MyDataFlowOne " +
                    "DefaultSupportSourceOp -> outstream<MyMap> {}" +
                    "MyMapOutputOp(outstream) {}" +
                    "DefaultSupportCaptureOp(outstream) {}",
                    path);

                var source = new DefaultSupportSourceOp(new object[] {MakeMap("E1", 1)});
                var outputOne = new MyMapOutputOp();
                var outputTwo = new DefaultSupportCaptureOp(env.Container.LockManager());
                var options =
                    new EPDataFlowInstantiationOptions()
                        .WithOperatorProvider(new DefaultSupportGraphOpProvider(source, outputOne, outputTwo));
                var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options);
                dfOne.Run();

                EPAssertionUtil.AssertPropsPerRow(
                    outputOne.GetAndReset().ToArray(),
                    new[] {"P0", "P1"},
                    new[] {
                        new object[] {"E1", 1}
                    });

                EPAssertionUtil.AssertPropsPerRow(
                    env.Container,
                    outputTwo.GetAndReset()[0].UnwrapIntoArray<object>(),
                    new[] {"P0", "P1"},
                    new[] {
                        new object[] {"E1", 1}
                    });

                env.UndeployAll();
            }