Skip to content

Commit 09dec2e

Browse files
committed
Handle new Reactor Emission FAIL_NON_SERIALIZED
* Rework WebFlux test to JUnit 5
1 parent 481d5eb commit 09dec2e

File tree

8 files changed

+30
-34
lines changed

8 files changed

+30
-34
lines changed

spring-integration-core/src/main/java/org/springframework/integration/channel/FluxMessageChannel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ protected boolean doSend(Message<?> message, long timeout) {
8383

8484
private boolean tryEmitMessage(Message<?> message) {
8585
switch (this.sink.tryEmitNext(message)) {
86+
case OK:
87+
return true;
88+
case FAIL_NON_SERIALIZED:
8689
case FAIL_OVERFLOW:
8790
return false;
8891
case FAIL_TERMINATED:
8992
case FAIL_CANCELLED:
9093
throw new IllegalStateException("Cannot emit messages into the cancelled or terminated sink: "
9194
+ this.sink);
9295
default:
93-
return true;
96+
throw new UnsupportedOperationException();
9497
}
9598
}
9699

spring-integration-core/src/main/java/org/springframework/integration/util/IntegrationReactiveUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ else if (messageChannel instanceof PollableChannel) {
124124
}
125125
}
126126

127+
@SuppressWarnings("unchecked")
127128
private static <T> Flux<Message<T>> adaptSubscribableChannelToPublisher(SubscribableChannel inputChannel) {
128129
return Flux.defer(() -> {
129130
Sinks.Many<Message<T>> sink = Sinks.many().unicast().onBackpressureError();
130131
MessageHandler messageHandler = (message) -> {
131132
while (true) {
132-
@SuppressWarnings("unchecked")
133-
Sinks.Emission emission = sink.tryEmitNext((Message<T>) message);
134-
switch (emission) {
133+
switch (sink.tryEmitNext((Message<T>) message)) {
134+
case FAIL_NON_SERIALIZED:
135135
case FAIL_OVERFLOW:
136136
LockSupport.parkNanos(1000); // NOSONAR
137137
break;

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxInboundChannelAdapterParserTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2019 the original author or authors.
2+
* Copyright 2018-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@
2020

2121
import java.util.Map;
2222

23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
2524

2625
import org.springframework.beans.DirectFieldAccessor;
2726
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +35,7 @@
3635
import org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint;
3736
import org.springframework.messaging.MessageChannel;
3837
import org.springframework.test.annotation.DirtiesContext;
39-
import org.springframework.test.context.junit4.SpringRunner;
38+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4039
import org.springframework.validation.Validator;
4140
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
4241

@@ -45,7 +44,7 @@
4544
*
4645
* @since 5.0.1
4746
*/
48-
@RunWith(SpringRunner.class)
47+
@SpringJUnitConfig
4948
@DirtiesContext
5049
public class WebFluxInboundChannelAdapterParserTests {
5150

@@ -120,7 +119,7 @@ public void reactiveFullConfig() {
120119

121120
CrossOrigin crossOrigin = (CrossOrigin) endpointAccessor.getPropertyValue("crossOrigin");
122121
assertThat(crossOrigin).isNotNull();
123-
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[] { "foo" });
122+
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[]{ "foo" });
124123

125124
assertThat(endpointAccessor.getPropertyValue("requestPayloadType"))
126125
.isEqualTo(ResolvableType.forClass(byte[].class));

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxInboundGatewayParserTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2019 the original author or authors.
2+
* Copyright 2018-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@
2020

2121
import java.util.Map;
2222

23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
23+
import org.junit.jupiter.api.Test;
2524

2625
import org.springframework.beans.DirectFieldAccessor;
2726
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,15 +35,15 @@
3635
import org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint;
3736
import org.springframework.messaging.MessageChannel;
3837
import org.springframework.test.annotation.DirtiesContext;
39-
import org.springframework.test.context.junit4.SpringRunner;
38+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4039
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
4140

4241
/**
4342
* @author Artem Bilan
4443
*
4544
* @since 5.0.1
4645
*/
47-
@RunWith(SpringRunner.class)
46+
@SpringJUnitConfig
4847
@DirtiesContext
4948
public class WebFluxInboundGatewayParserTests {
5049

@@ -115,7 +114,7 @@ public void reactiveFullConfig() {
115114

116115
CrossOrigin crossOrigin = (CrossOrigin) endpointAccessor.getPropertyValue("crossOrigin");
117116
assertThat(crossOrigin).isNotNull();
118-
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[] { "foo" });
117+
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[]{ "foo" });
119118

120119
assertThat(endpointAccessor.getPropertyValue("requestPayloadType"))
121120
.isEqualTo(ResolvableType.forClass(byte[].class));

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
import java.nio.charset.StandardCharsets;
2323
import java.util.Map;
2424

25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.Test;
2726

2827
import org.springframework.beans.DirectFieldAccessor;
2928
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,7 +34,7 @@
3534
import org.springframework.integration.test.util.TestUtils;
3635
import org.springframework.messaging.MessageChannel;
3736
import org.springframework.test.annotation.DirtiesContext;
38-
import org.springframework.test.context.junit4.SpringRunner;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3938
import org.springframework.util.ObjectUtils;
4039
import org.springframework.web.reactive.function.BodyExtractor;
4140
import org.springframework.web.reactive.function.client.WebClient;
@@ -45,7 +44,7 @@
4544
*
4645
* @since 5.0
4746
*/
48-
@RunWith(SpringRunner.class)
47+
@SpringJUnitConfig
4948
@DirtiesContext
5049
public class WebFluxOutboundGatewayParserTests {
5150

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpointTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@
1818

1919
import java.util.Objects;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
2524
import org.springframework.context.ApplicationContext;
@@ -35,7 +34,7 @@
3534
import org.springframework.integration.http.inbound.RequestMapping;
3635
import org.springframework.messaging.MessageChannel;
3736
import org.springframework.test.annotation.DirtiesContext;
38-
import org.springframework.test.context.junit4.SpringRunner;
37+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3938
import org.springframework.test.web.reactive.server.WebTestClient;
4039
import org.springframework.web.reactive.config.EnableWebFlux;
4140

@@ -48,7 +47,7 @@
4847
*
4948
* @since 5.0
5049
*/
51-
@RunWith(SpringRunner.class)
50+
@SpringJUnitConfig
5251
@DirtiesContext
5352
public class WebFluxInboundEndpointTests {
5453

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/management/IntegrationGraphControllerTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2019 the original author or authors.
2+
* Copyright 2018-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.integration.webflux.management;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.beans.factory.annotation.Autowired;
2322
import org.springframework.context.annotation.Configuration;
@@ -26,8 +25,7 @@
2625
import org.springframework.integration.http.config.EnableIntegrationGraphController;
2726
import org.springframework.test.annotation.DirtiesContext;
2827
import org.springframework.test.context.TestPropertySource;
29-
import org.springframework.test.context.junit4.SpringRunner;
30-
import org.springframework.test.context.web.WebAppConfiguration;
28+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
3129
import org.springframework.test.web.reactive.server.WebTestClient;
3230
import org.springframework.web.context.WebApplicationContext;
3331
import org.springframework.web.reactive.config.EnableWebFlux;
@@ -37,8 +35,7 @@
3735
*
3836
* @since 5.0.2
3937
*/
40-
@RunWith(SpringRunner.class)
41-
@WebAppConfiguration
38+
@SpringJUnitWebConfig
4239
@TestPropertySource(properties = "spring.application.name:testApplication")
4340
@DirtiesContext
4441
public class IntegrationGraphControllerTests {

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/outbound/WebFluxRequestExecutingMessageHandlerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ void testReactiveReturn() {
7878
.assertNext(m -> assertThat(m.getHeaders()).containsEntry(HttpHeaders.STATUS_CODE, HttpStatus.OK))
7979
.expectNoEvent(Duration.ofMillis(100))
8080
.thenCancel()
81-
.verify(Duration.ofSeconds(1));
81+
.verify(Duration.ofSeconds(10));
8282
}
8383

8484
@Test

0 commit comments

Comments
 (0)