当前位置:网站首页>Websocket long link pressure test
Websocket long link pressure test
2022-06-24 23:24:00 【Miaomiao boss】
package Script
import okhttp3.FormBody
import okhttp3.MediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.slf4j.Logger
import sun.misc.BASE64Encoder
import javax.crypto.BadPaddingException
import javax.crypto.Cipher
import javax.crypto.IllegalBlockSizeException
import javax.crypto.NoSuchPaddingException
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
import java.security.InvalidAlgorithmParameterException
import java.security.InvalidKeyException
import java.security.NoSuchAlgorithmException
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger
@TestSuite
class live {
public final Logger logger = TestUtils.LOGGER;
public static AtomicInteger incrKey = new AtomicInteger(1);
public final OkHttpClient client;
public final Request.Builder builder;
public static String transname = ""
public static String iv = ""
public final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8");
live() {
client = new OkHttpClient().newBuilder()
.connectTimeout(6, TimeUnit.SECONDS)
.readTimeout(6, TimeUnit.SECONDS)
.writeTimeout(6, TimeUnit.SECONDS)
.followRedirects(false)
.build();
builder = new Request.Builder();
logger.info("TestRunner init...");
}
public static String encrypt(String sSrc,String sKey){
Cipher cipher = null;
try {
cipher = Cipher.getInstance("");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
}
byte[] raw = sKey.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "");
IvParameterSpec iv = new IvParameterSpec(iv.getBytes());// Use CBC Pattern , We need a vector iv, It can increase the strength of encryption algorithm
try {
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
}
byte[] encrypted = new byte[0];
try {
encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new BASE64Encoder().encode(encrypted);// Use here BASE64 Transcoding .
}
static int increment() {
return incrKey.getAndIncrement();
}
@TestCase(record = false)
void test() {
int resultCode
String s = String.format("{\"random\":\"123456\",\"clientType\":\"ios\",\"secretKey\":\"\",\"pin\":\"\",\"appId\":\"\",\"groupId\":\"\",\"timestamp\":%d}",increment().toString(),System.currentTimeMillis())
logger.info(" Before encryption content The ginseng --------{}",s)
String content = encrypt(s,"").replaceAll("[\\s*\t\n\r]", "");
String json = String.format("{\"appId\":\"\",\"content\":\"%s\"}",content)
logger.info("json--------{}",json)
FormBody requestBodyPost = new FormBody.Builder()
.add("body",json)
.build();
Request requesturl = builder
.url("")
.post(requestBodyPost)
.build()
TestUtils.transactionBegin(transname)
try {
Response response = client.newCall(requesturl).execute();
String result;
resultCode =response.code();
result=response.body().string()
response.close();
if ((resultCode==200) & (result.contains(" Authentication success "))){
logger.info("response ==============:[ "+result +" ]")
TestUtils.transactionSuccess(transname)
}
else if ((resultCode==302)||(resultCode==301 || resultCode==500)){
logger.error(" Before encryption content The ginseng --------{}",s)
logger.error("result code error ===============:[ " + resultCode + " ]")
logger.error("request.url========"+ requesturl)
logger.error("response ERROR==========:[ "+result +" ]")
TestUtils.transactionFailure(transname)
}
else {
logger.error(" Before encryption content The ginseng --------{}",s)
logger.error("result code error ===============:[ " + resultCode + " ]")
logger.error("url ERROR ===============:[ "+requesturl +" ]")
logger.error("response ERROR==========:[ "+result +" ]")
TestUtils.transactionFailure(transname)
}
}catch (Exception e) {
e.properties;
logger.error(" Before encryption content The ginseng --------{}",s)
logger.error("errorException---:{}",e.getMessage())
TestUtils.transactionFailure(transname)
}
}
}
边栏推荐
- Laravel message queue
- OpenSSL SSL_read: Connection was reset, errno 10054
- 冒泡排序
- 宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
- 华为机器学习服务语音识别功能,让应用绘“声”绘色
- Super detailed cookie addition, deletion, modification and query
- 基本数据类型
- Docker-mysql8-master-slave
- Detailed explanation of online group chat and dating platform project (servlet implementation)
- Dig deep into MySQL - resolve the difference between clustered and non clustered indexes
猜你喜欢

HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
15 lines of code using mathematical formulas in wangeditor V5

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis

Online group chat and dating platform test point

【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化

【js】-【數組、棧、隊列、鏈錶基礎】-筆記

Case analysis: using "measurement" to improve enterprise R & D efficiency | ones talk

File contains vulnerability issues

Super detailed cookie addition, deletion, modification and query

EMI的主要原因-工模电流
随机推荐
Learn about redlock
RT thread uses RT kprintf
Uip1.0 active sending problem understanding
Binary lookup array subscript
Chapter VI skills related to e-learning 5 (super parameter verification)
Construction equipment [5]
Financial management [5]
257. 关押罪犯
R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
Basic data type
Dig deep into MySQL - resolve the clustered index / secondary index / federated index of InnoDB storage engine
laravel 验证器的使用
Selection (029) - what is the output of the following code?
golang convert map to json string
二分查找数组下标
Construction equipment [6]
Online group chat and dating platform test point
Financial management [3]
EMI的主要原因-工模电流
Installation and deployment of ganglia