Exemplo n.º 1
0
        // Update classloader if necessary
        //private void updateClassLoader()
        //{
        //    updatePath("search_paths",";"); //$NON-NLS-1$//$NON-NLS-2$
        //    updatePath("user.classpath",File.pathSeparator);//$NON-NLS-1$
        //}

        //private void updatePath(String property, String sep)
        //{
        //    String userpath= NetMeterUtils.getPropDefault(property,"");// $NON-NLS-1$
        //    if (userpath.Length <= 0) { return; }
        //    log.Info(property+"="+userpath); //$NON-NLS-1$
        //    StringTokenizer tok = new StringTokenizer(userpath, sep);
        //    while(tok.hasMoreTokens())
        //    {
        //        String path=tok.nextToken();
        //        File f=new File(path);
        //        if (!f.canRead() && !f.isDirectory())
        //        {
        //            log.Warn("Can't read "+path);
        //        }
        //        else
        //        {
        //            log.Info("Adding to classpath: "+path);
        //            try
        //            {
        //                NewDriver.addPath(path);
        //            }
        //            catch (MalformedURLException e)
        //            {
        //                log.Warn("Error adding: "+path+" "+e.getLocalizedMessage());
        //            }
        //        }
        //    }
        //}

        //private void initializeProperties(CLArgsParser parser)
        //{
        //    if (parser.GetArgumentById(PROPFILE_OPT) != null)
        //    {
        //        NetMeterUtils.loadJMeterProperties(parser.GetArgumentById(PROPFILE_OPT).GetArgument());
        //    }
        //    else
        //    {
        //        NetMeterUtils.loadJMeterProperties(NewDriver.getJMeterDir() + File.separator
        //                + "bin" + File.separator // $NON-NLS-1$
        //                + "jmeter.properties");// $NON-NLS-1$
        //    }

        //    if (parser.GetArgumentById(JMLOGFILE_OPT) != null){
        //        String jmlogfile=parser.GetArgumentById(JMLOGFILE_OPT).GetArgument();
        //        jmlogfile = processLAST(jmlogfile, ".log");// $NON-NLS-1$
        //        NetMeterUtils.setProperty(LoggingManager.LOG_FILE,jmlogfile);
        //    }

        //    NetMeterUtils.initLogging();
        //    // Bug 33845 - allow direct override of Home dir
        //    if (parser.GetArgumentById(JMETER_HOME_OPT) == null) {
        //        NetMeterUtils.setJMeterHome(NewDriver.getJMeterDir());
        //    } else {
        //        NetMeterUtils.setJMeterHome(parser.GetArgumentById(JMETER_HOME_OPT).GetArgument());
        //    }

        //    Properties jmeterProps = NetMeterUtils.getJMeterProperties();
        //    remoteProps = new Properties();

        //    // Add local JMeter properties, if the file is found
        //    String userProp = NetMeterUtils.getPropDefault("user.properties",""); //$NON-NLS-1$
        //    if (userProp.length() > 0){ //$NON-NLS-1$
        //        FileInputStream fis=null;
        //        try {
        //            File file = NetMeterUtils.findFile(userProp);
        //            if (file.canRead()){
        //                log.Info("Loading user properties from: "+file.getCanonicalPath());
        //                fis = new FileInputStream(file);
        //                Properties tmp = new Properties();
        //                tmp.load(fis);
        //                jmeterProps.putAll(tmp);
        //                LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
        //            }
        //        }
        //        catch (IOException e)
        //        {
        //            log.Warn("Error loading user property file: " + userProp, e);
        //        }
        //        finally
        //        {
        //            JOrphanUtils.closeQuietly(fis);
        //        }
        //    }

        //    // Add local system properties, if the file is found
        //    String sysProp = NetMeterUtils.getPropDefault("system.properties",""); //$NON-NLS-1$
        //    if (sysProp.length() > 0)
        //    {
        //        FileInputStream fis=null;
        //        try
        //        {
        //            File file = NetMeterUtils.findFile(sysProp);
        //            if (file())
        //            {
        //                log.Info("Loading system properties from: "+file.getCanonicalPath());
        //                fis = new FileInputStream(file);
        //                System.getProperties().load(fis);
        //            }
        //        }
        //        catch (IOException e)
        //        {
        //            log.Warn("Error loading system property file: " + sysProp, e);
        //        } finally {
        //            JOrphanUtils.closeQuietly(fis);
        //        }
        //    }

        //    // Process command line property definitions
        //    // These can potentially occur multiple times

        //    List<CLOption> clOptions = parser.GetArguments();
        //    int size = clOptions.Count;

        //    for (int i = 0; i < size; i++)
        //    {
        //        CLOption option = clOptions[i];
        //        String name = option.GetArgument(0);
        //        String value = option.GetArgument(1);
        //        FileInputStream fis = null;

        //        switch (option.GetDescriptor().GetId())
        //        {

        //        // Should not have any text arguments
        //        case CLOption.TEXT_ARGUMENT:
        //            throw new IllegalArgumentException("Unknown arg: "+option.GetArgument());

        //        case PROPFILE2_OPT: // Bug 33920 - allow multiple props
        //            try
        //            {
        //                fis = new FileInputStream(new File(name));
        //                Properties tmp = new Properties();
        //                tmp.load(fis);
        //                jmeterProps.putAll(tmp);
        //                LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
        //            }
        //            catch (FileNotFoundException e)
        //            {
        //                log.Warn("Can't find additional property file: " + name, e);
        //            }
        //            catch (IOException e)
        //            {
        //                log.Warn("Error loading additional property file: " + name, e);
        //            }
        //            finally
        //            {
        //                JOrphanUtils.closeQuietly(fis);
        //            }
        //            break;
        //        case SYSTEM_PROPFILE:
        //            log.Info("Setting System properties from file: " + name);
        //            try
        //            {
        //                fis = new FileInputStream(new File(name));
        //                System.getProperties().load(fis);
        //            }
        //            catch (IOException e)
        //            {
        //                log.Warn("Cannot find system property file "+e.getLocalizedMessage());
        //            }
        //            finally
        //            {
        //                JOrphanUtils.closeQuietly(fis);
        //            }
        //            break;
        //        case SYSTEM_PROPERTY:
        //            if (value.length() > 0)
        //            { // Set it
        //                log.Info("Setting System property: " + name + "=" + value);
        //                System.getProperties().setProperty(name, value);
        //            }
        //            else
        //            { // Reset it
        //                log.Warn("Removing System property: " + name);
        //                System.getProperties().remove(name);
        //            }
        //            break;
        //        case JMETER_PROPERTY:
        //            if (value.length() > 0) { // Set it
        //                log.Info("Setting JMeter property: " + name + "=" + value);
        //                jmeterProps.setProperty(name, value);
        //            } else { // Reset it
        //                log.Warn("Removing JMeter property: " + name);
        //                jmeterProps.remove(name);
        //            }
        //            break;
        //        case JMETER_GLOBAL_PROP:
        //            if (value.length() > 0) { // Set it
        //                log.Info("Setting Global property: " + name + "=" + value);
        //                remoteProps.setProperty(name, value);
        //            } else {
        //                File propFile = new File(name);
        //                if (propFile.canRead()) {
        //                    log.Info("Setting Global properties from the file " + name);
        //                    try
        //                    {
        //                        fis = new FileInputStream(propFile);
        //                        remoteProps.load(fis);
        //                    }
        //                    catch (FileNotFoundException e)
        //                    {
        //                        log.Warn("Could not find properties file: "+e.Message);
        //                    }
        //                    catch (IOException e)
        //                    {
        //                        log.Warn("Could not load properties file: " + e.Message);
        //                    }
        //                    finally
        //                    {
        //                        JOrphanUtils.closeQuietly(fis);
        //                    }
        //                }
        //            }
        //            break;
        //        case LOGLEVEL:
        //            if (value.Length > 0)
        //            { // Set category
        //                log.Info("LogLevel: " + name + "=" + value);
        //                LoggingManager.setPriority(value, name);
        //            } else { // Set root level
        //                log.Warn("LogLevel: " + name);
        //                LoggingManager.setPriority(name);
        //            }
        //            break;
        //        case REMOTE_STOP:
        //            remoteStop = true;
        //            break;
        //        default:
        //            // ignored
        //            break;
        //        }
        //    }

        //    String sample_variables = (String) jmeterProps.get(SampleEvent.SAMPLE_VARIABLES);
        //    if (sample_variables != null){
        //        remoteProps.put(SampleEvent.SAMPLE_VARIABLES, sample_variables);
        //    }
        //    jmeterProps.put("jmeter.version", NetMeterUtils.getJMeterVersion());
        //}

        /*
         * Checks for LAST or LASTsuffix.
         * Returns the LAST name with .JMX replaced by suffix.
         */
        //private String processLAST(String jmlogfile, String suffix)
        //{
        //    if (USE_LAST_JMX.Equals(jmlogfile) || USE_LAST_JMX.concat(suffix).equals(jmlogfile)){
        //        String last = LoadRecentProject.getRecentFile(0);// most recent
        //        String JMX_SUFFIX = ".JMX"; // $NON-NLS-1$
        //        if (last.ToUpper().EndsWith(JMX_SUFFIX))
        //        {
        //            jmlogfile = last.Substring(0, last.Length - JMX_SUFFIX.Length).concat(suffix);
        //        }
        //    }
        //    return jmlogfile;
        //}

        private void StartTest(String testFile, String logFile, CLOption remoteStart)
        {
            // add a system property so samplers can check to see if JMeter
            // is running in NonGui mode
            //System.setProperty(JMETER_NON_GUI, "true");// $NON-NLS-1$
            NetMeterServer driver = new NetMeterServer();// TODO - why does it create a new instance?

            driver.remoteProps = this.remoteProps;
            driver.remoteStop  = this.remoteStop;
            driver.parent      = this;

            String remote_hosts_string = null;

            if (remoteStart != null)
            {
                remote_hosts_string = remoteStart.GetArgument();
                if (remote_hosts_string == null)
                {
                    remote_hosts_string = "127.0.0.1";
                }
            }
            if (testFile == null)
            {
                throw new Exception("Non-GUI runs require a test plan");
            }
            driver.RunTest(testFile, logFile, remoteStart != null, remote_hosts_string);
        }
Exemplo n.º 2
0
        /**
         * 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;
            }
        }