Search in sources :

Example 1 with BindableProxyFactory

use of org.springframework.cloud.stream.binding.BindableProxyFactory in project spring-cloud-stream by spring-cloud.

the class AggregationTest method testBindableProxyFactoryCaching.

@Test
public void testBindableProxyFactoryCaching() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MockBinderRegistryConfiguration.class, TestSource2.class, TestProcessor.class);
    Map<String, BindableProxyFactory> factories = context.getBeansOfType(BindableProxyFactory.class);
    assertThat(factories).hasSize(2);
    Map<String, Source> sources = context.getBeansOfType(Source.class);
    assertThat(sources).hasSize(1);
    for (Source source : sources.values()) {
        source.output();
    }
    Map<String, FooSource> fooSources = context.getBeansOfType(FooSource.class);
    assertThat(fooSources).hasSize(1);
    for (FooSource source : fooSources.values()) {
        source.output();
    }
    Map<String, Processor> 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);
        }
        if (factory.getObjectType() == FooSource.class) {
            assertThat(targetCache).hasSize(1);
        } else if (factory.getObjectType() == Processor.class) {
            assertThat(targetCache).hasSize(2);
        } else {
            Assert.fail("Found unexpected type");
        }
    }
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Processor(org.springframework.cloud.stream.messaging.Processor) Source(org.springframework.cloud.stream.messaging.Source) Field(java.lang.reflect.Field) BindableProxyFactory(org.springframework.cloud.stream.binding.BindableProxyFactory) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 Map (java.util.Map)1 Test (org.junit.Test)1 BindableProxyFactory (org.springframework.cloud.stream.binding.BindableProxyFactory)1 Processor (org.springframework.cloud.stream.messaging.Processor)1 Source (org.springframework.cloud.stream.messaging.Source)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1