性能测试代码
This commit is contained in:
parent
a452376d8d
commit
18aa757871
@ -19,7 +19,7 @@ public class FunctionTest {
|
|||||||
private byte[] orgData = new byte[1024];
|
private byte[] orgData = new byte[1024];
|
||||||
private byte[] orgData2K = new byte[ 2 * 1024 ];
|
private byte[] orgData2K = new byte[ 2 * 1024 ];
|
||||||
private byte[] orgData2M = new byte[ 2 * 1024 * 1024 ];
|
private byte[] orgData2M = new byte[ 2 * 1024 * 1024 ];
|
||||||
private byte[] orgData10M = new byte[ 4 * 1024 * 1024 - 1024];
|
private byte[] orgData10M = new byte[ 10 * 1024 * 1024 ];
|
||||||
private String sign;
|
private String sign;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -130,8 +130,8 @@ public class FunctionTest {
|
|||||||
public void SYD_SM2_Encrypt_10M(){
|
public void SYD_SM2_Encrypt_10M(){
|
||||||
byte[] enData = this.api.SYD_SM2Encrypt(publicKey4Ende, orgData10M);
|
byte[] enData = this.api.SYD_SM2Encrypt(publicKey4Ende, orgData10M);
|
||||||
System.out.println("密文=" + Util.bytes2HexString(enData));
|
System.out.println("密文=" + Util.bytes2HexString(enData));
|
||||||
byte[] deData = this.api.SYD_SM2Decrypt(privateKey4Ende, enData);
|
// byte[] deData = this.api.SYD_SM2Decrypt(privateKey4Ende, enData);
|
||||||
Assert.assertArrayEquals(orgData10M, deData);
|
// Assert.assertArrayEquals(orgData10M, deData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,34 +1,87 @@
|
|||||||
package cmbpoc;
|
package cmbpoc;
|
||||||
|
|
||||||
|
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
import org.apache.jmeter.config.Arguments;
|
import org.apache.jmeter.config.Arguments;
|
||||||
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
|
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
|
||||||
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
|
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
|
||||||
import org.apache.jmeter.samplers.SampleResult;
|
import org.apache.jmeter.samplers.SampleResult;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
||||||
public class JmeterTest extends AbstractJavaSamplerClient {
|
public class JmeterTest extends AbstractJavaSamplerClient {
|
||||||
|
|
||||||
private byte[] publicKey;
|
private byte[] publicKey;
|
||||||
private byte[] plainData;
|
private byte[] plainData;
|
||||||
|
private byte[] encryptedData;
|
||||||
private int sleep = 1;
|
private int sleep = 1;
|
||||||
|
|
||||||
|
private byte[] privateKey4Ende;
|
||||||
|
private byte[] publicKey4Ende;
|
||||||
|
|
||||||
|
private String ip ;
|
||||||
|
private int port;
|
||||||
|
private int timeout;
|
||||||
|
private String ip2 ;
|
||||||
|
|
||||||
|
private ThreadLocal<SydApi4j> api;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Arguments getDefaultParameters() {
|
public Arguments getDefaultParameters() {
|
||||||
Arguments params = new Arguments();
|
Arguments params = new Arguments();
|
||||||
params.addArgument("function", "sleep");
|
params.addArgument("function", "sleep");
|
||||||
params.addArgument("sleep", "1");
|
params.addArgument("sleep", "1");
|
||||||
|
params.addArgument("plainDataLen", "1024");
|
||||||
|
params.addArgument("publicKey4Ende", "", "加密用的公钥");
|
||||||
|
params.addArgument("privateKey4Ende", "", "解密用的公钥");
|
||||||
|
params.addArgument("ip", "192.168.100.145");
|
||||||
|
params.addArgument("ip2", "172.1.41.96");
|
||||||
|
params.addArgument("port", "8889");
|
||||||
|
params.addArgument("timeout", "3000");
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupTest(JavaSamplerContext context) {
|
public void setupTest(JavaSamplerContext context) {
|
||||||
|
// 加密密钥对
|
||||||
|
String publicKey4Ende = context.getParameter("publicKey4Ende");
|
||||||
|
if ( null != publicKey4Ende && !publicKey4Ende.isEmpty()) {
|
||||||
|
this.publicKey4Ende = Util.hexString2Bytes(publicKey4Ende);
|
||||||
|
}
|
||||||
|
String privateKey4Ende = context.getParameter("privateKey4Ende");
|
||||||
|
if ( null != privateKey4Ende && !privateKey4Ende.isEmpty()) {
|
||||||
|
this.privateKey4Ende = Util.hexString2Bytes(privateKey4Ende);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 原始数据
|
||||||
|
int plainDataLen = context.getIntParameter("plainDataLen");
|
||||||
|
plainData = new byte[plainDataLen];
|
||||||
|
new Random().nextBytes(plainData);
|
||||||
|
System.out.println("原始数据长度:" + plainDataLen);
|
||||||
|
|
||||||
// 校准测试
|
// 校准测试
|
||||||
sleep = context.getIntParameter("sleep", 1);
|
sleep = context.getIntParameter("sleep", 1);
|
||||||
|
|
||||||
|
// api
|
||||||
|
ip = context.getParameter("ip");
|
||||||
|
ip2 = context.getParameter("ip2");
|
||||||
|
port = context.getIntParameter("port");
|
||||||
|
timeout = context.getIntParameter("timeout");
|
||||||
|
api = new ThreadLocal<SydApi4j>() {
|
||||||
|
@Override
|
||||||
|
public SydApi4j initialValue() {
|
||||||
|
return (SydApi4j) new SydApi4j().connect(ip, port, null, timeout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 线程开始时准备解密、验签数据
|
// 线程开始时准备解密、验签数据
|
||||||
String function = context.getParameter("function");
|
String function = context.getParameter("function");
|
||||||
switch (function) {
|
switch (function) {
|
||||||
|
case "SYD_SM2_Decrypt":
|
||||||
|
this.encryptedData = this.api.get().SYD_SM2Encrypt(this.publicKey4Ende, this.plainData);
|
||||||
|
break;
|
||||||
case "SYD_SM2_Sign":
|
case "SYD_SM2_Sign":
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -46,6 +99,12 @@ public class JmeterTest extends AbstractJavaSamplerClient {
|
|||||||
result.sampleStart(); // 开始计时
|
result.sampleStart(); // 开始计时
|
||||||
try {
|
try {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
|
case "SYD_SM2_Encrypt":
|
||||||
|
this.api.get().SYD_SM2Encrypt(privateKey4Ende, this.plainData);
|
||||||
|
break;
|
||||||
|
case "SYD_SM2_Decrypt":
|
||||||
|
this.api.get().SYD_SM2Decrypt(privateKey4Ende, this.encryptedData);
|
||||||
|
break;
|
||||||
case "SYD_SM2_Sign":
|
case "SYD_SM2_Sign":
|
||||||
break;
|
break;
|
||||||
case "sleep":
|
case "sleep":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user