See gh-31948
This commit is contained in:
Johnny Lim 2022-08-02 00:53:06 +09:00 committed by Stephane Nicoll
parent c05d0c51b7
commit 6a4681baf5
9 changed files with 18 additions and 20 deletions

View File

@ -41,7 +41,7 @@ import org.springframework.util.unit.DataSize;
*/ */
abstract class HttpSender extends Sender { abstract class HttpSender extends Sender {
private static final DataSize MESSAGE_MAX_BYTES = DataSize.ofKilobytes(512); private static final DataSize MESSAGE_MAX_SIZE = DataSize.ofKilobytes(512);
private volatile boolean closed; private volatile boolean closed;
@ -52,7 +52,7 @@ abstract class HttpSender extends Sender {
@Override @Override
public int messageMaxBytes() { public int messageMaxBytes() {
return (int) MESSAGE_MAX_BYTES.toBytes(); return (int) MESSAGE_MAX_SIZE.toBytes();
} }
@Override @Override

View File

@ -69,7 +69,7 @@ class ZipkinWebClientSender extends HttpSender {
@Override @Override
protected void doEnqueue(Callback<Void> callback) { protected void doEnqueue(Callback<Void> callback) {
sendRequest().subscribe((__) -> callback.onSuccess(null), callback::onError); sendRequest().subscribe((entity) -> callback.onSuccess(null), callback::onError);
} }
private Mono<ResponseEntity<Void>> sendRequest() { private Mono<ResponseEntity<Void>> sendRequest() {

View File

@ -58,11 +58,11 @@ abstract class ZipkinHttpSenderTests {
protected void makeRequest(List<byte[]> encodedSpans, boolean async) throws IOException { protected void makeRequest(List<byte[]> encodedSpans, boolean async) throws IOException {
if (async) { if (async) {
CallbackResult callbackResult = this.makeAsyncRequest(encodedSpans); CallbackResult callbackResult = makeAsyncRequest(encodedSpans);
assertThat(callbackResult.success()).isTrue(); assertThat(callbackResult.success()).isTrue();
} }
else { else {
this.makeSyncRequest(encodedSpans); makeSyncRequest(encodedSpans);
} }
} }

View File

@ -86,7 +86,7 @@ class ZipkinRestTemplateSenderTests extends ZipkinHttpSenderTests {
this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST)) this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST))
.andExpect(content().contentType("application/json")).andExpect(content().string("[span1,span2]")) .andExpect(content().contentType("application/json")).andExpect(content().string("[span1,span2]"))
.andRespond(withStatus(HttpStatus.ACCEPTED)); .andRespond(withStatus(HttpStatus.ACCEPTED));
this.makeRequest(List.of(toByteArray("span1"), toByteArray("span2")), async); makeRequest(List.of(toByteArray("span1"), toByteArray("span2")), async);
} }
@ParameterizedTest @ParameterizedTest
@ -95,12 +95,12 @@ class ZipkinRestTemplateSenderTests extends ZipkinHttpSenderTests {
this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST)) this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
if (async) { if (async) {
CallbackResult callbackResult = this.makeAsyncRequest(List.of()); CallbackResult callbackResult = makeAsyncRequest(List.of());
assertThat(callbackResult.success()).isFalse(); assertThat(callbackResult.success()).isFalse();
assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error"); assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error");
} }
else { else {
assertThatThrownBy(() -> this.makeSyncRequest(List.of())).hasMessageContaining("500 Internal Server Error"); assertThatThrownBy(() -> makeSyncRequest(List.of())).hasMessageContaining("500 Internal Server Error");
} }
} }
@ -114,7 +114,7 @@ class ZipkinRestTemplateSenderTests extends ZipkinHttpSenderTests {
this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST)) this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST))
.andExpect(header("Content-Encoding", "gzip")).andExpect(content().contentType("application/json")) .andExpect(header("Content-Encoding", "gzip")).andExpect(content().contentType("application/json"))
.andExpect(content().bytes(compressed)).andRespond(withStatus(HttpStatus.ACCEPTED)); .andExpect(content().bytes(compressed)).andRespond(withStatus(HttpStatus.ACCEPTED));
this.makeRequest(List.of(toByteArray(uncompressed)), async); makeRequest(List.of(toByteArray(uncompressed)), async);
} }
} }

View File

