Ejemplo n.º 1
0
        /**
         * @param threadContext
         * @return
         *
         */
        private IterationListener InitRun(NetMeterContext threadContext)
        {
            threadContext.SetVariables(threadVars);
            threadContext.SetThreadNum(getThreadNum());
            threadContext.GetVariables().Add(LAST_SAMPLE_OK, TRUE);
            threadContext.SetThread(this);
            threadContext.SetThreadGroup(threadGroup);
            threadContext.SetEngine(engine);
            testTree.Traverse(compiler);
            // log.info("Thread started: " + Thread.currentThread().getName());

            /*
             * Setting SamplingStarted before the contollers are initialised allows
             * them to access the running values of functions and variables (however
             * it does not seem to help with the listeners)
             */
            if (startEarlier)
            {
                threadContext.SetSamplingStarted(true);
            }
            controller.Initialize();
            IterationListener iterationListener = new IterationListener();

            controller.addIterationListener(iterationListener);
            if (!startEarlier)
            {
                threadContext.SetSamplingStarted(true);
            }
            ThreadStarted();
            return(iterationListener);
        }
Ejemplo n.º 2
0
        public void Start(int groupCount, ListenerNotifier notifier, OrderedHashTree threadGroupTree, StandardEngine engine)
        {
            int threadNumber = GetThreadsNumber();
            // TODO : log

            Int32           now     = System.DateTime.Now.Millisecond;
            NetMeterContext context = NetMeterContextManager.GetContext();

            for (int i = 0; running && i < threadNumber; i++)
            {
                NetMeterThread nmThread  = CreateThread(groupCount, notifier, threadGroupTree, engine, i, context);
                Thread         newThread = new Thread(nmThread.Run);
                RegisterStartedThread(nmThread, newThread);
                newThread.Start();
            }

            // TODO : log
        }
Ejemplo n.º 3
0
        private NetMeterThread CreateThread(int groupCount, ListenerNotifier notifier, OrderedHashTree threadGroupTree,
                                            StandardEngine engine, int i, NetMeterContext context)
        {
            String         groupName = GetName();
            NetMeterThread nmThread  = new NetMeterThread(CloneTree(threadGroupTree), this, notifier);

            nmThread.SetThreadNum(i);
            nmThread.SetThreadGroup(this);
            nmThread.SetInitialContext(context);
            String threadName = groupName + " " + (groupCount) + "-" + (i + 1);

            nmThread.SetThreadName(threadName);
            nmThread.SetEngine(engine);
            nmThread.SetOnErrorStopTest(GetOnErrorStopTest());
            nmThread.SetOnErrorStopTestNow(GetOnErrorStopTestNow());
            nmThread.SetOnErrorStopThread(GetOnErrorStopThread());
            nmThread.SetOnErrorStartNextLoop(GetOnErrorStartNextLoop());
            return(nmThread);
        }
Ejemplo n.º 4
0
        /**
         * Trigger end of loop on parent controllers up to Thread Group
         * @param sam Sampler Base sampler
         * @param threadContext
         */
        private void TriggerEndOfLoopOnParentControllers(TestAgent sam, NetMeterContext threadContext)
        {
            // Find parent controllers of current sampler
            //FindTestElementsUpToRootTraverser pathToRootTraverser=null;
            //TransactionSampler transactionSampler = null;
            //if(sam is TransactionSampler)
            //{
            //    transactionSampler = (TransactionSampler) sam;
            //    pathToRootTraverser = new FindTestElementsUpToRootTraverser((transactionSampler).getTransactionController());
            //}
            //else
            //{
            //    pathToRootTraverser = new FindTestElementsUpToRootTraverser(sam);
            //}
            //testTree.Traverse(pathToRootTraverser);
            //List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();

            //// Trigger end of loop condition on all parent controllers of current sampler
            //foreach (Controller cont in controllersToReinit)
            //{
            //    Controller parentController = cont;
            //    if (parentController is AbstractThreadGroup)
            //    {
            //        AbstractThreadGroup tg = (AbstractThreadGroup)parentController;
            //        tg.StartNextLoop();
            //    }
            //    else
            //    {
            //        parentController.triggerEndOfLoop();
            //    }
            //}
            //if(transactionSampler!=null)
            //{
            //    Process_sampler(transactionSampler, null, threadContext);
            //}
        }
