Beispiel #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);
        }
Beispiel #2
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());
 }
Beispiel #3
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;
 }
Beispiel #4
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());
 }
Beispiel #5
0
 public void SetInitialContext(NetMeterContext context)
 {
     threadVars.PutAll(context.GetVariables());
 }
Beispiel #6
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)
                }
            }
        }
Beispiel #7
0
 public void SetInitialContext(NetMeterContext context)
 {
     threadVars.PutAll(context.GetVariables());
 }