From d4ae410929dcde8ebb5ec840cca7da51b4881e84 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Thu, 26 May 2022 16:53:28 +0800 Subject: [PATCH] update --- .../test/java/me/zhengjie/LoginCacheTest.java | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java diff --git a/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java b/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java deleted file mode 100644 index 4cae4a8f..00000000 --- a/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package me.zhengjie; - -import me.zhengjie.modules.security.service.UserDetailsServiceImpl; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.annotation.Resource; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class LoginCacheTest { - - @Resource(name = "userDetailsService") - private UserDetailsServiceImpl userDetailsService; - ExecutorService executor = Executors.newCachedThreadPool(); - - @Test - public void testCache() throws InterruptedException { - long start1 = System.currentTimeMillis(); - int size = 1000; - CountDownLatch latch = new CountDownLatch(size); - for (int i = 0; i < size; i++) { - executor.submit(() -> userDetailsService.loadUserByUsername("admin")); - latch.countDown(); - } - latch.await(); - - long end1 = System.currentTimeMillis(); - //关闭缓存 - userDetailsService.setEnableCache(false); - long start2 = System.currentTimeMillis(); - for (int i = 0; i < size; i++) { - userDetailsService.loadUserByUsername("admin"); - } - long end2 = System.currentTimeMillis(); - System.out.print("使用缓存:" + (end1 - start1) + "毫秒\n 不使用缓存:" + (end2 - start2) + "毫秒"); - } - - @Test - public void testCacheManager() throws InterruptedException { - int size = 1000; - CountDownLatch latch = new CountDownLatch(size); - for (int i = 0; i < size; i++) { - int mod = i % 10; - executor.submit(() -> { - try { - Thread.sleep(mod * 2 + (int) (Math.random() * 10000)); - } catch (InterruptedException e) { - e.printStackTrace(); - } - userDetailsService.loadUserByUsername("admin" + mod); - latch.countDown(); - System.out.println("剩余未完成数量" + latch.getCount()); - }); - } - latch.await(); - } - -}