Example #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);
        }