-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9aca93
commit 837f230
Showing
16 changed files
with
107 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
eladmin-common/src/test/java/me/zhengjie/utils/DateUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
eladmin-common/src/test/java/me/zhengjie/utils/EncryptUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
eladmin-common/src/test/java/me/zhengjie/utils/FileUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 44 additions & 46 deletions
90
eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,62 @@ | ||
package me.zhengjie; | ||
|
||
import me.zhengjie.modules.security.service.UserDetailsServiceImpl; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.jupiter.api.Test; | ||
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(); | ||
@Resource(name = "userDetailsService") | ||
private UserDetailsServiceImpl userDetailsService; | ||
|
||
@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(); | ||
ExecutorService executor = Executors.newCachedThreadPool(); | ||
|
||
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 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(); | ||
} | ||
|
||
@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(); | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.