16
16
17
17
package org .springframework .data .couchbase .cache ;
18
18
19
- import com .couchbase .client .java .query .QueryOptions ;
20
19
import org .junit .jupiter .api .BeforeEach ;
21
20
import org .junit .jupiter .api .Test ;
22
21
import org .springframework .data .couchbase .util .Capabilities ;
26
25
27
26
import java .util .UUID ;
28
27
29
- import static com .couchbase .client .java .query .QueryScanConsistency .REQUEST_PLUS ;
30
28
import static org .junit .Assert .assertNotNull ;
31
29
import static org .junit .jupiter .api .Assertions .assertEquals ;
32
30
import static org .junit .jupiter .api .Assertions .assertNull ;
@@ -47,15 +45,7 @@ public void beforeEach() {
47
45
super .beforeEach ();
48
46
cache = CouchbaseCacheManager .create (couchbaseTemplate .getCouchbaseClientFactory ()).createCouchbaseCache ("myCache" ,
49
47
CouchbaseCacheConfiguration .defaultCacheConfig ().collection ("my_collection" ));
50
- clear (cache );
51
- }
52
-
53
- private void clear (CouchbaseCache c ) {
54
- couchbaseTemplate .getCouchbaseClientFactory ().getCluster ().query ("SELECT count(*) from `" + bucketName () + "`" ,
55
- QueryOptions .queryOptions ().scanConsistency (REQUEST_PLUS ));
56
- c .clear ();
57
- couchbaseTemplate .getCouchbaseClientFactory ().getCluster ().query ("SELECT count(*) from `" + bucketName () + "`" ,
58
- QueryOptions .queryOptions ().scanConsistency (REQUEST_PLUS ));
48
+ cache .clear ();
59
49
}
60
50
61
51
@ Test
@@ -76,9 +66,21 @@ void cacheEvict() {
76
66
cache .put (user1 .getId (), user1 ); // put user1
77
67
cache .put (user2 .getId (), user2 ); // put user2
78
68
cache .evict (user1 .getId ()); // evict user1
69
+ assertNull (cache .get (user1 .getId ())); // get user1 -> not present
79
70
assertEquals (user2 , cache .get (user2 .getId ()).get ()); // get user2 -> present
80
71
}
81
72
73
+ @ Test
74
+ void cacheClear () {
75
+ CacheUser user1 = new CacheUser (UUID .randomUUID ().toString (), "first1" , "last1" );
76
+ CacheUser user2 = new CacheUser (UUID .randomUUID ().toString (), "first2" , "last2" );
77
+ cache .put (user1 .getId (), user1 ); // put user1
78
+ cache .put (user2 .getId (), user2 ); // put user2
79
+ cache .clear ();
80
+ assertNull (cache .get (user1 .getId ())); // get user1 -> not present
81
+ assertNull (cache .get (user2 .getId ())); // get user2 -> not present
82
+ }
83
+
82
84
@ Test
83
85
void cacheHitMiss () {
84
86
CacheUser user1 = new CacheUser (UUID .randomUUID ().toString (), "first1" , "last1" );
0 commit comments