GH-430: Change Filter function to non-reactive
Fixes https://github.com/spring-cloud/stream-applications/issues/430 Fix greenmail exclusion. Added -X for github.debug
This commit is contained in:
committed by
GitHub
parent
d29546c9bd
commit
8e4c20dc77
@@ -18,8 +18,6 @@ package org.springframework.cloud.fn.filter;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -35,17 +33,22 @@ import org.springframework.messaging.Message;
|
||||
public class FilterFunctionConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<Flux<Message<?>>, Flux<Message<?>>> filterFunction(
|
||||
ExpressionEvaluatingTransformer filterExpressionEvaluatingTransformer) {
|
||||
public Function<Message<?>, Message<?>> filterFunction(
|
||||
ExpressionEvaluatingTransformer filterExpressionEvaluatingTransformer) {
|
||||
|
||||
return flux ->
|
||||
flux.filter((message) ->
|
||||
(Boolean) filterExpressionEvaluatingTransformer.transform(message).getPayload());
|
||||
return message -> {
|
||||
if ((Boolean) filterExpressionEvaluatingTransformer.transform(message).getPayload()) {
|
||||
return message;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ExpressionEvaluatingTransformer filterExpressionEvaluatingTransformer(
|
||||
FilterFunctionProperties filterFunctionProperties) {
|
||||
FilterFunctionProperties filterFunctionProperties) {
|
||||
|
||||
return new ExpressionEvaluatingTransformer(filterFunctionProperties.getExpression());
|
||||
}
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package org.springframework.cloud.fn.filter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -30,6 +34,8 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author David Turanski
|
||||
@@ -40,21 +46,17 @@ public class FilterFunctionApplicationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("filterFunction")
|
||||
Function<Flux<Message<?>>, Flux<Message<?>>> filter;
|
||||
Function<Message<?>, Message<?>> filter;
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
Flux<Message<?>> messageFlux =
|
||||
Flux.just("hello", "hello world")
|
||||
.map(GenericMessage::new);
|
||||
Flux<Message<?>> result = this.filter.apply(messageFlux);
|
||||
result
|
||||
.map(Message::getPayload)
|
||||
.cast(String.class)
|
||||
.as(StepVerifier::create)
|
||||
.expectNext("hello world")
|
||||
.expectComplete()
|
||||
.verify();
|
||||
Stream<Message<?>> messages = List.of("hello", "hello world")
|
||||
.stream()
|
||||
.map(GenericMessage::new);
|
||||
List<Message<?>> result = messages.filter(message -> this.filter.apply(message) != null).collect(Collectors.toList());
|
||||
assertThat(result.size()).isEqualTo(1);
|
||||
assertThat(result.get(0).getPayload()).isNotNull();
|
||||
assertThat(result.get(0).getPayload()).isEqualTo("hello world");
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
|
||||
Reference in New Issue
Block a user