REM:
1.修改缓存设备信息的哈希表key值
2.修改获取设备信息的单元测试
This commit is contained in:
chenlinghy 2021-01-22 14:29:55 +08:00
parent 1165e7e690
commit ae5457ada5
3 changed files with 21 additions and 12 deletions

View File

@ -18,9 +18,10 @@ public interface DisposeAbilityRouterService {
*
* @param ipAddr the ip addr
* @param ipPort the ip port
* @param deviceType the device type
* @return the ability device
*/
AbilityInfo getAbilityDevice(String ipAddr, String ipPort);
AbilityInfo getAbilityDevice(String ipAddr, String ipPort, String deviceType);
/**
* Gets ability device.

View File

@ -65,11 +65,12 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
*
* @param ipAddr the ip addr
* @param ipPort the ip port
* @param deviceType the device type
* @return the ability device
*/
@Override
public AbilityInfo getAbilityDevice(String ipAddr, String ipPort) {
return disposeAbilityMap.get(getAbilityDeviceHashKey(ipAddr, ipPort));
public AbilityInfo getAbilityDevice(String ipAddr, String ipPort, String deviceType) {
return disposeAbilityMap.get(getAbilityDeviceHashKey(ipAddr, ipPort, deviceType));
}
/**
@ -86,7 +87,8 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
.orElse(null);
if (dev != null) {
return disposeAbilityMap.get(getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort()));
return disposeAbilityMap.get(getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(),
String.valueOf(dev.getDeviceType())));
}
return null;
@ -113,7 +115,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
DisposeAbility db;
String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://";
String addr = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort());
String addr = (dev.getIpPort() == null || dev.getIpPort().length() == 0) ? dev.getIpAddr() : (dev.getIpAddr() + ":" + dev.getIpPort());
String url = httpType + addr + "/" + dev.getUrlPath();
switch (dev.getDeviceType()) {
@ -145,8 +147,11 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
db.initDeviceEnv(url, dev.getUserName(), dev.getPassword());
db.getDisposeDeviceProtectObject();
String hashKey = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(),
String.valueOf(dev.getDeviceType()));
// 缓存处置设备到Hash表中
disposeAbilityMap.put(addr, AbilityInfo.builder()
disposeAbilityMap.put(hashKey, AbilityInfo.builder()
.db(db)
.dev(dev)
.linkStatus(false)
@ -206,7 +211,8 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
* @param ipPort the ip port
* @return the ability device hash key
*/
private String getAbilityDeviceHashKey(String ipAddr, String ipPort) {
return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort);
private String getAbilityDeviceHashKey(String ipAddr, String ipPort, String deviceType) {
String addrPort = ipPort == null || ipPort.length() == 0 ? ipAddr : (ipAddr + ":" + ipPort);
return addrPort + "-" + deviceType;
}
}

View File

@ -149,7 +149,8 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
e.printStackTrace();
}
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort());
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort(),
String.valueOf(v.getDeviceType()));
Assert.assertNotNull(abilityInfo);
@ -251,7 +252,8 @@ public class DisposeAbilityRouterServiceTest extends InitTestEnvironment {
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceList));
deviceList.forEach(v -> {
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort());
AbilityInfo abilityInfo = disposeAbilityRouterService.getAbilityDevice(v.getIpAddr(), v.getIpPort(),
String.valueOf(v.getDeviceType()));
Assert.assertNotNull(abilityInfo);
Assert.assertNotNull(abilityInfo.getDev());