Search in sources :

Example 1 with SocketAcceptor

use of io.rsocket.SocketAcceptor in project spring-framework by spring-projects.

the class RSocketServerToClientIntegrationTests method setupOnce.

@BeforeAll
@SuppressWarnings("ConstantConditions")
static void setupOnce() {
    context = new AnnotationConfigApplicationContext(RSocketConfig.class);
    RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
    SocketAcceptor responder = messageHandler.responder();
    server = RSocketServer.create(responder).payloadDecoder(PayloadDecoder.ZERO_COPY).bind(TcpServerTransport.create("localhost", 0)).block();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SocketAcceptor(io.rsocket.SocketAcceptor) RSocketMessageHandler(org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with SocketAcceptor

use of io.rsocket.SocketAcceptor in project spring-framework by spring-projects.

the class RSocketBufferLeakTests method setupOnce.

@BeforeAll
void setupOnce() {
    context = new AnnotationConfigApplicationContext(ServerConfig.class);
    RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
    SocketAcceptor responder = messageHandler.responder();
    server = RSocketServer.create(responder).payloadDecoder(PayloadDecoder.ZERO_COPY).interceptors(// intercept responding
    registry -> registry.forResponder(payloadInterceptor)).bind(TcpServerTransport.create("localhost", 7000)).block();
    requester = RSocketRequester.builder().rsocketConnector(conn -> conn.interceptors(registry -> registry.forRequester(payloadInterceptor))).rsocketStrategies(context.getBean(RSocketStrategies.class)).tcp("localhost", 7000);
}
Also used : Sinks(reactor.core.publisher.Sinks) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) RSocketMessageHandler(org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloseableChannel(io.rsocket.transport.netty.server.CloseableChannel) Controller(org.springframework.stereotype.Controller) Disabled(org.junit.jupiter.api.Disabled) PayloadDecoder(io.rsocket.frame.decoder.PayloadDecoder) RSocketServer(io.rsocket.core.RSocketServer) AfterAll(org.junit.jupiter.api.AfterAll) ApplicationErrorException(io.rsocket.exceptions.ApplicationErrorException) TestInstance(org.junit.jupiter.api.TestInstance) RSocket(io.rsocket.RSocket) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Resource(org.springframework.core.io.Resource) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) SocketAcceptor(io.rsocket.SocketAcceptor) Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) ReferenceCounted(io.netty.util.ReferenceCounted) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping) RSocketInterceptor(io.rsocket.plugins.RSocketInterceptor) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) MessageExceptionHandler(org.springframework.messaging.handler.annotation.MessageExceptionHandler) Payload(org.springframework.messaging.handler.annotation.Payload) TcpServerTransport(io.rsocket.transport.netty.server.TcpServerTransport) Bean(org.springframework.context.annotation.Bean) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SocketAcceptor(io.rsocket.SocketAcceptor) RSocketMessageHandler(org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with SocketAcceptor

use of io.rsocket.SocketAcceptor in project spring-security by spring-projects.

the class PayloadSocketAcceptorInterceptorTests method captureExchange.

private PayloadExchange captureExchange() {
    given(this.socketAcceptor.accept(any(), any())).willReturn(Mono.just(this.rSocket));
    given(this.interceptor.intercept(any(), any())).willReturn(Mono.empty());
    SocketAcceptor wrappedAcceptor = this.acceptorInterceptor.apply(this.socketAcceptor);
    RSocket result = wrappedAcceptor.accept(this.setupPayload, this.rSocket).block();
    assertThat(result).isInstanceOf(PayloadInterceptorRSocket.class);
    given(this.rSocket.fireAndForget(any())).willReturn(Mono.empty());
    result.fireAndForget(this.payload).block();
    ArgumentCaptor<PayloadExchange> exchangeArg = ArgumentCaptor.forClass(PayloadExchange.class);
    verify(this.interceptor, times(2)).intercept(exchangeArg.capture(), any());
    return exchangeArg.getValue();
}
Also used : PayloadExchange(org.springframework.security.rsocket.api.PayloadExchange) SocketAcceptor(io.rsocket.SocketAcceptor) RSocket(io.rsocket.RSocket)

Example 4 with SocketAcceptor

use of io.rsocket.SocketAcceptor in project spring-framework by spring-projects.

the class RSocketClientToServerIntegrationTests method setupOnce.

@BeforeAll
@SuppressWarnings("ConstantConditions")
public static void setupOnce() {
    MimeType metadataMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());
    context = new AnnotationConfigApplicationContext(ServerConfig.class);
    RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
    SocketAcceptor responder = messageHandler.responder();
    server = RSocketServer.create(responder).interceptors(registry -> registry.forResponder(interceptor)).payloadDecoder(PayloadDecoder.ZERO_COPY).bind(TcpServerTransport.create("localhost", 7000)).block();
    requester = RSocketRequester.builder().metadataMimeType(metadataMimeType).rsocketStrategies(context.getBean(RSocketStrategies.class)).tcp("localhost", 7000);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SocketAcceptor(io.rsocket.SocketAcceptor) RSocketMessageHandler(org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with SocketAcceptor

use of io.rsocket.SocketAcceptor in project spring-framework by spring-projects.

the class RSocketServerToClientIntegrationTests method connectAndRunTest.

private static void connectAndRunTest(String connectionRoute) {
    context.getBean(ServerController.class).reset();
    RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
    SocketAcceptor responder = RSocketMessageHandler.responder(strategies, new ClientHandler());
    RSocketRequester requester = null;
    try {
        requester = RSocketRequester.builder().setupRoute(connectionRoute).rsocketStrategies(strategies).rsocketConnector(connector -> connector.acceptor(responder)).tcp("localhost", server.address().getPort());
        // Trigger connection establishment.
        requester.rsocketClient().source().block();
        context.getBean(ServerController.class).await(Duration.ofSeconds(5));
    } finally {
        if (requester != null) {
            requester.rsocketClient().dispose();
        }
    }
}
Also used : SocketAcceptor(io.rsocket.SocketAcceptor)

Aggregations

SocketAcceptor (io.rsocket.SocketAcceptor)5 BeforeAll (org.junit.jupiter.api.BeforeAll)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 RSocketMessageHandler (org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler)3 RSocket (io.rsocket.RSocket)2 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)1 ReferenceCounted (io.netty.util.ReferenceCounted)1 RSocketServer (io.rsocket.core.RSocketServer)1 ApplicationErrorException (io.rsocket.exceptions.ApplicationErrorException)1 PayloadDecoder (io.rsocket.frame.decoder.PayloadDecoder)1 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)1 RSocketInterceptor (io.rsocket.plugins.RSocketInterceptor)1 CloseableChannel (io.rsocket.transport.netty.server.CloseableChannel)1 TcpServerTransport (io.rsocket.transport.netty.server.TcpServerTransport)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterAll (org.junit.jupiter.api.AfterAll)1