You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by "vlsi (via GitHub)" <gi...@apache.org> on 2023/05/05 14:00:30 UTC

[GitHub] [jmeter] vlsi commented on a diff in pull request #5869: Add more variables to template to compute sampler names

vlsi commented on code in PR #5869:
URL: https://github.com/apache/jmeter/pull/5869#discussion_r1186133062


##########
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/proxy/DefaultSamplerCreator.java:
##########
@@ -359,18 +361,42 @@ protected void computeSamplerName(HTTPSamplerBase sampler,
         String prefix = StringUtils.defaultString(request.getPrefix(), "");
         int httpSampleNameMode = request.getHttpSampleNameMode();
         String format = getFormat(httpSampleNameMode, request.getHttpSampleNameFormat());
+        String url = null;
+        try {
+            url = sampler.getUrl().toString();
+        } catch (MalformedURLException e) {
+            url = "MALFORMED-URL";
+            log.warn("Could not get URL to name sample", e);
+        }
+        List<Object> values = Arrays.asList(
+                prefix,
+                sampler.getPath(),
+                sampler.getMethod(),
+                sampler.getDomain(),
+                sampler.getProtocol(),
+                sampler.getPort(),
+                url
+        );
+        Object[] valuesArray;
         if (!HTTPConstants.CONNECT.equals(request.getMethod()) && isNumberRequests()) {
-            sampler.setName(MessageFormat.format(format, prefix, sampler.getPath(), incrementRequestNumberAndGet()));
+            valuesArray = values.toArray(new Object[values.size() + 1]);
+            valuesArray[values.size()] = incrementRequestNumberAndGet();
         } else {
-            sampler.setName(MessageFormat.format(format, prefix, sampler.getPath()));
+            valuesArray = values.toArray();

Review Comment:
   I just wonder: is there a real reason to allow "request number" only in case the method is not CONNECT?
   What if we always supply the "request number", and we increase "request number" only in case the method matches?
   
   The dance with `toArray[size+1]` looks strange.
   



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

To unsubscribe, e-mail: dev-unsubscribe@jmeter.apache.org

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