Commit 075157417c90218244e0c369eb15cf20ad912536

Authored by YunaiV
1 parent 9a31613e

清理代码:无用的 test-integration 目录,暂时不考虑集成测试

yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/cache/CacheUtils.java
1 1 package cn.iocoder.yudao.framework.common.util.cache;
2 2  
3   -import com.alibaba.ttl.threadpool.TtlExecutors;
4 3 import com.google.common.cache.CacheBuilder;
5 4 import com.google.common.cache.CacheLoader;
6 5 import com.google.common.cache.LoadingCache;
7 6  
8 7 import java.time.Duration;
9   -import java.util.concurrent.Executor;
10   -import java.util.concurrent.ExecutorService;
11 8 import java.util.concurrent.Executors;
12 9  
13 10 /**
... ... @@ -17,17 +14,36 @@ import java.util.concurrent.Executors;
17 14 */
18 15 public class CacheUtils {
19 16  
  17 + /**
  18 + * 构建异步刷新的 LoadingCache 对象
  19 + *
  20 + * 注意:如果你的缓存和 ThreadLocal 有关系,要么自己处理 ThreadLocal 的传递,要么使用 {@link #buildCache(Duration, CacheLoader)} 方法
  21 + *
  22 + * 或者简单理解:
  23 + * 1、和“人”相关的,使用 {@link #buildCache(Duration, CacheLoader)} 方法
  24 + * 2、和“全局”、“系统”相关的,使用当前缓存方法
  25 + *
  26 + * @param duration 过期时间
  27 + * @param loader CacheLoader 对象
  28 + * @return LoadingCache 对象
  29 + */
20 30 public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader) {
21   - // 1. 使用 TTL 包装 ExecutorService,实现 ThreadLocal 的透传
22   - // https://github.com/YunaiV/ruoyi-vue-pro/issues/432
23   - ExecutorService executorService = Executors.newCachedThreadPool(); // TODO 芋艿:可能要思考下,未来要不要做成可配置
24   - Executor executor = TtlExecutors.getTtlExecutorService(executorService);
25   - // 2. 创建 Guava LoadingCache
26 31 return CacheBuilder.newBuilder()
27 32 // 只阻塞当前数据加载线程,其他线程返回旧值
28 33 .refreshAfterWrite(duration)
29 34 // 通过 asyncReloading 实现全异步加载,包括 refreshAfterWrite 被阻塞的加载线程
30   - .build(CacheLoader.asyncReloading(loader, executor));
  35 + .build(CacheLoader.asyncReloading(loader, Executors.newCachedThreadPool())); // TODO 芋艿:可能要思考下,未来要不要做成可配置
  36 + }
  37 +
  38 + /**
  39 + * 构建同步刷新的 LoadingCache 对象
  40 + *
  41 + * @param duration 过期时间
  42 + * @param loader CacheLoader 对象
  43 + * @return LoadingCache 对象
  44 + */
  45 + public static <K, V> LoadingCache<K, V> buildCache(Duration duration, CacheLoader<K, V> loader) {
  46 + return CacheBuilder.newBuilder().refreshAfterWrite(duration).build(loader);
31 47 }
32 48  
33 49 }
... ...
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java
... ... @@ -47,7 +47,6 @@ public interface ErrorCodeConstants {
47 47 ErrorCode CODEGEN_MASTER_TABLE_NOT_EXISTS = new ErrorCode(1_001_004_010, "主表(id={})定义不存在,请检查");
48 48 ErrorCode CODEGEN_SUB_COLUMN_NOT_EXISTS = new ErrorCode(1_001_004_011, "子表的字段(id={})不存在,请检查");
49 49 ErrorCode CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_TABLE = new ErrorCode(1_001_004_012, "主表生成代码失败,原因:它没有子表");
50   - ErrorCode CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_COLUMN = new ErrorCode(1_001_004_013, "主表生成代码失败,原因:它的子表({})没有字段");
51 50  
52 51 // ========== 文件配置 1-001-006-000 ==========
53 52 ErrorCode FILE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_006_000, "文件配置不存在");
... ... @@ -57,9 +56,6 @@ public interface ErrorCodeConstants {
57 56 ErrorCode DATA_SOURCE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_007_000, "数据源配置不存在");
58 57 ErrorCode DATA_SOURCE_CONFIG_NOT_OK = new ErrorCode(1_001_007_001, "数据源配置不正确,无法进行连接");
59 58  
60   - // ========== 数据源配置 1-001-107-000 ==========
61   - ErrorCode DEMO_STUDENT_NOT_EXISTS = new ErrorCode(1_001_107_000, "学生不存在");
62   -
63 59 // ========== 学生 1-001-201-000 ==========
64 60 ErrorCode DEMO01_CONTACT_NOT_EXISTS = new ErrorCode(1_001_201_000, "示例联系人不存在");
65 61 ErrorCode DEMO02_CATEGORY_NOT_EXISTS = new ErrorCode(1_001_201_001, "示例分类不存在");
... ...
yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/job/SchedulerManagerTest.java deleted
1   -package cn.iocoder.yudao.module.system.job;
2   -
3   -import cn.hutool.core.util.StrUtil;
4   -import cn.iocoder.yudao.framework.quartz.core.scheduler.SchedulerManager;
5   -import cn.iocoder.yudao.module.system.job.auth.UserSessionTimeoutJob;
6   -import cn.iocoder.yudao.module.system.test.BaseDbUnitTest;
7   -import org.junit.jupiter.api.Test;
8   -import org.quartz.SchedulerException;
9   -
10   -import jakarta.annotation.Resource;
11   -
12   -public class SchedulerManagerTest extends BaseDbUnitTest {
13   -
14   - @Resource
15   - private SchedulerManager schedulerManager;
16   -
17   - @Test
18   - public void testAddJob() throws SchedulerException {
19   - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName());
20   - schedulerManager.addJob(1L, jobHandlerName, "test", "0/10 * * * * ? *", 0, 0);
21   - }
22   -
23   - @Test
24   - public void testUpdateJob() throws SchedulerException {
25   - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName());
26   - schedulerManager.updateJob(jobHandlerName, "hahaha", "0/20 * * * * ? *", 0, 0);
27   - }
28   -
29   - @Test
30   - public void testDeleteJob() throws SchedulerException {
31   - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName());
32   - schedulerManager.deleteJob(jobHandlerName);
33   - }
34   -
35   - @Test
36   - public void testPauseJob() throws SchedulerException {
37   - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName());
38   - schedulerManager.pauseJob(jobHandlerName);
39   - }
40   -
41   - @Test
42   - public void testResumeJob() throws SchedulerException {
43   - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName());
44   - schedulerManager.resumeJob(jobHandlerName);
45   - }
46   -
47   - @Test
48   - public void testTriggerJob() throws SchedulerException {
49   - String jobHandlerName = StrUtil.lowerFirst(UserSessionTimeoutJob.class.getSimpleName());
50   - schedulerManager.triggerJob(1L, jobHandlerName, "niubi!!!");
51   - }
52   -
53   -}
yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/mq/RedisStreamTest.java deleted
1   -package cn.iocoder.yudao.module.system.mq;
2   -
3   -import cn.hutool.core.thread.ThreadUtil;
4   -import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
5   -import cn.iocoder.yudao.module.system.mq.consumer.mail.MailSendConsumer;
6   -import cn.iocoder.yudao.module.system.mq.consumer.sms.SmsSendConsumer;
7   -import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage;
8   -import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage;
9   -import cn.iocoder.yudao.module.system.test.BaseRedisIntegrationTest;
10   -import org.junit.jupiter.api.Disabled;
11   -import org.junit.jupiter.api.Test;
12   -import org.springframework.context.annotation.Import;
13   -import org.springframework.data.redis.core.RedisTemplate;
14   -
15   -import jakarta.annotation.Resource;
16   -import java.util.concurrent.TimeUnit;
17   -
18   -public class RedisStreamTest {
19   -
20   - @Import({SmsSendConsumer.class, MailSendConsumer.class})
21   - @Disabled
22   - public static class ConsumerTest extends BaseRedisIntegrationTest {
23   -
24   - @Test
25   - public void testConsumer() {
26   - ThreadUtil.sleep(1, TimeUnit.DAYS);
27   - }
28   -
29   - }
30   -
31   - @Disabled
32   - public static class ProducerTest extends BaseRedisIntegrationTest {
33   -
34   - @Resource
35   - private RedisMQTemplate redisMQTemplate;
36   -
37   - @Resource
38   - private RedisTemplate<String, Object> redisTemplate;
39   -
40   - @Test
41   - public void testProducer01() {
42   - for (int i = 0; i < 100; i++) {
43   - // 创建消息
44   - SmsSendMessage message = new SmsSendMessage();
45   - message.setMobile("15601691300").setApiTemplateId("test:" + i);
46   - // 发送消息
47   - redisMQTemplate.send(message);
48   - }
49   - }
50   -
51   - @Test
52   - public void testProducer02() {
53   - // 创建消息
54   - MailSendMessage message = new MailSendMessage();
55   - message.setAddress("fangfang@mihayou.com").setTemplateCode("test");
56   - // 发送消息
57   - redisMQTemplate.send(message);
58   - }
59   -
60   - }
61   -
62   -}
yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/package-info.java deleted
1   -/**
2   - * 占位
3   - */
4   -package cn.iocoder.yudao.module.system.service;
yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/service/sms/SmsServiceIntegrationTest.java deleted
1   -package cn.iocoder.yudao.module.system.service.sms;
2   -
3   -import cn.hutool.core.map.MapUtil;
4   -import cn.hutool.core.thread.ThreadUtil;
5   -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
6   -import cn.iocoder.yudao.framework.sms.config.YudaoSmsAutoConfiguration;
7   -import cn.iocoder.yudao.module.system.test.BaseDbAndRedisIntegrationTest;
8   -import cn.iocoder.yudao.module.system.mq.consumer.sms.SmsSendConsumer;
9   -import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer;
10   -import cn.iocoder.yudao.module.system.service.user.AdminUserService;
11   -import org.junit.jupiter.api.Test;
12   -import org.springframework.boot.test.mock.mockito.MockBean;
13   -import org.springframework.context.annotation.Import;
14   -
15   -import jakarta.annotation.Resource;
16   -import java.util.Map;
17   -import java.util.concurrent.TimeUnit;
18   -
19   -// TODO @芋艿:需要迁移
20   -@Import({YudaoSmsAutoConfiguration.class,
21   - SmsChannelServiceImpl.class, SmsSendServiceImpl.class, SmsTemplateServiceImpl.class, SmsLogServiceImpl.class,
22   - SmsProducer.class, SmsSendConsumer.class})
23   -public class SmsServiceIntegrationTest extends BaseDbAndRedisIntegrationTest {
24   -
25   - @Resource
26   - private SmsSendServiceImpl smsService;
27   - @Resource
28   - private SmsChannelServiceImpl smsChannelService;
29   -
30   - @MockBean
31   - private AdminUserService userService;
32   -
33   - @Test
34   - public void testSendSingleSms_aliyunSuccess() {
35   - // 参数准备
36   - String mobile = "15601691399";
37   - Long userId = 1L;
38   - Integer userType = UserTypeEnum.ADMIN.getValue();
39   - String templateCode = "test_02";
40   - Map<String, Object> templateParams = MapUtil.<String, Object>builder()
41   - .put("code", "1234").build();
42   - // 调用
43   - smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams);
44   -
45   - // 等待 MQ 消费
46   - ThreadUtil.sleep(1, TimeUnit.HOURS);
47   - }
48   -
49   -// @Test
50   -// public void testDoSendSms() {
51   -// // 等待 MQ 消费
52   -// ThreadUtil.sleep(1, TimeUnit.HOURS);
53   -// }
54   -
55   -}
yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseDbAndRedisIntegrationTest.java deleted
1   -package cn.iocoder.yudao.module.system.test;
2   -
3   -import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration;
4   -import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration;
5   -import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
6   -import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
7   -import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
8   -import org.redisson.spring.starter.RedissonAutoConfiguration;
9   -import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
10   -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
11   -import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
12   -import org.springframework.boot.test.context.SpringBootTest;
13   -import org.springframework.context.annotation.Import;
14   -import org.springframework.test.context.ActiveProfiles;
15   -
16   -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisIntegrationTest.Application.class)
17   -@ActiveProfiles("integration-test") // 设置使用 application-integration-test 配置文件
18   -public class BaseDbAndRedisIntegrationTest {
19   -
20   - @Import({
21   - // DB 配置类
22   - DynamicDataSourceAutoConfiguration.class, // Dynamic Datasource 配置类
23   - YudaoDataSourceAutoConfiguration.class, // 自己的 DB 配置类
24   - DataSourceAutoConfiguration.class, // Spring DB 自动配置类
25   - DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类
26   - // MyBatis 配置类
27   - YudaoMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类
28   - MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
29   -
30   - // Redis 配置类
31   - RedisAutoConfiguration.class, // Spring Redis 自动配置类
32   - YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类
33   - RedissonAutoConfiguration.class, // Redisson 自动高配置类
34   - })
35   - public static class Application {
36   - }
37   -
38   -}
yudao-module-system/yudao-module-system-biz/src/test-integration/java/cn/iocoder/yudao/module/system/test/BaseRedisIntegrationTest.java deleted
1   -package cn.iocoder.yudao.module.system.test;
2   -
3   -import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
4   -import org.redisson.spring.starter.RedissonAutoConfiguration;
5   -import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
6   -import org.springframework.boot.test.context.SpringBootTest;
7   -import org.springframework.context.annotation.Import;
8   -import org.springframework.test.context.ActiveProfiles;
9   -
10   -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseRedisIntegrationTest.Application.class)
11   -@ActiveProfiles("integration-test") // 设置使用 application-integration-test 配置文件
12   -public class BaseRedisIntegrationTest {
13   -
14   - @Import({
15   - // Redis 配置类
16   - RedisAutoConfiguration.class, // Spring Redis 自动配置类
17   - YudaoRedisAutoConfiguration.class, // 自己的 Redis 配置类
18   - RedissonAutoConfiguration.class, // Redisson 自动高配置类
19   - })
20   - public static class Application {
21   - }
22   -
23   -}
yudao-module-system/yudao-module-system-biz/src/test-integration/resources/application-integration-test.yaml deleted
1   -spring:
2   - main:
3   - lazy-initialization: true # 开启懒加载,加快速度
4   - banner-mode: off # 单元测试,禁用 Banner
5   -
6   ---- #################### 数据库相关配置 ####################
7   -
8   -spring:
9   - # 数据源配置项
10   - autoconfigure:
11   - exclude:
12   - - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
13   - datasource:
14   - druid: # Druid 【监控】相关的全局配置
15   - web-stat-filter:
16   - enabled: true
17   - stat-view-servlet:
18   - enabled: true
19   - allow: # 设置白名单,不填则允许所有访问
20   - url-pattern: /druid/*
21   - login-username: # 控制台管理用户名和密码
22   - login-password:
23   - filter:
24   - stat:
25   - enabled: true
26   - log-slow-sql: true # 慢 SQL 记录
27   - slow-sql-millis: 100
28   - merge-sql: true
29   - wall:
30   - config:
31   - multi-statement-allow: true
32   - dynamic: # 多数据源配置
33   - druid: # Druid 【连接池】相关的全局配置
34   - initial-size: 5 # 初始连接数
35   - min-idle: 10 # 最小连接池数量
36   - max-active: 20 # 最大连接池数量
37   - max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒
38   - time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒
39   - min-evictable-idle-time-millis: 300000 # 配置一个连接在池中最小生存的时间,单位:毫秒
40   - max-evictable-idle-time-millis: 900000 # 配置一个连接在池中最大生存的时间,单位:毫秒
41   - validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效
42   - test-while-idle: true
43   - test-on-borrow: false
44   - test-on-return: false
45   - primary: master
46   - datasource:
47   - master:
48   - name: ruoyi-vue-pro
49   - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
50   - driver-class-name: com.mysql.jdbc.Driver
51   - username: root
52   - password: 123456
53   - slave: # 模拟从库,可根据自己需要修改
54   - name: ruoyi-vue-pro
55   - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
56   - driver-class-name: com.mysql.jdbc.Driver
57   - username: root
58   - password: 123456
59   -
60   - # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
61   - data:
62   - redis:
63   - host: 127.0.0.1 # 地址
64   - port: 16379 # 端口(单元测试,使用 16379 端口)
65   - database: 0 # 数据库索引
66   -
67   -mybatis:
68   - lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
69   -
70   ---- #################### 定时任务相关配置 ####################
71   -
72   ---- #################### 配置中心相关配置 ####################
73   -
74   ---- #################### 服务保障相关配置 ####################
75   -
76   -# Lock4j 配置项(单元测试,禁用 Lock4j)
77   -
78   ---- #################### 监控相关配置 ####################
79   -
80   ---- #################### 芋道相关配置 ####################
81   -
82   -# 芋道配置项,设置当前项目所有自定义的配置
83   -yudao:
84   - security:
85   - token-header: Authorization
86   - token-secret: abcdefghijklmnopqrstuvwxyz
87   - token-timeout: 1d
88   - session-timeout: 30m
89   - mock-enable: true
90   - mock-secret: test
91   - swagger:
92   - enable: false # 单元测试,禁用 Swagger
93   - file:
94   - base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/
95   - xss:
96   - enable: false
97   - exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系
98   - - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求
99   - - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求