Fix timing issue with obtaining async result

Issue: SPR-11516
This commit is contained in:
Rossen Stoyanchev
2014-03-04 21:38:42 -05:00
parent c146be2eb7
commit 705efc5bdf
2 changed files with 38 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -89,6 +89,20 @@ public class AsyncTests {
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
}
@Test
@Ignore
public void testDeferredResultWithSetValue() throws Exception {
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("deferredResultWithSetValue", "true"))
.andExpect(request().asyncStarted())
.andExpect(request().asyncResult(new Person("Joe")))
.andReturn();
this.mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
}
@Controller
private static class AsyncController {
@@ -115,6 +129,14 @@ public class AsyncTests {
return deferredResult;
}
@RequestMapping(value="/{id}", params="deferredResultWithSetValue", produces="application/json")
@ResponseBody
public DeferredResult<Person> getDeferredResultWithSetValue() {
DeferredResult<Person> deferredResult = new DeferredResult<Person>();
deferredResult.setResult(new Person("Joe"));
return deferredResult;
}
public void onMessage(String name) {
for (DeferredResult<Person> deferredResult : this.deferredResults) {
deferredResult.setResult(new Person(name));