jmeter-dev mailing list archives

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

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



##########
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:
       This is the not-numbered path, so yes, I believe this is correct.
   I took the numbered formats (`{0}{1}-{2}`, `{0}-{2}` and `{0}-{2} {1}`) and *subtracted*
`-{2}` from those. That way you get `{0}{1}`, `{0}` and `{0} {1}`. N'est-ce pas?




----------------------------------------------------------------
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