【发布时间】:2022-11-05 02:14:19
【问题描述】:
我有一个 quarkus 应用程序,我正在尝试使用 Restassured 进行测试 但是,我在测试时收到此错误:
[org.jbo.res.rea.ser.cor.RuntimeExceptionMapper] (vert.x-eventloop-thread-1) A blocking operation occurred on the IO thread. This likely means you need to annotate my.package.MyController#update(class my.package.MyRequestDto) with @io.smallrye.common.annotation.Blocking. Alternatively you can annotate the class my.package.MyController to make every method on the class blocking, or annotate your sub class of the javax.ws.rs.core.Application class to make the whole application blocking
如果我运行这个应用程序并使用邮递员手动测试,这似乎不会发生,所以这似乎是一个测试设置问题。
我的测试如下:
@QuarkusTest
public class MyTest {
@Test
@TestReactiveTransaction
public void test_A() {
Response response = given()
.when()
.accept(MediaTypes.JSON_TYPE)
.contentType(MediaTypes.JSON_TYPE)
.body("{myRequestJsonHere}")
.patch("/path/to/api")
.then()
.extract().response();
// asserts
}
}
在我的控制器内部:
@Path("/path/to/api")
@ApplicationScoped
public class MyController{
@Inject MyService service;
@PATCH
public Uni<MyResultType> update(@NotNull @RequestBody @Valid MyRequestDto request) {
return service.update(request);
}
}
我的服务:
@ApplicationScoped
public class MyService {
@Inject MyRepository repository;
@Transactional
public Uni<MyResultType> update(MyRequestDto request) {
return repository.findAll().firstResult()
.onItem().transform(l -> mapping here))
.flatMap(repository::persistAndFlush);
}
}
我的存储库:
public interface MyRepository extends PanacheRepository<MyResultType> {
}
我还尝试将完整的测试内容包装在 UniAsserter.execute(() -> { }); 中,但仍然遇到同样的问题。
是否需要进行更多设置以确保正确使用线程?
【问题讨论】:
标签: quarkus rest-assured quarkus-panache quarkus-reactive