-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add prefix or suffix sampler numbering for HTTP Test Script Recorder #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
074911e
478ab74
be81754
636d30c
34357bb
543fc6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,15 +52,8 @@ public abstract class AbstractSamplerCreator implements SamplerCreator { | |
| JMeterUtils.getPropDefault("proxy.binary.directory",// $NON-NLS-1$ | ||
| System.getProperty("user.dir")); // $NON-NLS-1$ proxy.binary.fileType=binary | ||
|
|
||
| /* | ||
| * Optionally number the requests | ||
| */ | ||
| private static final boolean NUMBER_REQUESTS = | ||
| JMeterUtils.getPropDefault("proxy.number.requests", true); // $NON-NLS-1$ | ||
|
|
||
| private static AtomicInteger REQUEST_NUMBER = new AtomicInteger(0);// running number | ||
|
|
||
|
|
||
| static { | ||
| String binaries = JMeterUtils.getPropDefault("proxy.binary.types", // $NON-NLS-1$ | ||
| "application/x-amf,application/x-java-serialized-object,binary/octet-stream"); // $NON-NLS-1$ | ||
|
|
@@ -72,10 +65,6 @@ public abstract class AbstractSamplerCreator implements SamplerCreator { | |
| } | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * | ||
| */ | ||
| /** | ||
| * | ||
| */ | ||
|
|
@@ -86,30 +75,49 @@ public AbstractSamplerCreator() { | |
| /** | ||
| * @return int request number | ||
| */ | ||
| protected static int getRequestNumber() { | ||
| public int getRequestNumber() { | ||
| return REQUEST_NUMBER.get(); | ||
| } | ||
|
|
||
| /** | ||
| * set the RequestNumber to a specify value | ||
| * @param iValue the current number | ||
| */ | ||
| public void setRequestNumber(int iValue) { | ||
| REQUEST_NUMBER.set(iValue); | ||
| } | ||
|
|
||
| /** | ||
| * Increment request number | ||
| */ | ||
| protected static void incrementRequestNumber() { | ||
| protected void incrementRequestNumber() { | ||
| incrementRequestNumberAndGet(); | ||
| } | ||
|
|
||
| /** | ||
| * Increment request number | ||
| * @return int number for created sampler | ||
| */ | ||
| protected static int incrementRequestNumberAndGet() { | ||
| protected int incrementRequestNumberAndGet() { | ||
| return REQUEST_NUMBER.incrementAndGet(); | ||
| } | ||
|
|
||
| /** | ||
| * @return boolean is numbering requests is required | ||
| */ | ||
| protected static boolean isNumberRequests() { | ||
| return NUMBER_REQUESTS; | ||
| protected boolean isNumberRequests() { | ||
| boolean bNumberRequest = JMeterUtils.getPropDefault("proxy.number.requests", true); // $NON-NLS-1$; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it's not a simple getter ? just return NUMBER_REQUEST (to be camelCased) |
||
| return bNumberRequest; | ||
| } | ||
|
|
||
| protected String getNumberValueFormat() { | ||
| String sNumberValueFormat = JMeterUtils.getPropDefault("proxy.number.value_format", "%03d"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same note |
||
| return sNumberValueFormat; | ||
| } | ||
|
|
||
| protected String getNumberMode() { | ||
| String sMumberMode = JMeterUtils.getPropDefault("proxy.number.mode", "prefix"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same note |
||
| return sMumberMode; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,14 @@ | |
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.apache.jmeter.protocol.http.proxy; | ||
|
|
@@ -34,6 +35,7 @@ | |
| import org.apache.jmeter.config.Arguments; | ||
| import org.apache.jmeter.protocol.http.config.MultipartUrlConfig; | ||
| import org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui; | ||
| import org.apache.jmeter.protocol.http.proxy.ProxyControl.HttpSamplerNumberingMode; | ||
| import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; | ||
| import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory; | ||
| import org.apache.jmeter.protocol.http.sampler.PostWriter; | ||
|
|
@@ -283,32 +285,58 @@ public boolean isErrorDetected() { | |
| * @param sampler {@link HTTPSamplerBase} | ||
| * @param request {@link HttpRequestHdr} | ||
| */ | ||
| protected void computeSamplerName(HTTPSamplerBase sampler, | ||
| HttpRequestHdr request) { | ||
| String prefix = request.getPrefix(); | ||
| protected void computeSamplerName(HTTPSamplerBase sampler, HttpRequestHdr request) { | ||
| String prefix = request.getPrefix(); // pn for prefix name | ||
| int httpSampleNameMode = request.getHttpSampleNameMode(); | ||
| if (!HTTPConstants.CONNECT.equals(request.getMethod()) && isNumberRequests()) { | ||
| if(StringUtils.isNotEmpty(prefix)) { | ||
| // with a prefix name | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these parts be extracted in smaller functions/methods? You could use names to tell the reader what the function is doing instead of using a comment and at the same time the code gets less (at least here :) )
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I add a comment because "prefix" have 2 significations :
|
||
| if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_PREFIX) { | ||
| sampler.setName(prefix + sampler.getPath()+ "-" + incrementRequestNumberAndGet()); | ||
| if (HttpSamplerNumberingMode.SUFFIX.getStringMode().equals(getNumberMode())) { | ||
| // pn/img.png-001 | ||
| sampler.setName(prefix + sampler.getPath() + "-" + formatNumberingInteger(incrementRequestNumberAndGet())); | ||
| } | ||
| if (HttpSamplerNumberingMode.PREFIX.getStringMode().equals(getNumberMode())) { | ||
| // pn-001 /img.png | ||
| sampler.setName(prefix + "-" + formatNumberingInteger(incrementRequestNumberAndGet()) + " " + sampler.getPath()); | ||
| } | ||
| } else if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_COMPLETE) { | ||
| sampler.setName(prefix + "-" + incrementRequestNumberAndGet()); | ||
| if (HttpSamplerNumberingMode.SUFFIX.getStringMode().equals(getNumberMode())) { | ||
| // pn-001 | ||
| sampler.setName(prefix + "-" + formatNumberingInteger(incrementRequestNumberAndGet())); | ||
| } | ||
| if (HttpSamplerNumberingMode.PREFIX.getStringMode().equals(getNumberMode())) { | ||
| // 001-pn | ||
| sampler.setName(formatNumberingInteger(incrementRequestNumberAndGet()) + "-" + prefix); | ||
| } | ||
| } else { | ||
| log.debug("Sampler name naming mode not recognized"); | ||
| } | ||
| } else { | ||
| sampler.setName(sampler.getPath()+"-"+incrementRequestNumberAndGet()); | ||
| // no prefix name | ||
| if (HttpSamplerNumberingMode.SUFFIX.getStringMode().equals(getNumberMode())) { | ||
| // /img.png-001 | ||
| sampler.setName(sampler.getPath() + "-" + formatNumberingInteger(incrementRequestNumberAndGet())); | ||
| } | ||
| if (HttpSamplerNumberingMode.PREFIX.getStringMode().equals(getNumberMode())) { | ||
| // 001 /img.png | ||
| sampler.setName(formatNumberingInteger(incrementRequestNumberAndGet()) + " " + sampler.getPath()); | ||
| } | ||
| } | ||
| } else { | ||
| } else { // no numbering | ||
| if(StringUtils.isNotEmpty(prefix)) { | ||
| // with a prefix name | ||
| if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_PREFIX) { | ||
| // pn/img.png | ||
| sampler.setName(prefix + sampler.getPath()); | ||
| } else if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_COMPLETE) { | ||
| // pn | ||
| sampler.setName(prefix); | ||
| } else { | ||
| log.debug("Sampler name naming mode not recognized"); | ||
| } | ||
| } else { | ||
| // /img.png | ||
| sampler.setName(sampler.getPath()); | ||
| } | ||
| } | ||
|
|
@@ -448,4 +476,15 @@ protected void computeDomain(HTTPSamplerBase sampler, HttpRequestHdr request) { | |
| log.debug("Proxy: setting server: {}", sampler.getDomain()); | ||
| } | ||
| } | ||
|
|
||
| protected String formatNumberingInteger(int iValue) { | ||
| // format like %03d | ||
| String sFormat = getNumberValueFormat(); | ||
| if (sFormat.length() == 0) { | ||
| // the simplest format for an integer | ||
| sFormat = "%d"; | ||
| } | ||
| String sReturn = String.format(sFormat, iValue); | ||
| return sReturn; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change it to be non-static? (I am not sure, I like the static, but I would like to here your reasoning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method need to be public not protected (same package)
This method return value from a static value but i don't see why this method need to be static.
Other methods are not static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the static comes from the fact, that the result does not depend on the instance, but rather the class.