Use String.repeat() where feasible

See gh-31916
This commit is contained in:
Yanming Zhou 2023-12-28 15:00:37 +08:00 committed by Stéphane Nicoll
parent 7cfff4049d
commit dee1b726f9
2 changed files with 4 additions and 11 deletions

View File

@ -239,13 +239,10 @@ public class StompHeaderAccessorTests {
String actual = accessor.getShortLogMessage("payload".getBytes(StandardCharsets.UTF_8)); String actual = accessor.getShortLogMessage("payload".getBytes(StandardCharsets.UTF_8));
assertThat(actual).isEqualTo("SEND /foo session=123 application/json payload=payload"); assertThat(actual).isEqualTo("SEND /foo session=123 application/json payload=payload");
StringBuilder sb = new StringBuilder(); String string = "a".repeat(80);
for (int i = 0; i < 80; i++) { final String payload = string + " > 80";
sb.append('a');
}
final String payload = sb.toString() + " > 80";
actual = accessor.getShortLogMessage(payload.getBytes(StandardCharsets.UTF_8)); actual = accessor.getShortLogMessage(payload.getBytes(StandardCharsets.UTF_8));
assertThat(actual).isEqualTo(("SEND /foo session=123 application/json payload=" + sb + "...(truncated)")); assertThat(actual).isEqualTo(("SEND /foo session=123 application/json payload=" + string + "...(truncated)"));
} }
} }

View File

@ -162,11 +162,7 @@ public class ProtobufDecoderTests extends AbstractDecoderTests<ProtobufDecoder>
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void decodeSplitMessageSize() { public void decodeSplitMessageSize() {
this.decoder.setMaxMessageSize(100009); this.decoder.setMaxMessageSize(100009);
StringBuilder builder = new StringBuilder(); Msg bigMessage = Msg.newBuilder().setFoo("azertyuiop".repeat(10000)).setBlah(secondMsg2).build();
for (int i = 0; i < 10000; i++) {
builder.append("azertyuiop");
}
Msg bigMessage = Msg.newBuilder().setFoo(builder.toString()).setBlah(secondMsg2).build();
Flux<DataBuffer> input = Flux.just(bigMessage, bigMessage) Flux<DataBuffer> input = Flux.just(bigMessage, bigMessage)
.flatMap(msg -> Mono.defer(() -> { .flatMap(msg -> Mono.defer(() -> {