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(); }
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(); }
public void TestBlockingMultipleRunnable() { // declare _epService.EPAdministrator.CreateEPL( "create dataflow MyDataFlowOne " + "SourceOne -> outstream<SomeType> {}" + "SourceTwo -> outstream<SomeType> {}" + "Future(outstream) {}"); // instantiate var latchOne = new CountDownLatch(1); var latchTwo = new CountDownLatch(1); IDictionary <String, Object> ops = new Dictionary <String, Object>(); ops.Put( "SourceOne", new DefaultSupportSourceOp( new Object[] { latchOne, new Object[] { 1 } })); ops.Put( "SourceTwo", new DefaultSupportSourceOp( new Object[] { latchTwo, new Object[] { 1 } })); var future = new DefaultSupportCaptureOp(2); ops["Future"] = future; EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops)); EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); try { dfOne.Run(); Assert.Fail(); } catch (UnsupportedOperationException ex) { Assert.AreEqual( "The data flow 'MyDataFlowOne' has zero or multiple sources and requires the use of the start method instead", ex.Message); } latchTwo.CountDown(); dfOne.Start(); latchOne.CountDown(); dfOne.Join(); Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State); Assert.AreEqual(2, future.GetAndReset().Count); }
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(); }
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(); }
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); }
private void RunAssertionNonBlockingCancel(EPServiceProvider epService) { // declare epService.EPAdministrator.CreateEPL("create schema SomeType ()"); epService.EPAdministrator.CreateEPL( "create dataflow MyDataFlowOne " + "SourceOne -> outstream<SomeType> {}" + "OutputOp(outstream) {}"); // instantiate var latchOne = new CountDownLatch(1); var ops = new Dictionary<string, object>(); ops.Put("SourceOne", new DefaultSupportSourceOp(new object[] {latchOne, new object[] {1}})); var output = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager()); ops.Put("OutputOp", output); var options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops)); var 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); epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionAllTypes(String typeName, Object[] events) { String graph = "create dataflow MySelect\n" + "DefaultSupportSourceOp -> instream.with.dot<" + typeName + ">{}\n" + "Filter(instream.with.dot) -> outstream.dot {filter: myString = 'two'}\n" + "DefaultSupportCaptureOp(outstream.dot) {}"; EPStatement stmtGraph = _epService.EPAdministrator.CreateEPL(graph); DefaultSupportSourceOp source = new DefaultSupportSourceOp(events); DefaultSupportCaptureOp capture = new DefaultSupportCaptureOp(2); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions(); options.SetDataFlowInstanceUserObject("myuserobject"); options.SetDataFlowInstanceId("myinstanceid"); options.OperatorProvider(new DefaultSupportGraphOpProvider(source, capture)); EPDataFlowInstance instance = _epService.EPRuntime.DataFlowRuntime.Instantiate("MySelect", options); Assert.AreEqual("myuserobject", instance.UserObject); Assert.AreEqual("myinstanceid", instance.InstanceId); instance.Run(); Object[] result = capture.GetAndReset()[0].ToArray(); Assert.AreEqual(1, result.Length); Assert.AreSame(events[1], result[0]); instance.Cancel(); stmtGraph.Dispose(); }
private void 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(); }
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(); }
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> { name: 'SourceOne' }" + "DefaultSupportSourceOp -> outstream<SomeType> { name: 'SourceTwo' }" + "DefaultSupportCaptureOp(outstream) {}", path); // instantiate var latchOne = new CountDownLatch(1); var latchTwo = new CountDownLatch(1); IDictionary<string, object> ops = new Dictionary<string, object>(); ops.Put( "SourceOne", new DefaultSupportSourceOp( new object[] { latchOne, new object[] {1} })); ops.Put( "SourceTwo", new DefaultSupportSourceOp( new object[] { latchTwo, new object[] {1} })); var future = new DefaultSupportCaptureOp(2, env.Container.LockManager()); ops.Put("DefaultSupportCaptureOp", future); var options = new EPDataFlowInstantiationOptions().WithOperatorProvider( new DefaultSupportGraphOpProviderByOpName(ops)); var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options); dfOne.Start(); Sleep(50); Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State); latchOne.CountDown(); Sleep(200); Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State); latchTwo.CountDown(); try { dfOne.Join(); } catch (ThreadInterruptedException e) { throw new EPException(e); } Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State); Assert.AreEqual(2, future.GetAndReset().Count); env.UndeployAll(); }
public void TestBlockingCancel() { // 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); var cancellingThread = new Thread( () => { try { Thread.Sleep(300); dfOne.Cancel(); } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }); cancellingThread.Start(); try { dfOne.Run(); Assert.Fail(); } catch (EPDataFlowCancellationException ex) { Assert.AreEqual("Data flow 'MyDataFlowOne' execution was cancelled", ex.Message); } Assert.AreEqual(EPDataFlowState.CANCELLED, dfOne.State); Assert.AreEqual(0, output.GetAndReset().Count); }
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(); }
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(); }
public override void Run(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddImport(typeof(DefaultSupportCaptureOp).Name); string[] fields = "p0,p1".Split(','); epService.EPAdministrator.Configuration.AddEventType("MyOAEventType", fields, new object[] { typeof(string), typeof(int) }); epService.EPAdministrator.CreateEPL("create dataflow MyDataFlow " + "Emitter -> outstream<MyOAEventType> {name:'src1'}" + "DefaultSupportCaptureOp(outstream) {}"); var container = epService.Container; var captureOp = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager()); var options = new EPDataFlowInstantiationOptions(); options.OperatorProvider(new DefaultSupportGraphOpProvider(captureOp)); EPDataFlowInstance instance = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlow", options); EPDataFlowInstanceCaptive captiveStart = instance.StartCaptive(); Assert.AreEqual(0, captiveStart.Runnables.Count); Assert.AreEqual(1, captiveStart.Emitters.Count); Emitter emitter = captiveStart.Emitters.Get("src1"); Assert.AreEqual(EPDataFlowState.RUNNING, instance.State); emitter.Submit(new object[] { "E1", 10 }); EPAssertionUtil.AssertPropsPerRow(container, captureOp.Current, fields, new object[][] { new object[] { "E1", 10 } }); emitter.Submit(new object[] { "E2", 20 }); EPAssertionUtil.AssertPropsPerRow(container, captureOp.Current, fields, new object[][] { new object[] { "E1", 10 }, new object[] { "E2", 20 } }); emitter.SubmitSignal(new EPDataFlowSignalFinalMarkerImpl()); EPAssertionUtil.AssertPropsPerRow(container, captureOp.Current, fields, new Object[0][]); EPAssertionUtil.AssertPropsPerRow(container, captureOp.GetAndReset()[0].ToArray(), fields, new object[][] { new object[] { "E1", 10 }, new object[] { "E2", 20 } }); emitter.Submit(new object[] { "E3", 30 }); EPAssertionUtil.AssertPropsPerRow(container, captureOp.Current, fields, new object[][] { new object[] { "E3", 30 } }); // stays running until cancelled (no transition to complete) Assert.AreEqual(EPDataFlowState.RUNNING, instance.State); instance.Cancel(); Assert.AreEqual(EPDataFlowState.CANCELLED, instance.State); // test doc sample string epl = "create dataflow HelloWorldDataFlow\n" + " create schema SampleSchema(text string),\t// sample type\t\t\n" + "\t\n" + " Emitter -> helloworld.stream<SampleSchema> { name: 'myemitter' }\n" + " LogSink(helloworld.stream) {}"; epService.EPAdministrator.CreateEPL(epl); epService.EPRuntime.DataFlowRuntime.Instantiate("HelloWorldDataFlow"); }
public 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 latchOne = new CountDownLatch(1); IDictionary<string, object> ops = new Dictionary<string, object>(); ops.Put( "DefaultSupportSourceOp", new DefaultSupportSourceOp( new object[] { latchOne, new object[] {1} })); var output = new DefaultSupportCaptureOp(); ops.Put("DefaultSupportCaptureOp", output); var options = new EPDataFlowInstantiationOptions().WithOperatorProvider( new DefaultSupportGraphOpProviderByOpName(ops)); var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options); var cancellingThread = new Thread( () => { try { Thread.Sleep(300); dfOne.Cancel(); } catch (Exception e) { log.Error("Unexpected exception", e); } }); cancellingThread.Name = GetType().Name + "-cancelling"; cancellingThread.Start(); try { dfOne.Run(); Assert.Fail(); } catch (EPDataFlowCancellationException ex) { Assert.AreEqual("Data flow 'MyDataFlowOne' execution was cancelled", ex.Message); } Assert.AreEqual(EPDataFlowState.CANCELLED, dfOne.State); Assert.AreEqual(0, output.GetAndReset().Count); env.UndeployAll(); }
public void TestNonBlockingJoinMultipleRunnable() { // declare _epService.EPAdministrator.CreateEPL( "create dataflow MyDataFlowOne " + "SourceOne -> outstream<SomeType> {}" + "SourceTwo -> outstream<SomeType> {}" + "Future(outstream) {}"); // instantiate var latchOne = new CountDownLatch(1); var latchTwo = new CountDownLatch(1); IDictionary <String, Object> ops = new Dictionary <String, Object>(); ops.Put( "SourceOne", new DefaultSupportSourceOp( new Object[] { latchOne, new Object[] { 1 } })); ops.Put( "SourceTwo", new DefaultSupportSourceOp( new Object[] { latchTwo, new Object[] { 1 } })); var future = new DefaultSupportCaptureOp(2); ops["Future"] = future; EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops)); EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); dfOne.Start(); Thread.Sleep(50); Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State); latchOne.CountDown(); Thread.Sleep(200); Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State); latchTwo.CountDown(); dfOne.Join(); Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State); Assert.AreEqual(2, future.GetAndReset().Count); }
private IList<IList<object>> RunDataFlow(string epl) { var deployment = CompileDeploy(runtime, epl); var outputOp = new DefaultSupportCaptureOp(container.LockManager()); var instance = runtime.DataFlowService.Instantiate( deployment.DeploymentId, "ReadCSV", new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp))); instance.Run(); return outputOp.GetAndReset(); }
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(); }
public void TestReadWritePropsBean() { var configuration = new Configuration(_container); configuration.Common.AddEventType("ExampleMarketDataBeanReadWrite", typeof(ExampleMarketDataBeanReadWrite)); configuration.Common.AddImportNamespace(typeof(FileSourceCSV)); configuration.Common.AddImportNamespace(typeof(DefaultSupportCaptureOp)); _runtime = EPRuntimeProvider.GetRuntime("testExistingTypeNoOptions", configuration); _runtime.Initialize(); var stmt = CompileUtil.CompileDeploy(_runtime, "select * from ExampleMarketDataBeanReadWrite#length(100)").Statements[0]; var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var inputAdapter = new CSVInputAdapter( _runtime, new AdapterInputSource(_container, CSV_FILENAME_ONELINE_TRADE), "ExampleMarketDataBeanReadWrite"); inputAdapter.Start(); Assert.AreEqual(1, listener.GetNewDataList().Count); var eb = listener.GetNewDataList()[0][0]; Assert.IsTrue(typeof(ExampleMarketDataBeanReadWrite) == eb.Underlying.GetType()); Assert.AreEqual(55.5 * 1000, eb.Get("value")); // test graph var graph = "create dataflow ReadCSV " + "FileSource -> mystream<ExampleMarketDataBeanReadWrite> { file: '" + CSV_FILENAME_ONELINE_TRADE + "', hasTitleLine: true }" + "DefaultSupportCaptureOp(mystream) {}"; var deployment = CompileUtil.CompileDeploy(_runtime, graph); var outputOp = new DefaultSupportCaptureOp(); var instance = _runtime.DataFlowService.Instantiate( deployment.DeploymentId, "ReadCSV", new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp))); instance.Run(); var received = outputOp.GetAndReset()[0].ToArray(); Assert.That(received.Length, Is.EqualTo(1)); Assert.That(received[0], Is.InstanceOf <ExampleMarketDataBean>()); Assert.That( ((ExampleMarketDataBeanReadWrite)received[0]).Value, Is.EqualTo(55.5 * 1000.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(); }
private void RunAssertionBlockingMultipleRunnable(EPServiceProvider epService) { // declare epService.EPAdministrator.CreateEPL("create schema SomeType ()"); epService.EPAdministrator.CreateEPL( "create dataflow MyDataFlowOne " + "SourceOne -> outstream<SomeType> {}" + "SourceTwo -> outstream<SomeType> {}" + "Future(outstream) {}"); // instantiate var latchOne = new CountDownLatch(1); var latchTwo = new CountDownLatch(1); var ops = new Dictionary<string, object>(); ops.Put("SourceOne", new DefaultSupportSourceOp(new object[] {latchOne, new object[] {1}})); ops.Put("SourceTwo", new DefaultSupportSourceOp(new object[] {latchTwo, new object[] {1}})); var future = new DefaultSupportCaptureOp(2, SupportContainer.Instance.LockManager()); ops.Put("Future", future); var options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProviderByOpName(ops)); var dfOne = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); try { dfOne.Run(); Assert.Fail(); } catch (UnsupportedOperationException ex) { Assert.AreEqual( "The data flow 'MyDataFlowOne' has zero or multiple sources and requires the use of the start method instead", ex.Message); } latchTwo.CountDown(); dfOne.Start(); latchOne.CountDown(); dfOne.Join(); Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State); Assert.AreEqual(2, future.GetAndReset().Count); epService.EPAdministrator.DestroyAllStatements(); }
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(); }
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(); }
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 } }); }
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); }
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 latchOne = new CountDownLatch(1); IDictionary<string, object> ops = new Dictionary<string, object>(); ops.Put( "DefaultSupportSourceOp", new DefaultSupportSourceOp( new object[] { latchOne, new object[] {1} })); var output = new DefaultSupportCaptureOp(); ops.Put("DefaultSupportCaptureOp", output); var options = new EPDataFlowInstantiationOptions().WithOperatorProvider( new DefaultSupportGraphOpProviderByOpName(ops)); var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options); dfOne.Start(); Assert.AreEqual(EPDataFlowState.RUNNING, dfOne.State); dfOne.Cancel(); latchOne.CountDown(); Sleep(100); Assert.AreEqual(EPDataFlowState.CANCELLED, dfOne.State); Assert.AreEqual(0, output.GetAndReset().Count); env.UndeployAll(); }
private void RunAssertionCSVGraphSchema(EventRepresentationChoice representationEnum) { var fields = "MyString,MyInt,timestamp, MyDouble".SplitCsv(); CompileDeploy( runtime, representationEnum.GetAnnotationText() + " @public @buseventtype create schema MyEvent(MyString string, MyInt int, timestamp long, MyDouble double)"); var graph = "create dataflow ReadCSV " + "FileSource -> mystream<MyEvent> {" + " file: '../../../etc/regression/titleRow.csv'," + " hasHeaderLine: true " + "}" + "DefaultSupportCaptureOp(mystream) {}"; var deployment = CompileDeploy(runtime, graph); var outputOp = new DefaultSupportCaptureOp(); var instance = runtime.DataFlowService.Instantiate( deployment.DeploymentId, "ReadCSV", new EPDataFlowInstantiationOptions().WithOperatorProvider(new DefaultSupportGraphOpProvider(outputOp))); instance.Run(); var received = outputOp.GetAndReset(); Assert.AreEqual(1, received.Count); EPAssertionUtil.AssertPropsPerRow( container, received[0].ToArray(), fields, new object[][] { new object[] { "one", 1, 100L, 1.1 }, new object[] { "three", 3, 300L, 3.3 }, new object[] { "five", 5, 500L, 5.5 } }); Assert.IsTrue(representationEnum.MatchesClass(received[0].ToArray()[0].GetType())); UndeployAll(runtime); }
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); }
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); }