问题描述
我想使用cachemono并创建一个测试进行评估。因此,我创建了2个单声道并进行了串联。我注意到的是,oncachemissresume
被两个Mono调用,但是在第二个Mono上,未写入缓存。我的考试有什么问题吗?我想使用oncachemissresume
填充缓存,当前的测试结果对我没有帮助。
atomicreference<Context> storeRef = new atomicreference<>(Context.empty());
String key = "myid";
Mono<Integer> cachedMonoFirst = CacheMono
.lookup(k -> Mono.justOrEmpty(storeRef.get().<Integer>getorEmpty(k))
.map(integer -> {
log.error("first :: cache lookup result {}",integer);
return Signal.next(integer);
}),key)
.onCacheMissResume(() -> {
log.info("first :: cache missed ");
return Mono.just(123);})
.andWriteWith((k,sig) -> {
log.info("first :: cache write");
return Mono.fromrunnable(() ->
storeRef.updateAndGet(ctx -> ctx.put(k,sig.get())));});
Mono<Integer> cachedMonoSecond = CacheMono
.lookup(k -> Mono.justOrEmpty(storeRef.get().<Integer>getorEmpty(k))
.map(integer -> {
log.error("second :: cache lookup result {}",key)
.onCacheMissResume(() -> {
log.error("second :: cache missed");
return Mono.just(456);})
.andWriteWith((k,sig) -> {
log.info("second :: cache write");
return Mono.fromrunnable(() ->
storeRef.updateAndGet(ctx -> ctx.put(k,sig.get())));});
Flux<Integer> cacheFlux = cachedMonoFirst.concatWith(cachedMonoSecond);
StepVerifier
.create(cacheFlux)
.consumeNextWith(data -> {
assertthat(storeRef.get().<Integer>getorEmpty(key)).get().isEqualTo(data);
log.info(" first :: from cache {} {}",data,storeRef.get().<Integer>getorEmpty(key));
})
.consumeNextWith(data -> {
assertthat(storeRef.get().<Integer>getorEmpty(key)).get().isEqualTo(data);
log.info(" second :: from cache {} {}",storeRef.get().<Integer>getorEmpty(key));
})
.verifyComplete();
日志如下
CacheTest - first :: cache missed
CacheTest - first :: cache write
CacheTest - first :: from cache 123 Optional[123]
CacheTest - second :: cache missed
CacheTest - second :: cache lookup result 123
CacheTest - second :: from cache 123 Optional[123]
为什么second :: cache missed
在second :: cache lookup result 123
之前被调用?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)