17
17
package org .codeba .redis .keeper .springcloud ;
18
18
19
19
import lombok .RequiredArgsConstructor ;
20
+ import lombok .extern .slf4j .Slf4j ;
20
21
import org .codeba .redis .keeper .core .CacheTemplate ;
21
22
import org .codeba .redis .keeper .core .CacheTemplateProvider ;
22
23
import org .springframework .web .bind .annotation .RequestMapping ;
23
24
import org .springframework .web .bind .annotation .RestController ;
24
25
25
26
import java .util .Optional ;
27
+ import java .util .concurrent .CompletableFuture ;
26
28
27
29
/**
28
30
* The type Test controller.
29
31
*
30
32
* @author codeba
31
33
*/
34
+ @ Slf4j
32
35
@ RestController
33
36
@ RequiredArgsConstructor
34
37
public class TestController {
@@ -42,12 +45,38 @@ public class TestController {
42
45
* Test refresh.
43
46
*/
44
47
@ 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
+ }
50
74
});
75
+
76
+ CompletableFuture .allOf (f1 , f2 , f3 ).join ();
77
+ log .info ("cost time: {}" , (System .currentTimeMillis () - start ));
78
+
79
+ return true ;
51
80
}
52
81
53
82
0 commit comments