diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindableProxyFactory.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindableProxyFactory.java index 0ba5a7315..acf6167db 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindableProxyFactory.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindableProxyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-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. @@ -74,6 +74,8 @@ public class BindableProxyFactory implements MethodInterceptor, FactoryBean outputHolders = new HashMap<>(); + private final Map targetCache = new HashMap<>(2); + public BindableProxyFactory(Class type) { this.type = type; } @@ -81,16 +83,27 @@ public class BindableProxyFactory implements MethodInterceptor, FactoryBean factories = context.getBeansOfType(BindableProxyFactory.class); + assertThat(factories).hasSize(2); + + Map sources = context.getBeansOfType(Source.class); + assertThat(sources).hasSize(2); + for (Source source : sources.values()) { + source.output(); + } + + Map processors = context.getBeansOfType(Processor.class); + assertThat(processors).hasSize(1); + for (Processor processor : processors.values()) { + processor.input(); + processor.output(); + } + + for (BindableProxyFactory factory : factories.values()) { + Field field = ReflectionUtils.findField(BindableProxyFactory.class, "targetCache"); + ReflectionUtils.makeAccessible(field); + Map targetCache = (Map) ReflectionUtils.getField(field, factory); + if (factory.getObjectType() == Source.class) { + assertThat(targetCache).hasSize(1); + } else if (factory.getObjectType() == Processor.class) { + assertThat(targetCache).hasSize(2); + } else { + Assert.fail("Found unexpected type"); + } + } + context.close(); + } + @EnableBinding(Source.class) @EnableAutoConfiguration public static class TestSource {