[JAVA-27761] Upgraded spring-reactive-2 to spring boot 3 (#15293)

This commit is contained in:
panos-kakos 2023-12-07 13:12:55 +02:00 committed by GitHub
parent 232730dbbb
commit 19184bdf40
10 changed files with 60 additions and 56 deletions

View File

@ -10,9 +10,10 @@
<description>spring sample project about new features</description>
<parent>
<groupId>com.baeldung.spring.reactive</groupId>
<artifactId>spring-reactive-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-3</relativePath>
</parent>
<dependencies>
@ -45,8 +46,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
@ -64,6 +65,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
</dependencies>
<build>
@ -116,7 +122,7 @@
<properties>
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
<wiremock.version>2.24.0</wiremock.version>
<wiremock.version>3.3.1</wiremock.version>
</properties>
</project>

View File

@ -5,10 +5,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
@SpringBootApplication(exclude = { RedisAutoConfiguration.class })
public class Spring5ReactiveApplication{
public class Spring6ReactiveApplication {
public static void main(String[] args) {
SpringApplication.run(Spring5ReactiveApplication.class, args);
SpringApplication.run(Spring6ReactiveApplication.class, args);
}
}

View File

@ -22,9 +22,10 @@ public class ConsumerSSEApplication {
@Bean
public SecurityWebFilterChain sseConsumerSpringSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange()
.anyExchange()
.permitAll();
http.authorizeExchange(auth -> auth
.anyExchange().permitAll()
)
.csrf(ServerHttpSecurity.CsrfSpec::disable);
return http.build();
}

View File

@ -34,7 +34,7 @@ public class FormHandler {
private AtomicLong extractData(List<DataBuffer> dataBuffers) {
AtomicLong atomicLong = new AtomicLong(0);
dataBuffers.forEach(d -> atomicLong.addAndGet(d.asByteBuffer()
dataBuffers.forEach(d -> atomicLong.addAndGet(d.toByteBuffer()
.array().length));
return atomicLong;
}

View File

@ -9,7 +9,7 @@ public class CpuUtils {
private static OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
static Double getUsage() {
return (operatingSystemMXBean.getSystemCpuLoad() / operatingSystemMXBean.getAvailableProcessors()) * 100;
return (operatingSystemMXBean.getCpuLoad() / operatingSystemMXBean.getAvailableProcessors()) * 100;
}
}

View File

@ -23,7 +23,7 @@ public class StaticContentConfig {
GET("/"),
request -> ok()
.contentType(MediaType.TEXT_HTML)
.syncBody(html)
.bodyValue(html)
);
}

View File

@ -15,10 +15,11 @@ public class FunctionalValidationsApplication {
@Bean
public SecurityWebFilterChain functionalValidationsSpringSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange()
.anyExchange()
.permitAll();
http.csrf().disable();
http.authorizeExchange(auth -> auth
.anyExchange().permitAll()
)
.csrf(ServerHttpSecurity.CsrfSpec::disable);
return http.build();
}
}

View File

@ -1,7 +1,7 @@
package com.baeldung.validations.functional.model;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -24,49 +24,45 @@ public class BackpressureUnitTest {
);
StepVerifier.create(limit)
.expectSubscription()
.thenRequest(15)
.expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.expectNext(11, 12, 13, 14, 15)
.thenRequest(10)
.expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
.verifyComplete();
.expectSubscription()
.thenRequest(15)
.expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.expectNext(11, 12, 13, 14, 15)
.thenRequest(10)
.expectNext(16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
.verifyComplete();
}
@Test
public void whenRequestingChunks10_thenMessagesAreReceived() {
Flux<Integer> request = Flux.range(1, 50);
request.subscribe(
integer -> LOGGER.debug(String.valueOf(integer)),
err -> err.printStackTrace(),
() -> LOGGER.debug("All 50 items have been successfully processed!!!"),
subscription -> {
for (int i = 0; i < 5; i++) {
LOGGER.debug("Requesting the next 10 elements!!!");
subscription.request(10);
}
}
);
request.subscribe(integer -> LOGGER.debug(String.valueOf(integer)), err -> err.printStackTrace(), () -> LOGGER.debug("All 50 items have been successfully processed!!!"), subscription -> {
for (int i = 0; i < 5; i++) {
LOGGER.debug("Requesting the next 10 elements!!!");
subscription.request(10);
}
});
StepVerifier.create(request)
.expectSubscription()
.thenRequest(10)
.expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.thenRequest(10)
.expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
.thenRequest(10)
.expectNext(21, 22, 23, 24, 25, 26, 27 , 28, 29 ,30)
.thenRequest(10)
.expectNext(31, 32, 33, 34, 35, 36, 37 , 38, 39 ,40)
.thenRequest(10)
.expectNext(41, 42, 43, 44, 45, 46, 47 , 48, 49 ,50)
.verifyComplete();
.expectSubscription()
.thenRequest(10)
.expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.thenRequest(10)
.expectNext(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
.thenRequest(10)
.expectNext(21, 22, 23, 24, 25, 26, 27, 28, 29, 30)
.thenRequest(10)
.expectNext(31, 32, 33, 34, 35, 36, 37, 38, 39, 40)
.thenRequest(10)
.expectNext(41, 42, 43, 44, 45, 46, 47, 48, 49, 50)
.verifyComplete();
}
@Test
public void whenCancel_thenSubscriptionFinished() {
Flux<Integer> cancel = Flux.range(1, 10).log();
Flux<Integer> cancel = Flux.range(1, 10)
.log();
cancel.subscribe(new BaseSubscriber<Integer>() {
@Override
@ -78,9 +74,9 @@ public class BackpressureUnitTest {
});
StepVerifier.create(cancel)
.expectNext(1, 2, 3)
.thenCancel()
.verify();
.expectNext(1, 2, 3)
.thenCancel()
.verify();
}
}

View File

@ -8,11 +8,11 @@ import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import com.baeldung.reactive.Spring5ReactiveApplication;
import com.baeldung.reactive.Spring6ReactiveApplication;
import com.baeldung.reactive.controller.PathPatternController;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5ReactiveApplication.class)
@SpringBootTest(classes = Spring6ReactiveApplication.class)
@WithMockUser
public class PathPatternsUsingHandlerMethodIntegrationTest {