mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	短信渠道的本地缓存,使用 Job 轮询,替代 MQ 广播
This commit is contained in:
		| @@ -39,6 +39,9 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic | ||||
| import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||||
| import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | ||||
| import static java.util.Arrays.asList; | ||||
| import static org.hamcrest.CoreMatchers.anyOf; | ||||
| import static org.hamcrest.CoreMatchers.is; | ||||
| import static org.hamcrest.MatcherAssert.assertThat; | ||||
| import static org.junit.jupiter.api.Assertions.*; | ||||
| import static org.mockito.ArgumentMatchers.eq; | ||||
| import static org.mockito.ArgumentMatchers.isNull; | ||||
| @@ -289,7 +292,10 @@ public class OAuth2OpenControllerTest extends BaseMockitoUnitTest { | ||||
|                 scope, redirectUri, true, state); | ||||
|         // 断言 | ||||
|         assertEquals(0, result.getCode()); | ||||
|         assertEquals("https://www.iocoder.cn#access_token=test_access_token&token_type=bearer&state=test&expires_in=30&scope=read", result.getData()); | ||||
|         assertThat(result.getData(), anyOf( // 29 和 30 都有一定概率,主要是时间计算 | ||||
|                 is("https://www.iocoder.cn#access_token=test_access_token&token_type=bearer&state=test&expires_in=29&scope=read"), | ||||
|                 is("https://www.iocoder.cn#access_token=test_access_token&token_type=bearer&state=test&expires_in=30&scope=read") | ||||
|         )); | ||||
|     } | ||||
|  | ||||
|     @Test // autoApprove = false,通过 + code | ||||
|   | ||||
| @@ -9,13 +9,11 @@ import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannel | ||||
| import cn.iocoder.yudao.module.system.controller.admin.sms.vo.channel.SmsChannelUpdateReqVO; | ||||
| import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; | ||||
| import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper; | ||||
| import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; | ||||
| import org.junit.jupiter.api.Test; | ||||
| import org.springframework.boot.test.mock.mockito.MockBean; | ||||
| import org.springframework.context.annotation.Import; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||||
| @@ -42,8 +40,6 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { | ||||
|     private SmsClientFactory smsClientFactory; | ||||
|     @MockBean | ||||
|     private SmsTemplateService smsTemplateService; | ||||
|     @MockBean | ||||
|     private SmsProducer smsProducer; | ||||
|  | ||||
|     @Test | ||||
|     public void testInitLocalCache_success() { | ||||
| @@ -60,6 +56,10 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { | ||||
|                 argThat(properties -> isPojoEquals(smsChannelDO01, properties))); | ||||
|         verify(smsClientFactory, times(1)).createOrUpdateSmsClient( | ||||
|                 argThat(properties -> isPojoEquals(smsChannelDO02, properties))); | ||||
|         // 断言 channelCache 缓存 | ||||
|         assertEquals(2, smsChannelService.getChannelCache().size()); | ||||
|         assertPojoEquals(smsChannelDO01, smsChannelService.getChannelCache().get(0)); | ||||
|         assertPojoEquals(smsChannelDO02, smsChannelService.getChannelCache().get(1)); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
| @@ -74,8 +74,6 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { | ||||
|         // 校验记录的属性是否正确 | ||||
|         SmsChannelDO smsChannel = smsChannelMapper.selectById(smsChannelId); | ||||
|         assertPojoEquals(reqVO, smsChannel); | ||||
|         // 校验调用 | ||||
|         verify(smsProducer, times(1)).sendSmsChannelRefreshMessage(); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
| @@ -95,8 +93,6 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { | ||||
|         // 校验是否更新正确 | ||||
|         SmsChannelDO smsChannel = smsChannelMapper.selectById(reqVO.getId()); // 获取最新的 | ||||
|         assertPojoEquals(reqVO, smsChannel); | ||||
|         // 校验调用 | ||||
|         verify(smsProducer, times(1)).sendSmsChannelRefreshMessage(); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
| @@ -118,10 +114,8 @@ public class SmsChannelServiceTest extends BaseDbUnitTest { | ||||
|  | ||||
|         // 调用 | ||||
|         smsChannelService.deleteSmsChannel(id); | ||||
|        // 校验数据不存在了 | ||||
|        assertNull(smsChannelMapper.selectById(id)); | ||||
|         // 校验调用 | ||||
|         verify(smsProducer, times(1)).sendSmsChannelRefreshMessage(); | ||||
|         // 校验数据不存在了 | ||||
|         assertNull(smsChannelMapper.selectById(id)); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV