|
33 | 33 | import static io.rsocket.frame.FrameType.REQUEST_RESPONSE;
|
34 | 34 | import static io.rsocket.frame.FrameType.REQUEST_STREAM;
|
35 | 35 | import static org.assertj.core.api.Assertions.assertThat;
|
| 36 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
36 | 37 | import static org.mockito.ArgumentMatchers.any;
|
37 | 38 | import static org.mockito.Mockito.verify;
|
38 | 39 |
|
|
81 | 82 | import java.util.function.BiFunction;
|
82 | 83 | import java.util.function.Function;
|
83 | 84 | import java.util.stream.Stream;
|
84 |
| -import org.assertj.core.api.Assertions; |
85 | 85 | import org.assertj.core.api.Assumptions;
|
86 | 86 | import org.junit.jupiter.api.AfterEach;
|
87 | 87 | import org.junit.jupiter.api.BeforeEach;
|
@@ -169,7 +169,7 @@ protected void hookOnSubscribe(Subscription subscription) {
|
169 | 169 | public void testHandleSetupException() {
|
170 | 170 | rule.connection.addToReceivedBuffer(
|
171 | 171 | ErrorFrameCodec.encode(rule.alloc(), 0, new RejectedSetupException("boom")));
|
172 |
| - Assertions.assertThatThrownBy(() -> rule.socket.onClose().block()) |
| 172 | + assertThatThrownBy(() -> rule.socket.onClose().block()) |
173 | 173 | .isInstanceOf(RejectedSetupException.class);
|
174 | 174 | rule.assertHasNoLeaks();
|
175 | 175 | }
|
@@ -373,6 +373,65 @@ public void shouldThrownExceptionIfGivenPayloadIsExitsSizeAllowanceWithNoFragmen
|
373 | 373 | });
|
374 | 374 | }
|
375 | 375 |
|
| 376 | + @ParameterizedTest |
| 377 | + @ValueSource(ints = {128, 256, FRAME_LENGTH_MASK}) |
| 378 | + public void shouldThrownExceptionIfGivenPayloadIsExitsSizeAllowanceWithNoFragmentation1( |
| 379 | + int maxFrameLength) { |
| 380 | + rule.setMaxFrameLength(maxFrameLength); |
| 381 | + prepareCalls() |
| 382 | + .forEach( |
| 383 | + generator -> { |
| 384 | + byte[] metadata = new byte[maxFrameLength]; |
| 385 | + byte[] data = new byte[maxFrameLength]; |
| 386 | + ThreadLocalRandom.current().nextBytes(metadata); |
| 387 | + ThreadLocalRandom.current().nextBytes(data); |
| 388 | + |
| 389 | + assertThatThrownBy( |
| 390 | + () -> { |
| 391 | + final Publisher<?> source = |
| 392 | + generator.apply(rule.socket, DefaultPayload.create(data, metadata)); |
| 393 | + |
| 394 | + if (source instanceof Mono) { |
| 395 | + ((Mono<?>) source).block(); |
| 396 | + } else { |
| 397 | + ((Flux) source).blockLast(); |
| 398 | + } |
| 399 | + }) |
| 400 | + .isInstanceOf(IllegalArgumentException.class) |
| 401 | + .hasMessage(String.format(INVALID_PAYLOAD_ERROR_MESSAGE, maxFrameLength)); |
| 402 | + |
| 403 | + rule.assertHasNoLeaks(); |
| 404 | + }); |
| 405 | + } |
| 406 | + |
| 407 | + @Test |
| 408 | + public void shouldRejectCallOfNoMetadataPayload() { |
| 409 | + final ByteBuf data = rule.allocator.buffer(10); |
| 410 | + final Payload payload = ByteBufPayload.create(data); |
| 411 | + StepVerifier.create(rule.socket.metadataPush(payload)) |
| 412 | + .expectSubscription() |
| 413 | + .expectErrorSatisfies( |
| 414 | + t -> |
| 415 | + assertThat(t) |
| 416 | + .isInstanceOf(IllegalArgumentException.class) |
| 417 | + .hasMessage("Metadata push should have metadata field present")) |
| 418 | + .verify(); |
| 419 | + PayloadAssert.assertThat(payload).isReleased(); |
| 420 | + rule.assertHasNoLeaks(); |
| 421 | + } |
| 422 | + |
| 423 | + @Test |
| 424 | + public void shouldRejectCallOfNoMetadataPayloadBlocking() { |
| 425 | + final ByteBuf data = rule.allocator.buffer(10); |
| 426 | + final Payload payload = ByteBufPayload.create(data); |
| 427 | + |
| 428 | + assertThatThrownBy(() -> rule.socket.metadataPush(payload).block()) |
| 429 | + .isInstanceOf(IllegalArgumentException.class) |
| 430 | + .hasMessage("Metadata push should have metadata field present"); |
| 431 | + PayloadAssert.assertThat(payload).isReleased(); |
| 432 | + rule.assertHasNoLeaks(); |
| 433 | + } |
| 434 | + |
376 | 435 | static Stream<BiFunction<RSocket, Payload, Publisher<?>>> prepareCalls() {
|
377 | 436 | return Stream.of(
|
378 | 437 | RSocket::fireAndForget,
|
|
0 commit comments