Exemple #1
0
 public NetMeterThread(HashTree test, NetMeterThreadMonitor monitor, ListenerNotifier note)
 {
     this.monitor = monitor;
     threadVars = new NetMeterVariables();
     testTree = test;
     compiler = new TestCompiler(testTree);
     controller = (Controller) testTree.GetArray()[0];
     SearchByType<TestIterationListener> threadListenerSearcher = new SearchByType<TestIterationListener>();
     test.Traverse(threadListenerSearcher);
     testIterationStartListeners = threadListenerSearcher.GetSearchResults();
     notifier = note;
     running = true;
 }
Exemple #2
0
        private sealed object interruptLock = new object(); // ensure that interrupt cannot overlap with shutdown

        public NetMeterThread(HashTree test, NetMeterThreadMonitor monitor, ListenerNotifier note)
        {
            this.monitor = monitor;
            threadVars   = new NetMeterVariables();
            testTree     = test;
            compiler     = new TestCompiler(testTree);
            controller   = (Controller)testTree.GetArray()[0];
            SearchByType <TestIterationListener> threadListenerSearcher = new SearchByType <TestIterationListener>();

            test.Traverse(threadListenerSearcher);
            testIterationStartListeners = threadListenerSearcher.GetSearchResults();
            notifier = note;
            running  = true;
        }
        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
        }
Exemple #4
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
        }
Exemple #5
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);
        }
 public abstract void Start(int groupCount, ListenerNotifier notifier, OrderedHashTree threadGroupTree, StandardEngine engine);
 public abstract void Start(int groupCount, ListenerNotifier notifier, OrderedHashTree threadGroupTree, StandardEngine engine);
Exemple #8
0
        private void StartThreadGroup(AbstractThreadGroup group, int groupCount, SearchByType<AbstractThreadGroup> searcher, LinkedList<Object> testLevelElements, ListenerNotifier notifier)
        {
            int numThreads = group.GetNumThreads();
            NetMeterContextManager.AddTotalThreads(numThreads);
            Boolean onErrorStopTest = group.GetOnErrorStopTest();
            Boolean onErrorStopTestNow = group.GetOnErrorStopTestNow();
            Boolean onErrorStopThread = group.GetOnErrorStopThread();
            Boolean onErrorStartNextLoop = group.GetOnErrorStartNextLoop();
            String groupName = group.GetName();
            log.Info("Starting " + numThreads + " threads for group " + groupName + ".");

            if (onErrorStopTest) {
                log.Info("Test will stop on error");
            } else if (onErrorStopTestNow) {
                log.Info("Test will stop abruptly on error");
            } else if (onErrorStopThread) {
                log.Info("Thread will stop on error");
            } else if (onErrorStartNextLoop) {
                log.Info("Thread will start next loop on error");
            } else {
                log.Info("Thread will continue on error");
            }
            OrderedHashTree threadGroupTree = (OrderedHashTree) searcher.GetSubTree(group);
            threadGroupTree.Put(group, testLevelElements);

            groups.Add(group);
            group.Start(groupCount, notifier, threadGroupTree, this);
        }
Exemple #9
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);
        }
 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;
 }