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();
}
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();
}
Aggregations