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(); } }
private ExecutionEvent(ExecuteResult result, String threadGroup, String hostname, Boolean isTransactionSampleEvent) { String hn = ""; try { hn = Dns.GetHostName(); } catch (SocketException e) { log.Error("Cannot obtain local host name " + e); } HOSTNAME = hn; String vars = NetMeterUtils.getProperty(SAMPLE_VARIABLES); variableNames = vars != null?vars.Split(',') : new String[0]; varCount = variableNames.Length; if (varCount > 0) { log.Info(varCount + " sample_variables have been declared: " + vars); } this.result = result; this.threadGroup = threadGroup; this.hostname = hostname; values = new String[variableNames.Length]; this.isTransaction = isTransactionSampleEvent; }
private void PreloadVariables() { foreach (String prop in PRE_LOAD) { String value = NetMeterUtils.getProperty(prop); if (value != null) { variables.Add(prop, value); } } }
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); }
/** * Takes the command line arguments and uses them to determine how to * startup JMeter. * * Called reflectively by {@link NewDriver#main(String[])} */ public void Start(String[] args) { CLArgsParser parser = new CLArgsParser(args, options); String error = parser.GetErrorString(); if (null != error) { System.Console.WriteLine("Error: " + error); System.Console.WriteLine("Usage"); System.Console.WriteLine(CLUtil.DescribeOptions(options).ToString()); return; } try { //initializeProperties(parser); // Also initialises JMeter logging ///* // * The following is needed for HTTPClient. // * (originally tried doing this in HTTPSampler2, // * but it appears that it was done too late when running in GUI mode) // * Set the commons logging default to Avalon Logkit, if not already defined // */ //if (System.getProperty("org.apache.commons.logging.Log") == null) //{ // $NON-NLS-1$ // System.setProperty("org.apache.commons.logging.Log" // $NON-NLS-1$ // , "org.apache.commons.logging.impl.LogKitLogger"); // $NON-NLS-1$ //} //logProperty("java.version"); //$NON-NLS-1$ //logProperty("java.vm.name"); //$NON-NLS-1$ //logProperty("os.name"); //$NON-NLS-1$ //logProperty("os.arch"); //$NON-NLS-1$ //logProperty("os.version"); //$NON-NLS-1$ //logProperty("file.encoding"); // $NON-NLS-1$ //log.Info("NetMeterHome=" + NetMeterUtils.getJMeterHome()); //logProperty("user.dir"," ="); //$NON-NLS-1$ //log.Info("PWD =" + new File(".").getCanonicalPath());//$NON-NLS-1$ //log.Info("IP: "+NetMeterUtils.getLocalHostIP() // +" Name: "+NetMeterUtils.getLocalHostName() // +" FullName: "+NetMeterUtils.getLocalHostFullName()); //updateClassLoader(); //if (log.IsDebugEnabled) //{ // String jcp = System.getProperty("java.class.path");// $NON-NLS-1$ // String[] bits = jcp.Split(File.pathSeparator); // log.Debug("ClassPath"); // foreach(String bit in bits) // { // log.Debug(bit); // } // log.Debug(jcp); //} // Set some (hopefully!) useful properties Int64 now = DateTime.Now.Ticks; NetMeterUtils.setProperty("START.MS", now.ToString()); // $NON-NLS-1$ DateTime today = DateTime.Now; // so it agrees with above // TODO perhaps should share code with __time() function for this... //NetMeterUtils.setProperty("START.YMD",new SimpleDateFormat("yyyyMMdd").format(today));// $NON-NLS-1$ $NON-NLS-2$ //NetMeterUtils.setProperty("START.HMS",new SimpleDateFormat("HHmmss").format(today));// $NON-NLS-1$ $NON-NLS-2$ if (parser.GetArgumentById(SERVER_OPT) != null) { // Start the server try { ClientEngine.StartClient(); // $NON-NLS-1$ } catch (Exception ex) { System.Console.WriteLine("Server failed to start: " + ex); log.Error("Giving up, as server failed with:", ex); throw ex; } //startOptionalServers(); } else { String testFile = null; CLOption testFileOpt = parser.GetArgumentById(TESTFILE_OPT); if (testFileOpt != null) { testFile = testFileOpt.GetArgument(); if (USE_LAST_JMX.Equals(testFile)) { testFile = LoadRecentProject.getRecentFile(0);// most recent } } CLOption rem = parser.GetArgumentById(REMOTE_OPT_PARAM); if (rem == null) { rem = parser.GetArgumentById(REMOTE_OPT); } CLOption jtl = parser.GetArgumentById(LOGFILE_OPT); String jtlFile = null; //if (jtl != null) //{ // jtlFile=processLAST(jtl.GetArgument(), ".jtl"); // $NON-NLS-1$ //} StartTest(testFile, jtlFile, rem); } } //catch (IllegalUserActionException e) //{ // System.Console.WriteLine(e); // System.Console.WriteLine("Incorrect Usage"); // System.Console.WriteLine(CLUtil.DescribeOptions(options).toString()); //} catch (Exception ex) { log.Fatal("An error occurred: ", ex); System.Console.WriteLine("An error occurred: " + ex.Message); return; } }