You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/09/28 05:38:39 UTC

[GitHub] [pulsar] yuruguo commented on a change in pull request #12187: [testclient] Make --payload-file take effect in PerformanceClient

yuruguo commented on a change in pull request #12187:
URL: https://github.com/apache/pulsar/pull/12187#discussion_r717238556



##########
File path: pulsar-testclient/src/main/java/org/apache/pulsar/proxy/socket/client/PerformanceClient.java
##########
@@ -193,23 +212,49 @@ public Arguments loadArguments(String[] args) {
 
     }
 
-    public void runPerformanceTest(long messages, long limit, int numOfTopic, int sizeOfMessage, String baseUrl,
-            String topicName, String authPluginClassName, String authParams) throws InterruptedException, FileNotFoundException {
+    public void runPerformanceTest(Arguments arguments) throws InterruptedException, IOException {
+        // Read payload data from file if needed
+        final byte[] payloadBytes = new byte[arguments.msgSize];
+        Random random = new Random(0);
+        List<byte[]> payloadByteList = Lists.newArrayList();
+        if (arguments.payloadFilename != null) {
+            Path payloadFilePath = Paths.get(arguments.payloadFilename);
+            if (Files.notExists(payloadFilePath) || Files.size(payloadFilePath) == 0)  {
+                throw new IllegalArgumentException("Payload file doesn't exist or it is empty.");
+            }
+            // here escaping the default payload delimiter to correct value
+            String delimiter = arguments.payloadDelimiter.equals("\\n") ? "\n" : arguments.payloadDelimiter;
+            String[] payloadList = new String(Files.readAllBytes(payloadFilePath), StandardCharsets.UTF_8).split(delimiter);
+            log.info("Reading payloads from {} and {} records read", payloadFilePath.toAbsolutePath(), payloadList.length);
+            for (String payload : payloadList) {
+                payloadByteList.add(payload.getBytes(StandardCharsets.UTF_8));
+            }
+
+            if (arguments.formatPayload) {
+                messageFormatter = getMessageFormatter(arguments.formatterClass);
+            }
+        } else {
+            for (int i = 0; i < payloadBytes.length; ++i) {
+                payloadBytes[i] = (byte) (random.nextInt(26) + 65);

Review comment:
       The value of the `payloadBytes` is from `A` to `Z` and the ASCII of `A`-`Z` is `65` - `90`, so we need to add 65.




-- 
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: commits-unsubscribe@pulsar.apache.org

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