Upgrade to RSocket 1.0 RC7 snapshots

This commit is contained in:
Rossen Stoyanchev
2020-04-20 09:42:14 +01:00
parent 376434eb75
commit ed8c61a852
12 changed files with 335 additions and 130 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,8 @@ import io.netty.buffer.ByteBufAllocator;
import io.rsocket.ConnectionSetupPayload;
import io.rsocket.DuplexConnection;
import io.rsocket.RSocketFactory;
import io.rsocket.core.DefaultConnectionSetupPayload;
import io.rsocket.core.RSocketConnector;
import io.rsocket.frame.decoder.PayloadDecoder;
import io.rsocket.metadata.WellKnownMimeType;
import io.rsocket.transport.ClientTransport;
@@ -68,7 +70,7 @@ public class DefaultRSocketRequesterBuilderTests {
private final MockConnection connection = new MockConnection();
private final TestRSocketFactoryConfigurer rsocketFactoryConfigurer = new TestRSocketFactoryConfigurer();
private final TestRSocketConnectorConfigurer connectorConfigurer = new TestRSocketConnectorConfigurer();
@BeforeEach
@@ -80,32 +82,35 @@ public class DefaultRSocketRequesterBuilderTests {
@Test
@SuppressWarnings("unchecked")
public void rsocketFactoryConfigurerAppliesAtSubscription() {
public void rsocketConnectorConfigurerAppliesAtSubscription() {
Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(Consumer.class);
RSocketRequester.builder()
.rsocketFactory(this.rsocketFactoryConfigurer)
.rsocketConnector(this.connectorConfigurer)
.rsocketStrategies(strategiesConfigurer)
.connect(this.transport);
verifyNoInteractions(this.transport);
assertThat(this.rsocketFactoryConfigurer.rsocketFactory()).isNull();
assertThat(this.connectorConfigurer.connector()).isNull();
}
@Test
@SuppressWarnings("unchecked")
public void rsocketFactoryConfigurer() {
Consumer<RSocketStrategies.Builder> rsocketStrategiesConfigurer = mock(Consumer.class);
@SuppressWarnings({"unchecked", "deprecation"})
public void rsocketConnectorConfigurer() {
ClientRSocketFactoryConfigurer factoryConfigurer = mock(ClientRSocketFactoryConfigurer.class);
Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(Consumer.class);
RSocketRequester.builder()
.rsocketFactory(this.rsocketFactoryConfigurer)
.rsocketStrategies(rsocketStrategiesConfigurer)
.rsocketConnector(this.connectorConfigurer)
.rsocketFactory(factoryConfigurer)
.rsocketStrategies(strategiesConfigurer)
.connect(this.transport)
.block();
// RSocketStrategies and RSocketFactory configurers should have been called
// RSocketStrategies and RSocketConnector configurers should have been called
verify(this.transport).connect(anyInt());
verify(rsocketStrategiesConfigurer).accept(any(RSocketStrategies.Builder.class));
assertThat(this.rsocketFactoryConfigurer.rsocketFactory()).isNotNull();
verify(strategiesConfigurer).accept(any(RSocketStrategies.Builder.class));
verify(factoryConfigurer).configure(any(RSocketFactory.ClientRSocketFactory.class));
assertThat(this.connectorConfigurer.connector()).isNotNull();
}
@Test
@@ -143,7 +148,7 @@ public class DefaultRSocketRequesterBuilderTests {
.block();
ConnectionSetupPayload setupPayload = Mono.from(this.connection.sentFrames())
.map(ConnectionSetupPayload::create)
.map(DefaultConnectionSetupPayload::new)
.block();
assertThat(setupPayload.dataMimeType()).isEqualTo("application/json");
@@ -151,22 +156,22 @@ public class DefaultRSocketRequesterBuilderTests {
}
@Test
public void mimeTypesCannotBeChangedAtRSocketFactoryLevel() {
public void mimeTypesCannotBeChangedAtRSocketConnectorLevel() {
MimeType dataMimeType = MimeTypeUtils.APPLICATION_JSON;
MimeType metaMimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
RSocketRequester requester = RSocketRequester.builder()
.metadataMimeType(metaMimeType)
.dataMimeType(dataMimeType)
.rsocketFactory(factory -> {
factory.metadataMimeType("text/plain");
factory.dataMimeType("application/xml");
.rsocketConnector(connector -> {
connector.metadataMimeType("text/plain");
connector.dataMimeType("application/xml");
})
.connect(this.transport)
.block();
ConnectionSetupPayload setupPayload = Mono.from(this.connection.sentFrames())
.map(ConnectionSetupPayload::create)
.map(DefaultConnectionSetupPayload::new)
.block();
assertThat(setupPayload.dataMimeType()).isEqualTo(dataMimeType.toString());
@@ -186,7 +191,7 @@ public class DefaultRSocketRequesterBuilderTests {
.block();
ConnectionSetupPayload setupPayload = Mono.from(this.connection.sentFrames())
.map(ConnectionSetupPayload::create)
.map(DefaultConnectionSetupPayload::new)
.block();
assertThat(setupPayload.getMetadataUtf8()).isEqualTo("toA");
@@ -210,7 +215,7 @@ public class DefaultRSocketRequesterBuilderTests {
.block();
ConnectionSetupPayload payload = Mono.from(this.connection.sentFrames())
.map(ConnectionSetupPayload::create)
.map(DefaultConnectionSetupPayload::new)
.block();
MimeType compositeMimeType =
@@ -228,11 +233,11 @@ public class DefaultRSocketRequesterBuilderTests {
@Test
public void frameDecoderMatchesDataBufferFactory() throws Exception {
testFrameDecoder(new NettyDataBufferFactory(ByteBufAllocator.DEFAULT), PayloadDecoder.ZERO_COPY);
testFrameDecoder(new DefaultDataBufferFactory(), PayloadDecoder.DEFAULT);
testPayloadDecoder(new NettyDataBufferFactory(ByteBufAllocator.DEFAULT), PayloadDecoder.ZERO_COPY);
testPayloadDecoder(new DefaultDataBufferFactory(), PayloadDecoder.DEFAULT);
}
private void testFrameDecoder(DataBufferFactory bufferFactory, PayloadDecoder frameDecoder)
private void testPayloadDecoder(DataBufferFactory bufferFactory, PayloadDecoder payloadDecoder)
throws NoSuchFieldException {
RSocketStrategies strategies = RSocketStrategies.builder()
@@ -241,17 +246,17 @@ public class DefaultRSocketRequesterBuilderTests {
RSocketRequester.builder()
.rsocketStrategies(strategies)
.rsocketFactory(this.rsocketFactoryConfigurer)
.rsocketConnector(this.connectorConfigurer)
.connect(this.transport)
.block();
RSocketFactory.ClientRSocketFactory factory = this.rsocketFactoryConfigurer.rsocketFactory();
assertThat(factory).isNotNull();
RSocketConnector connector = this.connectorConfigurer.connector();
assertThat(connector).isNotNull();
Field field = RSocketFactory.ClientRSocketFactory.class.getDeclaredField("payloadDecoder");
Field field = RSocketConnector.class.getDeclaredField("payloadDecoder");
ReflectionUtils.makeAccessible(field);
PayloadDecoder decoder = (PayloadDecoder) ReflectionUtils.getField(field, factory);
assertThat(decoder).isSameAs(frameDecoder);
PayloadDecoder decoder = (PayloadDecoder) ReflectionUtils.getField(field, connector);
assertThat(decoder).isSameAs(payloadDecoder);
}
@@ -286,19 +291,17 @@ public class DefaultRSocketRequesterBuilderTests {
}
static class TestRSocketFactoryConfigurer implements ClientRSocketFactoryConfigurer {
static class TestRSocketConnectorConfigurer implements RSocketConnectorConfigurer {
private RSocketFactory.ClientRSocketFactory rsocketFactory;
private RSocketConnector connector;
RSocketFactory.ClientRSocketFactory rsocketFactory() {
return this.rsocketFactory;
RSocketConnector connector() {
return this.connector;
}
@Override
public void configure(RSocketFactory.ClientRSocketFactory rsocketFactory) {
this.rsocketFactory = rsocketFactory;
public void configure(RSocketConnector connector) {
this.connector = connector;
}
}
@@ -307,7 +310,6 @@ public class DefaultRSocketRequesterBuilderTests {
private final MimeType mimeType;
TestJsonDecoder(MimeType mimeType) {
this.mimeType = mimeType;
}
@@ -344,5 +346,4 @@ public class DefaultRSocketRequesterBuilderTests {
throw new UnsupportedOperationException();
}
}
}

View File

@@ -25,8 +25,8 @@ import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.ReferenceCounted;
import io.rsocket.AbstractRSocket;
import io.rsocket.RSocket;
import io.rsocket.RSocketFactory;
import io.rsocket.SocketAcceptor;
import io.rsocket.core.RSocketServer;
import io.rsocket.exceptions.ApplicationErrorException;
import io.rsocket.frame.decoder.PayloadDecoder;
import io.rsocket.plugins.RSocketInterceptor;
@@ -80,16 +80,14 @@ class RSocketBufferLeakTests {
RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
SocketAcceptor responder = messageHandler.responder();
server = RSocketFactory.receive()
.frameDecoder(PayloadDecoder.ZERO_COPY)
.addResponderPlugin(payloadInterceptor) // intercept responding
.acceptor(responder)
.transport(TcpServerTransport.create("localhost", 7000))
.start()
server = RSocketServer.create(responder)
.payloadDecoder(PayloadDecoder.ZERO_COPY)
.interceptors(registry -> registry.forResponder(payloadInterceptor)) // intercept responding
.bind(TcpServerTransport.create("localhost", 7000))
.block();
requester = RSocketRequester.builder()
.rsocketFactory(factory -> factory.addRequesterPlugin(payloadInterceptor))
.rsocketConnector(conn -> conn.interceptors(registry -> registry.forRequester(payloadInterceptor)))
.rsocketStrategies(context.getBean(RSocketStrategies.class))
.connectTcp("localhost", 7000)
.block();
@@ -157,6 +155,18 @@ class RSocketBufferLeakTests {
StepVerifier.create(result).expectError(ApplicationErrorException.class).verify(Duration.ofSeconds(5));
}
@Test
public void echoChannel() {
Flux<String> result = requester.route("echo-channel")
.data(Flux.range(1, 10).map(i -> "Hello " + i), String.class)
.retrieveFlux(String.class);
StepVerifier.create(result)
.expectNext("Hello 1 async").expectNextCount(8).expectNext("Hello 10 async")
.thenCancel() // https://github.com/rsocket/rsocket-java/issues/613
.verify(Duration.ofSeconds(5));
}
@Controller
static class ServerController {
@@ -192,6 +202,11 @@ class RSocketBufferLeakTests {
Mono<String> ignoreInput() {
return Mono.delay(Duration.ofMillis(10)).map(l -> "bar");
}
@MessageMapping("echo-channel")
Flux<String> echoChannel(Flux<String> payloads) {
return payloads.delayElements(Duration.ofMillis(10)).map(payload -> payload + " async");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@ package org.springframework.messaging.rsocket;
import java.time.Duration;
import io.rsocket.RSocketFactory;
import io.rsocket.SocketAcceptor;
import io.rsocket.core.RSocketServer;
import io.rsocket.frame.decoder.PayloadDecoder;
import io.rsocket.metadata.WellKnownMimeType;
import io.rsocket.transport.netty.server.CloseableChannel;
@@ -71,12 +71,10 @@ public class RSocketClientToServerIntegrationTests {
RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
SocketAcceptor responder = messageHandler.responder();
server = RSocketFactory.receive()
.addResponderPlugin(interceptor)
.frameDecoder(PayloadDecoder.ZERO_COPY)
.acceptor(responder)
.transport(TcpServerTransport.create("localhost", 7000))
.start()
server = RSocketServer.create(responder)
.interceptors(registry -> registry.forResponder(interceptor))
.payloadDecoder(PayloadDecoder.ZERO_COPY)
.bind(TcpServerTransport.create("localhost", 7000))
.block();
requester = RSocketRequester.builder()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@ package org.springframework.messaging.rsocket;
import java.time.Duration;
import io.rsocket.RSocketFactory;
import io.rsocket.SocketAcceptor;
import io.rsocket.core.RSocketServer;
import io.rsocket.frame.decoder.PayloadDecoder;
import io.rsocket.transport.netty.server.CloseableChannel;
import io.rsocket.transport.netty.server.TcpServerTransport;
@@ -62,11 +62,9 @@ public class RSocketServerToClientIntegrationTests {
RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
SocketAcceptor responder = messageHandler.responder();
server = RSocketFactory.receive()
.frameDecoder(PayloadDecoder.ZERO_COPY)
.acceptor(responder)
.transport(TcpServerTransport.create("localhost", 0))
.start()
server = RSocketServer.create(responder)
.payloadDecoder(PayloadDecoder.ZERO_COPY)
.bind(TcpServerTransport.create("localhost", 0))
.block();
}
@@ -99,23 +97,21 @@ public class RSocketServerToClientIntegrationTests {
private static void connectAndRunTest(String connectionRoute) {
ServerController serverController = context.getBean(ServerController.class);
serverController.reset();
context.getBean(ServerController.class).reset();
RSocketStrategies strategies = context.getBean(RSocketStrategies.class);
ClientRSocketFactoryConfigurer clientResponderConfigurer =
RSocketMessageHandler.clientResponder(strategies, new ClientHandler());
SocketAcceptor responder = RSocketMessageHandler.responder(strategies, new ClientHandler());
RSocketRequester requester = null;
try {
requester = RSocketRequester.builder()
.setupRoute(connectionRoute)
.rsocketStrategies(strategies)
.rsocketFactory(clientResponderConfigurer)
.rsocketConnector(connector -> connector.acceptor(responder))
.connectTcp("localhost", server.address().getPort())
.block();
serverController.await(Duration.ofSeconds(5));
context.getBean(ServerController.class).await(Duration.ofSeconds(5));
}
finally {
if (requester != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.springframework.messaging.rsocket
import io.netty.buffer.PooledByteBufAllocator
import io.rsocket.RSocketFactory
import io.rsocket.core.RSocketServer
import io.rsocket.frame.decoder.PayloadDecoder
import io.rsocket.transport.netty.server.CloseableChannel
import io.rsocket.transport.netty.server.TcpServerTransport
@@ -257,15 +257,13 @@ class RSocketClientToServerCoroutinesIntegrationTests {
fun setupOnce() {
context = AnnotationConfigApplicationContext(ServerConfig::class.java)
server = RSocketFactory.receive()
.frameDecoder(PayloadDecoder.ZERO_COPY)
.acceptor(context.getBean(RSocketMessageHandler::class.java).responder())
.transport(TcpServerTransport.create("localhost", 7000))
.start()
server = RSocketServer.create(context.getBean(RSocketMessageHandler::class.java).responder())
.payloadDecoder(PayloadDecoder.ZERO_COPY)
.bind(TcpServerTransport.create("localhost", 7000))
.block()!!
requester = RSocketRequester.builder()
.rsocketFactory { factory -> factory.frameDecoder(PayloadDecoder.ZERO_COPY) }
.rsocketConnector { connector -> connector.payloadDecoder(PayloadDecoder.ZERO_COPY) }
.rsocketStrategies(context.getBean(RSocketStrategies::class.java))
.connectTcp("localhost", 7000)
.block()!!