|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2018 the original author or authors. |
| 2 | + * Copyright 2012-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
76 | 76 | import org.springframework.web.filter.OncePerRequestFilter;
|
77 | 77 | import org.springframework.web.servlet.ModelAndView;
|
78 | 78 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
| 79 | +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; |
79 | 80 | import org.springframework.web.util.NestedServletException;
|
80 | 81 |
|
81 | 82 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -188,6 +189,16 @@ public void unhandledError() {
|
188 | 189 | .tags("exception", "RuntimeException").timer().count()).isEqualTo(1L);
|
189 | 190 | }
|
190 | 191 |
|
| 192 | + @Test |
| 193 | + public void streamingError() throws Exception { |
| 194 | + MvcResult result = this.mvc.perform(get("/api/c1/streamingError")) |
| 195 | + .andExpect(request().asyncStarted()).andReturn(); |
| 196 | + assertThatCode( |
| 197 | + () -> this.mvc.perform(asyncDispatch(result)).andExpect(status().isOk())); |
| 198 | + assertThat(this.registry.get("http.server.requests") |
| 199 | + .tags("exception", "IOException").timer().count()).isEqualTo(1L); |
| 200 | + } |
| 201 | + |
191 | 202 | @Test
|
192 | 203 | public void anonymousError() {
|
193 | 204 | try {
|
@@ -451,6 +462,14 @@ public String alwaysThrowsUnhandledException(@PathVariable Long id) {
|
451 | 462 | throw new RuntimeException("Boom on " + id + "!");
|
452 | 463 | }
|
453 | 464 |
|
| 465 | + @GetMapping("/streamingError") |
| 466 | + public ResponseBodyEmitter streamingError() { |
| 467 | + ResponseBodyEmitter emitter = new ResponseBodyEmitter(); |
| 468 | + emitter.completeWithError( |
| 469 | + new IOException("error while writing to the response")); |
| 470 | + return emitter; |
| 471 | + } |
| 472 | + |
454 | 473 | @Timed
|
455 | 474 | @GetMapping("/regex/{id:\\.[a-z]+}")
|
456 | 475 | public String successfulRegex(@PathVariable String id) {
|
|
0 commit comments