This commit is contained in:
Marcin Grzejszczak
2020-07-15 10:44:00 +02:00
parent 469615e130
commit 3df35b8d50
24 changed files with 323 additions and 13 deletions

View File

@@ -42,7 +42,11 @@ import org.springframework.messaging.MessageChannel;
* @since 3.0.2
*
*/
public class FunctionBindingTestUtils {
public final class FunctionBindingTestUtils {
private FunctionBindingTestUtils() {
throw new IllegalStateException("You should not instantiate utility classes");
}
@SuppressWarnings("rawtypes")
public static void bind(ConfigurableApplicationContext applicationContext, Object function) {

View File

@@ -51,7 +51,7 @@ import org.springframework.integration.config.EnableIntegration;
@EnableIntegration
public class TestChannelBinderConfiguration<T> {
public static final String NAME = "integration";
// public static final String NAME = "integration";
/**
* Utility operation to return an array of configuration classes defined in

View File

@@ -16,6 +16,11 @@
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
@@ -41,9 +46,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-http</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.springframework.boot.WebApplicationType;
@@ -203,7 +204,7 @@ public class BinderFactoryAutoConfigurationTests {
Binder binder1 = binderFactory.getBinder("binder1", MessageChannel.class);
assertThat(binder1).hasFieldOrPropertyWithValue("name", "foo");
assertThat(((StubBinder1) binder1).getOuterContext()).isNull();
Assertions.assertThat(((StubBinder1) binder1).getOuterContext()).isNull();
}
@SuppressWarnings("rawtypes")
@@ -260,7 +261,7 @@ public class BinderFactoryAutoConfigurationTests {
Binder defaultBinder = binderFactory.getBinder(null, MessageChannel.class);
assertThat(defaultBinder).isInstanceOf(StubBinder1.class);
assertThat(((StubBinder1) defaultBinder).getName()).isNullOrEmpty();
Assertions.assertThat(((StubBinder1) defaultBinder).getName()).isNullOrEmpty();
Binder binder1 = binderFactory.getBinder("binder1", MessageChannel.class);
assertThat(binder1).isInstanceOf(StubBinder1.class);

View File

@@ -20,6 +20,7 @@ import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -86,7 +87,7 @@ public class HealthIndicatorsConfigurationTests {
assertThat(binder2).isInstanceOf(StubBinder2.class);
CompositeHealthContributor bindersHealthContributor = context
.getBean("bindersHealthContributor", CompositeHealthContributor.class);
assertThat(bindersHealthContributor).isNotNull();
Assertions.assertThat(bindersHealthContributor).isNotNull();
assertThat(
context.getBean("test1HealthIndicator1", HealthContributor.class))
.isNotNull();
@@ -94,10 +95,10 @@ public class HealthIndicatorsConfigurationTests {
context.getBean("test2HealthIndicator2", HealthContributor.class))
.isNotNull();
assertThat(bindersHealthContributor.stream().map(NamedContributor::getName)).contains("binder1", "binder2");
assertThat(bindersHealthContributor.getContributor("binder1")).extracting("health").extracting("status")
Assertions.assertThat(bindersHealthContributor.stream().map(NamedContributor::getName)).contains("binder1", "binder2");
Assertions.assertThat(bindersHealthContributor.getContributor("binder1")).extracting("health").extracting("status")
.isEqualTo(Status.UP);
assertThat(bindersHealthContributor.getContributor("binder2")).extracting("health").extracting("status")
Assertions.assertThat(bindersHealthContributor.getContributor("binder2")).extracting("health").extracting("status")
.isEqualTo(Status.UNKNOWN);
context.close();

View File

@@ -0,0 +1,65 @@
/*
* Copyright 2015-2016 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.stream.binder.stub1;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.cloud.stream.binder.Binding;
import org.springframework.cloud.stream.binder.ConsumerProperties;
import org.springframework.cloud.stream.binder.ProducerProperties;
import org.springframework.context.ConfigurableApplicationContext;
/**
* @author Marius Bogoevici
* @author Mark Fisher
* @author Soby Chacko
*/
public class StubBinder1
implements Binder<Object, ConsumerProperties, ProducerProperties> {
private String name;
private ConfigurableApplicationContext outerContext;
public ConfigurableApplicationContext getOuterContext() {
return this.outerContext;
}
public void setOuterContext(ConfigurableApplicationContext outerContext) {
this.outerContext = outerContext;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Override
public Binding<Object> bindConsumer(String name, String group,
Object inboundBindTarget, ConsumerProperties properties) {
return null;
}
@Override
public Binding<Object> bindProducer(String name, Object outboundBindTarget,
ProducerProperties properties) {
return null;
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2015-2016 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.stream.binder.stub1;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.PingHealthIndicator;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Marius Bogoevici
* @author Soby Chacko
*/
@Configuration
@EnableConfigurationProperties
public class StubBinder1Configuration {
@Bean
@ConfigurationProperties("binder1")
public Binder<?, ?, ?> binder(BeanFactory beanFactory) {
StubBinder1 stubBinder1 = new StubBinder1();
ConfigurableApplicationContext outerContext = null;
try {
outerContext = (ConfigurableApplicationContext) beanFactory
.getBean("outerContext");
}
catch (BeansException be) {
// Pass through
}
if (outerContext != null) {
stubBinder1.setOuterContext(outerContext);
}
return stubBinder1;
}
@Bean
public HealthIndicator binderHealthIndicator() {
return new PingHealthIndicator();
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2015-2016 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.stream.binder.stub2;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.cloud.stream.binder.Binding;
import org.springframework.cloud.stream.binder.ConsumerProperties;
import org.springframework.cloud.stream.binder.ProducerProperties;
/**
* @author Marius Bogoevici
* @author Mark Fisher
*/
public class StubBinder2
implements Binder<Object, ConsumerProperties, ProducerProperties> {
@SuppressWarnings("unused")
private final StubBinder2Dependency stubBinder2Dependency;
public StubBinder2(StubBinder2Dependency stubBinder2Dependency) {
this.stubBinder2Dependency = stubBinder2Dependency;
}
@Override
public Binding<Object> bindConsumer(String name, String group,
Object inboundBindTarget, ConsumerProperties properties) {
return null;
}
@Override
public Binding<Object> bindProducer(String name, Object outboundBindTarget,
ProducerProperties properties) {
return null;
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2015-2016 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.stream.binder.stub2;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Marius Bogoevici
*/
@Configuration
public class StubBinder2ConfigurationA {
@Bean
public Binder<?, ?, ?> binder(StubBinder2Dependency dependency) {
return new StubBinder2(dependency);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2015-2019 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.stream.binder.stub2;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Marius Bogoevici
*/
@Configuration
public class StubBinder2ConfigurationB {
@Bean
public StubBinder2Dependency dependency() {
return new StubBinder2Dependency();
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2015-2019 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.stream.binder.stub2;
/**
* @author Marius Bogoevici
*/
public class StubBinder2Dependency {
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.stream.function.edgecases;
package org.springframework.cloud.stream.funciton.edgcases;
import java.util.function.Consumer;

View File

@@ -0,0 +1,2 @@
mock:\
org.springframework.cloud.stream.utils.MockBinderConfiguration

View File

@@ -0,0 +1 @@
binder1=org.springframework.cloud.stream.binder.stub1.StubBinder1Configuration

View File

@@ -0,0 +1,3 @@
binder2:\
org.springframework.cloud.stream.binder.stub2.StubBinder2ConfigurationA,\
org.springframework.cloud.stream.binder.stub2.StubBinder2ConfigurationB

View File

@@ -0,0 +1,4 @@
spring.cloud.stream.bindings.foo.destination=someQueue.0
spring.cloud.stream.bindings.bar.destination=someQueue.1
spring.cloud.stream.bindings.baz.destination=someQueue.2
spring.cloud.stream.bindings.qux.destination=someQueue.3

View File

@@ -0,0 +1,2 @@
spring.cloud.stream.function.producerProperties.useNativeEncoding:true
spring.cloud.stream.function.consumerProperties.maxAttempts:5

View File

@@ -0,0 +1,2 @@
spring.cloud.stream.bindings.output.destination=partOut
spring.cloud.stream.bindings.output.producer.partitionCount=3

View File

@@ -0,0 +1,5 @@
spring.cloud.stream.bindings.input.destination=partIn
spring.cloud.stream.bindings.input.consumer.partitioned=true
spring.cloud.stream.instanceCount=2
spring.cloud.stream.instanceIndex=0

View File

@@ -0,0 +1,4 @@
spring.cloud.stream.bindings.output.destination=partOut
spring.cloud.stream.bindings.output.producer.partitionKeyExpression=payload
spring.cloud.stream.bindings.output.producer.partitionCount=3

View File

@@ -0,0 +1,2 @@
spring.cloud.stream.bindings.input.destination=testtock.0
spring.cloud.stream.bindings.output.destination=testtock.1

View File

@@ -0,0 +1 @@
spring.cloud.stream.bindings.input.destination=testtock

View File

@@ -0,0 +1 @@
spring.cloud.stream.bindings.output.destination=testtock

View File

@@ -48,7 +48,7 @@ public class TestSupportBinderAutoConfiguration {
@Bean
@SuppressWarnings("unchecked")
public BinderFactory binderFactory(final Binder<MessageChannel, ?, ?> binder) {
public BinderFactory testSupportBinderFactory(final Binder<MessageChannel, ?, ?> binder) {
return new BinderFactory() {
@Override
public <T> Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties> getBinder(