Handle new Reactor Emission FAIL_NON_SERIALIZED

* Rework WebFlux test to JUnit 5
This commit is contained in:
Artem Bilan
2020-09-11 14:12:09 -04:00
parent 481d5eb2a5
commit 09dec2eab5
8 changed files with 30 additions and 34 deletions

View File

@@ -83,6 +83,9 @@ public class FluxMessageChannel extends AbstractMessageChannel
private boolean tryEmitMessage(Message<?> message) {
switch (this.sink.tryEmitNext(message)) {
case OK:
return true;
case FAIL_NON_SERIALIZED:
case FAIL_OVERFLOW:
return false;
case FAIL_TERMINATED:
@@ -90,7 +93,7 @@ public class FluxMessageChannel extends AbstractMessageChannel
throw new IllegalStateException("Cannot emit messages into the cancelled or terminated sink: "
+ this.sink);
default:
return true;
throw new UnsupportedOperationException();
}
}

View File

@@ -124,14 +124,14 @@ public final class IntegrationReactiveUtils {
}
}
@SuppressWarnings("unchecked")
private static <T> Flux<Message<T>> adaptSubscribableChannelToPublisher(SubscribableChannel inputChannel) {
return Flux.defer(() -> {
Sinks.Many<Message<T>> sink = Sinks.many().unicast().onBackpressureError();
MessageHandler messageHandler = (message) -> {
while (true) {
@SuppressWarnings("unchecked")
Sinks.Emission emission = sink.tryEmitNext((Message<T>) message);
switch (emission) {
switch (sink.tryEmitNext((Message<T>) message)) {
case FAIL_NON_SERIALIZED:
case FAIL_OVERFLOW:
LockSupport.parkNanos(1000); // NOSONAR
break;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-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.
@@ -20,8 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +35,7 @@ import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.validation.Validator;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
@@ -45,7 +44,7 @@ import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
*
* @since 5.0.1
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class WebFluxInboundChannelAdapterParserTests {
@@ -120,7 +119,7 @@ public class WebFluxInboundChannelAdapterParserTests {
CrossOrigin crossOrigin = (CrossOrigin) endpointAccessor.getPropertyValue("crossOrigin");
assertThat(crossOrigin).isNotNull();
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[] { "foo" });
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[]{ "foo" });
assertThat(endpointAccessor.getPropertyValue("requestPayloadType"))
.isEqualTo(ResolvableType.forClass(byte[].class));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-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.
@@ -20,8 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +35,7 @@ import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
/**
@@ -44,7 +43,7 @@ import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
*
* @since 5.0.1
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class WebFluxInboundGatewayParserTests {
@@ -115,7 +114,7 @@ public class WebFluxInboundGatewayParserTests {
CrossOrigin crossOrigin = (CrossOrigin) endpointAccessor.getPropertyValue("crossOrigin");
assertThat(crossOrigin).isNotNull();
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[] { "foo" });
assertThat(crossOrigin.getOrigin()).isEqualTo(new String[]{ "foo" });
assertThat(endpointAccessor.getPropertyValue("requestPayloadType"))
.isEqualTo(ResolvableType.forClass(byte[].class));

View File

@@ -22,8 +22,7 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,7 +34,7 @@ import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.ObjectUtils;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.client.WebClient;
@@ -45,7 +44,7 @@ import org.springframework.web.reactive.function.client.WebClient;
*
* @since 5.0
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class WebFluxOutboundGatewayParserTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-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,7 @@ package org.springframework.integration.webflux.inbound;
import java.util.Objects;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
@@ -35,7 +34,7 @@ import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.http.inbound.RequestMapping;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.config.EnableWebFlux;
@@ -48,7 +47,7 @@ import reactor.core.publisher.Flux;
*
* @since 5.0
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class WebFluxInboundEndpointTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-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.
@@ -16,8 +16,7 @@
package org.springframework.integration.webflux.management;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@@ -26,8 +25,7 @@ import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.http.config.EnableIntegrationGraphController;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.reactive.config.EnableWebFlux;
@@ -37,8 +35,7 @@ import org.springframework.web.reactive.config.EnableWebFlux;
*
* @since 5.0.2
*/
@RunWith(SpringRunner.class)
@WebAppConfiguration
@SpringJUnitWebConfig
@TestPropertySource(properties = "spring.application.name:testApplication")
@DirtiesContext
public class IntegrationGraphControllerTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-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.
@@ -78,7 +78,7 @@ class WebFluxRequestExecutingMessageHandlerTests {
.assertNext(m -> assertThat(m.getHeaders()).containsEntry(HttpHeaders.STATUS_CODE, HttpStatus.OK))
.expectNoEvent(Duration.ofMillis(100))
.thenCancel()
.verify(Duration.ofSeconds(1));
.verify(Duration.ofSeconds(10));
}
@Test