private void handleStreamZero(FrameType type, Frame frame) { switch (type) { case ERROR: RuntimeException error = Exceptions.from(frame); lifecycle.setTerminationError(error); errorConsumer.accept(error); connection.dispose(); break; case LEASE: break; case KEEPALIVE: if (keepAliveHandler != null) { keepAliveHandler.receive(frame); } break; default: // Ignore unknown frames. Throwing an error will close the socket. errorConsumer.accept( new IllegalStateException( "Client received supported frame on stream 0: " + frame.toString())); } }
switch (type) { case ERROR: receiver.onError(Exceptions.from(frame)); receivers.remove(streamId); break;
@DisplayName("from returns IllegalArgumentException if error frame has illegal error code") @Test void fromIllegalErrorFrame() { ByteBuf byteBuf = createErrorFrame(0x00000000, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(IllegalArgumentException.class) .withFailMessage("Invalid Error frame: %d, '%s'", 0, "test-message"); }
@DisplayName("from returns UnsupportedSetupException") @Test void fromUnsupportedSetupException() { ByteBuf byteBuf = createErrorFrame(UNSUPPORTED_SETUP, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(UnsupportedSetupException.class) .withFailMessage("test-message"); }
@DisplayName("from returns ConnectionCloseException") @Test void fromConnectionCloseException() { ByteBuf byteBuf = createErrorFrame(CONNECTION_CLOSE, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(ConnectionCloseException.class) .withFailMessage("test-message"); }
@DisplayName("from returns RejectedException") @Test void fromRejectedException() { ByteBuf byteBuf = createErrorFrame(REJECTED, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(RejectedException.class) .withFailMessage("test-message"); }
@DisplayName("from returns CanceledException") @Test void fromCanceledException() { ByteBuf byteBuf = createErrorFrame(CANCELED, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(CanceledException.class) .withFailMessage("test-message"); }
@DisplayName("from returns InvalidException") @Test void fromInvalidException() { ByteBuf byteBuf = createErrorFrame(INVALID, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(InvalidException.class) .withFailMessage("test-message"); }
@DisplayName("from returns ApplicationErrorException") @Test void fromApplicationException() { ByteBuf byteBuf = createErrorFrame(APPLICATION_ERROR, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(ApplicationErrorException.class) .withFailMessage("test-message"); }
@DisplayName("from returns ConnectionErrorException") @Test void fromConnectionErrorException() { ByteBuf byteBuf = createErrorFrame(CONNECTION_ERROR, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(ConnectionErrorException.class) .withFailMessage("test-message"); }
@DisplayName("from returns InvalidSetupException") @Test void fromInvalidSetupException() { ByteBuf byteBuf = createErrorFrame(INVALID_SETUP, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(InvalidSetupException.class) .withFailMessage("test-message"); }
@DisplayName("from returns RejectedResumeException") @Test void fromRejectedResumeException() { ByteBuf byteBuf = createErrorFrame(REJECTED_RESUME, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(RejectedResumeException.class) .withFailMessage("test-message"); }
@DisplayName("from returns RejectedSetupException") @Test void fromRejectedSetupException() { ByteBuf byteBuf = createErrorFrame(REJECTED_SETUP, "test-message"); assertThat(Exceptions.from(Frame.from(byteBuf))) .isInstanceOf(RejectedSetupException.class) .withFailMessage("test-message"); }
@Test void responderRejectSetup() { SingleConnectionTransport transport = new SingleConnectionTransport(); String errorMsg = "error"; RejectingAcceptor acceptor = new RejectingAcceptor(errorMsg); RSocketFactory.receive().acceptor(acceptor).transport(transport).start().block(); transport.connect(); Frame sentFrame = transport.awaitSent(); assertThat(sentFrame.getType()).isEqualTo(FrameType.ERROR); RuntimeException error = Exceptions.from(sentFrame); assertThat(errorMsg).isEqualTo(error.getMessage()); assertThat(error).isInstanceOf(RejectedSetupException.class); RSocket acceptorSender = acceptor.senderRSocket().block(); assertThat(acceptorSender.isDisposed()).isTrue(); }
@DisplayName("from throws NullPointerException with null frame") @Test void fromWithNullFrame() { assertThatNullPointerException() .isThrownBy(() -> Exceptions.from(null)) .withMessage("frame must not be null"); }
private void handleStreamZero(FrameType type, Frame frame) { switch (type) { case ERROR: RuntimeException error = Exceptions.from(frame); lifecycle.setTerminationError(error); errorConsumer.accept(error); connection.dispose(); break; case LEASE: break; case KEEPALIVE: if (keepAliveHandler != null) { keepAliveHandler.receive(frame); } break; default: // Ignore unknown frames. Throwing an error will close the socket. errorConsumer.accept( new IllegalStateException( "Client received supported frame on stream 0: " + frame.toString())); } }
switch (type) { case ERROR: receiver.onError(Exceptions.from(frame)); receivers.remove(streamId); break;