jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1332640 - in /jmeter/trunk: src/protocol/native/org/apache/jmeter/protocol/system/ src/protocol/native/org/apache/jmeter/protocol/system/gui/ xdocs/
Date Tue, 01 May 2012 13:24:54 GMT
Author: pmouawad
Date: Tue May  1 13:24:53 2012
New Revision: 1332640

URL: http://svn.apache.org/viewvc?rev=1332640&view=rev
Log:
Bug 53172 - OS Process Sampler - allow specification of Environment Variables

Modified:
    jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java
    jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java
    jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java?rev=1332640&r1=1332639&r2=1332640&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java
(original)
+++ jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/NativeCommand.java
Tue May  1 13:24:53 2012
@@ -20,7 +20,9 @@ package org.apache.jmeter.protocol.syste
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Native Command 
@@ -29,13 +31,17 @@ public class NativeCommand {
 
 	private StreamGobbler outputGobbler;
     private final File directory;
+    private final Map<String, String> env;
+    private Map<String, String> executionEnvironment;
 
 	/**
-	 * 
+	 * @param env Environment variables appended to environment
+	 * @param directory File working directory
 	 */
-	public NativeCommand(File directory) {
+	public NativeCommand(File directory, Map<String, String> env) {
 		super();
 		this.directory = directory;
+		this.env = env;
 	}
 
 	/**
@@ -49,6 +55,8 @@ public class NativeCommand {
 		try
 		{
 		    ProcessBuilder procBuild = new ProcessBuilder(arguments);
+		    procBuild.environment().putAll(env);
+		    this.executionEnvironment = Collections.unmodifiableMap(procBuild.environment());
 		    procBuild.directory(directory);
             procBuild.redirectErrorStream(true);
             proc = procBuild.start();
@@ -84,4 +92,11 @@ public class NativeCommand {
 	        return "";
 	    }
 	}
+
+    /**
+     * @return the executionEnvironment
+     */
+    public Map<String, String> getExecutionEnvironment() {
+        return executionEnvironment;
+    }
 }

Modified: jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java?rev=1332640&r1=1332639&r2=1332640&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java
(original)
+++ jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/SystemSampler.java
Tue May  1 13:24:53 2012
@@ -22,8 +22,10 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
@@ -51,6 +53,8 @@ public class SystemSampler extends Abstr
 
     public static final String ARGUMENTS = "SystemSampler.arguments";
     
+    public static final String ENVIRONMENT = "SystemSampler.environment";
+
     public static final String CHECK_RETURN_CODE = "SystemSampler.checkReturnCode";
     
     public static final String EXPECTED_RETURN_CODE = "SystemSampler.expectedReturnCode";
@@ -64,6 +68,7 @@ public class SystemSampler extends Abstr
             Arrays.asList(new String[]{
                     "org.apache.jmeter.config.gui.SimpleConfigGui"}));
 
+
     /**
      * Create a SystemSampler.
      */
@@ -85,6 +90,7 @@ public class SystemSampler extends Abstr
         try {
             String command = getCommand();
             Arguments args = getArguments();
+            Arguments environment = getEnvironmentVariables();
             boolean checkReturnCode = getCheckReturnCode();
             int expectedReturnCode = getExpectedReturnCode();
             
@@ -98,6 +104,11 @@ public class SystemSampler extends Abstr
                 cmdLine.append(cmds.get(i+1));
             }
 
+            Map<String,String> env = new HashMap<String, String>();
+            for (int i=0;i<environment.getArgumentCount();i++) {
+                Argument arg = environment.getArgument(i);
+                env.put(arg.getName(), arg.getPropertyAsString(Argument.VALUE));
+            }
             
             File directory = null;
             if(StringUtils.isEmpty(getDirectory())) {
@@ -111,17 +122,24 @@ public class SystemSampler extends Abstr
                     log.debug("Using configured directory:"+directory.getAbsolutePath());
                 }
             }
-            results.setSamplerData("Working Directory:"+directory.getAbsolutePath()+", Executing:"
+ cmdLine.toString());
+            results.setSamplerData("Working Directory:"+directory.getAbsolutePath()+
+                    ", Environment:"+env+
+                    ", Executing:" + cmdLine.toString());
             
