Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bin/jmeter.properties
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,15 @@ upgrade_properties=/bin/upgrade.properties
# it assumes that the user has clicked a new URL
#proxy.pause=5000

# Add numeric suffix to Sampler names (default true)
# Add number to Sampler names (default true)
#proxy.number.requests=true
# suffix or prefix numbering
# prefix numbering (default), eg.: 001 /image.png
#proxy.number.mode=prefix
# suffix numbering, e.g.: /image.png-001
#proxy.number.mode=suffix
# number format (%03d default), see String.format
#proxy.number.value_format=%03d

# List of URL patterns that will be added to URL Patterns to exclude
# Separate multiple lines with ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,18 @@ run_threadgroup_no_timers=Start no pauses
running_test=Running test
runtime_controller_title=Runtime Controller
runtime_seconds=Runtime (seconds)
salt_string=Salt to be used for hashing (optional)
sample_name_prefix=Prefix
sample_name_transaction=Transaction name
salt_string=Salt to be used for hashing (optional)
sample_numbering_mode=Numbering mode
sample_numbering_mode_example=Without numbering \: '/a.png', prefix \: '001 /a.png', suffix \: '/a.png-001'
sample_numbering_mode_no_number=Without numbering
sample_numbering_mode_prefix=Prefix number (start)
sample_numbering_mode_suffix=Suffix number (at the end)
sample_numbering_number_format=Number format (String.format) \:
sample_numbering_start_value=Next number \:
sample_numbering_start_value_error_digits=Only digits allowed
sample_numbering_start_value_error_invalid_data=Invalid data
sample_result_save_configuration=Sample Result Save Configuration
sample_scope=Apply to:
sample_scope_all=Main sample and sub-samples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,15 @@ runtime_seconds=Temps d'exécution (secondes) \:
salt_string=Sel à utiliser pour le hash
sample_name_prefix=Préfixe
sample_name_transaction=Nom de la transaction
sample_numbering_mode=Mode de numérotation
sample_numbering_mode_example=Sans numérotation \: '/a.png', préfixe \: '001 /a.png', suffixe \: '/a.png-001'
sample_numbering_mode_no_number=Sans numérotation
sample_numbering_mode_prefix=Numérotation préfixe (début)
sample_numbering_mode_suffix=Numérotation suffixe (en fin)
sample_numbering_number_format=Format du nombre (String.format) \:
sample_numbering_start_value=Prochain nombre \:
sample_numbering_start_value_error_digits=Seul les chiffres sont autorisés
sample_numbering_start_value_error_invalid_data=Valeur invalide
sample_result_save_configuration=Sauvegarder la configuration de la sauvegarde des échantillons
sample_scope=Appliquer sur
sample_scope_all=L'échantillon et ses ressources liées
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand All @@ -72,10 +65,6 @@ public abstract class AbstractSamplerCreator implements SamplerCreator {
}
}


/**
*
*/
/**
*
*/
Expand All @@ -86,30 +75,49 @@ public AbstractSamplerCreator() {
/**
* @return int request number
*/
protected static int getRequestNumber() {
public int getRequestNumber() {
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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.

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$;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same note

return sMumberMode;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 :) )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add a comment because "prefix" have 2 significations :

  • prefix name
  • prefix numbering
    This is prefix name.

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());
}
}
Expand Down Expand Up @@ -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;
}
}
Loading