private void TrySend(int numThreads, int numRepeats, EPStatement[] stmt) { BasicExecutorService threadPool = Executors.NewFixedThreadPool(numThreads); Future <bool>[] future = new Future <bool> [numThreads]; for (int i = 0; i < numThreads; i++) { ICallable <bool> callable = new StmtIterateCallable(i, _engine, stmt, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(5)); for (int i = 0; i < numThreads; i++) { Assert.IsTrue(future[i].GetValueOrDefault()); } }
// Start Count threads // each thread performs X loops // each loop gets a unique number Y from a shared object and performs setVersion in the synchronized block // then the thread performs reads, write and read of shared variables, writing the number Y // ==> the reads should not see any higher number (unless watemarks reached) // ==> reads should produce the exact same result unless setVersion called private void TryMT(int numThreads, int numLoops, int numVariables) { var coord = new VariableVersionCoord(_service); int ord = 'A'; // create variables var variables = new String[numVariables]; for (int i = 0; i < numVariables; i++) { variables[i] = String.Format("{0}", ((char)(ord + i))); _service.CreateNewVariable(null, variables[i], typeof(int).FullName, false, false, false, 0, null); _service.AllocateVariableState(variables[i], EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID, null, false); } BasicExecutorService threadPool = Executors.NewFixedThreadPool(numThreads); var callables = new VariableServiceCallable[numThreads]; var future = new Future <bool> [numThreads]; for (int i = 0; i < numThreads; i++) { callables[i] = new VariableServiceCallable(variables, _service, coord, numLoops); future[i] = threadPool.Submit(callables[i]); } threadPool.Shutdown(); threadPool.AwaitTermination(new TimeSpan(0, 0, 10)); for (int i = 0; i < numThreads; i++) { Assert.IsTrue(future[i].GetValueOrDefault()); } //Console.Out.WriteLine(service.ToString()); // Verify results per thread for (int i = 0; i < callables.Length; i++) { int[][] result = callables[i].Results; int[] marks = callables[i].Marks; } }
private void RunAssertion() { _idCounter = new AtomicLong(0); _executorService = Executors.NewCachedThreadPool(); _noActionUpdateListener = new NoActionUpdateListener(); var epConfig = new Configuration(SupportContainer.Instance); epConfig.AddEventType <SupportBean>(); epConfig.EngineDefaults.Threading.InsertIntoDispatchLocking = ConfigurationEngineDefaults.ThreadingConfig.Locking.SUSPEND; EPServiceProvider epServiceProvider = EPServiceProviderManager.GetProvider( SupportContainer.Instance, this.GetType().Name, epConfig); epServiceProvider.Initialize(); _epAdministrator = epServiceProvider.EPAdministrator; _epRuntime = epServiceProvider.EPRuntime; _epAdministrator.StartAllStatements(); string epl = "insert into Stream1 select count(*) as cnt from SupportBean#time(7 sec)"; CreateEPL(epl, _noActionUpdateListener.Update); epl = epl + " output every 10 seconds"; CreateEPL(epl, _noActionUpdateListener.Update); var sendTickEventRunnable = new SendEventRunnable(10000, SendEvent); Start(sendTickEventRunnable, 4); // Adjust here for long-running test Thread.Sleep(3000); _executorService.Shutdown(); _executorService.AwaitTermination(1, TimeUnit.SECONDS); }