From bf69f467e39b0ddef023b7d565b9079e09d84787 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 23 Feb 2018 14:58:16 +0000 Subject: [PATCH] Make Actuator optional --- .gitignore | 2 + spring-cloud-stream/pom.xml | 1 + .../AggregateApplicationBuilder.java | 95 ++++++---- ...ionPublishingMetricsAutoConfiguration.java | 33 ++-- .../stream/aggregation/AggregationTest.java | 173 +++++++++--------- 5 files changed, 172 insertions(+), 132 deletions(-) diff --git a/.gitignore b/.gitignore index 0dd7fdbd6..214f0bcb3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ _site/ .project .settings .springBeans +.sts4-cache/ +.attach_pid* .DS_Store *.sw* *.iml diff --git a/spring-cloud-stream/pom.xml b/spring-cloud-stream/pom.xml index e8d62b9e8..7e6df0444 100644 --- a/spring-cloud-stream/pom.xml +++ b/spring-cloud-stream/pom.xml @@ -17,6 +17,7 @@ org.springframework.boot spring-boot-starter-actuator + true org.springframework.boot diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java index cc29d2ec3..2ba290746 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java @@ -60,8 +60,8 @@ import org.springframework.util.StringUtils; * @author Oleg Zhurakousky */ @EnableBinding -public class AggregateApplicationBuilder implements AggregateApplication, ApplicationContextAware, - SmartInitializingSingleton { +public class AggregateApplicationBuilder implements AggregateApplication, + ApplicationContextAware, SmartInitializingSingleton { private static final String CHILD_CONTEXT_SUFFIX = ".spring.cloud.stream.context"; @@ -106,6 +106,11 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic private void addParentSources(Object[] sources) { if (!this.parentSources.contains(ParentConfiguration.class)) { this.parentSources.add(ParentConfiguration.class); + if (ClassUtils.isPresent( + "org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration", + null)) { + this.parentSources.add(ParentActuatorConfiguration.class); + } } this.parentSources.addAll(Arrays.asList(sources)); } @@ -150,23 +155,25 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic } @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(ApplicationContext applicationContext) + throws BeansException { this.parentContext = (ConfigurableApplicationContext) applicationContext; } @Override public T getBinding(Class bindableType, String namespace) { if (parentContext == null) { - throw new IllegalStateException("The aggregate application has not been started yet"); + throw new IllegalStateException( + "The aggregate application has not been started yet"); } try { - ChildContextHolder contextHolder = parentContext.getBean(namespace + CHILD_CONTEXT_SUFFIX, - ChildContextHolder.class); + ChildContextHolder contextHolder = parentContext + .getBean(namespace + CHILD_CONTEXT_SUFFIX, ChildContextHolder.class); return contextHolder.getChildContext().getBean(bindableType); } catch (BeansException e) { - throw new IllegalStateException("Binding not found for '" + bindableType.getName() + "' into namespace " + - namespace); + throw new IllegalStateException("Binding not found for '" + + bindableType.getName() + "' into namespace " + namespace); } } @@ -200,35 +207,41 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic // to remove illegal characters for new properties // binder // org.springframework.cloud.stream.aggregation.AggregationTest$TestSource - appConfigurer.namespace = AggregateApplicationUtils - .getDefaultNamespace(appConfigurer.getApp().getName().replaceAll("\\$", "."), i); + appConfigurer.namespace = AggregateApplicationUtils.getDefaultNamespace( + appConfigurer.getApp().getName().replaceAll("\\$", "."), i); } appsToEmbed.put(appToEmbed, appConfigurer.namespace); appConfigurers.put(appConfigurer, appConfigurer.namespace); } if (this.parentContext == null) { if (Boolean.TRUE.equals(this.webEnvironment)) { - Assert.isTrue(ClassUtils.isPresent("javax.servlet.ServletRequest", ClassUtils.getDefaultClassLoader()), + Assert.isTrue( + ClassUtils.isPresent("javax.servlet.ServletRequest", + ClassUtils.getDefaultClassLoader()), "'webEnvironment' is set to 'true' but 'javax.servlet.*' does not appear to be available in " - + "the classpath. Consider adding `org.springframework.boot:spring-boot-starter-web"); - this.addParentSources(new Object[] { ServletWebServerFactoryAutoConfiguration.class }); + + "the classpath. Consider adding `org.springframework.boot:spring-boot-starter-web"); + this.addParentSources( + new Object[] { ServletWebServerFactoryAutoConfiguration.class }); } this.parentContext = AggregateApplicationUtils.createParentContext( this.parentSources.toArray(new Class[0]), - this.parentArgs.toArray(new String[0]), selfContained(), this.webEnvironment, this.headless); + this.parentArgs.toArray(new String[0]), selfContained(), + this.webEnvironment, this.headless); } else { - if (BeanFactoryUtils.beansOfTypeIncludingAncestors(this.parentContext, SharedBindingTargetRegistry.class) - .size() == 0) { + if (BeanFactoryUtils.beansOfTypeIncludingAncestors(this.parentContext, + SharedBindingTargetRegistry.class).size() == 0) { SharedBindingTargetRegistry sharedBindingTargetRegistry = new SharedBindingTargetRegistry(); - this.parentContext.getBeanFactory().registerSingleton("sharedBindingTargetRegistry", - sharedBindingTargetRegistry); + this.parentContext.getBeanFactory().registerSingleton( + "sharedBindingTargetRegistry", sharedBindingTargetRegistry); } } SharedBindingTargetRegistry sharedBindingTargetRegistry = this.parentContext .getBean(SharedBindingTargetRegistry.class); - AggregateApplicationUtils.prepareSharedBindingTargetRegistry(sharedBindingTargetRegistry, appsToEmbed); - for (Map.Entry, String> appConfigurerEntry : appConfigurers.entrySet()) { + AggregateApplicationUtils.prepareSharedBindingTargetRegistry( + sharedBindingTargetRegistry, appsToEmbed); + for (Map.Entry, String> appConfigurerEntry : appConfigurers + .entrySet()) { AppConfigurer appConfigurer = appConfigurerEntry.getKey(); if (appConfigurerEntry.getValue() == null) { @@ -237,7 +250,8 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic String namespace = appConfigurerEntry.getValue().toLowerCase(); Set argsToUpdate = new LinkedHashSet<>(); Set argKeys = new LinkedHashSet<>(); - Map target = bindProperties(namespace, this.parentContext.getEnvironment()); + Map target = bindProperties(namespace, + this.parentContext.getEnvironment()); if (!target.isEmpty()) { for (Map.Entry entry : target.entrySet()) { @@ -255,9 +269,10 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic AppConfigurer appConfigurer = apps.get(i); appConfigurer.embed(); } - if (BeanFactoryUtils.beansOfTypeIncludingAncestors(this.parentContext, AggregateApplication.class) - .size() == 0) { - this.parentContext.getBeanFactory().registerSingleton("aggregateApplicationAccessor", this); + if (BeanFactoryUtils.beansOfTypeIncludingAncestors(this.parentContext, + AggregateApplication.class).size() == 0) { + this.parentContext.getBeanFactory() + .registerSingleton("aggregateApplicationAccessor", this); } return this.parentContext; } @@ -266,14 +281,16 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic return (this.sourceConfigurer != null) && (this.sinkConfigurer != null); } - private ChildContextBuilder childContext(Class app, ConfigurableApplicationContext parentContext, - String namespace) { - return new ChildContextBuilder(AggregateApplicationUtils.embedApp(parentContext, namespace, app)); + private ChildContextBuilder childContext(Class app, + ConfigurableApplicationContext parentContext, String namespace) { + return new ChildContextBuilder( + AggregateApplicationUtils.embedApp(parentContext, namespace, app)); } private Map bindProperties(String namepace, Environment environment) { Map target; - BindResult> bindResult = Binder.get(environment).bind(namepace, STRING_STRING_MAP); + BindResult> bindResult = Binder.get(environment) + .bind(namepace, STRING_STRING_MAP); if (bindResult.isBound()) { target = bindResult.get(); } @@ -297,7 +314,7 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic } } - @ImportAutoConfiguration({ ChannelBindingAutoConfiguration.class, EndpointAutoConfiguration.class }) + @ImportAutoConfiguration(ChannelBindingAutoConfiguration.class) @EnableBinding public static class ParentConfiguration { @Bean @@ -307,6 +324,10 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic } } + @ImportAutoConfiguration(EndpointAutoConfiguration.class) + public static class ParentActuatorConfiguration { + } + public class SourceConfigurer extends AppConfigurer { public SourceConfigurer(Class app) { @@ -397,20 +418,24 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic void embed() { final ConfigurableApplicationContext childContext = childContext(this.app, - AggregateApplicationBuilder.this.parentContext, this.namespace).args(this.args).config(this.names) - .profiles(this.profiles).run(); + AggregateApplicationBuilder.this.parentContext, this.namespace) + .args(this.args).config(this.names).profiles(this.profiles) + .run(); // Register bindable proxies as beans so they can be queried for later Map bindableProxies = BeanFactoryUtils - .beansOfTypeIncludingAncestors(childContext.getBeanFactory(), BindableProxyFactory.class); + .beansOfTypeIncludingAncestors(childContext.getBeanFactory(), + BindableProxyFactory.class); for (String bindableProxyName : bindableProxies.keySet()) { try { - AggregateApplicationBuilder.this.parentContext.getBeanFactory().registerSingleton( - this.getNamespace() + CHILD_CONTEXT_SUFFIX, new ChildContextHolder(childContext)); + AggregateApplicationBuilder.this.parentContext.getBeanFactory() + .registerSingleton(this.getNamespace() + CHILD_CONTEXT_SUFFIX, + new ChildContextHolder(childContext)); } catch (Exception e) { throw new IllegalStateException( "Error while trying to register the aggregate bound interface '" - + bindableProxyName + "' into namespace '" + this.getNamespace() + "'", + + bindableProxyName + "' into namespace '" + + this.getNamespace() + "'", e); } } diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/micrometer/DestinationPublishingMetricsAutoConfiguration.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/micrometer/DestinationPublishingMetricsAutoConfiguration.java index 70b202a5f..f80644a73 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/micrometer/DestinationPublishingMetricsAutoConfiguration.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/micrometer/DestinationPublishingMetricsAutoConfiguration.java @@ -46,32 +46,41 @@ import org.springframework.context.annotation.Configuration; @Configuration @AutoConfigureBefore(SimpleMetricsExportAutoConfiguration.class) @AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnClass(Binder.class) -@ConditionalOnProperty("spring.cloud.stream.bindings." + MetersPublisherBinding.APPLICATION_METRICS + ".destination") +@ConditionalOnClass({ Binder.class, MetricsAutoConfiguration.class }) +@ConditionalOnProperty("spring.cloud.stream.bindings." + + MetersPublisherBinding.APPLICATION_METRICS + ".destination") @EnableConfigurationProperties(ApplicationMetricsProperties.class) public class DestinationPublishingMetricsAutoConfiguration { @Bean @ConditionalOnMissingBean - public MetricsPublisherConfig metricsPublisherConfig(ApplicationMetricsProperties metersPublisherProperties) { + public MetricsPublisherConfig metricsPublisherConfig( + ApplicationMetricsProperties metersPublisherProperties) { return new MetricsPublisherConfig(metersPublisherProperties); } @Bean @ConditionalOnMissingBean - public DefaultDestinationPublishingMeterRegistry defaultDestinationPublishingMeterRegistry(ApplicationMetricsProperties applicationMetricsProperties, - MetersPublisherBinding publisherBinding, MetricsPublisherConfig metricsPublisherConfig, Clock clock) { - return new DefaultDestinationPublishingMeterRegistry(applicationMetricsProperties, publisherBinding, metricsPublisherConfig, clock); + public DefaultDestinationPublishingMeterRegistry defaultDestinationPublishingMeterRegistry( + ApplicationMetricsProperties applicationMetricsProperties, + MetersPublisherBinding publisherBinding, + MetricsPublisherConfig metricsPublisherConfig, Clock clock) { + return new DefaultDestinationPublishingMeterRegistry(applicationMetricsProperties, + publisherBinding, metricsPublisherConfig, clock); } - + @Bean public BeanFactoryPostProcessor metersPublisherBindingRegistrant() { - return new BeanFactoryPostProcessor() { + return new BeanFactoryPostProcessor() { @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - RootBeanDefinition emitterBindingDefinition = new RootBeanDefinition(BindableProxyFactory.class); - emitterBindingDefinition.getConstructorArgumentValues().addGenericArgumentValue(MetersPublisherBinding.class); - ((DefaultListableBeanFactory)beanFactory).registerBeanDefinition(MetersPublisherBinding.class.getName(), emitterBindingDefinition); + public void postProcessBeanFactory( + ConfigurableListableBeanFactory beanFactory) throws BeansException { + RootBeanDefinition emitterBindingDefinition = new RootBeanDefinition( + BindableProxyFactory.class); + emitterBindingDefinition.getConstructorArgumentValues() + .addGenericArgumentValue(MetersPublisherBinding.class); + ((DefaultListableBeanFactory) beanFactory).registerBeanDefinition( + MetersPublisherBinding.class.getName(), emitterBindingDefinition); } }; } diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java index c9d68d600..cc839c967 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java @@ -51,8 +51,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; - - /** * @author Marius Bogoevici * @author Ilayaperumal Gopinathan @@ -84,10 +82,7 @@ public class AggregationTest { public void aggregation() { aggregatedApplicationContext = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class, "--server.port=0", "--debug=true") - .web(false) - .from(TestSource.class) - .to(TestProcessor.class) - .run(); + .web(false).from(TestSource.class).to(TestProcessor.class).run(); SharedBindingTargetRegistry sharedBindingTargetRegistry = aggregatedApplicationContext .getBean(SharedBindingTargetRegistry.class); BindingTargetFactory channelFactory = aggregatedApplicationContext @@ -115,7 +110,7 @@ public class AggregationTest { @Test @SuppressWarnings("unchecked") public void testParentArgsAndSources() { - + List argsToVerify = new ArrayList<>(); argsToVerify.add("--foo1=bar1"); argsToVerify.add("--foo2=bar2"); @@ -124,15 +119,15 @@ public class AggregationTest { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class, "--foo1=bar1"); final ConfigurableApplicationContext context = aggregateApplicationBuilder - .parent(DummyConfig.class, "--foo2=bar2") - .web(false) - .from(TestSource.class) - .namespace("foo").to(TestProcessor.class).namespace("bar") - .run("--foo3=bar3", "--server.port=0"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); - final List parentArgs = (List) aggregateApplicationBuilderAccessor.getPropertyValue( - "parentArgs"); - assertThat(parentArgs).containsExactlyInAnyOrder(argsToVerify.toArray(new String[argsToVerify.size()])); + .parent(DummyConfig.class, "--foo2=bar2").web(false) + .from(TestSource.class).namespace("foo").to(TestProcessor.class) + .namespace("bar").run("--foo3=bar3", "--server.port=0"); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); + final List parentArgs = (List) aggregateApplicationBuilderAccessor + .getPropertyValue("parentArgs"); + assertThat(parentArgs).containsExactlyInAnyOrder( + argsToVerify.toArray(new String[argsToVerify.size()])); context.close(); } @@ -143,12 +138,15 @@ public class AggregationTest { MockBinderRegistryConfiguration.class, "--foo1=bar1"); final ConfigurableApplicationContext context = aggregateApplicationBuilder .parent(DummyConfig.class, "--foo2=bar2").web(false) - .from(TestSource.class) - .namespace("foo").to(TestProcessor.class).namespace("bar") - .run("--server.port=0"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); - List sources = (List) aggregateApplicationBuilderAccessor.getPropertyValue("parentSources"); - assertThat(sources).containsExactlyInAnyOrder(AggregateApplicationBuilder.ParentConfiguration.class, + .from(TestSource.class).namespace("foo").to(TestProcessor.class) + .namespace("bar").run("--server.port=0"); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); + List sources = (List) aggregateApplicationBuilderAccessor + .getPropertyValue("parentSources"); + assertThat(sources).containsExactlyInAnyOrder( + AggregateApplicationBuilder.ParentConfiguration.class, + AggregateApplicationBuilder.ParentActuatorConfiguration.class, MockBinderRegistryConfiguration.class, DummyConfig.class); context.close(); } @@ -158,17 +156,18 @@ public class AggregationTest { public void testNamespacePrefixesFromCmdLine() { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder + .parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").via(TestProcessor.class).namespace("b") .via(TestProcessor.class).namespace("c") .run("--a.foo1=bar1", "--b.foo1=bar2", "--c.foo1=bar3"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); assertTrue(Arrays.equals( - ((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")) - .getArgs(), + ((SourceConfigurer) aggregateApplicationBuilderAccessor + .getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--foo1=bar1" })); - final List processorConfigurers = - (List) aggregateApplicationBuilderAccessor + final List processorConfigurers = (List) aggregateApplicationBuilderAccessor .getPropertyValue("processorConfigurers"); for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) { if (processorConfigurer.getNamespace().equals("b")) { @@ -188,18 +187,18 @@ public class AggregationTest { public void testNamespacePrefixesFromCmdLineVsArgs() { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) - .namespace("a").args("--fooValue=bar") - .via(TestProcessor.class).namespace("b").args("--foo1=argbarb") - .via(TestProcessor.class).namespace("c") - .run("--a.fooValue=bara", "--c.foo1=barc"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); + aggregatedApplicationContext = aggregateApplicationBuilder + .parent(DummyConfig.class).web(false).from(TestSource.class) + .namespace("a").args("--fooValue=bar").via(TestProcessor.class) + .namespace("b").args("--foo1=argbarb").via(TestProcessor.class) + .namespace("c").run("--a.fooValue=bara", "--c.foo1=barc"); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); assertTrue(Arrays.equals( - ((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")) - .getArgs(), + ((SourceConfigurer) aggregateApplicationBuilderAccessor + .getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--fooValue=bara" })); - final List processorConfigurers = - (List) aggregateApplicationBuilderAccessor + final List processorConfigurers = (List) aggregateApplicationBuilderAccessor .getPropertyValue("processorConfigurers"); for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) { if (processorConfigurer.getNamespace().equals("b")) { @@ -219,18 +218,19 @@ public class AggregationTest { public void testNamespacePrefixesFromCmdLineWithRelaxedNames() { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) - .namespace("a").args("--foo-value=bar") - .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") - .via(TestProcessor.class).namespace("c") + aggregatedApplicationContext = aggregateApplicationBuilder + .parent(DummyConfig.class).web(false).from(TestSource.class) + .namespace("a").args("--foo-value=bar").via(TestProcessor.class) + .namespace("b").args("--fooValue=argbarb").via(TestProcessor.class) + .namespace("c") .run("--a.fooValue=bara", "--b.foo-value=barb", "--c.foo1=barc"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); assertTrue(Arrays.equals( - ((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")) - .getArgs(), + ((SourceConfigurer) aggregateApplicationBuilderAccessor + .getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--fooValue=bara" })); - final List processorConfigurers = - (List) aggregateApplicationBuilderAccessor + final List processorConfigurers = (List) aggregateApplicationBuilderAccessor .getPropertyValue("processorConfigurers"); for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) { if (processorConfigurer.getNamespace().equals("b")) { @@ -238,7 +238,8 @@ public class AggregationTest { new String[] { "--foo-value=barb" })); } if (processorConfigurer.getNamespace().equals("c")) { - assertThat(processorConfigurer.getArgs(), is(new String[] { "--foo1=barc" })); + assertThat(processorConfigurer.getArgs(), + is(new String[] { "--foo1=barc" })); } } aggregatedApplicationContext.close(); @@ -252,18 +253,18 @@ public class AggregationTest { System.setProperty("a.foo-value", "sysbara"); System.setProperty("c.fooValue", "sysbarc"); System.setProperty("server.port", "0"); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) - .namespace("a").args("--foo-value=bar") - .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") - .via(TestProcessor.class).namespace("c").args("--foo-value=argbarc") - .run("--a.fooValue=bara"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); + aggregatedApplicationContext = aggregateApplicationBuilder + .parent(DummyConfig.class).web(false).from(TestSource.class) + .namespace("a").args("--foo-value=bar").via(TestProcessor.class) + .namespace("b").args("--fooValue=argbarb").via(TestProcessor.class) + .namespace("c").args("--foo-value=argbarc").run("--a.fooValue=bara"); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); assertTrue(Arrays.equals( - ((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")) - .getArgs(), + ((SourceConfigurer) aggregateApplicationBuilderAccessor + .getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--fooValue=bara", "--foo-value=bara" })); - final List processorConfigurers = - (List) aggregateApplicationBuilderAccessor + final List processorConfigurers = (List) aggregateApplicationBuilderAccessor .getPropertyValue("processorConfigurers"); for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) { if (processorConfigurer.getNamespace().equals("b")) { @@ -286,20 +287,19 @@ public class AggregationTest { System.setProperty("a.foo-value", "sysbara"); System.setProperty("c.fooValue", "sysbarc"); System.setProperty("server.port", "0"); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) - .namespace("a").args("--foo-value=bar") - .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") - .via(TestProcessor.class).namespace("c").args("--foo-value=argbarc") - .run(); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); + aggregatedApplicationContext = aggregateApplicationBuilder + .parent(DummyConfig.class).web(false).from(TestSource.class) + .namespace("a").args("--foo-value=bar").via(TestProcessor.class) + .namespace("b").args("--fooValue=argbarb").via(TestProcessor.class) + .namespace("c").args("--foo-value=argbarc").run(); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); assertTrue(Arrays.equals( - ((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")) - .getArgs(), + ((SourceConfigurer) aggregateApplicationBuilderAccessor + .getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--foo-value=sysbara" })); - for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : - ((List) aggregateApplicationBuilderAccessor - .getPropertyValue( - "processorConfigurers"))) { + for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : ((List) aggregateApplicationBuilderAccessor + .getPropertyValue("processorConfigurers"))) { if (processorConfigurer.getNamespace().equals("b")) { assertTrue(Arrays.equals(processorConfigurer.getArgs(), new String[] { "--fooValue=argbarb" })); @@ -319,15 +319,16 @@ public class AggregationTest { MockBinderRegistryConfiguration.class); System.setProperty("a.fooValue", "sysbara"); System.setProperty("c.fooValue", "sysbarc"); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) - .namespace("a").args("--foo-value=bar") - .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") - .via(TestProcessor.class).namespace("c").args("--foo-value=argbarc") - .run("--a.fooValue=highest"); - DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder); - assertThat( - ((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")) - .getArgs()).containsExactly(new String[] { "--fooValue=highest" }); + aggregatedApplicationContext = aggregateApplicationBuilder + .parent(DummyConfig.class).web(false).from(TestSource.class) + .namespace("a").args("--foo-value=bar").via(TestProcessor.class) + .namespace("b").args("--fooValue=argbarb").via(TestProcessor.class) + .namespace("c").args("--foo-value=argbarc").run("--a.fooValue=highest"); + DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor( + aggregateApplicationBuilder); + assertThat(((SourceConfigurer) aggregateApplicationBuilderAccessor + .getPropertyValue("sourceConfigurer")).getArgs()) + .containsExactly(new String[] { "--fooValue=highest" }); final List processorConfigurers = (List) aggregateApplicationBuilderAccessor .getPropertyValue("processorConfigurers"); for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) { @@ -353,7 +354,8 @@ public class AggregationTest { .getBean(SharedBindingTargetRegistry.class); BindingTargetFactory channelFactory = aggregatedApplicationContext .getBean(SubscribableChannelBindingTargetFactory.class); - MessageChannel fooOutput = sharedChannelRegistry.get("foo.output", MessageChannel.class); + MessageChannel fooOutput = sharedChannelRegistry.get("foo.output", + MessageChannel.class); assertThat(fooOutput).isNotNull(); Object barInput = sharedChannelRegistry.get("bar.input", MessageChannel.class); assertThat(barInput).isNotNull(); @@ -365,9 +367,10 @@ public class AggregationTest { @Test public void testBindableProxyFactoryCaching() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( - MockBinderRegistryConfiguration.class, - TestSource2.class, TestProcessor.class); - Map factories = context.getBeansOfType(BindableProxyFactory.class); + MockBinderRegistryConfiguration.class, TestSource2.class, + TestProcessor.class); + Map factories = context + .getBeansOfType(BindableProxyFactory.class); assertThat(factories).hasSize(2); Map sources = context.getBeansOfType(Source.class); @@ -390,7 +393,8 @@ public class AggregationTest { } for (BindableProxyFactory factory : factories.values()) { - Field field = ReflectionUtils.findField(BindableProxyFactory.class, "targetCache"); + Field field = ReflectionUtils.findField(BindableProxyFactory.class, + "targetCache"); ReflectionUtils.makeAccessible(field); Map targetCache = (Map) ReflectionUtils.getField(field, factory); if (factory.getObjectType() == Source.class) { @@ -434,7 +438,6 @@ public class AggregationTest { } - @Configuration public static class DummyConfig {