测试,线程中断测试
parent
4e33949c95
commit
230e69f64b
|
@ -6,6 +6,7 @@ import com.muyu.utils.VehicleUtils;
|
||||||
import com.muyu.vehicle.core.LocalContainer;
|
import com.muyu.vehicle.core.LocalContainer;
|
||||||
import com.muyu.vehicle.model.VehicleData;
|
import com.muyu.vehicle.model.VehicleData;
|
||||||
import com.muyu.vehicle.model.properties.MqttProperties;
|
import com.muyu.vehicle.model.properties.MqttProperties;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -21,22 +22,30 @@ import static java.lang.Thread.sleep;
|
||||||
* @description:
|
* @description:
|
||||||
* @Date 2023-11-17 上午 09:02
|
* @Date 2023-11-17 上午 09:02
|
||||||
*/
|
*/
|
||||||
|
@Log4j2
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
public static CountDownLatch countDownLatch;
|
public static CountDownLatch countDownLatch;
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
log.info("开始生成VIN");
|
||||||
|
long genVinStartTime = System.currentTimeMillis();
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
list.add(VehicleUtils.genVin());
|
list.add(VehicleUtils.genVin());
|
||||||
}
|
}
|
||||||
countDownLatch = new CountDownLatch(list.size());
|
log.info("生成VIN结束:[{}MS]", System.currentTimeMillis()-genVinStartTime);
|
||||||
|
log.info("开始创建车辆");
|
||||||
|
long initVehicleStartTime = System.currentTimeMillis();
|
||||||
|
list.forEach(Test::init);
|
||||||
|
log.info("创建车辆结束:[{}MS]", System.currentTimeMillis()-initVehicleStartTime);
|
||||||
list.forEach(vin -> {
|
list.forEach(vin -> {
|
||||||
init(vin);
|
VehicleInstance vehicleIns = LocalContainer.getVehicleInstance(vin);
|
||||||
new Thread(new TestThread(vin)).start();
|
vehicleIns.initVehicleThread();
|
||||||
|
vehicleIns.startSend();
|
||||||
});
|
});
|
||||||
countDownLatch.await();
|
// countDownLatch.await();
|
||||||
ThreadPool.shutdown();
|
// ThreadPool.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(String vin){
|
public static void init(String vin){
|
||||||
|
|
|
@ -105,10 +105,9 @@ public class VehicleInstance {
|
||||||
options.setKeepAliveInterval(60);
|
options.setKeepAliveInterval(60);
|
||||||
// 连接
|
// 连接
|
||||||
client.connect(options);
|
client.connect(options);
|
||||||
log.info("mqtt初始化成功");
|
log.info("车辆:[{}] 客户端初始化成功", getVin());
|
||||||
} catch (MqttException e) {
|
} catch (MqttException e) {
|
||||||
log.error("mqtt链接服务器异常:{}", e.getMessage(), e);
|
log.error("车辆:[{}] 客户端初始化异常", getVin(), e);
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ public class VehicleData {
|
||||||
//车速
|
//车速
|
||||||
sb.append(getValue(speed,6));
|
sb.append(getValue(speed,6));
|
||||||
//总里程
|
//总里程
|
||||||
sb.append(getValue(mileage.toString(),11));
|
sb.append(getValue(mileage == null ? "" : mileage.toString(),11));
|
||||||
// 总电压
|
// 总电压
|
||||||
sb.append(getValue(voltage,6));
|
sb.append(getValue(voltage,6));
|
||||||
//总电流
|
//总电流
|
||||||
|
@ -291,7 +291,7 @@ public class VehicleData {
|
||||||
//绝缘电阻 79 - 87
|
//绝缘电阻 79 - 87
|
||||||
sb.append(getValue(resistance,9));
|
sb.append(getValue(resistance,9));
|
||||||
//档位
|
//档位
|
||||||
sb.append(gear);
|
sb.append(gear == null ? "D" : gear);
|
||||||
// 加速踏板行程值
|
// 加速踏板行程值
|
||||||
sb.append(getValue(accelerationPedal,2));
|
sb.append(getValue(accelerationPedal,2));
|
||||||
// 制动踏板行程值
|
// 制动踏板行程值
|
||||||
|
@ -311,7 +311,7 @@ public class VehicleData {
|
||||||
//电机电流
|
//电机电流
|
||||||
sb.append(getValue(motorCurrent,8));
|
sb.append(getValue(motorCurrent,8));
|
||||||
//动力电池剩余电量SOC
|
//动力电池剩余电量SOC
|
||||||
sb.append(getValue(remainingBattery.toString(),6));
|
sb.append(getValue(remainingBattery == null ? "" : remainingBattery.toString(),6));
|
||||||
//当前状态允许的最大反馈功率
|
//当前状态允许的最大反馈功率
|
||||||
sb.append(getValue(maximumFeedbackPower,6));
|
sb.append(getValue(maximumFeedbackPower,6));
|
||||||
//当前状态允许最大放电功率
|
//当前状态允许最大放电功率
|
||||||
|
@ -370,6 +370,9 @@ public class VehicleData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(String val , int valLength){
|
public String getValue(String val , int valLength){
|
||||||
|
if(val == null){
|
||||||
|
val = "";
|
||||||
|
}
|
||||||
int length = val.length();
|
int length = val.length();
|
||||||
if (length > valLength){
|
if (length > valLength){
|
||||||
return val.substring( 0 , valLength);
|
return val.substring( 0 , valLength);
|
||||||
|
|
|
@ -25,9 +25,10 @@ public class VehicleThread implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!isStop){
|
if (!isStop){
|
||||||
if (!isPaused){
|
if (!isPaused){
|
||||||
log.info("{} - 模拟数据", this.vehicleInstance.getVin());
|
|
||||||
log.info("{} - 上报数据", this.vehicleInstance.getVin());
|
log.info("{} - 上报数据", this.vehicleInstance.getVin());
|
||||||
this.vehicleInstance.sendMsg(String.format("%s - 上报数据", this.vehicleInstance.getVin()));
|
this.vehicleInstance.sendMsg(
|
||||||
|
String.format("%s - 上报数据: %s", this.vehicleInstance.getVin(), this.vehicleInstance.getVehicleData().getMsg())
|
||||||
|
);
|
||||||
}else {
|
}else {
|
||||||
log.info("暂停模拟和上报:[{}]", this.vehicleInstance.getVin());
|
log.info("暂停模拟和上报:[{}]", this.vehicleInstance.getVin());
|
||||||
}
|
}
|
||||||
|
@ -49,9 +50,6 @@ public class VehicleThread implements Runnable {
|
||||||
*/
|
*/
|
||||||
public void resume() {
|
public void resume() {
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
synchronized (this) {
|
|
||||||
notify(); // 唤醒线程
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue