You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/12/22 22:00:16 UTC
svn commit: r1775750 -
/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java
Author: pmouawad
Date: Thu Dec 22 22:00:16 2016
New Revision: 1775750
URL: http://svn.apache.org/viewvc?rev=1775750&view=rev
Log:
Sonar : Fix errors and code smells
Modified:
jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java?rev=1775750&r1=1775749&r2=1775750&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleResult.java Thu Dec 22 22:00:16 2016
@@ -56,6 +56,10 @@ public class SampleResult implements Ser
* The value is ISO-8859-1.
*/
public static final String DEFAULT_HTTP_ENCODING = StandardCharsets.ISO_8859_1.name();
+
+ private static final String OK_CODE = Integer.toString(HttpURLConnection.HTTP_OK);
+ private static final String OK_MSG = "OK"; // $NON-NLS-1$
+
// Bug 33196 - encoding ISO-8859-1 is only suitable for Western countries
// However the suggested System.getProperty("file.encoding") is Cp1252 on
@@ -71,7 +75,9 @@ public class SampleResult implements Ser
= JMeterUtils.getPropDefault("sampleresult.default.encoding", // $NON-NLS-1$
DEFAULT_HTTP_ENCODING);
- /* The default used by {@link #setResponseData(String, String)} */
+ /**
+ * The default used by {@link #setResponseData(String, String)}
+ */
private static final String DEFAULT_CHARSET = Charset.defaultCharset().name();
/**
@@ -89,9 +95,23 @@ public class SampleResult implements Ser
* @see #setDataType(java.lang.String)
*/
public static final String BINARY = "bin"; // $NON-NLS-1$
+
+ // List of types that are known to be binary
+ private static final String[] BINARY_TYPES = {
+ "image/", //$NON-NLS-1$
+ "audio/", //$NON-NLS-1$
+ "video/", //$NON-NLS-1$
+ };
+
+ // List of types that are known to be ascii, although they may appear to be binary
+ private static final String[] NON_BINARY_TYPES = {
+ "audio/x-mpegurl", //$NON-NLS-1$ (HLS Media Manifest)
+ "video/f4m" //$NON-NLS-1$ (Flash Media Manifest)
+ };
+
/** empty array which can be returned instead of null */
- public static final byte[] EMPTY_BA = new byte[0];
+ private static final byte[] EMPTY_BA = new byte[0];
private static final SampleResult[] EMPTY_SR = new SampleResult[0];
@@ -106,21 +126,41 @@ public class SampleResult implements Ser
private static final boolean GETBYTES_NETWORK_SIZE =
GETBYTES_HEADERS_SIZE && GETBYTES_BODY_REALSIZE;
- private SampleSaveConfiguration saveConfig;
-
- private SampleResult parent = null;
+ private static final boolean START_TIMESTAMP =
+ JMeterUtils.getPropDefault("sampleresult.timestamp.start", false); // $NON-NLS-1$
+ // Allow read-only access from test code
+ private static final boolean USENANOTIME =
+ JMeterUtils.getPropDefault("sampleresult.useNanoTime", true); // $NON-NLS-1$
+
/**
- * @param propertiesToSave
- * The propertiesToSave to set.
+ * How long between checks of nanotime; default 5000ms; set to <=0 to disable the thread
*/
- public void setSaveConfig(SampleSaveConfiguration propertiesToSave) {
- this.saveConfig = propertiesToSave;
- }
+ private static final long NANOTHREAD_SLEEP =
+ JMeterUtils.getPropDefault("sampleresult.nanoThreadSleep", 5000); // $NON-NLS-1$;
- public SampleSaveConfiguration getSaveConfig() {
- return saveConfig;
+ static {
+ if (START_TIMESTAMP) {
+ log.info("Note: Sample TimeStamps are START times");
+ } else {
+ log.info("Note: Sample TimeStamps are END times");
+ }
+ log.info("sampleresult.default.encoding is set to " + DEFAULT_ENCODING);
+ log.info("sampleresult.useNanoTime="+USENANOTIME);
+ log.info("sampleresult.nanoThreadSleep="+NANOTHREAD_SLEEP);
+
+ if (USENANOTIME && NANOTHREAD_SLEEP > 0) {
+ // Make sure we start with a reasonable value
+ NanoOffset.nanoOffset = System.currentTimeMillis() - SampleResult.sampleNsClockInMs();
+ NanoOffset nanoOffset = new NanoOffset();
+ nanoOffset.setDaemon(true);
+ nanoOffset.setName("NanoOffset");
+ nanoOffset.start();
+ }
}
+ private SampleSaveConfiguration saveConfig;
+
+ private SampleResult parent;
private byte[] responseData = EMPTY_BA;
@@ -140,8 +180,6 @@ public class SampleResult implements Ser
private String responseHeaders = ""; // Never return null
- private String contentType = ""; // e.g. text/html; charset=utf-8
-
private String requestHeaders = "";
// TODO timeStamp == 0 means either not yet initialised or no stamp available (e.g. when loading a results file)
@@ -179,9 +217,12 @@ public class SampleResult implements Ser
*/
private final Set<String> files = new HashSet<>(3);
+ // TODO do contentType and/or dataEncoding belong in HTTPSampleResult instead?
private String dataEncoding;// (is this really the character set?) e.g.
// ISO-8895-1, UTF-8
+ private String contentType = ""; // e.g. text/html; charset=utf-8
+
/** elapsed time */
private long elapsedTime = 0;
@@ -219,40 +260,6 @@ public class SampleResult implements Ser
/** Currently active threads in all thread groups */
private volatile int allThreads = 0;
- // TODO do contentType and/or dataEncoding belong in HTTPSampleResult instead?
-
- private static final boolean startTimeStamp
- = JMeterUtils.getPropDefault("sampleresult.timestamp.start", false); // $NON-NLS-1$
-
- // Allow read-only access from test code
- static final boolean USENANOTIME
- = JMeterUtils.getPropDefault("sampleresult.useNanoTime", true); // $NON-NLS-1$
-
- // How long between checks of nanotime; default 5000ms; set to <=0 to disable the thread
- private static final long NANOTHREAD_SLEEP =
- JMeterUtils.getPropDefault("sampleresult.nanoThreadSleep", 5000); // $NON-NLS-1$;
-
- static {
- if (startTimeStamp) {
- log.info("Note: Sample TimeStamps are START times");
- } else {
- log.info("Note: Sample TimeStamps are END times");
- }
- log.info("sampleresult.default.encoding is set to " + DEFAULT_ENCODING);
- log.info("sampleresult.useNanoTime="+USENANOTIME);
- log.info("sampleresult.nanoThreadSleep="+NANOTHREAD_SLEEP);
-
- if (USENANOTIME && NANOTHREAD_SLEEP > 0) {
- // Make sure we start with a reasonable value
- NanoOffset.nanoOffset = System.currentTimeMillis() - SampleResult.sampleNsClockInMs();
- NanoOffset nanoOffset = new NanoOffset();
- nanoOffset.setDaemon(true);
- nanoOffset.setName("NanoOffset");
- nanoOffset.start();
- }
- }
-
-
private final long nanoTimeOffset;
// Allow testcode access to the settings
@@ -260,20 +267,12 @@ public class SampleResult implements Ser
final long nanoThreadSleep;
+ private long sentBytes;
+
/**
* Cache for responseData as string to avoid multiple computations
*/
- private volatile transient String responseDataAsString;
-
- private long sentBytes;
-
- private long initOffset(){
- if (useNanoTime){
- return nanoThreadSleep > 0 ? NanoOffset.getNanoOffset() : System.currentTimeMillis() - sampleNsClockInMs();
- } else {
- return Long.MIN_VALUE;
- }
- }
+ private transient volatile String responseDataAsString;
public SampleResult() {
this(USENANOTIME, NANOTHREAD_SLEEP);
@@ -300,7 +299,7 @@ public class SampleResult implements Ser
public SampleResult(SampleResult res) {
this();
allThreads = res.allThreads;//OK
- assertionResults = res.assertionResults;// TODO ??
+ assertionResults = res.assertionResults;
bytes = res.bytes;
headersSize = res.headersSize;
bodySize = res.bodySize;
@@ -315,7 +314,7 @@ public class SampleResult implements Ser
latency = res.latency;
connectTime = res.connectTime;
location = res.location;//OK
- parent = res.parent; // TODO ??
+ parent = res.parent;
pauseTime = res.pauseTime;
requestHeaders = res.requestHeaders;//OK
responseCode = res.responseCode;//OK
@@ -323,7 +322,9 @@ public class SampleResult implements Ser
responseDataAsString = null;
responseHeaders = res.responseHeaders;//OK
responseMessage = res.responseMessage;//OK
- // Don't copy this; it is per instance resultFileName = res.resultFileName;
+ /**
+ * Don't copy this; it is per instance resultFileName = res.resultFileName;
+ */
sampleCount = res.sampleCount;
samplerData = res.samplerData;
saveConfig = res.saveConfig;
@@ -333,17 +334,13 @@ public class SampleResult implements Ser
stopTestNow = res.stopTestNow;
stopThread = res.stopThread;
startNextThreadLoop = res.startNextThreadLoop;
- subResults = res.subResults; // TODO ??
+ subResults = res.subResults;
success = res.success;//OK
threadName = res.threadName;//OK
elapsedTime = res.elapsedTime;
timeStamp = res.timeStamp;
}
-
- public boolean isStampedAtStart() {
- return startTimeStamp;
- }
-
+
/**
* Create a sample with a specific elapsed time but don't allow the times to
* be changed later
@@ -366,6 +363,48 @@ public class SampleResult implements Ser
}
/**
+ * Allow users to create a sample with specific timestamp and elapsed times
+ * for cloning purposes, but don't allow the times to be changed later
+ *
+ * Currently used by CSVSaveService and
+ * StatisticalSampleResult
+ *
+ * @param stamp
+ * this may be a start time or an end time (both in
+ * milliseconds)
+ * @param elapsed
+ * time in milliseconds
+ */
+ public SampleResult(long stamp, long elapsed) {
+ this();
+ stampAndTime(stamp, elapsed);
+ }
+
+ private long initOffset(){
+ if (useNanoTime){
+ return nanoThreadSleep > 0 ? NanoOffset.getNanoOffset() : System.currentTimeMillis() - sampleNsClockInMs();
+ } else {
+ return Long.MIN_VALUE;
+ }
+ }
+
+ /**
+ * @param propertiesToSave
+ * The propertiesToSave to set.
+ */
+ public void setSaveConfig(SampleSaveConfiguration propertiesToSave) {
+ this.saveConfig = propertiesToSave;
+ }
+
+ public SampleSaveConfiguration getSaveConfig() {
+ return saveConfig;
+ }
+
+ public boolean isStampedAtStart() {
+ return START_TIMESTAMP;
+ }
+
+ /**
* Create a sample with specific start and end times for test purposes, but
* don't allow the times to be changed later
*
@@ -397,24 +436,6 @@ public class SampleResult implements Ser
return createTestSample(now, now + elapsed);
}
- /**
- * Allow users to create a sample with specific timestamp and elapsed times
- * for cloning purposes, but don't allow the times to be changed later
- *
- * Currently used by CSVSaveService and
- * StatisticalSampleResult
- *
- * @param stamp
- * this may be a start time or an end time (both in
- * milliseconds)
- * @param elapsed
- * time in milliseconds
- */
- public SampleResult(long stamp, long elapsed) {
- this();
- stampAndTime(stamp, elapsed);
- }
-
private static long sampleNsClockInMs() {
return System.nanoTime() / 1000000;
}
@@ -439,7 +460,7 @@ public class SampleResult implements Ser
// Helper method to maintain timestamp relationships
private void stampAndTime(long stamp, long elapsed) {
- if (startTimeStamp) {
+ if (START_TIMESTAMP) {
startTime = stamp;
endTime = stamp + elapsed;
} else {
@@ -482,9 +503,6 @@ public class SampleResult implements Ser
return responseCode;
}
- private static final String OK_CODE = Integer.toString(HttpURLConnection.HTTP_OK);
- private static final String OK_MSG = "OK"; // $NON-NLS-1$
-
/**
* Set response code to OK, i.e. "200"
*
@@ -799,10 +817,10 @@ public class SampleResult implements Ser
// N.B. The meta tag:
// <META http-equiv="content-type" content="text/html; charset=foobar">
// is now processed by HTTPSampleResult#getDataEncodingWithDefault
- final String CS_PFX = "charset="; // $NON-NLS-1$
- int cset = ct.toLowerCase(java.util.Locale.ENGLISH).indexOf(CS_PFX);
+ final String charsetPrefix = "charset="; // $NON-NLS-1$
+ int cset = ct.toLowerCase(java.util.Locale.ENGLISH).indexOf(charsetPrefix);
if (cset >= 0) {
- String charSet = ct.substring(cset + CS_PFX.length());
+ String charSet = ct.substring(cset + charsetPrefix.length());
// handle: ContentType: text/plain; charset=ISO-8859-1; format=flowed
int semiColon = charSet.indexOf(';');
if (semiColon >= 0) {
@@ -823,19 +841,6 @@ public class SampleResult implements Ser
}
}
- // List of types that are known to be binary
- private static final String[] BINARY_TYPES = {
- "image/", //$NON-NLS-1$
- "audio/", //$NON-NLS-1$
- "video/", //$NON-NLS-1$
- };
-
- // List of types that are known to be ascii, although they may appear to be binary
- private static final String[] NON_BINARY_TYPES = {
- "audio/x-mpegurl", //$NON-NLS-1$ (HLS Media Manifest)
- "video/f4m" //$NON-NLS-1$ (Flash Media Manifest)
- };
-
/*
* Determine if content-type is known to be binary, i.e. not displayable as text.
*
@@ -1033,14 +1038,14 @@ public class SampleResult implements Ser
*/
protected final void setStartTime(long start) {
startTime = start;
- if (startTimeStamp) {
+ if (START_TIMESTAMP) {
timeStamp = startTime;
}
}
public void setEndTime(long end) {
endTime = end;
- if (!startTimeStamp) {
+ if (!START_TIMESTAMP) {
timeStamp = endTime;
}
if (startTime == 0) {