1616
1717package org .springframework .data .couchbase .cache ;
1818
19- import static com .couchbase .client .java .query .QueryScanConsistency .REQUEST_PLUS ;
20- import static org .junit .Assert .assertNotNull ;
2119import static org .junit .jupiter .api .Assertions .assertEquals ;
2220import static org .junit .jupiter .api .Assertions .assertNull ;
2321
@@ -57,7 +55,7 @@ public void beforeEach() {
5755 super .beforeEach ();
5856 cache = CouchbaseCacheManager .create (couchbaseTemplate .getCouchbaseClientFactory ()).createCouchbaseCache ("myCache" ,
5957 CouchbaseCacheConfiguration .defaultCacheConfig ());
60- clear (cache );
58+ cache . clear ();
6159 ApplicationContext ac = new AnnotationConfigApplicationContext (Config .class );
6260 cacheManager = ac .getBean (CouchbaseCacheManager .class );
6361 userRepository = ac .getBean (UserRepository .class );
@@ -66,17 +64,11 @@ public void beforeEach() {
6664 @ AfterEach
6765 @ Override
6866 public void afterEach () {
69- clear (cache );
67+ cache . clear ();
7068 super .afterEach ();
7169 }
7270
73- private void clear (CouchbaseCache c ) {
74- couchbaseTemplate .getCouchbaseClientFactory ().getCluster ().query ("SELECT count(*) from `" + bucketName () + "`" ,
75- QueryOptions .queryOptions ().scanConsistency (REQUEST_PLUS ));
76- c .clear ();
77- couchbaseTemplate .getCouchbaseClientFactory ().getCluster ().query ("SELECT count(*) from `" + bucketName () + "`" ,
78- QueryOptions .queryOptions ().scanConsistency (REQUEST_PLUS ));
79- }
71+
8072
8173 @ Test
8274 void cachePutGet () {
@@ -109,17 +101,19 @@ void cacheEvict() {
109101 cache .put (user1 .getId (), user1 ); // put user1
110102 cache .put (user2 .getId (), user2 ); // put user2
111103 cache .evict (user1 .getId ()); // evict user1
104+ assertNull (cache .get (user1 .getId ())); // get user1 -> not present
112105 assertEquals (user2 , cache .get (user2 .getId ()).get ()); // get user2 -> present
113106 }
114107
115108 @ Test
116- void cacheHitMiss () {
109+ void cacheClear () {
117110 CacheUser user1 = new CacheUser (UUID .randomUUID ().toString (), "first1" , "last1" );
118111 CacheUser user2 = new CacheUser (UUID .randomUUID ().toString (), "first2" , "last2" );
119- assertNull (cache .get (user2 .getId ())); // get user2 -> cacheMiss
120- cache .put (user1 .getId (), null ); // cache a null
121- assertNotNull (cache .get (user1 .getId ())); // cacheHit null
122- assertNull (cache .get (user1 .getId ()).get ()); // fetch cached null
112+ cache .put (user1 .getId (), user1 ); // put user1
113+ cache .put (user2 .getId (), user2 ); // put user2
114+ cache .clear ();
115+ assertNull (cache .get (user1 .getId ())); // get user1 -> not present
116+ assertNull (cache .get (user2 .getId ())); // get user2 -> not present
123117 }
124118
125119 @ Test
@@ -131,12 +125,6 @@ void cachePutIfAbsent() {
131125 assertEquals (user1 , cache .get (user1 .getId ()).get ()); // user1.getId() is still user1
132126 }
133127
134- @ Test // this test FAILS (local empty (i.e. fast) Couchbase installation)
135- public void clearFail () {
136- cache .put ("KEY" , "VALUE" ); // no delay between put and clear, entry will not be
137- cache .clear (); // will not be indexed when clear() executes
138- assertNotNull (cache .get ("KEY" )); // will still find entry, clear failed to delete
139- }
140128
141129 @ Test // this WORKS
142130 public void clearWithDelayOk () throws InterruptedException {
0 commit comments