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 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(source, future)); var dfOne = env.Runtime.DataFlowService.Instantiate(env.DeploymentId("flow"), "MyDataFlowOne", options); Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName); Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State); var joiningRunnable = new MyJoiningRunnable(dfOne); var joiningThread = new Thread(joiningRunnable.Run); joiningThread.Name = GetType().Name + "-joining"; var unlatchingThread = new Thread( () => { try { while (dfOne.State != EPDataFlowState.RUNNING) { Thread.Sleep(10); } Thread.Sleep(1000); latch.CountDown(); } catch (Exception e) { log.Error("Unexpected exception", e); } }); unlatchingThread.Name = GetType().Name + "-unlatching"; joiningThread.Start(); unlatchingThread.Start(); dfOne.Run(); Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State); Assert.AreEqual(1, future.GetAndReset()[0].Count); Assert.AreEqual(2, source.CurrentCount); try { joiningThread.Join(); unlatchingThread.Join(); } catch (ThreadInterruptedException e) { throw new EPException(e); } var deltaJoin = joiningRunnable.End - joiningRunnable.Start; Assert.IsTrue(deltaJoin >= 500, "deltaJoin=" + deltaJoin); env.UndeployAll(); }
public void TestBlockingRunJoin() { // declare _epService.EPAdministrator.CreateEPL( "create dataflow MyDataFlowOne " + "DefaultSupportSourceOp -> s<SomeType> {}" + "DefaultSupportCaptureOp(s) {}"); // instantiate var latch = new CountDownLatch(1); var source = new DefaultSupportSourceOp( new Object[] { latch, new Object[] { 1 } }); var future = new DefaultSupportCaptureOp(1); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions().OperatorProvider(new DefaultSupportGraphOpProvider(source, future)); EPDataFlowInstance dfOne = _epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); Assert.AreEqual("MyDataFlowOne", dfOne.DataFlowName); Assert.AreEqual(EPDataFlowState.INSTANTIATED, dfOne.State); var joiningRunnable = new MyJoiningRunnable(dfOne); var joiningThread = new Thread(joiningRunnable.Run); var unlatchingThread = new Thread( () => { try { while (dfOne.State != EPDataFlowState.RUNNING) { } Thread.Sleep(1000); latch.CountDown(); } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }); joiningThread.Start(); unlatchingThread.Start(); dfOne.Run(); Assert.AreEqual(EPDataFlowState.COMPLETE, dfOne.State); Assert.AreEqual(1, future.GetAndReset()[0].Count); Assert.AreEqual(2, source.GetCurrentCount()); joiningThread.Join(); unlatchingThread.Join(); long deltaJoin = joiningRunnable.End - joiningRunnable.Start; Assert.That(deltaJoin, Is.GreaterThanOrEqualTo(500)); }