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 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); }
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; }
// run test in batch mode private void RunTest(String testFile, String logFile, Boolean remoteStart, String remote_hosts_string) { FileStream reader = null; try { if (!File.Exists(testFile)) { println("Could not open " + testFile); return; } //FileServer.getFileServer().setBaseForScript(f); reader = new FileStream(testFile, FileMode.Open, FileAccess.Read, FileShare.Read); log.Info("Loading file: " + testFile); HashTree tree = IOService.loadTree(reader); // Deliberate use of deprecated ctor NetMeterTreeModel treeModel = new NetMeterTreeModel(new Object());// Create non-GUI version to avoid headless problems NetMeterTreeNode root = (NetMeterTreeNode)treeModel.getRoot(); treeModel.addSubTree(tree, root); // Hack to resolve ModuleControllers in non GUI mode SearchByType <ReplaceableController> replaceableControllers = new SearchByType <ReplaceableController>(); tree.Traverse(replaceableControllers); List <ReplaceableController> replaceableControllersRes = replaceableControllers.GetSearchResults(); foreach (ReplaceableController controller in replaceableControllersRes) { controller.resolveReplacementSubTree(root); } // Remove the disabled items // For GUI runs this is done in Start.java ConvertSubTree(tree); ResultCollector summer = null; String summariserName = "Summariser";//$NON-NLS-1$ log.Info("Creating summariser <" + summariserName + ">"); println("Creating summariser <" + summariserName + ">"); summer = new ResultCollector(summariserName); if (logFile != null) { ResultCollector logger = new ResultCollector(summer); logger.setFilename(logFile); tree.Add(tree.GetArray()[0], logger); } else { // only add Summariser if it can not be shared with the ResultCollector if (summer != null) { tree.Add(tree.GetArray()[0], summer); } } LinkedList <NetMeterEngine> engines = new LinkedList <NetMeterEngine>(); tree.Put(tree.GetArray()[0], new ListenToTest(parent, (remoteStart && remoteStop) ? engines : null)); println("Created the tree successfully using " + testFile); if (!remoteStart) { NetMeterEngine engine = new StandardEngine(); engine.Configure(tree); Int64 now = DateTime.Now.Ticks; println("Starting the test @ " + DateTime.Now.ToString() + " (" + now + ")"); engine.RunTest(); engines.AddLast(engine); } //else //{ // java.util.StringTokenizer st = new java.util.StringTokenizer(remote_hosts_string, ",");//$NON-NLS-1$ // List<String> failingEngines = new ArrayList<String>(st.countTokens()); // while (st.hasMoreElements()) // { // String el = (String) st.nextElement(); // println("Configuring remote engine for " + el); // log.info("Configuring remote engine for " + el); // JMeterEngine eng = doRemoteInit(el.trim(), tree); // if (null != eng) // { // engines.add(eng); // } // else // { // failingEngines.add(el); // println("Failed to configure "+el); // } // } // if (engines.isEmpty()) // { // println("No remote engines were started."); // return; // } // if(failingEngines.size()>0) { // throw new IllegalArgumentException("The following remote engines could not be configured:"+failingEngines); // } // println("Starting remote engines"); // log.Info("Starting remote engines"); // long now = System.currentTimeMillis(); // println("Starting the test @ "+new Date(now)+" ("+now+")"); // foreach (NetMeterEngine engine in engines) // { // engine.runTest(); // } // println("Remote engines have been started"); // log.Info("Remote engines have been started"); //} StartUdpDdaemon(engines); } catch (Exception e) { System.Console.WriteLine("Error in NonGUIDriver " + e.Message); log.Error("Error in NonGUIDriver", e); } finally { reader.Close(); } }