Skip to content

Commit 6138041

Browse files
committed
Polish
Fixes gh-16014
1 parent a6ccdbe commit 6138041

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilterTests.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,6 +76,7 @@
7676
import org.springframework.web.filter.OncePerRequestFilter;
7777
import org.springframework.web.servlet.ModelAndView;
7878
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
79+
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter;
7980
import org.springframework.web.util.NestedServletException;
8081

8182
import static org.assertj.core.api.Assertions.assertThat;
@@ -188,6 +189,16 @@ public void unhandledError() {
188189
.tags("exception", "RuntimeException").timer().count()).isEqualTo(1L);
189190
}
190191

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+
191202
@Test
192203
public void anonymousError() {
193204
try {
@@ -451,6 +462,14 @@ public String alwaysThrowsUnhandledException(@PathVariable Long id) {
451462
throw new RuntimeException("Boom on " + id + "!");
452463
}
453464

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+
454473
@Timed
455474
@GetMapping("/regex/{id:\\.[a-z]+}")
456475
public String successfulRegex(@PathVariable String id) {

0 commit comments

Comments
 (0)