Azure负载测试:利用外部JAR转换JPG的JMeter脚本(java.nio.file.NoSuchFileException)

t5fffqht  于 2023-10-20  发布在  Java
关注(0)|答案(1)|浏览(118)

我有以下基于JMeter的Azure负载测试,它利用外部JAR将给定的JPG转换为DICOM(文件类型)

**注意:**自定义接口(Dicom接口)在JMeter之外单独测试时没有任何问题。
**注意:**此自定义函数有两个参数,输入和输出文件。
JMeter -预处理器(基于Groovy)

import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.commons.lang3.RandomStringUtils;

String ext = "dcm";
String outputFilePath = String.format("%s.%s", RandomStringUtils.randomAlphanumeric(8), ext);

try {
    log.error("Current Path : " + System.getProperty("user.dir")); 
    
    String command = "java -jar Dicom.jar Images-1-min.jpg " + outputFilePath;
    
    log.error("Command is: " + command);

    def process = command.execute();
     
    // Capture and log the process output
    def output = new StringBuilder();
    process.waitForProcessOutput(output, System.err);
    process.waitFor();

    // Log the process output
    log.error("Process output: " + output.toString());

    def p = "ls -R".execute();

    
    // Capture and log the process output
    def o = new StringBuilder();
    p.waitForProcessOutput(o, System.err);
    p.waitFor();
    
    log.error("List Directory : " + o.toString());

    try {
        byte[] binaryData = Files.readAllBytes(Paths.get("output.dcm"));
        
        sampler.getArguments().removeAllArguments();
        sampler.addNonEncodedArgument('', new String(binaryData), '');
    
        // Set the Content-Type header (optional, only if required by the server)
        sampler.setPostBodyRaw(true);
    } catch (Exception ex) {
        log.error("Error modifying and sending DICOM file: " + ex.getMessage());
        throw ex;
    }

} catch (Exception e) {
    log.error("Error executing command: " + e.toString());
}

配置YAML:

displayName: DICOM
testPlan: DICOM Load Test.jmx
description: ''
engineInstances: 1
testId: fcba51b1-b4fd-4ae7-a3c2-694080bfd662
splitAllCSVs: False
configurationFiles:
- Dicom.jar
- output.dcm
- Images-1-min.jpg
failureCriteria: []
env:
- name: SUBSCRIPTION_KEY
  value: xxxxxxx
- name: APIM_FHIR_URL
  value: xxxxxxx.azure-api.net
- name: TENANT_ID
  value: xxxx
- name: THREADS_NUM
  value: 1
- name: THREADS_LOOP
  value: 1
autoStop:
  errorPercentage: 90
  timeWindow: 60

如你所见,我已经上传了所有需要的文件

执行负载测试时出现以下错误

2023-08-15 12:23:22,241 WARN o.a.j.JMeter: LogLevel: INFO
2023-08-15 12:23:22,918 WARN c.a.c.j.j.c.MALTListener: TEST STARTED EVENT - received
2023-08-15 12:23:23,139 WARN c.a.c.j.j.c.MALTFileWriterListener: Received Event testStarted
2023-08-15 12:23:23,150 WARN c.a.c.j.j.c.MALTAutostopListener: MALT autostop test started with error rate 90 for 60s.
2023-08-15 12:23:24,650 ERROR o.a.j.m.J.Convert JPG to DICOM and set it as a Body: Current Path : /
2023-08-15 12:23:24,651 ERROR o.a.j.m.J.Convert JPG to DICOM and set it as a Body: Command is: java -jar Dicom.jar Images-1-min.jpg xaNzytIY.dcm
2023-08-15 12:23:24,692 ERROR o.a.j.m.J.Convert JPG to DICOM and set it as a Body: Process output: 
2023-08-15 12:23:24,909 ERROR o.a.j.m.J.Convert JPG to DICOM and set it as a Body: List Directory : .:
./jmeter/lib/ext:
ApacheJMeter_bolt.jar
ApacheJMeter_components.jar
ApacheJMeter_core.jar
ApacheJMeter_ftp.jar
ApacheJMeter_functions.jar
ApacheJMeter_http.jar
ApacheJMeter_java.jar
ApacheJMeter_jdbc.jar
ApacheJMeter_jms.jar
ApacheJMeter_junit.jar
ApacheJMeter_ldap.jar
ApacheJMeter_mail.jar
ApacheJMeter_mongodb.jar
ApacheJMeter_native.jar
ApacheJMeter_tcp.jar
Dicom.jar
azure-loadtesting-getsecret-0.0.2.jar
jmeter-plugins-autostop-0.1.jar
jmeter-plugins-casutg-2.10.jar
jmeter-plugins-cmn-jmeter-0.7.jar
jmeter-plugins-dummy-0.4.jar
jmeter-plugins-graphs-additional-2.0.jar
jmeter-plugins-graphs-basic-2.0.jar
jmeter-plugins-malt-2.4.jar
jmeter-plugins-manager-1.8.jar
jmeter-plugins-tst-2.6.jar
json-lib-2.4-jdk15.jar
log4j-layout-template-json-2.17.2.jar
readme.txt
./root/artifacts:
Dicom.jar
Images-1-min.jpg
jmeter.log
logs
metrics
output.dcm
results
testplan.jmx
2023-08-14 20:38:56,306 ERROR o.a.j.m.J.Convert JPG to DICOM and set it as a Body: Error modifying and sending DICOM file: output.dcm
2023-08-14 20:38:56,307 ERROR o.a.j.m.J.Convert JPG to DICOM and set it as a Body: Error executing command: java.nio.file.NoSuchFileException: output.dcm
2023-08-14 20:38:56,398 WARN o.a.j.u.SSLManager: Keystore file not found, loading empty keystore
2023-08-14 20:38:57,388 WARN c.a.c.j.j.c.MALTListener: TEST ENDED EVENT - received
2023-08-14 20:38:57,399 WARN c.a.c.j.j.c.MALTListener: TEST ENDED EVENT - uploading jmeter.log file
2023-08-14 20:38:57,432 WARN c.a.c.j.j.c.MALTListener: TEST ENDED EVENT - completed
2023-08-14 20:38:57,433 WARN c.a.c.j.j.c.MALTFileWriterListener: Received Event testEnded
2023-08-14 20:38:57,435 INFO o.a.j.r.Summariser: summary =      1 in 00:00:03 =    0.4/s Avg:  1008 Min:  1008 Max:  1008 Err:     1 (100.00%)

我可以在**./jmeter/lib/ext文件夹 * 下看到自定义文件夹(Dicom.jar)文件,但在任何地方都看不到 *output.dcmImages-1-min.jpg

oyxsuwqo

oyxsuwqo1#

我能够“看到”文件在/root/artifacts文件夹下

另外,考虑到您的“自定义”Dicom.jar是一个Java库,您可以直接从Groovy调用它的main method或相关的转换函数,而不必运行命令行解释器,在这种情况下,您的测试将是跨平台的。
更多信息请参阅:

相关问题