Remove deleted-test directory
This commit is contained in:
@@ -1,257 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017-2018 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.binding;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.binder.PartitionHandler;
|
||||
import org.springframework.cloud.stream.binder.PartitionKeyExtractorStrategy;
|
||||
import org.springframework.cloud.stream.binder.PartitionSelectorStrategy;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.cloud.stream.partitioning.CustomPartitionKeyExtractorClass;
|
||||
import org.springframework.cloud.stream.partitioning.CustomPartitionSelectorClass;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||
import org.springframework.integration.annotation.Poller;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Ilayaperumal Gopinathan
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class CustomPartitionedProducerTest {
|
||||
|
||||
@Test
|
||||
public void testCustomPartitionedProducer() {
|
||||
ApplicationContext context = SpringApplication.run(
|
||||
CustomPartitionedProducerTest.TestSource.class,
|
||||
"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorClass="
|
||||
+ "org.springframework.cloud.stream.partitioning.CustomPartitionKeyExtractorClass",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionSelectorClass="
|
||||
+ "org.springframework.cloud.stream.partitioning.CustomPartitionSelectorClass",
|
||||
"--spring.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel
|
||||
.getInterceptors()) {
|
||||
if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
|
||||
Field partitionHandlerField = ReflectionUtils.findField(
|
||||
MessageConverterConfigurer.PartitioningInterceptor.class,
|
||||
"partitionHandler");
|
||||
ReflectionUtils.makeAccessible(partitionHandlerField);
|
||||
PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
|
||||
.getField(partitionHandlerField, channelInterceptor);
|
||||
Field partitonKeyExtractorField = ReflectionUtils.findField(
|
||||
PartitionHandler.class, "partitionKeyExtractorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonKeyExtractorField);
|
||||
Field partitonSelectorField = ReflectionUtils
|
||||
.findField(PartitionHandler.class, "partitionSelectorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonSelectorField);
|
||||
assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
|
||||
.getField(partitonKeyExtractorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
|
||||
assertThat(((PartitionSelectorStrategy) ReflectionUtils
|
||||
.getField(partitonSelectorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionSelectorClass.class)).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPartitionedProducerByName() {
|
||||
ApplicationContext context = SpringApplication.run(
|
||||
CustomPartitionedProducerTest.TestSource.class,
|
||||
"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorName=customPartitionKeyExtractor",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelector",
|
||||
"--spring.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel
|
||||
.getInterceptors()) {
|
||||
if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
|
||||
Field partitionHandlerField = ReflectionUtils.findField(
|
||||
MessageConverterConfigurer.PartitioningInterceptor.class,
|
||||
"partitionHandler");
|
||||
ReflectionUtils.makeAccessible(partitionHandlerField);
|
||||
PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
|
||||
.getField(partitionHandlerField, channelInterceptor);
|
||||
Field partitonKeyExtractorField = ReflectionUtils.findField(
|
||||
PartitionHandler.class, "partitionKeyExtractorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonKeyExtractorField);
|
||||
Field partitonSelectorField = ReflectionUtils
|
||||
.findField(PartitionHandler.class, "partitionSelectorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonSelectorField);
|
||||
assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
|
||||
.getField(partitonKeyExtractorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
|
||||
assertThat(((PartitionSelectorStrategy) ReflectionUtils
|
||||
.getField(partitonSelectorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionSelectorClass.class)).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPartitionedProducerAsSingletons() {
|
||||
ApplicationContext context = SpringApplication.run(
|
||||
CustomPartitionedProducerTest.TestSource.class,
|
||||
"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
|
||||
"--spring.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel
|
||||
.getInterceptors()) {
|
||||
if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
|
||||
Field partitionHandlerField = ReflectionUtils.findField(
|
||||
MessageConverterConfigurer.PartitioningInterceptor.class,
|
||||
"partitionHandler");
|
||||
ReflectionUtils.makeAccessible(partitionHandlerField);
|
||||
PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
|
||||
.getField(partitionHandlerField, channelInterceptor);
|
||||
Field partitonKeyExtractorField = ReflectionUtils.findField(
|
||||
PartitionHandler.class, "partitionKeyExtractorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonKeyExtractorField);
|
||||
Field partitonSelectorField = ReflectionUtils
|
||||
.findField(PartitionHandler.class, "partitionSelectorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonSelectorField);
|
||||
assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
|
||||
.getField(partitonKeyExtractorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
|
||||
assertThat(((PartitionSelectorStrategy) ReflectionUtils
|
||||
.getField(partitonSelectorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionSelectorClass.class)).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testCustomPartitionedProducerMultipleInstances() {
|
||||
ApplicationContext context = SpringApplication.run(
|
||||
CustomPartitionedProducerTest.TestSourceMultipleStrategies.class,
|
||||
"--spring.jmx.enabled=false", "--spring.main.web-application-type=none",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorName=customPartitionKeyExtractorOne",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelectorTwo",
|
||||
"--spring.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel
|
||||
.getInterceptors()) {
|
||||
if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
|
||||
Field partitionHandlerField = ReflectionUtils.findField(
|
||||
MessageConverterConfigurer.PartitioningInterceptor.class,
|
||||
"partitionHandler");
|
||||
ReflectionUtils.makeAccessible(partitionHandlerField);
|
||||
PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils
|
||||
.getField(partitionHandlerField, channelInterceptor);
|
||||
Field partitonKeyExtractorField = ReflectionUtils.findField(
|
||||
PartitionHandler.class, "partitionKeyExtractorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonKeyExtractorField);
|
||||
Field partitonSelectorField = ReflectionUtils
|
||||
.findField(PartitionHandler.class, "partitionSelectorStrategy");
|
||||
ReflectionUtils.makeAccessible(partitonSelectorField);
|
||||
assertThat(((PartitionKeyExtractorStrategy) ReflectionUtils
|
||||
.getField(partitonKeyExtractorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionKeyExtractorClass.class)).isTrue();
|
||||
assertThat(((PartitionSelectorStrategy) ReflectionUtils
|
||||
.getField(partitonSelectorField, partitionHandler)).getClass()
|
||||
.equals(CustomPartitionSelectorClass.class)).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EnableBinding(Source.class)
|
||||
@EnableAutoConfiguration
|
||||
@PropertySource("classpath:/org/springframework/cloud/stream/binder/custom-partitioned-producer-test.properties")
|
||||
public static class TestSource {
|
||||
|
||||
@Bean
|
||||
public CustomPartitionSelectorClass customPartitionSelector() {
|
||||
return new CustomPartitionSelectorClass();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomPartitionKeyExtractorClass customPartitionKeyExtractor() {
|
||||
return new CustomPartitionKeyExtractorClass();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
|
||||
public MessageSource<String> timerMessageSource() {
|
||||
return new MessageSource<String>() {
|
||||
@Override
|
||||
public Message<String> receive() {
|
||||
throw new MessagingException("test");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableBinding(Source.class)
|
||||
@EnableAutoConfiguration
|
||||
@PropertySource("classpath:/org/springframework/cloud/stream/binder/custom-partitioned-producer-test.properties")
|
||||
public static class TestSourceMultipleStrategies {
|
||||
|
||||
@Bean
|
||||
public CustomPartitionSelectorClass customPartitionSelectorOne() {
|
||||
return new CustomPartitionSelectorClass();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomPartitionSelectorClass customPartitionSelectorTwo() {
|
||||
return new CustomPartitionSelectorClass();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomPartitionKeyExtractorClass customPartitionKeyExtractorOne() {
|
||||
return new CustomPartitionKeyExtractorClass();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomPartitionKeyExtractorClass customPartitionKeyExtractorTwo() {
|
||||
return new CustomPartitionKeyExtractorClass();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
|
||||
public MessageSource<String> timerMessageSource() {
|
||||
return new MessageSource<String>() {
|
||||
@Override
|
||||
public Message<String> receive() {
|
||||
throw new MessagingException("test");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.actuate.health.CompositeHealthContributor;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthContributor;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.actuate.health.NamedContributor;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.binder.stub1.StubBinder1;
|
||||
import org.springframework.cloud.stream.binder.stub2.StubBinder2;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
public class HealthIndicatorsConfigurationTests {
|
||||
|
||||
public static ConfigurableApplicationContext createBinderTestContext(
|
||||
String[] additionalClasspathDirectories, String... properties)
|
||||
throws IOException {
|
||||
URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ? new URL[0]
|
||||
: new URL[additionalClasspathDirectories.length];
|
||||
if (!ObjectUtils.isEmpty(additionalClasspathDirectories)) {
|
||||
for (int i = 0; i < additionalClasspathDirectories.length; i++) {
|
||||
urls[i] = new URL(new ClassPathResource(additionalClasspathDirectories[i])
|
||||
.getURL().toString() + "/");
|
||||
}
|
||||
}
|
||||
ClassLoader classLoader = new URLClassLoader(urls,
|
||||
BinderFactoryAutoConfigurationTests.class.getClassLoader());
|
||||
|
||||
return new SpringApplicationBuilder(SimpleSource.class)
|
||||
.resourceLoader(new DefaultResourceLoader(classLoader))
|
||||
.properties(properties).web(WebApplicationType.NONE).run();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void healthIndicatorsCheck() throws Exception {
|
||||
ConfigurableApplicationContext context = createBinderTestContext(
|
||||
new String[] { "binder1", "binder2" },
|
||||
"spring.cloud.stream.defaultBinder:binder2",
|
||||
"--spring.jmx.enabled=false");
|
||||
Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1",
|
||||
MessageChannel.class);
|
||||
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||
Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2",
|
||||
MessageChannel.class);
|
||||
assertThat(binder2).isInstanceOf(StubBinder2.class);
|
||||
CompositeHealthContributor bindersHealthContributor = context
|
||||
.getBean("bindersHealthContributor", CompositeHealthContributor.class);
|
||||
assertThat(bindersHealthContributor).isNotNull();
|
||||
assertThat(
|
||||
context.getBean("test1HealthIndicator1", HealthContributor.class))
|
||||
.isNotNull();
|
||||
assertThat(
|
||||
context.getBean("test2HealthIndicator2", HealthContributor.class))
|
||||
.isNotNull();
|
||||
|
||||
assertThat(bindersHealthContributor.stream().map(NamedContributor::getName)).contains("binder1", "binder2");
|
||||
// assertThat(bindersHealthContributor.getContributor("binder1")).extracting("health").extracting("status")
|
||||
// .isEqualTo(Status.UP);
|
||||
// assertThat(bindersHealthContributor.getContributor("binder2")).extracting("health").extracting("status")
|
||||
// .isEqualTo(Status.UNKNOWN);
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void healthIndicatorsCheckWhenDisabled() throws Exception {
|
||||
ConfigurableApplicationContext context = createBinderTestContext(
|
||||
new String[] { "binder1", "binder2" },
|
||||
"spring.cloud.stream.defaultBinder:binder2",
|
||||
"management.health.binders.enabled:false", "--spring.jmx.enabled=false");
|
||||
|
||||
Binder binder1 = context.getBean(BinderFactory.class).getBinder("binder1",
|
||||
MessageChannel.class);
|
||||
assertThat(binder1).isInstanceOf(StubBinder1.class);
|
||||
Binder binder2 = context.getBean(BinderFactory.class).getBinder("binder2",
|
||||
MessageChannel.class);
|
||||
assertThat(binder2).isInstanceOf(StubBinder2.class);
|
||||
try {
|
||||
context.getBean("bindersHealthContributor", CompositeHealthContributor.class);
|
||||
fail("The 'bindersHealthContributor' bean should have not been defined");
|
||||
}
|
||||
catch (NoSuchBeanDefinitionException e) {
|
||||
}
|
||||
assertThat(
|
||||
context.getBean("test1HealthIndicator1", HealthContributor.class))
|
||||
.isNotNull();
|
||||
assertThat(
|
||||
context.getBean("test2HealthIndicator2", HealthContributor.class))
|
||||
.isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@EnableBinding
|
||||
public static class SimpleSource {
|
||||
|
||||
@Configuration
|
||||
static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public HealthIndicator test1HealthIndicator1() {
|
||||
return () -> Health.unknown().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HealthIndicator test2HealthIndicator2() {
|
||||
return () -> Health.unknown().build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user