Clean up warnings and polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -30,8 +30,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.web.Person;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -46,14 +44,14 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class AsyncTests {
|
||||
class AsyncTests {
|
||||
|
||||
private final WebTestClient testClient =
|
||||
MockMvcWebTestClient.bindToController(new AsyncController()).build();
|
||||
|
||||
|
||||
@Test
|
||||
public void callable() {
|
||||
void callable() {
|
||||
this.testClient.get()
|
||||
.uri("/1?callable=true")
|
||||
.exchange()
|
||||
@@ -63,7 +61,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streaming() {
|
||||
void streaming() {
|
||||
this.testClient.get()
|
||||
.uri("/1?streaming=true")
|
||||
.exchange()
|
||||
@@ -72,7 +70,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamingSlow() {
|
||||
void streamingSlow() {
|
||||
this.testClient.get()
|
||||
.uri("/1?streamingSlow=true")
|
||||
.exchange()
|
||||
@@ -81,7 +79,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamingJson() {
|
||||
void streamingJson() {
|
||||
this.testClient.get()
|
||||
.uri("/1?streamingJson=true")
|
||||
.exchange()
|
||||
@@ -91,7 +89,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deferredResult() {
|
||||
void deferredResult() {
|
||||
this.testClient.get()
|
||||
.uri("/1?deferredResult=true")
|
||||
.exchange()
|
||||
@@ -101,7 +99,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deferredResultWithImmediateValue() {
|
||||
void deferredResultWithImmediateValue() {
|
||||
this.testClient.get()
|
||||
.uri("/1?deferredResultWithImmediateValue=true")
|
||||
.exchange()
|
||||
@@ -111,7 +109,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deferredResultWithDelayedError() {
|
||||
void deferredResultWithDelayedError() {
|
||||
this.testClient.get()
|
||||
.uri("/1?deferredResultWithDelayedError=true")
|
||||
.exchange()
|
||||
@@ -120,7 +118,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenableFuture() {
|
||||
void listenableFuture() {
|
||||
this.testClient.get()
|
||||
.uri("/1?listenableFuture=true")
|
||||
.exchange()
|
||||
@@ -130,7 +128,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void completableFutureWithImmediateValue() throws Exception {
|
||||
void completableFutureWithImmediateValue() throws Exception {
|
||||
this.testClient.get()
|
||||
.uri("/1?completableFutureWithImmediateValue=true")
|
||||
.exchange()
|
||||
@@ -145,17 +143,17 @@ public class AsyncTests {
|
||||
private static class AsyncController {
|
||||
|
||||
@GetMapping(params = "callable")
|
||||
public Callable<Person> getCallable() {
|
||||
Callable<Person> getCallable() {
|
||||
return () -> new Person("Joe");
|
||||
}
|
||||
|
||||
@GetMapping(params = "streaming")
|
||||
public StreamingResponseBody getStreaming() {
|
||||
StreamingResponseBody getStreaming() {
|
||||
return os -> os.write("name=Joe".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@GetMapping(params = "streamingSlow")
|
||||
public StreamingResponseBody getStreamingSlow() {
|
||||
StreamingResponseBody getStreamingSlow() {
|
||||
return os -> {
|
||||
os.write("name=Joe".getBytes());
|
||||
try {
|
||||
@@ -169,41 +167,43 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@GetMapping(params = "streamingJson")
|
||||
public ResponseEntity<StreamingResponseBody> getStreamingJson() {
|
||||
ResponseEntity<StreamingResponseBody> getStreamingJson() {
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
|
||||
.body(os -> os.write("{\"name\":\"Joe\",\"someDouble\":0.5}".getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
@GetMapping(params = "deferredResult")
|
||||
public DeferredResult<Person> getDeferredResult() {
|
||||
DeferredResult<Person> getDeferredResult() {
|
||||
DeferredResult<Person> result = new DeferredResult<>();
|
||||
delay(100, () -> result.setResult(new Person("Joe")));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping(params = "deferredResultWithImmediateValue")
|
||||
public DeferredResult<Person> getDeferredResultWithImmediateValue() {
|
||||
DeferredResult<Person> getDeferredResultWithImmediateValue() {
|
||||
DeferredResult<Person> result = new DeferredResult<>();
|
||||
result.setResult(new Person("Joe"));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping(params = "deferredResultWithDelayedError")
|
||||
public DeferredResult<Person> getDeferredResultWithDelayedError() {
|
||||
DeferredResult<Person> getDeferredResultWithDelayedError() {
|
||||
DeferredResult<Person> result = new DeferredResult<>();
|
||||
delay(100, () -> result.setErrorResult(new RuntimeException("Delayed Error")));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping(params = "listenableFuture")
|
||||
public ListenableFuture<Person> getListenableFuture() {
|
||||
ListenableFutureTask<Person> futureTask = new ListenableFutureTask<>(() -> new Person("Joe"));
|
||||
@SuppressWarnings("deprecation")
|
||||
org.springframework.util.concurrent.ListenableFuture<Person> getListenableFuture() {
|
||||
org.springframework.util.concurrent.ListenableFutureTask<Person> futureTask =
|
||||
new org.springframework.util.concurrent.ListenableFutureTask<>(() -> new Person("Joe"));
|
||||
delay(100, futureTask);
|
||||
return futureTask;
|
||||
}
|
||||
|
||||
@GetMapping(params = "completableFutureWithImmediateValue")
|
||||
public CompletableFuture<Person> getCompletableFutureWithImmediateValue() {
|
||||
CompletableFuture<Person> getCompletableFutureWithImmediateValue() {
|
||||
CompletableFuture<Person> future = new CompletableFuture<>();
|
||||
future.complete(new Person("Joe"));
|
||||
return future;
|
||||
@@ -211,7 +211,7 @@ public class AsyncTests {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public String errorHandler(Exception ex) {
|
||||
String errorHandler(Exception ex) {
|
||||
return ex.getMessage();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -31,8 +31,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.web.Person;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
@@ -58,7 +56,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standal
|
||||
* @author Sam Brannen
|
||||
* @author Jacek Suchenia
|
||||
*/
|
||||
public class AsyncTests {
|
||||
class AsyncTests {
|
||||
|
||||
private final AsyncController asyncController = new AsyncController();
|
||||
|
||||
@@ -66,7 +64,7 @@ public class AsyncTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void callable() throws Exception {
|
||||
void callable() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("callable", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andExpect(request().asyncResult(equalTo(new Person("Joe"))))
|
||||
@@ -80,7 +78,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streaming() throws Exception {
|
||||
void streaming() throws Exception {
|
||||
this.mockMvc.perform(get("/1").param("streaming", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andDo(MvcResult::getAsyncResult) // fetch async result similar to "asyncDispatch" builder
|
||||
@@ -89,7 +87,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamingSlow() throws Exception {
|
||||
void streamingSlow() throws Exception {
|
||||
this.mockMvc.perform(get("/1").param("streamingSlow", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andDo(MvcResult::getAsyncResult)
|
||||
@@ -98,7 +96,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamingJson() throws Exception {
|
||||
void streamingJson() throws Exception {
|
||||
this.mockMvc.perform(get("/1").param("streamingJson", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andDo(MvcResult::getAsyncResult)
|
||||
@@ -108,7 +106,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deferredResult() throws Exception {
|
||||
void deferredResult() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("deferredResult", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
@@ -120,7 +118,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deferredResultWithImmediateValue() throws Exception {
|
||||
void deferredResultWithImmediateValue() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("deferredResultWithImmediateValue", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andExpect(request().asyncResult(new Person("Joe")))
|
||||
@@ -133,7 +131,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13079
|
||||
public void deferredResultWithDelayedError() throws Exception {
|
||||
void deferredResultWithDelayedError() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("deferredResultWithDelayedError", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
@@ -144,7 +142,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenableFuture() throws Exception {
|
||||
void listenableFuture() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("listenableFuture", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
@@ -156,7 +154,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12597
|
||||
public void completableFutureWithImmediateValue() throws Exception {
|
||||
void completableFutureWithImmediateValue() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("completableFutureWithImmediateValue", "true"))
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
@@ -168,7 +166,7 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@Test // SPR-12735
|
||||
public void printAsyncResult() throws Exception {
|
||||
void printAsyncResult() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("deferredResult", "true"))
|
||||
@@ -194,17 +192,17 @@ public class AsyncTests {
|
||||
private static class AsyncController {
|
||||
|
||||
@RequestMapping(params = "callable")
|
||||
public Callable<Person> getCallable() {
|
||||
Callable<Person> getCallable() {
|
||||
return () -> new Person("Joe");
|
||||
}
|
||||
|
||||
@RequestMapping(params = "streaming")
|
||||
public StreamingResponseBody getStreaming() {
|
||||
StreamingResponseBody getStreaming() {
|
||||
return os -> os.write("name=Joe".getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@RequestMapping(params = "streamingSlow")
|
||||
public StreamingResponseBody getStreamingSlow() {
|
||||
StreamingResponseBody getStreamingSlow() {
|
||||
return os -> {
|
||||
os.write("name=Joe".getBytes());
|
||||
try {
|
||||
@@ -218,41 +216,43 @@ public class AsyncTests {
|
||||
}
|
||||
|
||||
@RequestMapping(params = "streamingJson")
|
||||
public ResponseEntity<StreamingResponseBody> getStreamingJson() {
|
||||
ResponseEntity<StreamingResponseBody> getStreamingJson() {
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON)
|
||||
.body(os -> os.write("{\"name\":\"Joe\",\"someDouble\":0.5}".getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
@RequestMapping(params = "deferredResult")
|
||||
public DeferredResult<Person> getDeferredResult() {
|
||||
DeferredResult<Person> getDeferredResult() {
|
||||
DeferredResult<Person> result = new DeferredResult<>();
|
||||
delay(100, () -> result.setResult(new Person("Joe")));
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(params = "deferredResultWithImmediateValue")
|
||||
public DeferredResult<Person> getDeferredResultWithImmediateValue() {
|
||||
DeferredResult<Person> getDeferredResultWithImmediateValue() {
|
||||
DeferredResult<Person> deferredResult = new DeferredResult<>();
|
||||
deferredResult.setResult(new Person("Joe"));
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
@RequestMapping(params = "deferredResultWithDelayedError")
|
||||
public DeferredResult<Person> getDeferredResultWithDelayedError() {
|
||||
DeferredResult<Person> getDeferredResultWithDelayedError() {
|
||||
DeferredResult<Person> result = new DeferredResult<>();
|
||||
delay(100, () -> result.setErrorResult(new RuntimeException("Delayed Error")));
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(params = "listenableFuture")
|
||||
public ListenableFuture<Person> getListenableFuture() {
|
||||
ListenableFutureTask<Person> futureTask = new ListenableFutureTask<>(() -> new Person("Joe"));
|
||||
@SuppressWarnings("deprecation")
|
||||
org.springframework.util.concurrent.ListenableFuture<Person> getListenableFuture() {
|
||||
org.springframework.util.concurrent.ListenableFutureTask<Person> futureTask =
|
||||
new org.springframework.util.concurrent.ListenableFutureTask<>(() -> new Person("Joe"));
|
||||
delay(100, futureTask);
|
||||
return futureTask;
|
||||
}
|
||||
|
||||
@RequestMapping(params = "completableFutureWithImmediateValue")
|
||||
public CompletableFuture<Person> getCompletableFutureWithImmediateValue() {
|
||||
CompletableFuture<Person> getCompletableFutureWithImmediateValue() {
|
||||
CompletableFuture<Person> future = new CompletableFuture<>();
|
||||
future.complete(new Person("Joe"));
|
||||
return future;
|
||||
@@ -260,7 +260,7 @@ public class AsyncTests {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public String errorHandler(Exception ex) {
|
||||
String errorHandler(Exception ex) {
|
||||
return ex.getMessage();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user