[英]R2dbc integration test persisted data not available via API
I am trying to learn Spring web flux with r2dbc.我正在尝试使用 r2dbc 学习 Spring web 通量。 I am trying to execute a test case as follows:
我正在尝试按如下方式执行测试用例:
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:(看起来像一些与上下文相关的问题,但不确定发生了什么:(
After calling the saveAll
method of the repository, I was not blocking the saveAll
method and was immediately going for fetching the data with APIs.调用存储库的
saveAll
方法后,我没有阻止saveAll
方法,而是立即使用 API 获取数据。 I blocked it with saveAll(items).blockLast()
.我用
saveAll(items).blockLast()
阻止了它。 So the correct code should be:所以正确的代码应该是:
@Test
void searchItem() {
// Arrange
itemRepository.saveAll(TestHelper.createItemEntitiesToInsert()).blockLast();
// Act
final var responseBody = get("/api/v1/items/search?name=ite")
.returnResult(ItemResource.class)
.getResponseBody();
// Assert
StepVerifier.create(responseBody)
.expectNextCount(2)
.expectComplete()
.verify();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.