Home How to prevent SpringBootTest stop server before async methods finished?
Reply: 0

How to prevent SpringBootTest stop server before async methods finished?

uuur Published in 2018-01-12 15:53:55Z

I have code like this

@RequestMapping(value = "/create", method = RequestMethod.POST)
public Result createModel(DataModel model) {
    CompletableFuture.runAsync(() -> doSomeThing(model));
    return new Result("your request has been recieved successfully");      

and i try to write integration test like

 @@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("integration_tests, linux")
 public class DataServiceTestIT {
    private WebApplicationContext wac;

    this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();

    assertEquals(1, JdbcTestUtil.countRowsInTable(jdbcTemplate, "data_model_table));

When back-side received request, will response successful message immediately, real jobs is processed asynchronously. After response is sent, server is stopped and i can't test doSomeThing code.(My real code is more complicated and there are multiple async parts)

How to prevent server stopping or waiting other methods finsihing. My controller don't return callable result. When process finished, send notifications to users. I try to use get MvcResult.getAsyncResult() but i think that it is not suitable for this.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.3067 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO