jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [jmeter] pmouawad commented on a change in pull request #595: Add freestyle naming scheme to proxy samples
Date Mon, 06 Jul 2020 11:38:44 GMT

pmouawad commented on a change in pull request #595:
URL: https://github.com/apache/jmeter/pull/595#discussion_r450162256



##########
File path: src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java
##########
@@ -285,33 +288,49 @@ public boolean isErrorDetected() {
      */
     protected void computeSamplerName(HTTPSamplerBase sampler,
             HttpRequestHdr request) {
-        String prefix = request.getPrefix();
+        String prefix = StringUtils.defaultString(request.getPrefix(), "");
         int httpSampleNameMode = request.getHttpSampleNameMode();
+        String format = getFormat(httpSampleNameMode, request.getHttpSampleNameFormat());
         if (!HTTPConstants.CONNECT.equals(request.getMethod()) && isNumberRequests())
{
-            if(StringUtils.isNotEmpty(prefix)) {
-                if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_PREFIX) {
-                    sampler.setName(prefix + sampler.getPath()+ "-" + incrementRequestNumberAndGet());
-                } else if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_COMPLETE) {
-                    sampler.setName(prefix + "-" + incrementRequestNumberAndGet());
-                } else {
-                    log.debug("Sampler name naming mode not recognized");
-                }
-            } else {
-                sampler.setName(sampler.getPath()+"-"+incrementRequestNumberAndGet());
-            }
+            sampler.setName(MessageFormat.format(format, prefix, sampler.getPath(), incrementRequestNumberAndGet()));
         } else {
-            if(StringUtils.isNotEmpty(prefix)) {
-                if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_PREFIX) {
-                    sampler.setName(prefix + sampler.getPath());
-                } else if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_COMPLETE) {
-                    sampler.setName(prefix);
-                } else {
-                    log.debug("Sampler name naming mode not recognized");
-                }
-            } else {
-                sampler.setName(sampler.getPath());
-            }
+            sampler.setName(MessageFormat.format(format, prefix, sampler.getPath()));
+        }
+    }
+
+    private String getFormat(int httpSampleNameMode, String format) {
+        if (isNumberRequests()) {
+            return getNumberedFormat(httpSampleNameMode, format);
+        }
+        if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_PREFIX) {
+            return "{0}{1}";
+        }
+        if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_COMPLETE) {
+            return "{0}";
+        }
+        if (httpSampleNameMode == SAMPLER_NAME_NAMING_MODE_SUFFIX) {
+            return "{0} {1}";

Review comment:
       Is it regular that PREFIX and SUFFIX only vary by space ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message