Commit f877a24eaa1fdfd15568e750adeea0571d97fd01

Authored by YunaiV
1 parent 762c19ec

【代码优化】PAY:移除 PayClient 缓存,减少复杂性,性能足够(非高频读取)

yudao-module-pay/yudao-module-pay-biz/src/test/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceTest.java
... ... @@ -60,8 +60,6 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
60 60 PayChannelDO channel = channelMapper.selectById(channelId);
61 61 assertPojoEquals(reqVO, channel, "config");
62 62 assertPojoEquals(config, channel.getConfig());
63   - // 校验缓存
64   - assertNull(channelService.getClientCache().getIfPresent(channelId));
65 63 }
66 64  
67 65 @Test
... ... @@ -102,8 +100,6 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
102 100 PayChannelDO channel = channelMapper.selectById(reqVO.getId()); // 获取最新的
103 101 assertPojoEquals(reqVO, channel, "config");
104 102 assertPojoEquals(config, channel.getConfig());
105   - // 校验缓存
106   - assertNull(channelService.getClientCache().getIfPresent(channel.getId()));
107 103 }
108 104  
109 105 @Test
... ... @@ -134,8 +130,6 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
134 130 channelService.deleteChannel(id);
135 131 // 校验数据不存在了
136 132 assertNull(channelMapper.selectById(id));
137   - // 校验缓存
138   - assertNull(channelService.getClientCache().getIfPresent(id));
139 133 }
140 134  
141 135 @Test
... ... @@ -306,20 +300,20 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
306 300 PayChannelDO channel = randomPojo(PayChannelDO.class, o -> {
307 301 o.setCode(PayChannelEnum.ALIPAY_APP.getCode());
308 302 o.setConfig(randomAlipayPayClientConfig());
  303 + o.setStatus(CommonStatusEnum.ENABLE.getStatus());
309 304 });
310 305 channelMapper.insert(channel);
311 306 // mock 参数
312 307 Long id = channel.getId();
313 308 // mock 方法
314 309 PayClient mockClient = mock(PayClient.class);
315   - when(payClientFactory.getPayClient(eq(id))).thenReturn(mockClient);
  310 + when(payClientFactory.createOrUpdatePayClient(eq(id), eq(channel.getCode()), eq(channel.getConfig())))
  311 + .thenReturn(mockClient);
316 312  
317 313 // 调用
318 314 PayClient client = channelService.getPayClient(id);
319 315 // 断言
320 316 assertSame(client, mockClient);
321   - verify(payClientFactory).createOrUpdatePayClient(eq(id), eq(channel.getCode()),
322   - eq(channel.getConfig()));
323 317 }
324 318  
325 319 public WxPayClientConfig randomWxPayClientConfig() {
... ...