@ -46,7 +46,7 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {
private static MockWebServer mockBackEnd; private static MockWebServer mockBackEnd;
public static String ZIPKIN_URL; private static String ZIPKIN_URL;
@BeforeAll @BeforeAll
static void beforeAll() throws IOException { static void beforeAll() throws IOException {
@ -92,7 +92,7 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {
void sendSpansShouldSendSpansToZipkin(boolean async) throws IOException, InterruptedException { void sendSpansShouldSendSpansToZipkin(boolean async) throws IOException, InterruptedException {
mockBackEnd.enqueue(new MockResponse()); mockBackEnd.enqueue(new MockResponse());
List<byte[]> encodedSpans = List.of(toByteArray("span1"), toByteArray("span2")); List<byte[]> encodedSpans = List.of(toByteArray("span1"), toByteArray("span2"));
this.makeRequest(encodedSpans, async); makeRequest(encodedSpans, async);
requestAssertions((request) -> { requestAssertions((request) -> {
assertThat(request.getMethod()).isEqualTo("POST"); assertThat(request.getMethod()).isEqualTo("POST");
@ -106,12 +106,12 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {
void sendSpansShouldHandleHttpFailures(boolean async) throws InterruptedException { void sendSpansShouldHandleHttpFailures(boolean async) throws InterruptedException {
mockBackEnd.enqueue(new MockResponse().setResponseCode(500)); mockBackEnd.enqueue(new MockResponse().setResponseCode(500));
if (async) { if (async) {
CallbackResult callbackResult = this.makeAsyncRequest(List.of()); CallbackResult callbackResult = makeAsyncRequest(List.of());
assertThat(callbackResult.success()).isFalse(); assertThat(callbackResult.success()).isFalse();
assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error"); assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error");
} }
else { else {
assertThatThrownBy(() -> this.makeSyncRequest(List.of())).hasMessageContaining("500 Internal Server Error"); assertThatThrownBy(() -> makeSyncRequest(List.of())).hasMessageContaining("500 Internal Server Error");
} }
requestAssertions((request) -> assertThat(request.getMethod()).isEqualTo("POST")); requestAssertions((request) -> assertThat(request.getMethod()).isEqualTo("POST"));
@ -127,7 +127,7 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {
mockBackEnd.enqueue(new MockResponse()); mockBackEnd.enqueue(new MockResponse());
this.makeRequest(List.of(toByteArray(uncompressed)), async); makeRequest(List.of(toByteArray(uncompressed)), async);
requestAssertions((request) -> { requestAssertions((request) -> {
assertThat(request.getMethod()).isEqualTo("POST"); assertThat(request.getMethod()).isEqualTo("POST");

View File

@ -315,7 +315,6 @@ class WebMvcMetricsFilterTests {
@Test @Test
void trailingSlashShouldNotRecordDuplicateMetrics() throws Exception { void trailingSlashShouldNotRecordDuplicateMetrics() throws Exception {
this.mvc.perform(get("/api/c1/simple/10")).andExpect(status().isOk()); this.mvc.perform(get("/api/c1/simple/10")).andExpect(status().isOk());
this.mvc.perform(get("/api/c1/simple/10/")).andExpect(status().isOk()); this.mvc.perform(get("/api/c1/simple/10/")).andExpect(status().isOk());
assertThat(this.registry.get("http.server.requests").tags("status", "200", "uri", "/api/c1/simple/{id}").timer() assertThat(this.registry.get("http.server.requests").tags("status", "200", "uri", "/api/c1/simple/{id}").timer()

View File

@ -56,7 +56,7 @@ class WebResourcesRuntimeHintsTests {
assertThat(hints.resources().resourcePatterns()).isEmpty(); assertThat(hints.resources().resourcePatterns()).isEmpty();
} }
RuntimeHints register(ClassLoader classLoader) { private RuntimeHints register(ClassLoader classLoader) {
RuntimeHints hints = new RuntimeHints(); RuntimeHints hints = new RuntimeHints();
WebResourcesRuntimeHints registrar = new WebResourcesRuntimeHints(); WebResourcesRuntimeHints registrar = new WebResourcesRuntimeHints();
registrar.registerHints(hints, classLoader); registrar.registerHints(hints, classLoader);

View File

@ -86,7 +86,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
private JarEntryCertification[] certifications; private JarEntryCertification[] certifications;
private final Map<Integer, FileHeader> entriesCache = Collections private final Map<Integer, FileHeader> entriesCache = Collections
.synchronizedMap(new LinkedHashMap<Integer, FileHeader>(16, 0.75f, true) { .synchronizedMap(new LinkedHashMap<>(16, 0.75f, true) {
@Override @Override
protected boolean removeEldestEntry(Map.Entry<Integer, FileHeader> eldest) { protected boolean removeEldestEntry(Map.Entry<Integer, FileHeader> eldest) {
@ -338,7 +338,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
// We fall back to use JarInputStream to obtain the certs. This isn't that // We fall back to use JarInputStream to obtain the certs. This isn't that
// fast, but hopefully doesn't happen too often. // fast, but hopefully doesn't happen too often.
try (JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream())) { try (JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream())) {
java.util.jar.JarEntry certifiedEntry = null; java.util.jar.JarEntry certifiedEntry;
while ((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) { while ((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) {
// Entry must be closed to trigger a read and set entry certificates // Entry must be closed to trigger a read and set entry certificates
certifiedJarStream.closeEntry(); certifiedJarStream.closeEntry();

View File

@ -33,8 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author HaiTao Zhang * @author HaiTao Zhang
*/ */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.web.base-path=/", "management.server.port=0", properties = { "management.endpoints.web.base-path=/", "management.server.port=0" })
"logging.level.org.springframework.web=trace" })
class ManagementDifferentPortSampleActuatorApplicationTests { class ManagementDifferentPortSampleActuatorApplicationTests {
@LocalManagementPort @LocalManagementPort