1717package org .codeba .redis .keeper .springcloud ;
1818
1919import lombok .RequiredArgsConstructor ;
20+ import lombok .extern .slf4j .Slf4j ;
2021import org .codeba .redis .keeper .core .CacheTemplate ;
2122import org .codeba .redis .keeper .core .CacheTemplateProvider ;
2223import org .springframework .web .bind .annotation .RequestMapping ;
2324import org .springframework .web .bind .annotation .RestController ;
2425
2526import java .util .Optional ;
27+ import java .util .concurrent .CompletableFuture ;
2628
2729/**
2830 * The type Test controller.
2931 *
3032 * @author codeba
3133 */
34+ @ Slf4j
3235@ RestController
3336@ RequiredArgsConstructor
3437public class TestController {
@@ -42,12 +45,38 @@ public class TestController {
4245 * Test refresh.
4346 */
4447 @ RequestMapping ("/refresh" )
45- public void testRefresh () {
46- final Optional <CacheTemplate > templateOptional = provider .getTemplate ("ds1" );
47- templateOptional .ifPresent (cacheTemplate -> {
48- cacheTemplate .set ("foo" , "bar" );
49- cacheTemplate .del ("foo" );
48+ public boolean testRefresh () {
49+ final long start = System .currentTimeMillis ();
50+
51+ final CompletableFuture <Void > f1 = CompletableFuture .runAsync (() -> {
52+ for (int i = 0 ; i < 100000 ; i ++) {
53+ final Optional <CacheTemplate > templateOptional = provider .getTemplate ("ds4" );
54+ templateOptional .ifPresent (cacheTemplate -> {
55+ cacheTemplate .incr ("testRefresh" );
56+ });
57+ }
58+ });
59+ final CompletableFuture <Void > f2 = CompletableFuture .runAsync (() -> {
60+ for (int i = 0 ; i < 100000 ; i ++) {
61+ final Optional <CacheTemplate > templateOptional = provider .getTemplate ("ds4" );
62+ templateOptional .ifPresent (cacheTemplate -> {
63+ cacheTemplate .incr ("testRefresh" );
64+ });
65+ }
66+ });
67+ final CompletableFuture <Void > f3 = CompletableFuture .runAsync (() -> {
68+ for (int i = 0 ; i < 100000 ; i ++) {
69+ final Optional <CacheTemplate > templateOptional = provider .getTemplate ("ds4" );
70+ templateOptional .ifPresent (cacheTemplate -> {
71+ cacheTemplate .incr ("testRefresh" );
72+ });
73+ }
5074 });
75+
76+ CompletableFuture .allOf (f1 , f2 , f3 ).join ();
77+ log .info ("cost time: {}" , (System .currentTimeMillis () - start ));
78+
79+ return true ;
5180 }
5281
5382
0 commit comments