-            NativeCommand nativeCommand = new NativeCommand(directory);
+            NativeCommand nativeCommand = new NativeCommand(directory, env);
             
             String responseData = null;
             try {
                 if(log.isDebugEnabled()) {
-                    log.debug("Will run :"+cmdLine);
+                    log.debug("Will run :"+cmdLine + " using working directory:"+directory.getAbsolutePath()+
+                            " with environment:"+env);
                 }
                 results.sampleStart();
-                int returnCode = nativeCommand.run(cmds);   
+                int returnCode = nativeCommand.run(cmds);
+                if(log.isDebugEnabled()) {
+                    log.debug("Ran :"+cmdLine + " using working directory:"+directory.getAbsolutePath()+
+                            " with execution environment:"+nativeCommand.getExecutionEnvironment());
+                }
                 results.sampleEnd();
 
                 if (checkReturnCode && (returnCode != expectedReturnCode)) {
@@ -246,4 +264,20 @@ public class SystemSampler extends Abstr
     public int getExpectedReturnCode() {
         return getPropertyAsInt(EXPECTED_RETURN_CODE);
     }
+
+    /**
+     * @param arguments Env vars
+     */
+    public void setEnvironmentVariables(Arguments arguments) {
+        setProperty(new TestElementProperty(ENVIRONMENT, arguments));
+    }
+    
+    /**
+     * Get the env variables
+     * 
+     * @return the arguments
+     */
+    public Arguments getEnvironmentVariables() {
+        return (Arguments) getProperty(ENVIRONMENT).getObjectValue();
+    }
 }
\ No newline at end of file

Modified: jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java?rev=1332640&r1=1332639&r2=1332640&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java
(original)
+++ jmeter/trunk/src/protocol/native/org/apache/jmeter/protocol/system/gui/SystemSamplerGui.java
Tue May  1 13:24:53 2012
@@ -55,6 +55,7 @@ public class SystemSamplerGui extends Ab
     private JLabeledTextField directory;
     private JLabeledTextField command;
     private ArgumentsPanel argsPanel;
+    private ArgumentsPanel envPanel;
     
     /**
      * Constructor for JavaTestSamplerGui
@@ -106,6 +107,7 @@ public class SystemSamplerGui extends Ab
         }
         sampler.setProperty(SystemSampler.COMMAND, command.getText());
         ((SystemSampler)sampler).setArguments((Arguments)argsPanel.createTestElement());
+        ((SystemSampler)sampler).setEnvironmentVariables((Arguments)envPanel.createTestElement());
         sampler.setProperty(SystemSampler.DIRECTORY, directory.getText());
     }
 
@@ -118,6 +120,7 @@ public class SystemSamplerGui extends Ab
         desiredReturnCode.setEnabled(checkReturnCode.isSelected());
         command.setText(el.getPropertyAsString(SystemSampler.COMMAND));
         argsPanel.configure((Arguments)el.getProperty(SystemSampler.ARGUMENTS).getObjectValue());
+        envPanel.configure((Arguments)el.getProperty(SystemSampler.ENVIRONMENT).getObjectValue());
         directory.setText(el.getPropertyAsString(SystemSampler.DIRECTORY));
     }
 
@@ -156,6 +159,7 @@ public class SystemSamplerGui extends Ab
         cmdPanel.add(command);
         panel.add(cmdPanel, BorderLayout.NORTH);
         panel.add(makeArgumentsPanel(), BorderLayout.CENTER);
+        panel.add(makeEnvironmentPanel(), BorderLayout.SOUTH);
         return panel;
     }
     
@@ -173,6 +177,14 @@ public class SystemSamplerGui extends Ab
                         new Class[] {String.class }));
         return argsPanel;
     }
+    
+    /**
+     * @return JPanel Environment Panel
+     */
+    private JPanel makeEnvironmentPanel() {
+        envPanel = new ArgumentsPanel(JMeterUtils.getResString("environment_panel_title"));
+        return envPanel;
+    }
 
     /**
      * @see org.apache.jmeter.gui.AbstractJMeterGuiComponent#clearGui()
@@ -183,6 +195,7 @@ public class SystemSamplerGui extends Ab
         directory.setText("");
         command.setText("");
         argsPanel.clearGui();
+        envPanel.clearGui();
         desiredReturnCode.setText("");
         checkReturnCode.setSelected(false);
         desiredReturnCode.setEnabled(false);

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1332640&r1=1332639&r2=1332640&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue May  1 13:24:53 2012
@@ -170,6 +170,7 @@ Graph Full Results Listener has been rem
 <li>Bug 52939 - Webservice Sampler : Make MaintainSession configurable</li>
 <li>Bug 53073 - Allow to assign the OUT result of a JDBC CALLABLE to JMeter variables</li>
 <li>Bug 53164 - New System Sampler</li>
+<li>Bug 53172 - OS Process Sampler - allow specification of Environment Variables</li>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message