public void Run(Object obj) { running = false; if (now) { StandardEngine engine = (StandardEngine)obj; engine.TellThreadGroupsToStop(); Thread.Sleep(10 * engine.CountActiveThreads()); Boolean stopped = engine.VerifyThreadsStopped(); if (!stopped) { // we totally failed to stop the test // TODO should we call test listeners? That might hang too ... log.Fatal(NetMeterUtils.getResString("stopping_test_failed")); if (SYSTEM_EXIT_ON_STOP_FAIL) { // default is true log.Fatal("Exitting"); System.Console.WriteLine("Fatal error, could not stop test, exitting"); } else { System.Console.WriteLine("Fatal error, could not stop test"); } } // else will be done by threadFinished() } else { engine.StopAllThreadGroups(); } }
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 }
public StandardEngine(String host) { this.host = host; // Hack to allow external control engine = this; }
public abstract void Start(int groupCount, ListenerNotifier notifier, OrderedHashTree threadGroupTree, StandardEngine engine);
public void SetEngine(StandardEngine engine) { this.engine = engine; }
// 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(); } }
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; }