I wanted to use reactive programming inside the JUnit testing framework to do system tests on a remote rest api.
I thus wrote:
@Test
void testWebClient() {
WebClient webClient = WebClient.builder()
.baseUrl(GITHUB_API_BASE_URL)
.defaultHeader(HttpHeaders.CONTENT_TYPE, GITHUB_V3_MIME_TYPE)
.defaultHeader(HttpHeaders.USER_AGENT, USER_AGENT)
.filter(ExchangeFilterFunctions
.basicAuthentication(appProperties.getGithub().getUsername(),
appProperties.getGithub().getToken()))
.build();
var response = webClient.get()
.uri("/user/repos?sort={sortField}&direction={sortDirection}",
"updated", "desc")
.exchange()
.doOnError(e -> {
System.out.println(e.toString());
})
.subscribe(r -> {
System.out.println(r );
});
}
to get all my github repos. I kept catching this error:
java.lang.IllegalStateException: executor not accepting a task
until add ".block()" after ".exchange()" to do the call synchronously and everything start to work fine.
I suspect JUnit to start a special thread context or something like that. Do you know what can is happening?
Thanks a lot