Skip to content

Commit

Permalink
Merge branch '1.0.x' into 1.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Mar 20, 2019
2 parents eaeda6b + 47c0426 commit 2965323
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">

<!-- TreeWalker Checks -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* Intercepts incoming HTTP requests and records metrics about execution time and results.
*
* @author Jon Schneider
* @author Johnny Lim
*/
@NonNullApi
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
Expand Down Expand Up @@ -120,6 +121,9 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
record(timingContext, response, request, handlerObject, e.getCause());
throw e;
} catch (ServletException | IOException | RuntimeException ex) {
record(timingContext, response, request, handlerObject, ex);
throw ex;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
Expand All @@ -66,7 +68,9 @@
import static io.micrometer.spring.web.servlet.WebMvcMetricsFilterTest.RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

/**
Expand Down Expand Up @@ -168,6 +172,16 @@ public void unhandledError() {
.timer().count()).isEqualTo(1L);
}

@Test
public void streamingError() throws Exception {
MvcResult result = this.mvc.perform(get("/api/c1/streamingError"))
.andExpect(request().asyncStarted()).andReturn();
assertThatCode(
() -> this.mvc.perform(asyncDispatch(result)).andExpect(status().isOk()));
assertThat(this.registry.get("http.server.requests")
.tags("exception", "IOException").timer().count()).isEqualTo(1L);
}

@Test
public void endpointThrowsError() throws Exception {
mvc.perform(get("/api/c1/error/10")).andExpect(status().is4xxClientError());
Expand Down Expand Up @@ -355,6 +369,14 @@ public String alwaysThrowsUnhandledException(@PathVariable Long id) {
throw new RuntimeException("Boom on " + id + "!");
}

@GetMapping("/streamingError")
public ResponseBodyEmitter streamingError() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
emitter.completeWithError(
new IOException("error while writing to the response"));
return emitter;
}

@Timed
@GetMapping("/regex/{id:\\.[a-z]+}")
public String successfulRegex(@PathVariable String id) {
Expand Down

0 comments on commit 2965323

Please sign in to comment.