Skip to content

Commit 424aedc

Browse files
committed
fixes
Signed-off-by: Oleh Dokuka <[email protected]>
1 parent 47e4e3b commit 424aedc

3 files changed

Lines changed: 67 additions & 13 deletions

File tree

rsocket-core/src/test/java/io/rsocket/exceptions/ExceptionsTest.java

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import io.netty.buffer.ByteBuf;
3333
import io.netty.buffer.UnpooledByteBufAllocator;
34-
import io.rsocket.RaceTestConstants;
34+
import io.rsocket.FrameAssert;import io.rsocket.RaceTestConstants;
3535
import io.rsocket.frame.ErrorFrameCodec;
3636
import java.util.concurrent.ThreadLocalRandom;
3737
import org.junit.jupiter.api.DisplayName;
@@ -43,6 +43,7 @@ final class ExceptionsTest {
4343
void fromApplicationException() {
4444
ByteBuf byteBuf = createErrorFrame(1, APPLICATION_ERROR, "test-message");
4545

46+
try{
4647
assertThat(Exceptions.from(1, byteBuf))
4748
.isInstanceOf(ApplicationErrorException.class)
4849
.hasMessage("test-message");
@@ -51,26 +52,37 @@ void fromApplicationException() {
5152
.isInstanceOf(IllegalArgumentException.class)
5253
.hasMessage(
5354
"Invalid Error frame in Stream ID 0: 0x%08X '%s'", APPLICATION_ERROR, "test-message");
55+
} finally{
56+
byteBuf.release();
57+
}
5458
}
5559

5660
@DisplayName("from returns CanceledException")
5761
@Test
5862
void fromCanceledException() {
5963
ByteBuf byteBuf = createErrorFrame(1, CANCELED, "test-message");
6064

65+
try{
66+
67+
68+
6169
assertThat(Exceptions.from(1, byteBuf))
6270
.isInstanceOf(CanceledException.class)
6371
.hasMessage("test-message");
6472

6573
assertThat(Exceptions.from(0, byteBuf))
6674
.isInstanceOf(IllegalArgumentException.class)
6775
.hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", CANCELED, "test-message");
76+
} finally{
77+
byteBuf.release();
78+
}
6879
}
6980

7081
@DisplayName("from returns ConnectionCloseException")
7182
@Test
7283
void fromConnectionCloseException() {
7384
ByteBuf byteBuf = createErrorFrame(0, CONNECTION_CLOSE, "test-message");
85+
try{
7486

7587
assertThat(Exceptions.from(0, byteBuf))
7688
.isInstanceOf(ConnectionCloseException.class)
@@ -80,13 +92,19 @@ void fromConnectionCloseException() {
8092
.isInstanceOf(IllegalArgumentException.class)
8193
.hasMessage(
8294
"Invalid Error frame in Stream ID 1: 0x%08X '%s'", CONNECTION_CLOSE, "test-message");
95+
} finally{
96+
byteBuf.release();
97+
}
8398
}
8499

85100
@DisplayName("from returns ConnectionErrorException")
86101
@Test
87102
void fromConnectionErrorException() {
88103
ByteBuf byteBuf = createErrorFrame(0, CONNECTION_ERROR, "test-message");
89104

105+
try{
106+
107+
90108
assertThat(Exceptions.from(0, byteBuf))
91109
.isInstanceOf(ConnectionErrorException.class)
92110
.hasMessage("test-message");
@@ -95,12 +113,18 @@ void fromConnectionErrorException() {
95113
.isInstanceOf(IllegalArgumentException.class)
96114
.hasMessage(
97115
"Invalid Error frame in Stream ID 1: 0x%08X '%s'", CONNECTION_ERROR, "test-message");
116+
} finally{
117+
byteBuf.release();
118+
}
98119
}
99120

100121
@DisplayName("from returns IllegalArgumentException if error frame has illegal error code")
101122
@Test
102123
void fromIllegalErrorFrame() {
103124
ByteBuf byteBuf = createErrorFrame(0, 0x00000000, "test-message");
125+
try{
126+
127+
104128

105129
assertThat(Exceptions.from(0, byteBuf))
106130
.hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", 0, "test-message")
@@ -109,27 +133,33 @@ void fromIllegalErrorFrame() {
109133
assertThat(Exceptions.from(1, byteBuf))
110134
.hasMessage("Invalid Error frame in Stream ID 1: 0x%08X '%s'", 0x00000000, "test-message")
111135
.isInstanceOf(IllegalArgumentException.class);
136+
} finally{
137+
byteBuf.release();
138+
}
112139
}
113140

114141
@DisplayName("from returns InvalidException")
115142
@Test
116143
void fromInvalidException() {
117144
ByteBuf byteBuf = createErrorFrame(1, INVALID, "test-message");
118-
119-
assertThat(Exceptions.from(1, byteBuf))
120-
.isInstanceOf(InvalidException.class)
121-
.hasMessage("test-message");
145+
try{
146+
assertThat(Exceptions.from(1, byteBuf))
147+
.isInstanceOf(InvalidException.class)
148+
.hasMessage("test-message");
122149

123150
assertThat(Exceptions.from(0, byteBuf))
124151
.hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", INVALID, "test-message")
125152
.isInstanceOf(IllegalArgumentException.class);
153+
} finally{
154+
byteBuf.release();
155+
}
126156
}
127157

128158
@DisplayName("from returns InvalidSetupException")
129159
@Test
130160
void fromInvalidSetupException() {
131161
ByteBuf byteBuf = createErrorFrame(0, INVALID_SETUP, "test-message");
132-
162+
try {
133163
assertThat(Exceptions.from(0, byteBuf))
134164
.isInstanceOf(InvalidSetupException.class)
135165
.hasMessage("test-message");
@@ -138,12 +168,16 @@ void fromInvalidSetupException() {
138168
.hasMessage(
139169
"Invalid Error frame in Stream ID 1: 0x%08X '%s'", INVALID_SETUP, "test-message")
140170
.isInstanceOf(IllegalArgumentException.class);
171+
} finally{
172+
byteBuf.release();
173+
}
141174
}
142175

143176
@DisplayName("from returns RejectedException")
144177
@Test
145178
void fromRejectedException() {
146179
ByteBuf byteBuf = createErrorFrame(1, REJECTED, "test-message");
180+
try {
147181

148182
assertThat(Exceptions.from(1, byteBuf))
149183
.isInstanceOf(RejectedException.class)
@@ -152,12 +186,16 @@ void fromRejectedException() {
152186
assertThat(Exceptions.from(0, byteBuf))
153187
.hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", REJECTED, "test-message")
154188
.isInstanceOf(IllegalArgumentException.class);
189+
} finally{
190+
byteBuf.release();
191+
}
155192
}
156193

157194
@DisplayName("from returns RejectedResumeException")
158195
@Test
159196
void fromRejectedResumeException() {
160197
ByteBuf byteBuf = createErrorFrame(0, REJECTED_RESUME, "test-message");
198+
try {
161199

162200
assertThat(Exceptions.from(0, byteBuf))
163201
.isInstanceOf(RejectedResumeException.class)
@@ -167,12 +205,16 @@ void fromRejectedResumeException() {
167205
.hasMessage(
168206
"Invalid Error frame in Stream ID 1: 0x%08X '%s'", REJECTED_RESUME, "test-message")
169207
.isInstanceOf(IllegalArgumentException.class);
208+
} finally{
209+
byteBuf.release();
210+
}
170211
}
171212

172213
@DisplayName("from returns RejectedSetupException")
173214
@Test
174215
void fromRejectedSetupException() {
175216
ByteBuf byteBuf = createErrorFrame(0, REJECTED_SETUP, "test-message");
217+
try {
176218

177219
assertThat(Exceptions.from(0, byteBuf))
178220
.isInstanceOf(RejectedSetupException.class)
@@ -182,13 +224,16 @@ void fromRejectedSetupException() {
182224
.hasMessage(
183225
"Invalid Error frame in Stream ID 1: 0x%08X '%s'", REJECTED_SETUP, "test-message")
184226
.isInstanceOf(IllegalArgumentException.class);
227+
} finally{
228+
byteBuf.release();
229+
}
185230
}
186231

187232
@DisplayName("from returns UnsupportedSetupException")
188233
@Test
189234
void fromUnsupportedSetupException() {
190235
ByteBuf byteBuf = createErrorFrame(0, UNSUPPORTED_SETUP, "test-message");
191-
236+
try {
192237
assertThat(Exceptions.from(0, byteBuf))
193238
.isInstanceOf(UnsupportedSetupException.class)
194239
.hasMessage("test-message");
@@ -197,6 +242,9 @@ void fromUnsupportedSetupException() {
197242
.hasMessage(
198243
"Invalid Error frame in Stream ID 1: 0x%08X '%s'", UNSUPPORTED_SETUP, "test-message")
199244
.isInstanceOf(IllegalArgumentException.class);
245+
} finally{
246+
byteBuf.release();
247+
}
200248
}
201249

202250
@DisplayName("from returns CustomRSocketException")
@@ -210,16 +258,18 @@ void fromCustomRSocketException() {
210258
: ThreadLocalRandom.current()
211259
.nextInt(ErrorFrameCodec.MIN_USER_ALLOWED_ERROR_CODE, Integer.MAX_VALUE);
212260
ByteBuf byteBuf = createErrorFrame(0, randomCode, "test-message");
213-
261+
try {
214262
assertThat(Exceptions.from(1, byteBuf))
215263
.isInstanceOf(CustomRSocketException.class)
216264
.hasMessage("test-message");
217265

218266
assertThat(Exceptions.from(0, byteBuf))
219267
.hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", randomCode, "test-message")
220268
.isInstanceOf(IllegalArgumentException.class);
269+
} finally{
221270
byteBuf.release();
222271
}
272+
}
223273
}
224274

225275
@DisplayName("from throws NullPointerException with null frame")

rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceRSocketClientTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class LoadbalanceRSocketClientTest {
3333
public static final Duration LONG_DURATION = Duration.ofMillis(75);
3434

3535
private static final Publisher<Payload> SOURCE =
36-
Flux.interval(SHORT_DURATION).map(String::valueOf).map(DefaultPayload::create);
36+
Flux.interval(SHORT_DURATION)
37+
.onBackpressureBuffer()
38+
.map(String::valueOf)
39+
.map(DefaultPayload::create);
3740

3841
private static final Mono<RSocket> PROGRESSING_HANDLER =
3942
Mono.just(

rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ public Mono<Void> fireAndForget(Payload payload) {
7171
return Mono.empty();
7272
}
7373
};
74-
final RSocketConnector rSocketConnectorMock =
75-
RSocketConnector.create()
76-
.interceptors(
77-
ir -> ir.forRequester((RSocketInterceptor) socket -> new TestRSocket(rSocket)));
74+
75+
final RSocketConnector rSocketConnectorMock = Mockito.mock(RSocketConnector.class);
76+
final ClientTransport mockTransport1 = Mockito.mock(ClientTransport.class);
77+
Mockito.when(rSocketConnectorMock.connect(mockTransport1))
78+
.then(im -> Mono.just(new TestRSocket(rSocket)));
7879

7980
final List<LoadbalanceTarget> collectionOfDestination1 =
8081
Collections.singletonList(LoadbalanceTarget.from("1", mockTransport));

0 commit comments

Comments
 (0)