R2DBC集成测试持续存在的数据无法通过API获得
我正在尝试使用R2DBC学习春季Web通量。我试图执行测试用例如下:
- 通过直接调用存储库BEAN来保存数据。
- 通过使用WebFlux测试客户端调用API来获取保存的数据。
在成功插入两个记录时,第二步不会返回任何数据。
@Test
void searchItem() {
// Arrange
itemRepository.saveAll(createItemEntitiesToInsert());
// Act
final var responseBody = get("/api/v1/items/search?name=ite")
.returnResult(ItemResource.class)
.getResponseBody();
// Assert
StepVerifier.create(responseBody)
.expectNextCount(2)
.expectComplete()
.verify();
}
看起来像某些与上下文有关的问题,但不确定发生了什么:(
I am trying to learn Spring web flux with r2dbc. I am trying to execute a test case as follows:
- Save the data by calling the save method directly via a repository bean.
- Fetch the saved data by invoking the API using the webflux test client.
Step two does not return any data while the two records were getting inserted successfully.
@Test
void searchItem() {
// Arrange
itemRepository.saveAll(createItemEntitiesToInsert());
// Act
final var responseBody = get("/api/v1/items/search?name=ite")
.returnResult(ItemResource.class)
.getResponseBody();
// Assert
StepVerifier.create(responseBody)
.expectNextCount(2)
.expectComplete()
.verify();
}
Looks like some context-related issue but not sure what is happening :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 martin ,
在调用
saveall
方法之后,我没有阻止saveall
方法,而是立即使用API获取数据。我用saveall(items).blocklast()
将其阻止。因此,正确的代码应该是:Thanks to Martin,
After calling the
saveAll
method of the repository, I was not blocking thesaveAll
method and was immediately going for fetching the data with APIs. I blocked it withsaveAll(items).blockLast()
. So the correct code should be: