コード例 #1
0
        /**
         * Process the current sampler, handling transaction samplers.
         *
         * @param current sampler
         * @param parent sampler
         * @param threadContext
         * @return SampleResult if a transaction was processed
         */
        private ExecuteResult ProcessTestAgent(TestAgent current, TestAgent parent, NetMeterContext threadContext)
        {
            ExecuteResult transactionResult = null;

            try
            {
                // Check if we have a sampler to sample
                if (current != null)
                {
                    threadContext.SetCurrentSampler(current);
                    // Get the sampler ready to sample
                    ExecutionPackage pack = compiler.ConfigureSampler(current);
                    // runPreProcessors(pack.getPreProcessors());

                    // Hack: save the package for any transaction controllers
                    threadVars.PutObject(PACKAGE_OBJECT, pack);

                    //delay(pack.getTimers());
                    TestAgent sampler = pack.GetSampler();
                    sampler.SetThreadContext(threadContext);
                    // TODO should this set the thread names for all the subsamples?
                    // might be more efficient than fetching the name elsewehere
                    sampler.SetThreadName(threadName);
                    // TestBeanHelper.prepare(sampler);

                    // Perform the actual sample
                    currentSampler = sampler;
                    ExecuteResult result = sampler.Execute(null);
                    currentSampler = null;
                    // TODO: remove this useless Entry parameter

                    // If we got any results, then perform processing on the result
                    if (result != null)
                    {
                        result.SetGroupThreads(threadGroup.GetNumberOfThreads());
                        result.SetAllThreads(NetMeterContextManager.GetNumberOfThreads());
                        result.SetThreadName(threadName);
                        threadContext.SetPreviousResult(result);
                        RunPostProcessors(pack.GetPostProcessors());
                        CheckTestAssertions(pack.GetAssertions(), result, threadContext);
                        // Do not send subsamples to listeners which receive the transaction sample
                        List <ExecutionListener> sampleListeners = GetSampleListeners(pack);
                        NotifyListeners(sampleListeners, result);
                        compiler.Done(pack);

                        // Check if thread or test should be stopped
                        if (result.isStopThread() || (!result.Success && onErrorStopThread))
                        {
                            StopThread();
                        }
                        if (result.isStopTest() || (!result.Success && onErrorStopTest))
                        {
                            StopTest();
                        }
                        if (result.isStopTestNow() || (!result.Success && onErrorStopTestNow))
                        {
                            StopTestNow();
                        }
                        if (result.isStartNextThreadLoop())
                        {
                            threadContext.restartNextLoop = true;
                        }
                    }
                    else
                    {
                        compiler.Done(pack); // Finish up
                    }
                }
                if (scheduler)
                {
                    // checks the scheduler to stop the iteration
                    StopScheduler();
                }
            }
            catch (Exception e)
            {
                if (current != null)
                {
                    log.Error("Error while processing sampler '" + current.GetName() + "' :", e);
                }
                else
                {
                    log.Error("", e);
                }
                StopThread();
            }
            return(transactionResult);
        }
コード例 #2
0
        private static sealed Boolean reversePostProcessors = false; // $NON-NLS-1$

        public void Run()
        {
            // threadContext is not thread-safe, so keep within thread
            NetMeterContext       threadContext     = NetMeterContextManager.GetContext();
            LoopIterationListener iterationListener = null;

            try
            {
                iterationListener = InitRun(threadContext);
                while (running)
                {
                    TestAgent sam = (TestAgent)controller.next();
                    while (running && sam != null)
                    {
                        ProcessTestAgent(sam, null, threadContext);
                        threadContext.CleanAfterExecute();
                        if (onErrorStartNextLoop || threadContext.restartNextLoop)
                        {
                            if (threadContext.restartNextLoop)
                            {
                                TriggerEndOfLoopOnParentControllers(sam, threadContext);
                                sam = null;
                                threadContext.GetVariables().Add(LAST_SAMPLE_OK, TRUE);
                                threadContext.restartNextLoop = false;
                            }
                            else
                            {
                                Boolean lastSampleFailed = !TRUE.Equals(threadContext.GetVariables().Get(LAST_SAMPLE_OK));
                                if (lastSampleFailed)
                                {
//                                  if(log.isDebugEnabled())
//                                    {
//                                      log.debug("StartNextLoop option is on, Last sample failed, starting next loop");
//                                  }
                                    TriggerEndOfLoopOnParentControllers(sam, threadContext);
                                    sam = null;
                                    threadContext.GetVariables().Add(LAST_SAMPLE_OK, TRUE);
                                }
                                else
                                {
                                    sam = (TestAgent)controller.next();
                                }
                            }
                        }
                        else
                        {
                            sam = (TestAgent)controller.next();
                        }
                    }
                    if (controller.isDone())
                    {
                        running = false;
                    }
                }
            }
            // Might be found by contoller.next()
            //catch (NetMeterStopTestException e)
            //{
            //    log.info("Stopping Test: " + e.toString());
            //    stopTest();
            //}
            //catch (JMeterStopTestNowException e)
            //{
            //    log.info("Stopping Test Now: " + e.toString());
            //    stopTestNow();
            //}
            //catch (JMeterStopThreadException e)
            //{
            //    log.info("Stop Thread seen: " + e.toString());
            //}
            catch (Exception ex)
            {
                log.Error("Test failed!", ex);
            }
            //catch (ThreadDeath e)
            //{
            //    throw e; // Must not ignore this one
            //}
            finally
            {
                currentSampler = null; // prevent any further interrupts
                try
                {
                    Monitor.Enter(interruptLock);  // make sure current interrupt is finished, prevent another starting yet
                    threadContext.Clear();
//                    log.info("Thread finished: " + threadName);
                    ThreadFinished(iterationListener);
                    monitor.ThreadFinished(this);           // Tell the monitor we are done
                    NetMeterContextManager.RemoveContext(); // Remove the ThreadLocal entry
                }
                finally
                {
                    Monitor.Exit(interruptLock); // Allow any pending interrupt to complete (OK because currentSampler == null)
                }
            }
        }