Skip to content

Commit 553632e

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

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

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

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

193193
if (!FragmentationUtils.isValid(this.mtu, payload)) {
194194
payload.release();
195-
return Mono.error(new IllegalArgumentException("Too big Payload size"));
195+
return Mono.error(
196+
new IllegalArgumentException(
197+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
196198
}
197199

198200
final int streamId = streamIdSupplier.nextStreamId(receivers);
@@ -221,7 +223,9 @@ private Mono<Payload> handleRequestResponse(final Payload payload) {
221223

222224
if (!FragmentationUtils.isValid(this.mtu, payload)) {
223225
payload.release();
224-
return Mono.error(new IllegalArgumentException("Too big Payload size"));
226+
return Mono.error(
227+
new IllegalArgumentException(
228+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
225229
}
226230

227231
int streamId = streamIdSupplier.nextStreamId(receivers);
@@ -271,7 +275,9 @@ private Flux<Payload> handleRequestStream(final Payload payload) {
271275

272276
if (!FragmentationUtils.isValid(this.mtu, payload)) {
273277
payload.release();
274-
return Flux.error(new IllegalArgumentException("Too big Payload size"));
278+
return Flux.error(
279+
new IllegalArgumentException(
280+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
275281
}
276282

277283
int streamId = streamIdSupplier.nextStreamId(receivers);
@@ -339,7 +345,8 @@ private Flux<Payload> handleChannel(Flux<Payload> request) {
339345
if (!FragmentationUtils.isValid(mtu, payload)) {
340346
payload.release();
341347
final IllegalArgumentException t =
342-
new IllegalArgumentException("Too big Payload size");
348+
new IllegalArgumentException(
349+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
343350
errorConsumer.accept(t);
344351
return Mono.error(t);
345352
}
@@ -371,7 +378,8 @@ protected void hookOnNext(Payload payload) {
371378
payload.release();
372379
cancel();
373380
final IllegalArgumentException t =
374-
new IllegalArgumentException("Too big Payload size");
381+
new IllegalArgumentException(
382+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
375383
errorConsumer.accept(t);
376384
// no need to send any errors.
377385
sendProcessor.onNext(CancelFrameFlyweight.encode(allocator, streamId));
@@ -466,7 +474,9 @@ private Mono<Void> handleMetadataPush(Payload payload) {
466474

467475
if (!FragmentationUtils.isValid(this.mtu, payload)) {
468476
payload.release();
469-
return Mono.error(new IllegalArgumentException("Too big Payload size"));
477+
return Mono.error(
478+
new IllegalArgumentException(
479+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory."));
470480
}
471481

472482
return UnicastMonoEmpty.newInstance(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ protected void hookOnNext(Payload payload) {
380380
payload.release();
381381
cancel();
382382
final IllegalArgumentException t =
383-
new IllegalArgumentException("Too big Payload size");
383+
new IllegalArgumentException(
384+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
384385
handleError(streamId, t);
385386
return;
386387
}
@@ -435,7 +436,8 @@ protected void hookOnNext(Payload payload) {
435436
payload.release();
436437
cancel();
437438
final IllegalArgumentException t =
438-
new IllegalArgumentException("Too big Payload size");
439+
new IllegalArgumentException(
440+
"The payload is too big to send as a single frame with a 24-bit encoded length. Consider enabling fragmentation via RSocketFactory.");
439441
handleError(streamId, t);
440442
return;
441443
}

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/core/RSocketRequesterTest.java

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
153153
Assertions.assertThat(rule.errors)
154154
.first()
155155
.isInstanceOf(IllegalArgumentException.class)
156-
.hasToString("java.lang.IllegalArgumentException: Too big Payload size");
156+
.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.");
157157
Assertions.assertThat(rule.connection.getSent())
158158
.hasSize(1)
159159
.first()
160160
.matches(bb -> FrameHeaderFlyweight.frameType(bb) == FrameType.ERROR)
161-
.matches(bb -> ErrorFrameFlyweight.dataUtf8(bb).contains("Too big Payload size"));
161+
.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."));
162162

163163
assertThat("Subscription not cancelled.", cancelled.get(), is(true));
164164
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)