@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2021 the original author or authors.
|
||||
* Copyright 2021-2022 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.
|
||||
@@ -38,24 +38,25 @@ import org.springframework.util.MimeTypeUtils;
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
public class MessageRoutingCallbackRSocketTests {
|
||||
|
||||
@Test
|
||||
public void testRoutingWithRoutingCallback() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(RoutingCallbackFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.expected-content-type=text/plain",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
int port = applicationContext.getEnvironment().getProperty("local.rsocket.server.port", Integer.class);
|
||||
|
||||
// imperative
|
||||
rsocketRequesterBuilder.tcp("localhost", port)
|
||||
.route("foo")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2021 the original author or authors.
|
||||
* Copyright 2021-2022 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.
|
||||
@@ -41,20 +41,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
* @author Chris Bono
|
||||
*/
|
||||
public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoToStringViaMessage() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -76,14 +77,15 @@ public class MessagingTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testPojoToStringViaMessageMap() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -107,14 +109,15 @@ public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoToStringViaMessageExpectMessage() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -136,14 +139,15 @@ public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoMessageToPojoViaMessage() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -167,14 +171,15 @@ public class MessagingTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testPojoMessageToPojoViaMap() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -200,14 +205,15 @@ public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoMessageToPojoViaMessageExpectMessage() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -229,14 +235,15 @@ public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoMessageToPojoViaMessageExpectMessageRawPayload() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -258,14 +265,15 @@ public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoMessageToPojoViaMessageExpectMessageStringPayload() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -287,14 +295,15 @@ public class MessagingTests {
|
||||
|
||||
@Test
|
||||
public void testPojoToMessageMap() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(MessagingConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
Person p = new Person();
|
||||
@@ -311,7 +320,9 @@ public class MessagingTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getLocalRsocketPort(ConfigurableApplicationContext context) {
|
||||
return context.getEnvironment().getProperty("local.rsocket.server.port", Integer.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2021 the original author or authors.
|
||||
* Copyright 2021-2022 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.
|
||||
@@ -44,12 +44,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Chris Bono
|
||||
* @since 3.1
|
||||
*/
|
||||
public class RSocketAutoConfigurationRoutingTests {
|
||||
@Test
|
||||
public void testRoutingWithRoute() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
@@ -57,8 +57,10 @@ public class RSocketAutoConfigurationRoutingTests {
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.routing-expression=headers.func_name",
|
||||
"--spring.cloud.function.expected-content-type=text/plain",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = applicationContext.getEnvironment().getProperty("local.rsocket.server.port", Integer.class);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -97,7 +99,6 @@ public class RSocketAutoConfigurationRoutingTests {
|
||||
|
||||
@Test
|
||||
public void testRoutingWithDefinition() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
@@ -106,8 +107,10 @@ public class RSocketAutoConfigurationRoutingTests {
|
||||
"--spring.cloud.function.definition=uppercase",
|
||||
"--spring.cloud.function.routing-expression=headers.func_name",
|
||||
"--spring.cloud.function.expected-content-type=text/plain",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = applicationContext.getEnvironment().getProperty("local.rsocket.server.port", Integer.class);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -146,7 +149,6 @@ public class RSocketAutoConfigurationRoutingTests {
|
||||
|
||||
@Test
|
||||
public void testRoutingWithDefinitionMessageFunction() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
@@ -155,8 +157,9 @@ public class RSocketAutoConfigurationRoutingTests {
|
||||
"--spring.cloud.function.definition=uppercase",
|
||||
"--spring.cloud.function.routing-expression=headers.func_name",
|
||||
"--spring.cloud.function.expected-content-type=text/plain",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = applicationContext.getEnvironment().getProperty("local.rsocket.server.port", Integer.class);
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
* Copyright 2020-2022 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.
|
||||
@@ -48,20 +48,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Chris Bono
|
||||
* @since 3.1
|
||||
*/
|
||||
public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testNonExistingFunctionInRoute() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -77,14 +79,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testNonExistingFunctionInRouteSingleFunctionInCatalog() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SingleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -103,15 +106,16 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testImperativeFunctionAsRequestReplyWithDefinition() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.definition=uppercase",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -129,15 +133,16 @@ public class RSocketAutoConfigurationTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testWithCborContentType() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.definition=uppercase",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -158,7 +163,6 @@ public class RSocketAutoConfigurationTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void testImperativeFunctionAsRequestReplyWithDefinitionExplicitExpectedOutputCt() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
@@ -166,8 +170,10 @@ public class RSocketAutoConfigurationTests {
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.definition=uppercase",
|
||||
"--spring.cloud.function.expected-content-type=application/json",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -184,14 +190,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testImperativeFunctionAsRequestReply() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -208,15 +215,16 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testWithRouteAndDefinition() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.definition=echo",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -233,14 +241,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testImperativeFunctionAsRequestReplyWithComposition() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -257,14 +266,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testSupplierAsRequestReply() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -281,14 +291,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testImperativeFunctionAsRequestStream() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -305,14 +316,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testImperativeFunctionAsRequestChannel() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -330,14 +342,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testReactiveFunctionAsRequestReply() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -354,14 +367,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testReactiveFunctionAsRequestStream() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -394,14 +408,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testReactiveFunctionAsRequestChannel() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -418,16 +433,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRequestReplyFunctionWithDistributedComposition() {
|
||||
int portA = SocketUtils.findAvailableTcpPort();
|
||||
int portB = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.definition=uppercase|concat",
|
||||
"--spring.rsocket.server.port=" + portA);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int portA = getLocalRsocketPort(applicationContext);
|
||||
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext2 =
|
||||
@@ -435,9 +449,11 @@ public class RSocketAutoConfigurationTests {
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.definition=reverse>localhost:" + portA + "|wrap",
|
||||
"--spring.rsocket.server.port=" + portB);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
|
||||
int portB = getLocalRsocketPort(applicationContext2);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext2.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -497,17 +513,17 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testFireAndForgetConsumer() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
|
||||
SampleFunctionConfiguration config = applicationContext.getBean(SampleFunctionConfiguration.class);
|
||||
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
@@ -560,15 +576,16 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRoutingWithRoutingFunction() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.routing-expression=headers.function_definition",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -586,14 +603,15 @@ public class RSocketAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testByteArrayInOut() {
|
||||
int port = SocketUtils.findAvailableTcpPort();
|
||||
try (
|
||||
ConfigurableApplicationContext applicationContext =
|
||||
new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.rsocket.server.port=" + port);
|
||||
"--spring.rsocket.server.port=0");
|
||||
) {
|
||||
int port = getLocalRsocketPort(applicationContext);
|
||||
|
||||
RSocketRequester.Builder rsocketRequesterBuilder =
|
||||
applicationContext.getBean(RSocketRequester.Builder.class);
|
||||
|
||||
@@ -615,6 +633,10 @@ public class RSocketAutoConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
private int getLocalRsocketPort(ConfigurableApplicationContext context) {
|
||||
return context.getEnvironment().getProperty("local.rsocket.server.port", Integer.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
public static class SampleFunctionConfiguration {
|
||||
|
||||
@@ -29,7 +29,6 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.utils.SocketUtils;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -95,14 +94,14 @@ public class RoutingBrokerTests {
|
||||
}
|
||||
|
||||
private void setup(boolean routingWithProperty) {
|
||||
int brokerProxyPort = SocketUtils.findAvailableTcpPort();
|
||||
int brokerClusterPort = SocketUtils.findAvailableTcpPort();
|
||||
int brokerProxyPort = TestSocketUtils.findAvailableTcpPort();
|
||||
int brokerClusterPort = TestSocketUtils.findAvailableTcpPort();
|
||||
// start broker
|
||||
brokerContext = new SpringApplicationBuilder(SimpleConfiguration.class).web(WebApplicationType.NONE).run(
|
||||
"--logging.level.io.rsocket.broker=TRACE",
|
||||
"--spring.cloud.function.rsocket.enabled=false",
|
||||
"--io.rsocket.broker.client.enabled=false",
|
||||
"--io.rsocket.broker.enabled=true",
|
||||
"--io.rsocket.broker.enaFunctionEndpointInitializerbled=true",
|
||||
"--io.rsocket.broker.uri=tcp://localhost:" + brokerProxyPort,
|
||||
"--io.rsocket.broker.cluster.uri=tcp://localhost:" + brokerClusterPort);
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2022-2022 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.rsocket;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
|
||||
/**
|
||||
* Simple test utility to find a random available TCP port.
|
||||
* <p>Inspired by the now removed {@code org.springframework.util.SocketUtils} and is only used in a testing capacity.
|
||||
*
|
||||
* @author Chris Bono
|
||||
* @deprecated will soon be removed or consolidated - do not use further
|
||||
*/
|
||||
@Deprecated
|
||||
public final class TestSocketUtils {
|
||||
|
||||
private static final Random random = new Random(System.nanoTime());
|
||||
|
||||
private TestSocketUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an available TCP port randomly selected from the range {@code 1024-65535}.
|
||||
* @return an available TCP port number
|
||||
* @throws IllegalStateException if no available port could be found
|
||||
*/
|
||||
public static int findAvailableTcpPort() {
|
||||
int minPort = 1024;
|
||||
int maxPort = 65535;
|
||||
int portRange = maxPort - minPort;
|
||||
int candidatePort;
|
||||
int searchCounter = 0;
|
||||
do {
|
||||
if (searchCounter > portRange) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Could not find an available TCP port after %d attempts", searchCounter));
|
||||
}
|
||||
candidatePort = minPort + random.nextInt(portRange + 1);
|
||||
searchCounter++;
|
||||
}
|
||||
while (!isPortAvailable(candidatePort));
|
||||
|
||||
return candidatePort;
|
||||
}
|
||||
|
||||
private static boolean isPortAvailable(int port) {
|
||||
try {
|
||||
ServerSocket serverSocket = ServerSocketFactory.getDefault().createServerSocket(
|
||||
port, 1, InetAddress.getByName("localhost"));
|
||||
serverSocket.close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user