Ejemplo n.º 5
0
 public static void ReplaceContext(NetMeterContext context)
 {
     threadContext.Dispose();
     threadContext.Value = context;
 }
Ejemplo n.º 6
0
        /**
         * Trigger end of loop on parent controllers up to Thread Group
         * @param sam Sampler Base sampler
         * @param threadContext
         */
        private void TriggerEndOfLoopOnParentControllers(TestAgent sam, NetMeterContext threadContext)
        {
            // Find parent controllers of current sampler
            //FindTestElementsUpToRootTraverser pathToRootTraverser=null;
            //TransactionSampler transactionSampler = null;
            //if(sam is TransactionSampler)
            //{
            //    transactionSampler = (TransactionSampler) sam;
            //    pathToRootTraverser = new FindTestElementsUpToRootTraverser((transactionSampler).getTransactionController());
            //}
            //else
            //{
            //    pathToRootTraverser = new FindTestElementsUpToRootTraverser(sam);
            //}
            //testTree.Traverse(pathToRootTraverser);
            //List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();

            //// Trigger end of loop condition on all parent controllers of current sampler
            //foreach (Controller cont in controllersToReinit)
            //{
            //    Controller parentController = cont;
            //    if (parentController is AbstractThreadGroup)
            //    {
            //        AbstractThreadGroup tg = (AbstractThreadGroup)parentController;
            //        tg.StartNextLoop();
            //    }
            //    else
            //    {
            //        parentController.triggerEndOfLoop();
            //    }
            //}
            //if(transactionSampler!=null)
            //{
            //    Process_sampler(transactionSampler, null, threadContext);
            //}
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
 /**
  * @param threadContext
  * @return
  *
  */
 private IterationListener InitRun(NetMeterContext threadContext)
 {
     threadContext.SetVariables(threadVars);
     threadContext.SetThreadNum(getThreadNum());
     threadContext.GetVariables().Add(LAST_SAMPLE_OK, TRUE);
     threadContext.SetThread(this);
     threadContext.SetThreadGroup(threadGroup);
     threadContext.SetEngine(engine);
     testTree.Traverse(compiler);
     // log.info("Thread started: " + Thread.currentThread().getName());
     /*
      * Setting SamplingStarted before the contollers are initialised allows
      * them to access the running values of functions and variables (however
      * it does not seem to help with the listeners)
      */
     if (startEarlier)
     {
         threadContext.SetSamplingStarted(true);
     }
     controller.Initialize();
     IterationListener iterationListener = new IterationListener();
     controller.addIterationListener(iterationListener);
     if (!startEarlier)
     {
         threadContext.SetSamplingStarted(true);
     }
     ThreadStarted();
     return iterationListener;
 }
Ejemplo n.º 9
0
 public void SetInitialContext(NetMeterContext context)
 {
     threadVars.PutAll(context.GetVariables());
 }
Ejemplo n.º 10
0
 public void SetInitialContext(NetMeterContext context)
 {
     threadVars.PutAll(context.GetVariables());
 }
Ejemplo n.º 11
0
 public static void ReplaceContext(NetMeterContext context)
 {
     threadContext.Dispose();
     threadContext.Value = context;
 }
Ejemplo n.º 12
0
 private void CheckTestAssertions(List <Assertion> assertions, ExecuteResult parent, NetMeterContext threadContext)
 {
     foreach (Assertion assertion in assertions)
     {
         //TestBeanHelper.prepare((TestElement) assertion);
         if (assertion is AbstractScopedAssertion)
         {
             AbstractScopedAssertion scopedAssertion = (AbstractScopedAssertion)assertion;
             String scope = scopedAssertion.fetchScope();
             if (scopedAssertion.isScopeParent(scope) || scopedAssertion.isScopeAll(scope) || scopedAssertion.isScopeVariable(scope))
             {
                 ProcessTestAssertion(parent, assertion);
             }
             if (scopedAssertion.isScopeChildren(scope) || scopedAssertion.isScopeAll(scope))
             {
                 ExecuteResult[] children   = parent.getSubResults();
                 Boolean         childError = false;
                 foreach (ExecuteResult child in children)
                 {
                     ProcessTestAssertion(child, assertion);
                     if (!child.Success)
                     {
                         childError = true;
                     }
                 }
                 // If parent is OK, but child failed, add a message and flag the parent as failed
                 if (childError && parent.Success)
                 {
                     AssertionResult assertionResult = new AssertionResult(((AbstractTestElement)assertion).GetName());
                     assertionResult.setResultForFailure("One or more sub-samples failed");
                     parent.addAssertionResult(assertionResult);
                     parent.Success = false;
                 }
             }
         }
         else
         {
             ProcessTestAssertion(parent, assertion);
         }
     }
     threadContext.GetVariables().Add(LAST_SAMPLE_OK, parent.Success.ToString());
 }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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)
                }
            }
        }
