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