Skip to content

Commit 09686c2

Browse files
committed
fixes tests and changes error message
Signed-off-by: Oleh Dokuka <[email protected]>
1 parent a124aea commit 09686c2

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

rsocket-core/src/main/java/io/rsocket/RSocketRequester.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ private Mono<Void> handleFireAndForget(Payload payload) {
189189

190190
if (!FragmentationUtils.isValid(this.mtu, payload)) {
191191
payload.release();
192-
return Mono.error(new IllegalArgumentException("Too big Payload size"));
192+
return Mono.error(
193+
new IllegalArgumentException(
194+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
193195
}
194196

195197
final int streamId = streamIdSupplier.nextStreamId(receivers);
@@ -218,7 +220,9 @@ private Mono<Payload> handleRequestResponse(final Payload payload) {
218220

219221
if (!FragmentationUtils.isValid(this.mtu, payload)) {
220222
payload.release();
221-
return Mono.error(new IllegalArgumentException("Too big Payload size"));
223+
return Mono.error(
224+
new IllegalArgumentException(
225+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
222226
}
223227

224228
int streamId = streamIdSupplier.nextStreamId(receivers);
@@ -268,7 +272,9 @@ private Flux<Payload> handleRequestStream(final Payload payload) {
268272

269273
if (!FragmentationUtils.isValid(this.mtu, payload)) {
270274
payload.release();
271-
return Flux.error(new IllegalArgumentException("Too big Payload size"));
275+
return Flux.error(
276+
new IllegalArgumentException(
277+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
272278
}
273279

274280
int streamId = streamIdSupplier.nextStreamId(receivers);
@@ -336,7 +342,8 @@ private Flux<Payload> handleChannel(Flux<Payload> request) {
336342
if (!FragmentationUtils.isValid(mtu, payload)) {
337343
payload.release();
338344
final IllegalArgumentException t =
339-
new IllegalArgumentException("Too big Payload size");
345+
new IllegalArgumentException(
346+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
340347
errorConsumer.accept(t);
341348
return Mono.error(t);
342349
}
@@ -368,7 +375,8 @@ protected void hookOnNext(Payload payload) {
368375
payload.release();
369376
cancel();
370377
final IllegalArgumentException t =
371-
new IllegalArgumentException("Too big Payload size");
378+
new IllegalArgumentException(
379+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
372380
errorConsumer.accept(t);
373381
// no need to send any errors.
374382
sendProcessor.onNext(CancelFrameFlyweight.encode(allocator, streamId));
@@ -463,7 +471,9 @@ private Mono<Void> handleMetadataPush(Payload payload) {
463471

464472
if (!FragmentationUtils.isValid(this.mtu, payload)) {
465473
payload.release();
466-
return Mono.error(new IllegalArgumentException("Too big Payload size"));
474+
return Mono.error(
475+
new IllegalArgumentException(
476+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
467477
}
468478

469479
return UnicastMonoEmpty.newInstance(

rsocket-core/src/main/java/io/rsocket/RSocketResponder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ protected void hookOnNext(Payload payload) {
376376
payload.release();
377377
cancel();
378378
final IllegalArgumentException t =
379-
new IllegalArgumentException("Too big Payload size");
379+
new IllegalArgumentException(
380+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
380381
handleError(streamId, t);
381382
return;
382383
}
@@ -431,7 +432,8 @@ protected void hookOnNext(Payload payload) {
431432
payload.release();
432433
cancel();
433434
final IllegalArgumentException t =
434-
new IllegalArgumentException("Too big Payload size");
435+
new IllegalArgumentException(
436+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
435437
handleError(streamId, t);
436438
return;
437439
}

rsocket-core/src/main/java/io/rsocket/fragmentation/FragmentationUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public final class FragmentationUtils {
99
public static boolean isValid(int mtu, Payload payload) {
1010
return payload.hasMetadata()
1111
? isValid(mtu, payload.data(), payload.metadata())
12-
: isValid(mtu, payload.metadata());
12+
: isValid(mtu, payload.data());
1313
}
1414

1515
public static boolean isValid(int mtu, ByteBuf data) {

rsocket-core/src/test/java/io/rsocket/RSocketRequesterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public void shouldThrownExceptionIfGivenPayloadIsExitsSizeAllowanceWithNoFragmen
299299
t ->
300300
Assertions.assertThat(t)
301301
.isInstanceOf(IllegalArgumentException.class)
302-
.hasMessage("Too big Payload size"))
302+
.hasMessage("The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."))
303303
.verify();
304304
});
305305
}
@@ -326,7 +326,7 @@ public void shouldThrownExceptionIfGivenPayloadIsExitsSizeAllowanceWithNoFragmen
326326
t ->
327327
Assertions.assertThat(t)
328328
.isInstanceOf(IllegalArgumentException.class)
329-
.hasMessage("Too big Payload size"))
329+
.hasMessage("The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."))
330330
.verify();
331331
}
332332

rsocket-core/src/test/java/io/rsocket/RSocketResponderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
150150
Assertions.assertThat(rule.errors)
151151
.first()
152152
.isInstanceOf(IllegalArgumentException.class)
153-
.hasToString("java.lang.IllegalArgumentException: Too big Payload size");
153+
.hasToString("java.lang.IllegalArgumentException: The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
154154
Assertions.assertThat(rule.connection.getSent())
155155
.hasSize(1)
156156
.first()
157157
.matches(bb -> FrameHeaderFlyweight.frameType(bb) == FrameType.ERROR)
158-
.matches(bb -> ErrorFrameFlyweight.dataUtf8(bb).contains("Too big Payload size"));
158+
.matches(bb -> ErrorFrameFlyweight.dataUtf8(bb).contains("The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
159159

160160
assertThat("Subscription not cancelled.", cancelled.get(), is(true));
161161
rule.init();

rsocket-core/src/test/java/io/rsocket/fragmentation/FragmentationUtilsTest.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.rsocket.fragmentation;
22

3-
import static org.junit.jupiter.api.Assertions.*;
4-
53
import io.rsocket.Payload;
64
import io.rsocket.frame.FrameHeaderFlyweight;
75
import io.rsocket.frame.FrameLengthFlyweight;
@@ -13,7 +11,7 @@
1311
class FragmentationUtilsTest {
1412

1513
@Test
16-
void shouldValidFrameWithNoFragmentation() {
14+
void shouldBeValidFrameWithNoFragmentation() {
1715
byte[] data =
1816
new byte
1917
[FrameLengthFlyweight.FRAME_LENGTH_MASK
@@ -26,7 +24,21 @@ void shouldValidFrameWithNoFragmentation() {
2624
}
2725

2826
@Test
29-
void shouldValidFrameWithNoFragmentation0() {
27+
void shouldBeInValidFrameWithNoFragmentation() {
28+
byte[] data =
29+
new byte
30+
[FrameLengthFlyweight.FRAME_LENGTH_MASK
31+
- FrameLengthFlyweight.FRAME_LENGTH_SIZE
32+
- FrameHeaderFlyweight.size()
33+
+ 1];
34+
ThreadLocalRandom.current().nextBytes(data);
35+
final Payload payload = DefaultPayload.create(data);
36+
37+
Assertions.assertThat(FragmentationUtils.isValid(0, payload)).isFalse();
38+
}
39+
40+
@Test
41+
void shouldBeValidFrameWithNoFragmentation0() {
3042
byte[] metadata = new byte[FrameLengthFlyweight.FRAME_LENGTH_MASK / 2];
3143
byte[] data =
3244
new byte
@@ -42,7 +54,7 @@ void shouldValidFrameWithNoFragmentation0() {
4254
}
4355

4456
@Test
45-
void shouldValidFrameWithNoFragmentation1() {
57+
void shouldBeInValidFrameWithNoFragmentation1() {
4658
byte[] metadata = new byte[FrameLengthFlyweight.FRAME_LENGTH_MASK];
4759
byte[] data = new byte[FrameLengthFlyweight.FRAME_LENGTH_MASK];
4860
ThreadLocalRandom.current().nextBytes(metadata);
@@ -53,7 +65,7 @@ void shouldValidFrameWithNoFragmentation1() {
5365
}
5466

5567
@Test
56-
void shouldValidFrameWithNoFragmentation2() {
68+
void shouldBeValidFrameWithNoFragmentation2() {
5769
byte[] metadata = new byte[1];
5870
byte[] data = new byte[1];
5971
ThreadLocalRandom.current().nextBytes(metadata);
@@ -64,7 +76,7 @@ void shouldValidFrameWithNoFragmentation2() {
6476
}
6577

6678
@Test
67-
void shouldValidFrameWithNoFragmentation3() {
79+
void shouldBeValidFrameWithNoFragmentation3() {
6880
byte[] metadata = new byte[FrameLengthFlyweight.FRAME_LENGTH_MASK];
6981
byte[] data = new byte[FrameLengthFlyweight.FRAME_LENGTH_MASK];
7082
ThreadLocalRandom.current().nextBytes(metadata);
@@ -75,7 +87,7 @@ void shouldValidFrameWithNoFragmentation3() {
7587
}
7688

7789
@Test
78-
void shouldValidFrameWithNoFragmentation4() {
90+
void shouldBeValidFrameWithNoFragmentation4() {
7991
byte[] metadata = new byte[1];
8092
byte[] data = new byte[1];
8193
ThreadLocalRandom.current().nextBytes(metadata);

0 commit comments

Comments
 (0)