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



##########
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:
       What is this `65`?

##########
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:
       I see.
   I think it would be easier for developers to understand that if 65 is 
replaced with a constant or if comments are added.

##########
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:
       I see.
   I think it would be easier for developers to understand that if `65` is 
replaced with a constant or if comments are added.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to