Search in sources :

Example 1 with AbstractBinder

use of org.springframework.cloud.stream.binder.AbstractBinder in project spring-cloud-stream by spring-cloud.

the class RetryTemplateTests method testSpecificCustomRetryTemplate.

@SuppressWarnings("rawtypes")
@Test
public void testSpecificCustomRetryTemplate() throws Exception {
    ApplicationContext context = new SpringApplicationBuilder(SpecificCustomRetryTemplateConfiguration.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.processor-in-0.consumer.retry-template-name=retryTemplateTwo");
    RetryTemplate retryTemplateTwo = context.getBean("retryTemplateTwo", RetryTemplate.class);
    BindingServiceProperties bindingServiceProperties = context.getBean(BindingServiceProperties.class);
    ConsumerProperties consumerProperties = bindingServiceProperties.getConsumerProperties("processor-in-0");
    AbstractBinder binder = context.getBean(AbstractBinder.class);
    Method m = AbstractBinder.class.getDeclaredMethod("buildRetryTemplate", ConsumerProperties.class);
    m.setAccessible(true);
    RetryTemplate retryTemplate = (RetryTemplate) m.invoke(binder, consumerProperties);
    assertThat(retryTemplate).isEqualTo(retryTemplateTwo);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) StreamRetryTemplate(org.springframework.cloud.stream.annotation.StreamRetryTemplate) RetryTemplate(org.springframework.retry.support.RetryTemplate) AbstractBinder(org.springframework.cloud.stream.binder.AbstractBinder) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Method(java.lang.reflect.Method) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) Test(org.junit.Test)

Example 2 with AbstractBinder

use of org.springframework.cloud.stream.binder.AbstractBinder in project spring-cloud-stream by spring-cloud.

the class RetryTemplateTests method testSingleCustomRetryTemplate.

@SuppressWarnings("rawtypes")
@Test
public void testSingleCustomRetryTemplate() throws Exception {
    ApplicationContext context = new SpringApplicationBuilder(SingleCustomRetryTemplateConfiguration.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
    AbstractBinder binder = context.getBean(AbstractBinder.class);
    Field f = AbstractBinder.class.getDeclaredField("consumerBindingRetryTemplates");
    f.setAccessible(true);
    @SuppressWarnings("unchecked") Map<String, RetryTemplate> consumerBindingRetryTemplates = (Map<String, RetryTemplate>) f.get(binder);
    assertThat(consumerBindingRetryTemplates).hasSize(1);
}
Also used : Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) StreamRetryTemplate(org.springframework.cloud.stream.annotation.StreamRetryTemplate) RetryTemplate(org.springframework.retry.support.RetryTemplate) AbstractBinder(org.springframework.cloud.stream.binder.AbstractBinder) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)2 StreamRetryTemplate (org.springframework.cloud.stream.annotation.StreamRetryTemplate)2 AbstractBinder (org.springframework.cloud.stream.binder.AbstractBinder)2 ApplicationContext (org.springframework.context.ApplicationContext)2 RetryTemplate (org.springframework.retry.support.RetryTemplate)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)1