Ejemplo n.º 15
0
 /**
  * @return Returns the threadContext.
  */
 public NetMeterContext getThreadContext()
 {
     if (threadContext == null) {
         /*
          * Only samplers have the thread context set up by JMeterThread at
          * present, so suppress the warning for now
          */
         // log.warn("ThreadContext was not set up - should only happen in
         // JUnit testing..."
         // ,new Throwable("Debug"));
         threadContext = NetMeterContextManager.GetContext();
     }
     return threadContext;
 }
Ejemplo n.º 16
0
 private void CheckTestAssertions(List<Assertion> assertions, ExecuteResult parent, NetMeterContext threadContext)
 {
     foreach (Assertion assertion in assertions)
     {
         //TestBeanHelper.prepare((TestElement) assertion);
         if (assertion is AbstractScopedAssertion)
         {
             AbstractScopedAssertion scopedAssertion = (AbstractScopedAssertion) assertion;
             String scope = scopedAssertion.fetchScope();
             if (scopedAssertion.isScopeParent(scope) || scopedAssertion.isScopeAll(scope) || scopedAssertion.isScopeVariable(scope))
             {
                 ProcessTestAssertion(parent, assertion);
             }
             if (scopedAssertion.isScopeChildren(scope) || scopedAssertion.isScopeAll(scope))
             {
                 ExecuteResult[] children = parent.getSubResults();
                 Boolean childError = false;
                 foreach (ExecuteResult child in children)
                 {
                     ProcessTestAssertion(child, assertion);
                     if (!child.Success)
                     {
                         childError = true;
                     }
                 }
                 // If parent is OK, but child failed, add a message and flag the parent as failed
                 if (childError && parent.Success)
                 {
                     AssertionResult assertionResult = new AssertionResult(((AbstractTestElement)assertion).GetName());
                     assertionResult.setResultForFailure("One or more sub-samples failed");
                     parent.addAssertionResult(assertionResult);
                     parent.Success = false;
                 }
             }
         }
         else
         {
             ProcessTestAssertion(parent, assertion);
         }
     }
     threadContext.GetVariables().Add(LAST_SAMPLE_OK, parent.Success.ToString());
 }
Ejemplo n.º 17
0
 /**
  * @param inthreadContext
  *            The threadContext to set.
  */
 public void SetThreadContext(NetMeterContext inthreadContext)
 {
     if (threadContext != null)
     {
         if (inthreadContext != threadContext)
         {
             throw new Exception("Attempting to reset the thread context");
         }
     }
     this.threadContext = inthreadContext;
 }
Ejemplo n.º 18
0
 private NetMeterThread CreateThread(int groupCount, ListenerNotifier notifier, OrderedHashTree threadGroupTree,
         StandardEngine engine, int i, NetMeterContext context)
 {
     String groupName = GetName();
     NetMeterThread nmThread = new NetMeterThread(CloneTree(threadGroupTree), this, notifier);
     nmThread.SetThreadNum(i);
     nmThread.SetThreadGroup(this);
     nmThread.SetInitialContext(context);
     String threadName = groupName + " " + (groupCount) + "-" + (i + 1);
     nmThread.SetThreadName(threadName);
     nmThread.SetEngine(engine);
     nmThread.SetOnErrorStopTest(GetOnErrorStopTest());
     nmThread.SetOnErrorStopTestNow(GetOnErrorStopTestNow());
     nmThread.SetOnErrorStopThread(GetOnErrorStopThread());
     nmThread.SetOnErrorStartNextLoop(GetOnErrorStartNextLoop());
     return nmThread;
 }