@@ -202,9 +202,9 @@ void spr14235AdaptsToCompletableFuture() {
202
202
assertThat (bean .findById ("tb2" ).join ()).isNotSameAs (tb );
203
203
assertThat (cache .get ("tb2" )).isNull ();
204
204
205
- assertThat (bean .findByIdEmpty ("" ).join ()).isNull ();
206
205
assertThat (bean .findByIdEmpty ("" ).join ()).isNull ();
207
206
assertThat (cache .get ("" ).get ()).isNull ();
207
+ assertThat (bean .findByIdEmpty ("" ).join ()).isNull ();
208
208
209
209
context .close ();
210
210
}
@@ -230,9 +230,9 @@ void spr14235AdaptsToCompletableFutureWithSync() throws Exception {
230
230
assertThat (bean .findById ("tb1" ).get ()).isSameAs (tb );
231
231
assertThat (cache .get ("tb1" ).get ()).isSameAs (tb );
232
232
233
- assertThat (bean .findById ("" ).join ()).isNull ();
234
233
assertThat (bean .findById ("" ).join ()).isNull ();
235
234
assertThat (cache .get ("" ).get ()).isNull ();
235
+ assertThat (bean .findById ("" ).join ()).isNull ();
236
236
237
237
context .close ();
238
238
}
@@ -265,9 +265,9 @@ void spr14235AdaptsToReactorMono() {
265
265
assertThat (bean .findById ("tb2" ).block ()).isNotSameAs (tb );
266
266
assertThat (cache .get ("tb2" )).isNull ();
267
267
268
- assertThat (bean .findByIdEmpty ("" ).block ()).isNull ();
269
268
assertThat (bean .findByIdEmpty ("" ).block ()).isNull ();
270
269
assertThat (cache .get ("" ).get ()).isNull ();
270
+ assertThat (bean .findByIdEmpty ("" ).block ()).isNull ();
271
271
272
272
context .close ();
273
273
}
@@ -293,9 +293,9 @@ void spr14235AdaptsToReactorMonoWithSync() {
293
293
assertThat (bean .findById ("tb1" ).block ()).isSameAs (tb );
294
294
assertThat (cache .get ("tb1" ).get ()).isSameAs (tb );
295
295
296
- assertThat (bean .findById ("" ).block ()).isNull ();
297
296
assertThat (bean .findById ("" ).block ()).isNull ();
298
297
assertThat (cache .get ("" ).get ()).isNull ();
298
+ assertThat (bean .findById ("" ).block ()).isNull ();
299
299
300
300
context .close ();
301
301
}
@@ -328,9 +328,9 @@ void spr14235AdaptsToReactorFlux() {
328
328
assertThat (bean .findById ("tb2" ).collectList ().block ()).isNotEqualTo (tb );
329
329
assertThat (cache .get ("tb2" )).isNull ();
330
330
331
- assertThat (bean .findByIdEmpty ("" ).collectList ().block ()).isEmpty ();
332
331
assertThat (bean .findByIdEmpty ("" ).collectList ().block ()).isEmpty ();
333
332
assertThat (cache .get ("" ).get ()).isEqualTo (Collections .emptyList ());
333
+ assertThat (bean .findByIdEmpty ("" ).collectList ().block ()).isEmpty ();
334
334
335
335
context .close ();
336
336
}
@@ -356,9 +356,9 @@ void spr14235AdaptsToReactorFluxWithSync() {
356
356
assertThat (bean .findById ("tb1" ).collectList ().block ()).isEqualTo (tb );
357
357
assertThat (cache .get ("tb1" ).get ()).isEqualTo (tb );
358
358
359
- assertThat (bean .findById ("" ).collectList ().block ()).isEmpty ();
360
359
assertThat (bean .findById ("" ).collectList ().block ()).isEmpty ();
361
360
assertThat (cache .get ("" ).get ()).isEqualTo (Collections .emptyList ());
361
+ assertThat (bean .findById ("" ).collectList ().block ()).isEmpty ();
362
362
363
363
context .close ();
364
364
}
@@ -587,13 +587,17 @@ public Spr14230Service service() {
587
587
588
588
public static class Spr14235FutureService {
589
589
590
+ private boolean emptyCalled ;
591
+
590
592
@ Cacheable (value = "itemCache" , unless = "#result.name == 'tb2'" )
591
593
public CompletableFuture <TestBean > findById (String id ) {
592
594
return CompletableFuture .completedFuture (new TestBean (id ));
593
595
}
594
596
595
597
@ Cacheable (value = "itemCache" )
596
598
public CompletableFuture <TestBean > findByIdEmpty (String id ) {
599
+ assertThat (emptyCalled ).isFalse ();
600
+ emptyCalled = true ;
597
601
return CompletableFuture .completedFuture (null );
598
602
}
599
603
@@ -611,9 +615,16 @@ public CompletableFuture<Void> clear() {
611
615
612
616
public static class Spr14235FutureServiceSync {
613
617
618
+ private boolean emptyCalled ;
619
+
614
620
@ Cacheable (value = "itemCache" , sync = true )
615
621
public CompletableFuture <TestBean > findById (String id ) {
616
- return CompletableFuture .completedFuture (id .isEmpty () ? null : new TestBean (id ));
622
+ if (id .isEmpty ()) {
623
+ assertThat (emptyCalled ).isFalse ();
624
+ emptyCalled = true ;
625
+ return CompletableFuture .completedFuture (null );
626
+ }
627
+ return CompletableFuture .completedFuture (new TestBean (id ));
617
628
}
618
629
619
630
@ CachePut (cacheNames = "itemCache" , key = "#item.name" )
@@ -625,13 +636,17 @@ public TestBean insertItem(TestBean item) {
625
636
626
637
public static class Spr14235MonoService {
627
638
639
+ private boolean emptyCalled ;
640
+
628
641
@ Cacheable (value = "itemCache" , unless = "#result.name == 'tb2'" )
629
642
public Mono <TestBean > findById (String id ) {
630
643
return Mono .just (new TestBean (id ));
631
644
}
632
645
633
646
@ Cacheable (value = "itemCache" )
634
647
public Mono <TestBean > findByIdEmpty (String id ) {
648
+ assertThat (emptyCalled ).isFalse ();
649
+ emptyCalled = true ;
635
650
return Mono .empty ();
636
651
}
637
652
@@ -649,9 +664,16 @@ public Mono<Void> clear() {
649
664
650
665
public static class Spr14235MonoServiceSync {
651
666
667
+ private boolean emptyCalled ;
668
+
652
669
@ Cacheable (value = "itemCache" , sync = true )
653
670
public Mono <TestBean > findById (String id ) {
654
- return (id .isEmpty () ? Mono .empty () : Mono .just (new TestBean (id )));
671
+ if (id .isEmpty ()) {
672
+ assertThat (emptyCalled ).isFalse ();
673
+ emptyCalled = true ;
674
+ return Mono .empty ();
675
+ }
676
+ return Mono .just (new TestBean (id ));
655
677
}
656
678
657
679
@ CachePut (cacheNames = "itemCache" , key = "#item.name" )
@@ -665,13 +687,17 @@ public static class Spr14235FluxService {
665
687
666
688
private int counter = 0 ;
667
689
690
+ private boolean emptyCalled ;
691
+
668
692
@ Cacheable (value = "itemCache" , unless = "#result[0].name == 'tb2'" )
669
693
public Flux <TestBean > findById (String id ) {
670
694
return Flux .just (new TestBean (id ), new TestBean (id + (counter ++)));
671
695
}
672
696
673
697
@ Cacheable (value = "itemCache" )
674
698
public Flux <TestBean > findByIdEmpty (String id ) {
699
+ assertThat (emptyCalled ).isFalse ();
700
+ emptyCalled = true ;
675
701
return Flux .empty ();
676
702
}
677
703
@@ -691,9 +717,16 @@ public static class Spr14235FluxServiceSync {
691
717
692
718
private int counter = 0 ;
693
719
720
+ private boolean emptyCalled ;
721
+
694
722
@ Cacheable (value = "itemCache" , sync = true )
695
723
public Flux <TestBean > findById (String id ) {
696
- return (id .isEmpty () ? Flux .empty () : Flux .just (new TestBean (id ), new TestBean (id + (counter ++))));
724
+ if (id .isEmpty ()) {
725
+ assertThat (emptyCalled ).isFalse ();
726
+ emptyCalled = true ;
727
+ return Flux .empty ();
728
+ }
729
+ return Flux .just (new TestBean (id ), new TestBean (id + (counter ++)));
697
730
}
698
731
699
732
@ CachePut (cacheNames = "itemCache" , key = "#id" )
0 commit comments