⚡ 优化单元测试.
This commit is contained in:
@@ -20,21 +20,21 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.dromara.visor.launch.configuration;
|
package org.dromara.visor.common.configuration;
|
||||||
|
|
||||||
import cn.orionsec.kit.spring.SpringHolder;
|
import cn.orionsec.kit.spring.SpringHolder;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用配置类
|
* spring 配置类
|
||||||
*
|
*
|
||||||
* @author Jiahang Li
|
* @author Jiahang Li
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 2023/6/20 10:34
|
* @since 2023/6/20 10:34
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class LaunchApplicationConfiguration {
|
public class SpringConfiguration {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return spring 容器工具类
|
* @return spring 容器工具类
|
||||||
@@ -24,6 +24,7 @@ package org.dromara.visor.framework.test.core.base;
|
|||||||
|
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||||
|
import org.dromara.visor.common.configuration.SpringConfiguration;
|
||||||
import org.dromara.visor.framework.datasource.configuration.OrionDataSourceAutoConfiguration;
|
import org.dromara.visor.framework.datasource.configuration.OrionDataSourceAutoConfiguration;
|
||||||
import org.dromara.visor.framework.mybatis.configuration.OrionMybatisAutoConfiguration;
|
import org.dromara.visor.framework.mybatis.configuration.OrionMybatisAutoConfiguration;
|
||||||
import org.dromara.visor.framework.redis.configuration.OrionRedisAutoConfiguration;
|
import org.dromara.visor.framework.redis.configuration.OrionRedisAutoConfiguration;
|
||||||
@@ -57,6 +58,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
public class BaseUnitTest {
|
public class BaseUnitTest {
|
||||||
|
|
||||||
@Import({
|
@Import({
|
||||||
|
// spring
|
||||||
|
SpringConfiguration.class,
|
||||||
// mock
|
// mock
|
||||||
OrionMockBeanTestConfiguration.class,
|
OrionMockBeanTestConfiguration.class,
|
||||||
OrionMockRedisTestConfiguration.class,
|
OrionMockRedisTestConfiguration.class,
|
||||||
@@ -74,7 +77,6 @@ public class BaseUnitTest {
|
|||||||
RedisAutoConfiguration.class,
|
RedisAutoConfiguration.class,
|
||||||
RedissonAutoConfiguration.class,
|
RedissonAutoConfiguration.class,
|
||||||
})
|
})
|
||||||
// TODO
|
|
||||||
public static class Application {
|
public static class Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,11 @@ import java.util.Optional;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 2023/6/19 16:55
|
* @since 2023/6/19 16:55
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication(scanBasePackages = {"org.dromara.visor.launch", "org.dromara.visor.module"})
|
@SpringBootApplication(scanBasePackages = {
|
||||||
|
"org.dromara.visor.launch",
|
||||||
|
"org.dromara.visor.common",
|
||||||
|
"org.dromara.visor.module"
|
||||||
|
})
|
||||||
public class LaunchApplication {
|
public class LaunchApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -82,6 +82,10 @@
|
|||||||
<groupId>org.dromara.visor</groupId>
|
<groupId>org.dromara.visor</groupId>
|
||||||
<artifactId>orion-visor-spring-boot-starter-job</artifactId>
|
<artifactId>orion-visor-spring-boot-starter-job</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dromara.visor</groupId>
|
||||||
|
<artifactId>orion-visor-spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -135,13 +135,6 @@ public interface HostService {
|
|||||||
*/
|
*/
|
||||||
void deleteHostRelByIdListAsync(List<Long> idList);
|
void deleteHostRelByIdListAsync(List<Long> idList);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前更新配置的 hostId
|
|
||||||
*
|
|
||||||
* @return hostId
|
|
||||||
*/
|
|
||||||
Long getCurrentUpdateConfigHostId();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除缓存
|
* 清除缓存
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -83,8 +83,6 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
public class HostServiceImpl implements HostService {
|
public class HostServiceImpl implements HostService {
|
||||||
|
|
||||||
private static final ThreadLocal<Long> CURRENT_UPDATE_CONFIG_ID = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private HostDAO hostDAO;
|
private HostDAO hostDAO;
|
||||||
|
|
||||||
@@ -185,30 +183,25 @@ public class HostServiceImpl implements HostService {
|
|||||||
OperatorLogs.add(ExtraFieldConst.CONFIG, param);
|
OperatorLogs.add(ExtraFieldConst.CONFIG, param);
|
||||||
log.info("HostService-updateHostConfig request: {}", param);
|
log.info("HostService-updateHostConfig request: {}", param);
|
||||||
Long id = request.getId();
|
Long id = request.getId();
|
||||||
try {
|
// 查询主机信息
|
||||||
CURRENT_UPDATE_CONFIG_ID.set(id);
|
HostDO host = hostDAO.selectById(id);
|
||||||
// 查询主机信息
|
Valid.notNull(host, ErrorMessage.HOST_ABSENT);
|
||||||
HostDO host = hostDAO.selectById(id);
|
HostTypeEnum type = Valid.valid(HostTypeEnum::of, host.getType());
|
||||||
Valid.notNull(host, ErrorMessage.HOST_ABSENT);
|
GenericsDataModel beforeConfig = type.parse(host.getConfig());
|
||||||
HostTypeEnum type = Valid.valid(HostTypeEnum::of, host.getType());
|
GenericsDataModel newConfig = type.parse(request.getConfig());
|
||||||
GenericsDataModel beforeConfig = type.parse(host.getConfig());
|
// 添加日志参数
|
||||||
GenericsDataModel newConfig = type.parse(request.getConfig());
|
OperatorLogs.add(OperatorLogs.ID, id);
|
||||||
// 添加日志参数
|
OperatorLogs.add(OperatorLogs.NAME, host.getName());
|
||||||
OperatorLogs.add(OperatorLogs.ID, id);
|
// 更新前校验
|
||||||
OperatorLogs.add(OperatorLogs.NAME, host.getName());
|
type.doValid(beforeConfig, newConfig);
|
||||||
// 更新前校验
|
// 修改配置
|
||||||
type.doValid(beforeConfig, newConfig);
|
HostDO updateHost = HostDO.builder()
|
||||||
// 修改配置
|
.id(id)
|
||||||
HostDO updateHost = HostDO.builder()
|
.config(newConfig.serial())
|
||||||
.id(id)
|
.build();
|
||||||
.config(newConfig.serial())
|
int effect = hostDAO.updateById(updateHost);
|
||||||
.build();
|
log.info("HostService-updateHostConfig effect: {}", effect);
|
||||||
int effect = hostDAO.updateById(updateHost);
|
return effect;
|
||||||
log.info("HostService-updateHostConfig effect: {}", effect);
|
|
||||||
return effect;
|
|
||||||
} finally {
|
|
||||||
CURRENT_UPDATE_CONFIG_ID.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -348,11 +341,6 @@ public class HostServiceImpl implements HostService {
|
|||||||
dataExtraApi.deleteByRelIdList(DataExtraTypeEnum.HOST, idList);
|
dataExtraApi.deleteByRelIdList(DataExtraTypeEnum.HOST, idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long getCurrentUpdateConfigHostId() {
|
|
||||||
return CURRENT_UPDATE_CONFIG_ID.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
RedisMaps.scanKeysDelete(HostCacheKeyDefine.HOST_INFO.format("*"));
|
RedisMaps.scanKeysDelete(HostCacheKeyDefine.HOST_INFO.format("*"));
|
||||||
|
|||||||
Reference in New Issue
Block a user