From a9436d29317b484615dad9ce0901a31e7bc94a01 Mon Sep 17 00:00:00 2001 From: Lyon <18423215834@163.com> Date: Tue, 9 Mar 2021 20:23:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=B6=85=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC,?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0test=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/job/auth/SysUserSessionTimeoutJob.java | 5 +---- .../service/auth/SysUserSessionService.java | 2 -- .../auth/SysUserSessionServiceImplTest.java | 15 +++++++++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/job/auth/SysUserSessionTimeoutJob.java b/src/main/java/cn/iocoder/dashboard/modules/system/job/auth/SysUserSessionTimeoutJob.java index 5c1aae405..f6182dd86 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/job/auth/SysUserSessionTimeoutJob.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/job/auth/SysUserSessionTimeoutJob.java @@ -21,10 +21,7 @@ public class SysUserSessionTimeoutJob implements JobHandler { @Override public String execute(String param) throws Exception { - log.info("[execute][执行任务:{}]", "移除超时的在线用户"); - long timeoutCount = sysUserSessionService.clearSessionTimeout(); - log.info("[execute][执行任务:{}:{}]", "移除超时的在线用户完成", timeoutCount); - return null; + return String.valueOf(sysUserSessionService.clearSessionTimeout()); } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionService.java index 3f8869a0f..9e946d901 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionService.java @@ -64,8 +64,6 @@ public interface SysUserSessionService { * 移除超时的在线用户 * * @return {@link Long } 移出的超时用户数量 - * @author Lyon - * @date 2021/3/7 **/ long clearSessionTimeout(); } diff --git a/src/test/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionServiceImplTest.java b/src/test/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionServiceImplTest.java index 5e76b3665..fdce6cc6d 100644 --- a/src/test/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionServiceImplTest.java +++ b/src/test/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserSessionServiceImplTest.java @@ -11,6 +11,7 @@ import cn.iocoder.dashboard.modules.system.service.auth.impl.SysUserSessionServi import cn.iocoder.dashboard.modules.system.service.dept.impl.SysDeptServiceImpl; import cn.iocoder.dashboard.modules.system.service.logger.impl.SysLoginLogServiceImpl; import cn.iocoder.dashboard.modules.system.service.user.SysUserServiceImpl; +import cn.iocoder.dashboard.util.AssertUtils; import cn.iocoder.dashboard.util.RandomUtils; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; @@ -31,9 +32,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; * @version 1.0 * @since
3月 8, 2021
*/ -@Import({ - SysUserSessionServiceImpl.class -}) +@Import( + SysUserSessionServiceImpl.class) public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { @Resource @@ -62,14 +62,17 @@ public class SysUserSessionServiceImplTest extends BaseDbAndRedisUnitTest { .limit(expectedTimeoutCount) .map(i -> RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetSecond(new Date(), -1)))) .collect(Collectors.toList()); - prepareData.add(RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetMinute(new Date(), 30)))); + SysUserSessionDO sessionDO = RandomUtils.randomPojo(SysUserSessionDO.class, o -> o.setSessionTimeout(DateUtil.offsetMinute(new Date(), 30))); + prepareData.add(sessionDO); prepareData.forEach(sysUserSessionMapper::insert); //清空超时数据 long actualTimeoutCount = sysUserSessionService.clearSessionTimeout(); + //校验 assertEquals(expectedTimeoutCount, actualTimeoutCount); - Integer actualTotal = sysUserSessionMapper.selectCount(new QueryWrapperX<>()); - assertEquals(expectedTotal, actualTotal); + List userSessionDOS = sysUserSessionMapper.selectList(); + assertEquals(expectedTotal, userSessionDOS.size()); + AssertUtils.assertPojoEquals(sessionDO, userSessionDOS.get(0), "updateTime"); } }