From 424aedca722ad6274fcb63efcf81496961e4868f Mon Sep 17 00:00:00 2001 From: Oleh Dokuka Date: Tue, 18 Apr 2023 11:34:33 +0300 Subject: [PATCH] fixes Signed-off-by: Oleh Dokuka --- .../io/rsocket/exceptions/ExceptionsTest.java | 66 ++++++++++++++++--- .../LoadbalanceRSocketClientTest.java | 5 +- .../rsocket/loadbalance/LoadbalanceTest.java | 9 +-- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/rsocket-core/src/test/java/io/rsocket/exceptions/ExceptionsTest.java b/rsocket-core/src/test/java/io/rsocket/exceptions/ExceptionsTest.java index ff7e4ff17..04d415e1b 100644 --- a/rsocket-core/src/test/java/io/rsocket/exceptions/ExceptionsTest.java +++ b/rsocket-core/src/test/java/io/rsocket/exceptions/ExceptionsTest.java @@ -31,7 +31,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; -import io.rsocket.RaceTestConstants; +import io.rsocket.FrameAssert;import io.rsocket.RaceTestConstants; import io.rsocket.frame.ErrorFrameCodec; import java.util.concurrent.ThreadLocalRandom; import org.junit.jupiter.api.DisplayName; @@ -43,6 +43,7 @@ final class ExceptionsTest { void fromApplicationException() { ByteBuf byteBuf = createErrorFrame(1, APPLICATION_ERROR, "test-message"); + try{ assertThat(Exceptions.from(1, byteBuf)) .isInstanceOf(ApplicationErrorException.class) .hasMessage("test-message"); @@ -51,6 +52,9 @@ void fromApplicationException() { .isInstanceOf(IllegalArgumentException.class) .hasMessage( "Invalid Error frame in Stream ID 0: 0x%08X '%s'", APPLICATION_ERROR, "test-message"); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns CanceledException") @@ -58,6 +62,10 @@ void fromApplicationException() { void fromCanceledException() { ByteBuf byteBuf = createErrorFrame(1, CANCELED, "test-message"); + try{ + + + assertThat(Exceptions.from(1, byteBuf)) .isInstanceOf(CanceledException.class) .hasMessage("test-message"); @@ -65,12 +73,16 @@ void fromCanceledException() { assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", CANCELED, "test-message"); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns ConnectionCloseException") @Test void fromConnectionCloseException() { ByteBuf byteBuf = createErrorFrame(0, CONNECTION_CLOSE, "test-message"); + try{ assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(ConnectionCloseException.class) @@ -80,6 +92,9 @@ void fromConnectionCloseException() { .isInstanceOf(IllegalArgumentException.class) .hasMessage( "Invalid Error frame in Stream ID 1: 0x%08X '%s'", CONNECTION_CLOSE, "test-message"); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns ConnectionErrorException") @@ -87,6 +102,9 @@ void fromConnectionCloseException() { void fromConnectionErrorException() { ByteBuf byteBuf = createErrorFrame(0, CONNECTION_ERROR, "test-message"); + try{ + + assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(ConnectionErrorException.class) .hasMessage("test-message"); @@ -95,12 +113,18 @@ void fromConnectionErrorException() { .isInstanceOf(IllegalArgumentException.class) .hasMessage( "Invalid Error frame in Stream ID 1: 0x%08X '%s'", CONNECTION_ERROR, "test-message"); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns IllegalArgumentException if error frame has illegal error code") @Test void fromIllegalErrorFrame() { ByteBuf byteBuf = createErrorFrame(0, 0x00000000, "test-message"); + try{ + + assertThat(Exceptions.from(0, byteBuf)) .hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", 0, "test-message") @@ -109,27 +133,33 @@ void fromIllegalErrorFrame() { assertThat(Exceptions.from(1, byteBuf)) .hasMessage("Invalid Error frame in Stream ID 1: 0x%08X '%s'", 0x00000000, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns InvalidException") @Test void fromInvalidException() { ByteBuf byteBuf = createErrorFrame(1, INVALID, "test-message"); - - assertThat(Exceptions.from(1, byteBuf)) - .isInstanceOf(InvalidException.class) - .hasMessage("test-message"); +try{ + assertThat(Exceptions.from(1, byteBuf)) + .isInstanceOf(InvalidException.class) + .hasMessage("test-message"); assertThat(Exceptions.from(0, byteBuf)) .hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", INVALID, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns InvalidSetupException") @Test void fromInvalidSetupException() { ByteBuf byteBuf = createErrorFrame(0, INVALID_SETUP, "test-message"); - + try { assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(InvalidSetupException.class) .hasMessage("test-message"); @@ -138,12 +168,16 @@ void fromInvalidSetupException() { .hasMessage( "Invalid Error frame in Stream ID 1: 0x%08X '%s'", INVALID_SETUP, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns RejectedException") @Test void fromRejectedException() { ByteBuf byteBuf = createErrorFrame(1, REJECTED, "test-message"); + try { assertThat(Exceptions.from(1, byteBuf)) .isInstanceOf(RejectedException.class) @@ -152,12 +186,16 @@ void fromRejectedException() { assertThat(Exceptions.from(0, byteBuf)) .hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", REJECTED, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns RejectedResumeException") @Test void fromRejectedResumeException() { ByteBuf byteBuf = createErrorFrame(0, REJECTED_RESUME, "test-message"); + try { assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(RejectedResumeException.class) @@ -167,12 +205,16 @@ void fromRejectedResumeException() { .hasMessage( "Invalid Error frame in Stream ID 1: 0x%08X '%s'", REJECTED_RESUME, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns RejectedSetupException") @Test void fromRejectedSetupException() { ByteBuf byteBuf = createErrorFrame(0, REJECTED_SETUP, "test-message"); + try { assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(RejectedSetupException.class) @@ -182,13 +224,16 @@ void fromRejectedSetupException() { .hasMessage( "Invalid Error frame in Stream ID 1: 0x%08X '%s'", REJECTED_SETUP, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns UnsupportedSetupException") @Test void fromUnsupportedSetupException() { ByteBuf byteBuf = createErrorFrame(0, UNSUPPORTED_SETUP, "test-message"); - + try { assertThat(Exceptions.from(0, byteBuf)) .isInstanceOf(UnsupportedSetupException.class) .hasMessage("test-message"); @@ -197,6 +242,9 @@ void fromUnsupportedSetupException() { .hasMessage( "Invalid Error frame in Stream ID 1: 0x%08X '%s'", UNSUPPORTED_SETUP, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ + byteBuf.release(); + } } @DisplayName("from returns CustomRSocketException") @@ -210,7 +258,7 @@ void fromCustomRSocketException() { : ThreadLocalRandom.current() .nextInt(ErrorFrameCodec.MIN_USER_ALLOWED_ERROR_CODE, Integer.MAX_VALUE); ByteBuf byteBuf = createErrorFrame(0, randomCode, "test-message"); - + try { assertThat(Exceptions.from(1, byteBuf)) .isInstanceOf(CustomRSocketException.class) .hasMessage("test-message"); @@ -218,8 +266,10 @@ void fromCustomRSocketException() { assertThat(Exceptions.from(0, byteBuf)) .hasMessage("Invalid Error frame in Stream ID 0: 0x%08X '%s'", randomCode, "test-message") .isInstanceOf(IllegalArgumentException.class); + } finally{ byteBuf.release(); } + } } @DisplayName("from throws NullPointerException with null frame") diff --git a/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceRSocketClientTest.java b/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceRSocketClientTest.java index c838d704c..a35e89391 100644 --- a/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceRSocketClientTest.java +++ b/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceRSocketClientTest.java @@ -33,7 +33,10 @@ class LoadbalanceRSocketClientTest { public static final Duration LONG_DURATION = Duration.ofMillis(75); private static final Publisher SOURCE = - Flux.interval(SHORT_DURATION).map(String::valueOf).map(DefaultPayload::create); + Flux.interval(SHORT_DURATION) + .onBackpressureBuffer() + .map(String::valueOf) + .map(DefaultPayload::create); private static final Mono PROGRESSING_HANDLER = Mono.just( diff --git a/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceTest.java b/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceTest.java index fcd3ae4a9..9a9a34fda 100644 --- a/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceTest.java +++ b/rsocket-core/src/test/java/io/rsocket/loadbalance/LoadbalanceTest.java @@ -71,10 +71,11 @@ public Mono fireAndForget(Payload payload) { return Mono.empty(); } }; - final RSocketConnector rSocketConnectorMock = - RSocketConnector.create() - .interceptors( - ir -> ir.forRequester((RSocketInterceptor) socket -> new TestRSocket(rSocket))); + + final RSocketConnector rSocketConnectorMock = Mockito.mock(RSocketConnector.class); + final ClientTransport mockTransport1 = Mockito.mock(ClientTransport.class); + Mockito.when(rSocketConnectorMock.connect(mockTransport1)) + .then(im -> Mono.just(new TestRSocket(rSocket))); final List collectionOfDestination1 = Collections.singletonList(LoadbalanceTarget.from("1", mockTransport));