You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2007/12/06 21:36:21 UTC

svn commit: r601848 - /jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleEvent.java

Author: sebb
Date: Thu Dec  6 12:36:20 2007
New Revision: 601848

URL: http://svn.apache.org/viewvc?rev=601848&view=rev
Log:
Add variable names and allow values to be saved

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleEvent.java

Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleEvent.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleEvent.java?rev=601848&r1=601847&r2=601848&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleEvent.java (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleEvent.java Thu Dec  6 12:36:20 2007
@@ -22,6 +22,8 @@
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
+import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
@@ -32,8 +34,18 @@
 public class SampleEvent implements Serializable {
     private static final Logger log = LoggingManager.getLoggerForClass();
 
+    private static final long serialVersionUID = 232L;
+
     public static final String HOSTNAME;
 
+    // List of variable names to be saved in JTL files
+	private static final String[] variableNames;
+	// Number of variable names
+	private static final int varCount;
+
+	// The values. Entries be null, but there will be the correct number.
+    private final String[] values;
+    
 	static {
         String hn="";
 		try {
@@ -42,21 +54,58 @@
             log.error("Cannot obtain local host name "+e);
 		}
         HOSTNAME=hn;
+        
+        String vars = JMeterUtils.getProperty("sample_variables"); // $NON-NLS-1$
+       	variableNames=vars != null ? vars.split(",") : new String[0];
+       	varCount=variableNames.length;
+        if (varCount>0){
+        	log.info(varCount + " sample_variables have been declared: "+vars);
+        }
 	}
 
-	SampleResult result;
 
-	String threadGroup; // TODO appears to duplicate the threadName field in SampleResult
+	private final SampleResult result;
+
+	private final String threadGroup; // TODO appears to duplicate the threadName field in SampleResult
 
-	String hostname;
+	private final String hostname;
 
+
+	/*
+	 * Only for Unit tests
+	 */
 	public SampleEvent() {
+		this(null, null);
 	}
 
+	/**
+	 * Creates SampleEvent without saving any variables.
+	 * 
+	 * Use by Proxy and StatisticalSampleSender.
+	 * 
+	 * @param result SampleResult
+	 * @param threadGroup name
+	 */
 	public SampleEvent(SampleResult result, String threadGroup) {
 		this.result = result;
 		this.threadGroup = threadGroup;
 		this.hostname = HOSTNAME;
+		values = new String[variableNames.length];
+	}
+
+	/**
+	 * Contructor used for normal samples, saves variable values if any are defined.
+	 * 
+	 * @param result
+	 * @param threadGroup name
+	 * @param jmvars Jmeter variables
+	 */
+	public SampleEvent(SampleResult result, String threadGroup, JMeterVariables jmvars) {
+		this.result = result;
+		this.threadGroup = threadGroup;
+		this.hostname = HOSTNAME;
+		values = new String[variableNames.length];
+		saveVars(jmvars);
 	}
 
 	/**
@@ -70,8 +119,30 @@
 		this.result = result;
 		this.threadGroup = threadGroup;
 		this.hostname = hostname;
+		values = new String[variableNames.length];
+	}
+
+	private void saveVars(JMeterVariables vars){
+		for(int i = 0; i < variableNames.length; i++){
+			values[i] = vars.get(variableNames[i]);
+		}
+	}
+
+	/** Return the number of variables defined */
+	public static int getVarCount(){
+		return varCount;
 	}
 
+	/** Get the nth variable name (zero-based) */
+	public static String getVarName(int i){
+		return variableNames[i];
+	}
+
+	/** Get the nth variable value (zero-based) */
+	public String getVarValue(int i){
+		return values[i];
+	}
+		
 	public SampleResult getResult() {
 		return result;
 	}



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org