[英]Spring WebFlux: block() method return null in Spring Data Reactive MongoDB
i'm trying to learn project Reactor and have the problem. 我正在尝试学习Reactor项目并遇到问题。
@Test
@DisplayName("check that standaloneUser fields are correct")
void validateUserFields() {
userService.save(standaloneUser).subscribe();
assertEquals(userService.count().block(), Long.valueOf(1));
User user = userService.findByEmail("test@gmail.com").block();
assertNotNull(user);
assertNotNull(user.getId());
assertEquals(user.getFirstName(), "test");
assertEquals(user.getLastName(), "test");
assertNotEquals(user.getPassword(), "test");
assertEquals(user.getRole(), Role.CANDIDATE);
assertNotNull(user.getCreatedDate());
assertNull(user.getStoppedDate());
assertEquals(user.getEmail(), "test@gmail.com");
}
Sometimes block() method returns null. 有时,block()方法返回null。 Who can explain me this?
谁能解释这个? Thanks
谢谢
block()
can return null, it means the Mono
completed empty, which in this case means the user wasn't found. block()
可以返回null,这意味着Mono
已完成为空,在这种情况下,这意味着找不到用户。
Could it be that it wasn't properly saved? 可能是由于未正确保存? (although you assert the user count)
(尽管您断言用户数)
Note that you do userService.save(standaloneUser).subscribe()
. 请注意,您需要执行
userService.save(standaloneUser).subscribe()
。 This form is often not ideal, as it is "async fire-and-forget": 这种形式通常不是理想的,因为它是“异步即发即弃”的:
Make an habit of at least setting onNext and onError handler lambdas when calling subscribe
. 养成至少在调用
subscribe
时设置onNext和onError处理程序lambdas的习惯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.