Search in sources :

Example 1 with ProvisioningProvider

use of org.springframework.cloud.stream.provisioning.ProvisioningProvider in project spring-cloud-stream by spring-cloud.

the class AbstractMessageChannelBinderTests method testEndpointLifecycle.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testEndpointLifecycle() throws Exception {
    AbstractMessageChannelBinder<ConsumerProperties, ProducerProperties, ProvisioningProvider<ConsumerProperties, ProducerProperties>> binder = context.getBean(AbstractMessageChannelBinder.class);
    ConsumerProperties consumerProperties = new ConsumerProperties();
    // to force error infrastructure creation
    consumerProperties.setMaxAttempts(1);
    Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo", "fooGroup", new DirectChannel(), consumerProperties);
    DirectFieldAccessor consumerBindingAccessor = new DirectFieldAccessor(consumerBinding);
    MessageProducer messageProducer = (MessageProducer) consumerBindingAccessor.getPropertyValue("lifecycle");
    assertTrue(((Lifecycle) messageProducer).isRunning());
    assertNotNull(messageProducer.getOutputChannel());
    SubscribableChannel errorChannel = (SubscribableChannel) consumerBindingAccessor.getPropertyValue("lifecycle.errorChannel");
    assertThat(errorChannel).isNotNull();
    Set<MessageHandler> handlers = TestUtils.getPropertyValue(errorChannel, "dispatcher.handlers", Set.class);
    assertThat(handlers.size()).isEqualTo(2);
    Iterator<MessageHandler> iterator = handlers.iterator();
    assertThat(iterator.next()).isInstanceOf(BridgeHandler.class);
    assertThat(iterator.next()).isInstanceOf(LastSubscriberMessageHandler.class);
    assertThat(context.containsBean("foo.fooGroup.errors")).isTrue();
    assertThat(context.containsBean("foo.fooGroup.errors.recoverer")).isTrue();
    assertThat(context.containsBean("foo.fooGroup.errors.handler")).isTrue();
    assertThat(context.containsBean("foo.fooGroup.errors.bridge")).isTrue();
    consumerBinding.unbind();
    assertThat(context.containsBean("foo.fooGroup.errors")).isFalse();
    assertThat(context.containsBean("foo.fooGroup.errors.recoverer")).isFalse();
    assertThat(context.containsBean("foo.fooGroup.errors.handler")).isFalse();
    assertThat(context.containsBean("foo.fooGroup.errors.bridge")).isFalse();
    assertFalse(((Lifecycle) messageProducer).isRunning());
    ProducerProperties producerProps = new ProducerProperties();
    producerProps.setErrorChannelEnabled(true);
    Binding<MessageChannel> producerBinding = binder.bindProducer("bar", new DirectChannel(), producerProps);
    assertThat(context.containsBean("bar.errors")).isTrue();
    assertThat(context.containsBean("bar.errors.bridge")).isTrue();
    producerBinding.unbind();
    assertThat(context.containsBean("bar.errors")).isFalse();
    assertThat(context.containsBean("bar.errors.bridge")).isFalse();
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageChannel(org.springframework.messaging.MessageChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ProvisioningProvider(org.springframework.cloud.stream.provisioning.ProvisioningProvider) MessageProducer(org.springframework.integration.core.MessageProducer) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 2 with ProvisioningProvider

use of org.springframework.cloud.stream.provisioning.ProvisioningProvider in project spring-cloud-stream by spring-cloud.

the class AbstractMessageChannelBinderTests method testEndpointBinderHasRecoverer.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testEndpointBinderHasRecoverer() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration()).web(WebApplicationType.NONE).run();
    AbstractMessageChannelBinder<ConsumerProperties, ProducerProperties, ProvisioningProvider<ConsumerProperties, ProducerProperties>> binder = context.getBean(AbstractMessageChannelBinder.class);
    Binding<MessageChannel> consumerBinding = binder.bindConsumer("foo", "fooGroup", new DirectChannel(), new ConsumerProperties());
    DirectFieldAccessor consumerBindingAccessor = new DirectFieldAccessor(consumerBinding);
    SubscribableChannel errorChannel = (SubscribableChannel) consumerBindingAccessor.getPropertyValue("lifecycle.errorChannel");
    assertThat(errorChannel).isNull();
    errorChannel = (SubscribableChannel) consumerBindingAccessor.getPropertyValue("lifecycle.recoveryCallback.channel");
    assertThat(errorChannel).isNotNull();
    Set<MessageHandler> handlers = TestUtils.getPropertyValue(errorChannel, "dispatcher.handlers", Set.class);
    assertThat(handlers.size()).isEqualTo(2);
    Iterator<MessageHandler> iterator = handlers.iterator();
    assertThat(iterator.next()).isInstanceOf(BridgeHandler.class);
    assertThat(iterator.next()).isInstanceOf(LastSubscriberMessageHandler.class);
    assertThat(context.containsBean("foo.fooGroup.errors")).isTrue();
    assertThat(context.containsBean("foo.fooGroup.errors.recoverer")).isTrue();
    assertThat(context.containsBean("foo.fooGroup.errors.handler")).isTrue();
    assertThat(context.containsBean("foo.fooGroup.errors.bridge")).isTrue();
    consumerBinding.unbind();
    assertThat(context.containsBean("foo.fooGroup.errors")).isFalse();
    assertThat(context.containsBean("foo.fooGroup.errors.recoverer")).isFalse();
    assertThat(context.containsBean("foo.fooGroup.errors.handler")).isFalse();
    assertThat(context.containsBean("foo.fooGroup.errors.bridge")).isFalse();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageHandler(org.springframework.messaging.MessageHandler) DirectChannel(org.springframework.integration.channel.DirectChannel) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) MessageChannel(org.springframework.messaging.MessageChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ProvisioningProvider(org.springframework.cloud.stream.provisioning.ProvisioningProvider) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ProvisioningProvider (org.springframework.cloud.stream.provisioning.ProvisioningProvider)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 MessageChannel (org.springframework.messaging.MessageChannel)2 MessageHandler (org.springframework.messaging.MessageHandler)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 MessageProducer (org.springframework.integration.core.MessageProducer)1