Skip to content

Commit

Permalink
Merge pull request #31948 from izeye
Browse files Browse the repository at this point in the history
* pr/31948:
  Polish

Closes gh-31948
  • Loading branch information
snicoll committed Aug 2, 2022
2 parents c05d0c5 + 6a4681b commit 5527769
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
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;

Expand All @@ -52,7 +52,7 @@ public Encoding encoding() {

@Override
public int messageMaxBytes() {
return (int) MESSAGE_MAX_BYTES.toBytes();
return (int) MESSAGE_MAX_SIZE.toBytes();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected Void doExecute() {

@Override
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ void sendSpansShouldThrowIfCloseWasCalled() throws IOException {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void sendSpansShouldSendSpansToZipkin(boolean async) throws IOException {
this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST))
.andExpect(content().contentType("application/json")).andExpect(content().string("[span1,span2]"))
.andRespond(withStatus(HttpStatus.ACCEPTED));
this.makeRequest(List.of(toByteArray("span1"), toByteArray("span2")), async);
makeRequest(List.of(toByteArray("span1"), toByteArray("span2")), async);
}

@ParameterizedTest
Expand All @@ -95,12 +95,12 @@ void sendSpansShouldHandleHttpFailures(boolean async) {
this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
if (async) {
CallbackResult callbackResult = this.makeAsyncRequest(List.of());
CallbackResult callbackResult = makeAsyncRequest(List.of());
assertThat(callbackResult.success()).isFalse();
assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error");
}
else {
assertThatThrownBy(() -> this.makeSyncRequest(List.of())).hasMessageContaining("500 Internal Server Error");
assertThatThrownBy(() -> makeSyncRequest(List.of())).hasMessageContaining("500 Internal Server Error");
}
}

Expand All @@ -114,7 +114,7 @@ void sendSpansShouldCompressData(boolean async) throws IOException {
this.mockServer.expect(requestTo(ZIPKIN_URL)).andExpect(method(HttpMethod.POST))
.andExpect(header("Content-Encoding", "gzip")).andExpect(content().contentType("application/json"))
.andExpect(content().bytes(compressed)).andRespond(withStatus(HttpStatus.ACCEPTED));
this.makeRequest(List.of(toByteArray(uncompressed)), async);
makeRequest(List.of(toByteArray(uncompressed)), async);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ZipkinWebClientSenderTests extends ZipkinHttpSenderTests {

private static MockWebServer mockBackEnd;

public static String ZIPKIN_URL;
private static String ZIPKIN_URL;

@BeforeAll
static void beforeAll() throws IOException {
Expand Down Expand Up @@ -92,7 +92,7 @@ void checkShouldNotRaiseException() throws InterruptedException {
void sendSpansShouldSendSpansToZipkin(boolean async) throws IOException, InterruptedException {
mockBackEnd.enqueue(new MockResponse());
List<byte[]> encodedSpans = List.of(toByteArray("span1"), toByteArray("span2"));
this.makeRequest(encodedSpans, async);
makeRequest(encodedSpans, async);

requestAssertions((request) -> {
assertThat(request.getMethod()).isEqualTo("POST");
Expand All @@ -106,12 +106,12 @@ void sendSpansShouldSendSpansToZipkin(boolean async) throws IOException, Interru
void sendSpansShouldHandleHttpFailures(boolean async) throws InterruptedException {
mockBackEnd.enqueue(new MockResponse().setResponseCode(500));
if (async) {
CallbackResult callbackResult = this.makeAsyncRequest(List.of());
CallbackResult callbackResult = makeAsyncRequest(List.of());
assertThat(callbackResult.success()).isFalse();
assertThat(callbackResult.error()).isNotNull().hasMessageContaining("500 Internal Server Error");
}
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"));
Expand All @@ -127,7 +127,7 @@ void sendSpansShouldCompressData(boolean async) throws IOException, InterruptedE

mockBackEnd.enqueue(new MockResponse());

this.makeRequest(List.of(toByteArray(uncompressed)), async);
makeRequest(List.of(toByteArray(uncompressed)), async);

requestAssertions((request) -> {
assertThat(request.getMethod()).isEqualTo("POST");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ void recordHistogram() throws Exception {

@Test
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());
assertThat(this.registry.get("http.server.requests").tags("status", "200", "uri", "/api/c1/simple/{id}").timer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void registerHintsWithNoLocation() {
assertThat(hints.resources().resourcePatterns()).isEmpty();
}

RuntimeHints register(ClassLoader classLoader) {
private RuntimeHints register(ClassLoader classLoader) {
RuntimeHints hints = new RuntimeHints();
WebResourcesRuntimeHints registrar = new WebResourcesRuntimeHints();
registrar.registerHints(hints, classLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
private JarEntryCertification[] certifications;

private final Map<Integer, FileHeader> entriesCache = Collections
.synchronizedMap(new LinkedHashMap<Integer, FileHeader>(16, 0.75f, true) {
.synchronizedMap(new LinkedHashMap<>(16, 0.75f, true) {

@Override
protected boolean removeEldestEntry(Map.Entry<Integer, FileHeader> eldest) {
Expand Down Expand Up @@ -338,7 +338,7 @@ JarEntryCertification getCertification(JarEntry entry) throws IOException {
// We fall back to use JarInputStream to obtain the certs. This isn't that
// fast, but hopefully doesn't happen too often.
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) {
// Entry must be closed to trigger a read and set entry certificates
certifiedJarStream.closeEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
* @author HaiTao Zhang
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "management.endpoints.web.base-path=/", "management.server.port=0",
"logging.level.org.springframework.web=trace" })
properties = { "management.endpoints.web.base-path=/", "management.server.port=0" })
class ManagementDifferentPortSampleActuatorApplicationTests {

@LocalManagementPort
Expand Down

0 comments on commit 5527769

Please sign in to comment.