Ejemplo n.º 1
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.º 2
0
        public void AddNode(Object node, HashTree subTree)
        {
            if (isRemote && typeof(ResultCollector).IsAssignableFrom(node.GetType()))
            {
                try
                {
                    replacer.ReplaceValues((TestElement)node);
                }
                catch (InvalidVariableException e)
                {
                    log.Error("invalid variables", e);
                }
            }
            if (isRemote)
            {
                return;
            }
            if (typeof(TestElement).IsAssignableFrom(node.GetType()))
            {
                try
                {
                    replacer.ReplaceValues((TestElement)node);
                }
                catch (Exception ex)
                {
                    log.Error("invalid variables", e);
                }
            }
            if (typeof(TestPlan).IsAssignableFrom(node.GetType()))
            {
                ((TestPlan)node).prepareForPreCompile(); //A hack to make user-defined variables in the testplan element more dynamic
                Dictionary <String, String> args = ((TestPlan)node).GetUserDefinedVariables();
                replacer.SetUserDefinedVariables(args);
                NetMeterVariables vars = new NetMeterVariables();
                vars.PutAll(args);
                NetMeterContextManager.GetContext().SetVariables(vars);
            }

            if (typeof(Arguments).IsAssignableFrom(node.GetType()))
            {
                ((Arguments)node).setRunningVersion(true);
                Dictionary <String, String> args = ((Arguments)node).GetArgumentsAsMap();
                replacer.AddVariables(args);
                NetMeterContextManager.GetContext().GetVariables().PutAll(args);
            }
        }
Ejemplo n.º 3
0
        public void Run()
        {
            log.Info("Running the test!");
            running = true;

            NetMeterContextManager.StartTest();
            //try
            //{
            //    PreCompiler compiler = new PreCompiler();
            //    test.Traverse(compiler);
            //}
            //catch (Exception ex)
            //{
            //    log.Error(String.Format("Error occurred compiling the tree: {0}", ex.Message));
            //    return; // no point continuing
            //}

            /**
             * Notification of test listeners needs to happen after function
             * replacement, but before setting RunningVersion to true.
             */
            SearchByType <TestStateListener> testListeners = new SearchByType <TestStateListener>(); // TL - S&E

            test.Traverse(testListeners);

            // Merge in any additional test listeners
            // currently only used by the function parser
            testListeners.GetSearchResults().AddRange(testList);
            testList.Clear(); // no longer needed

            //if (!startListenersLater )
            //{
            //    NotifyTestListenersOfStart(testListeners);
            //}
            test.Traverse(new TurnElementsOn());
            //if (startListenersLater)
            //{
            //    NotifyTestListenersOfStart(testListeners);
            //}

            LinkedList <Object> testLevelElements = new LinkedList <Object>(test.list(test.GetArray()[0]));

            RemoveThreadGroups(testLevelElements);

            SearchByType <AbstractThreadGroup> searcher = new SearchByType <AbstractThreadGroup>();

            test.Traverse(searcher);

            TestCompiler.Initialize();

            ListenerNotifier notifier = new ListenerNotifier();

            int groupCount = 0;

            NetMeterContextManager.ClearTotalThreads();

            /*
             * Here's where the test really starts. Run a Full GC now: it's no harm
             * at all (just delays test start by a tiny amount) and hitting one too
             * early in the test can impair results for short tests.
             */
            NetMeterUtils.helpGC();

            NetMeterContextManager.GetContext().SetSamplingStarted(true);
            Boolean mainGroups = running; // still running at this point, i.e. setUp was not cancelled

            while (running)
            {
                foreach (AbstractThreadGroup group in searcher.GetSearchResults())
                {
                    groupCount++;
                    String groupName = group.GetName();
                    log.Info(String.Format("Starting ThreadGroup: {0} : {1}", groupCount, groupName));
                    StartThreadGroup(group, groupCount, searcher, testLevelElements, notifier);
                    if (serialized)
                    {
                        log.Info(String.Format("Waiting for thread group: {0} to finish before starting next group", groupName));
                        group.WaitThreadsStopped();
                    }
                }
            }

            if (groupCount == 0)
            { // No TGs found
                log.Info("No enabled thread groups found");
            }
            else
            {
                if (running)
                {
                    log.Info("All thread groups have been started");
                }
                else
                {
                    log.Info("Test stopped - no more thread groups will be started");
                }
            }

            //wait for all Test Threads To Exit
            WaitThreadsStopped();
            NotifyTestListenersOfEnd(testListeners);
        }