|
|
|
@ -17,6 +17,7 @@ |
|
|
|
package org.springframework.test.web.servlet.samples.standalone; |
|
|
|
package org.springframework.test.web.servlet.samples.standalone; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.StringWriter; |
|
|
|
import java.io.StringWriter; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.concurrent.Callable; |
|
|
|
import java.util.concurrent.Callable; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
@ -39,7 +40,6 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
import org.springframework.web.context.request.async.DeferredResult; |
|
|
|
import org.springframework.web.context.request.async.DeferredResult; |
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; |
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; |
|
|
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; |
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; |
|
|
|
@ -154,10 +154,7 @@ public class AsyncTests { |
|
|
|
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); |
|
|
|
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Test // SPR-12597
|
|
|
|
* SPR-12597 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void completableFutureWithImmediateValue() throws Exception { |
|
|
|
public void completableFutureWithImmediateValue() throws Exception { |
|
|
|
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("completableFutureWithImmediateValue", "true")) |
|
|
|
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("completableFutureWithImmediateValue", "true")) |
|
|
|
.andExpect(request().asyncStarted()) |
|
|
|
.andExpect(request().asyncStarted()) |
|
|
|
@ -169,10 +166,7 @@ public class AsyncTests { |
|
|
|
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); |
|
|
|
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Test // SPR-12735
|
|
|
|
* SPR-12735 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void printAsyncResult() throws Exception { |
|
|
|
public void printAsyncResult() throws Exception { |
|
|
|
StringWriter writer = new StringWriter(); |
|
|
|
StringWriter writer = new StringWriter(); |
|
|
|
|
|
|
|
|
|
|
|
@ -204,7 +198,6 @@ public class AsyncTests { |
|
|
|
|
|
|
|
|
|
|
|
private final Collection<ListenableFutureTask<Person>> futureTasks = new CopyOnWriteArrayList<>(); |
|
|
|
private final Collection<ListenableFutureTask<Person>> futureTasks = new CopyOnWriteArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(params = "callable") |
|
|
|
@RequestMapping(params = "callable") |
|
|
|
public Callable<Person> getCallable() { |
|
|
|
public Callable<Person> getCallable() { |
|
|
|
return () -> new Person("Joe"); |
|
|
|
return () -> new Person("Joe"); |
|
|
|
@ -212,7 +205,7 @@ public class AsyncTests { |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(params = "streaming") |
|
|
|
@RequestMapping(params = "streaming") |
|
|
|
public StreamingResponseBody getStreaming() { |
|
|
|
public StreamingResponseBody getStreaming() { |
|
|
|
return os -> os.write("name=Joe".getBytes(UTF_8)); |
|
|
|
return os -> os.write("name=Joe".getBytes(StandardCharsets.UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(params = "streamingSlow") |
|
|
|
@RequestMapping(params = "streamingSlow") |
|
|
|
@ -221,7 +214,7 @@ public class AsyncTests { |
|
|
|
os.write("name=Joe".getBytes()); |
|
|
|
os.write("name=Joe".getBytes()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Thread.sleep(200); |
|
|
|
Thread.sleep(200); |
|
|
|
os.write("&someBoolean=true".getBytes(UTF_8)); |
|
|
|
os.write("&someBoolean=true".getBytes(StandardCharsets.UTF_8)); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (InterruptedException e) { |
|
|
|
catch (InterruptedException e) { |
|
|
|
/* no-op */ |
|
|
|
/* no-op */ |
|
|
|
@ -232,7 +225,7 @@ public class AsyncTests { |
|
|
|
@RequestMapping(params = "streamingJson") |
|
|
|
@RequestMapping(params = "streamingJson") |
|
|
|
public ResponseEntity<StreamingResponseBody> getStreamingJson() { |
|
|
|
public ResponseEntity<StreamingResponseBody> getStreamingJson() { |
|
|
|
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8) |
|
|
|
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8) |
|
|
|
.body(os -> os.write("{\"name\":\"Joe\",\"someDouble\":0.5}".getBytes(UTF_8))); |
|
|
|
.body(os -> os.write("{\"name\":\"Joe\",\"someDouble\":0.5}".getBytes(StandardCharsets.UTF_8))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(params = "deferredResult") |
|
|
|
@RequestMapping(params = "deferredResult") |
|
|
|
|