当前位置:网站首页>websocket长链接压测
websocket长链接压测
2022-06-24 19:43:00 【苗苗大佬】
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());//使用CBC模式,需要一个向量iv,可增加加密算法的强度
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);//此处使用BASE64做转码。
}
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("加密前content传参--------{}",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("鉴权成功"))){
logger.info("response ==============:[ "+result +" ]")
TestUtils.transactionSuccess(transname)
}
else if ((resultCode==302)||(resultCode==301 || resultCode==500)){
logger.error("加密前content传参--------{}",s)
logger.error("result code error ===============:[ " + resultCode + " ]")
logger.error("request.url========"+ requesturl)
logger.error("response ERROR==========:[ "+result +" ]")
TestUtils.transactionFailure(transname)
}
else {
logger.error("加密前content传参--------{}",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("加密前content传参--------{}",s)
logger.error("errorException---:{}",e.getMessage())
TestUtils.transactionFailure(transname)
}
}
}
边栏推荐
- Laravel scheduled task
- 华为机器学习服务语音识别功能,让应用绘“声”绘色
- 378. 骑士放置
- 宁德时代定增450亿:高瓴认购30亿 曾毓群仍控制23%股权
- Laravel user authorization
- 【js】-【栈、队-应用】-学习笔记
- Accounting standards for business enterprises application [5]
- 監聽 Markdown 文件並熱更新 Next.js 頁面
- Dig deep into MySQL - resolve the difference between clustered and non clustered indexes
- golang convert map to json string
猜你喜欢

01_ Getting started with the spingboot framework

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

安装IBM CPLEX学术版 academic edition | conda 安装 CPLEX
![[JS] - [linked list - application] - learning notes](/img/e1/76d2a347b05212de349322f43e0b3a.png)
[JS] - [linked list - application] - learning notes

03_SpingBoot 核心配置文件

SimpleDateFormat 格式化和解析日期的具体类

点的螺旋距离

03_ Spingboot core profile

Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!

Canvas to add watermark to pictures
随机推荐
07_ Springboot for restful style
【js】-【栈、队-应用】-学习笔记
golang map clear
379. hide and seek
Notes for laravel model
Laravel creates a service layer
第六章 网络学习相关技巧5(超参数验证)
Epics record reference 2 -- epics process database concept
laravel学习笔记
379. 捉迷藏
378. Knight placement
Uip1.0 active sending problem understanding
Financial management [5]
Some updates about a hand slider (6-18, JS reverse)
Installation and deployment of ganglia
Construction equipment [6]
Laravel pagoda security configuration
EMI的主要原因-工模电流
UNION ALL UNION FULL JOIN
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)